|
@@ -6,7 +6,6 @@ import java.awt.Component;
|
|
import java.awt.Cursor;
|
|
import java.awt.Cursor;
|
|
import java.awt.Dimension;
|
|
import java.awt.Dimension;
|
|
import java.awt.Image;
|
|
import java.awt.Image;
|
|
-import java.awt.MouseInfo;
|
|
|
|
import java.awt.Point;
|
|
import java.awt.Point;
|
|
import java.awt.Toolkit;
|
|
import java.awt.Toolkit;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionEvent;
|
|
@@ -14,7 +13,6 @@ import java.awt.event.ActionListener;
|
|
import java.awt.event.KeyEvent;
|
|
import java.awt.event.KeyEvent;
|
|
import java.awt.event.MouseAdapter;
|
|
import java.awt.event.MouseAdapter;
|
|
import java.awt.event.MouseEvent;
|
|
import java.awt.event.MouseEvent;
|
|
-import java.awt.event.MouseListener;
|
|
|
|
import java.beans.PropertyChangeEvent;
|
|
import java.beans.PropertyChangeEvent;
|
|
import java.beans.PropertyChangeListener;
|
|
import java.beans.PropertyChangeListener;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
@@ -57,14 +55,13 @@ import javax.swing.border.LineBorder;
|
|
import javax.swing.event.ChangeEvent;
|
|
import javax.swing.event.ChangeEvent;
|
|
import javax.swing.event.ChangeListener;
|
|
import javax.swing.event.ChangeListener;
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
-import javax.swing.plaf.FileChooserUI;
|
|
|
|
import javax.swing.table.DefaultTableModel;
|
|
import javax.swing.table.DefaultTableModel;
|
|
|
|
+import javax.swing.table.TableCellEditor;
|
|
|
|
+import javax.swing.table.TableCellRenderer;
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
import javax.swing.tree.TreeCellRenderer;
|
|
import javax.swing.tree.TreeCellRenderer;
|
|
|
|
|
|
-import com.sun.corba.se.spi.orbutil.fsm.Action;
|
|
|
|
-
|
|
|
|
import Interfaces.CategoryListener;
|
|
import Interfaces.CategoryListener;
|
|
import classes.Category;
|
|
import classes.Category;
|
|
import classes.CpsEdge;
|
|
import classes.CpsEdge;
|
|
@@ -73,18 +70,15 @@ import classes.HolonElement;
|
|
import classes.HolonObject;
|
|
import classes.HolonObject;
|
|
import classes.HolonSwitch;
|
|
import classes.HolonSwitch;
|
|
import classes.HolonTransformer;
|
|
import classes.HolonTransformer;
|
|
-import classes.Position;
|
|
|
|
import ui.controller.Control;
|
|
import ui.controller.Control;
|
|
-import ui.model.Model;
|
|
|
|
-import javax.swing.JList;
|
|
|
|
-import javax.swing.Box;;
|
|
|
|
|
|
+import ui.model.Model;;
|
|
|
|
|
|
public class GUI<E> implements CategoryListener {
|
|
public class GUI<E> implements CategoryListener {
|
|
|
|
|
|
private JFrame frmCyberPhysical;
|
|
private JFrame frmCyberPhysical;
|
|
|
|
|
|
private final SimulationMenu simMenu;
|
|
private final SimulationMenu simMenu;
|
|
-
|
|
|
|
|
|
+
|
|
private final JMenuBar menuBar = new JMenuBar();
|
|
private final JMenuBar menuBar = new JMenuBar();
|
|
private final JMenu mnNewMenu = new JMenu("File");
|
|
private final JMenu mnNewMenu = new JMenu("File");
|
|
private final JMenu mnNewMenu_1 = new JMenu("Edit");
|
|
private final JMenu mnNewMenu_1 = new JMenu("Edit");
|
|
@@ -140,7 +134,25 @@ public class GUI<E> implements CategoryListener {
|
|
// HolonObject, such as connections, name, Type, etc.
|
|
// HolonObject, such as connections, name, Type, etc.
|
|
// Table for Properties --> Cell with (0,1) is editable by CpsObjt and
|
|
// Table for Properties --> Cell with (0,1) is editable by CpsObjt and
|
|
// Cell(3,1) is editable by Edges
|
|
// Cell(3,1) is editable by Edges
|
|
- private JTable tableProperties = new JTable();
|
|
|
|
|
|
+ private JTable tableProperties = new JTable() {
|
|
|
|
+ @Override
|
|
|
|
+ public TableCellRenderer getCellRenderer(int row, int column) {
|
|
|
|
+ if (getValueAt(row, column) instanceof Boolean) {
|
|
|
|
+ return super.getDefaultRenderer(Boolean.class);
|
|
|
|
+ } else {
|
|
|
|
+ return super.getCellRenderer(row, column);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public TableCellEditor getCellEditor(int row, int column) {
|
|
|
|
+ if (getValueAt(row, column) instanceof Boolean) {
|
|
|
|
+ return super.getDefaultEditor(Boolean.class);
|
|
|
|
+ } else {
|
|
|
|
+ return super.getCellEditor(row, column);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
private JPanel graphLabel = new JPanel();
|
|
private JPanel graphLabel = new JPanel();
|
|
private DefaulTable tableModelProperties;
|
|
private DefaulTable tableModelProperties;
|
|
private final JScrollPane scrollProperties = new JScrollPane();
|
|
private final JScrollPane scrollProperties = new JScrollPane();
|
|
@@ -232,7 +244,7 @@ public class GUI<E> implements CategoryListener {
|
|
* Initialize the contents of the frame.
|
|
* Initialize the contents of the frame.
|
|
*/
|
|
*/
|
|
@SuppressWarnings({ "serial", "unchecked" })
|
|
@SuppressWarnings({ "serial", "unchecked" })
|
|
- private void initialize() {
|
|
|
|
|
|
+ private void initialize() {
|
|
simulationSpeedField.setColumns(10);
|
|
simulationSpeedField.setColumns(10);
|
|
frmCyberPhysical = new JFrame();
|
|
frmCyberPhysical = new JFrame();
|
|
frmCyberPhysical.setTitle("Cyber Physical Systems Model");
|
|
frmCyberPhysical.setTitle("Cyber Physical Systems Model");
|
|
@@ -340,13 +352,13 @@ public class GUI<E> implements CategoryListener {
|
|
@Override
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
public void actionPerformed(ActionEvent e) {
|
|
model.getSelectedCpsObjects().clear();
|
|
model.getSelectedCpsObjects().clear();
|
|
- for (CpsObject cps: model.getObjectsOnCanvas()) {
|
|
|
|
|
|
+ for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
controller.addSelectedObject(cps);
|
|
controller.addSelectedObject(cps);
|
|
}
|
|
}
|
|
canvas.repaint();
|
|
canvas.repaint();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
String delDown = "delete";
|
|
String delDown = "delete";
|
|
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false), delDown);
|
|
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false), delDown);
|
|
actionMap.put(delDown, new AbstractAction() {
|
|
actionMap.put(delDown, new AbstractAction() {
|
|
@@ -536,7 +548,6 @@ public class GUI<E> implements CategoryListener {
|
|
|
|
|
|
canvas.setBackground(Color.WHITE);
|
|
canvas.setBackground(Color.WHITE);
|
|
canvas.setPreferredSize(new Dimension(1000, 1000));
|
|
canvas.setPreferredSize(new Dimension(1000, 1000));
|
|
-
|
|
|
|
|
|
|
|
/********************
|
|
/********************
|
|
* RIGHT CONTAINER (INFORMATION)
|
|
* RIGHT CONTAINER (INFORMATION)
|
|
@@ -794,18 +805,26 @@ public class GUI<E> implements CategoryListener {
|
|
* Update any change in the Property table
|
|
* Update any change in the Property table
|
|
*/
|
|
*/
|
|
tableProperties.addPropertyChangeListener(new PropertyChangeListener() {
|
|
tableProperties.addPropertyChangeListener(new PropertyChangeListener() {
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public void propertyChange(PropertyChangeEvent evt) {
|
|
public void propertyChange(PropertyChangeEvent evt) {
|
|
try {
|
|
try {
|
|
Object temp;
|
|
Object temp;
|
|
|
|
+ Point mousePos = tableProperties.getMousePosition();
|
|
if (getActualCps() != null) {
|
|
if (getActualCps() != null) {
|
|
|
|
+ temp = tableModelProperties.getValueAt(mousePos.y / tableProperties.getRowHeight(),
|
|
|
|
+ mousePos.x / (tableProperties.getWidth() / 2));
|
|
if (getActualCps() instanceof HolonObject) {
|
|
if (getActualCps() instanceof HolonObject) {
|
|
- temp = tableModelProperties.getValueAt(0, 1);
|
|
|
|
getActualCps().setName(temp.toString());
|
|
getActualCps().setName(temp.toString());
|
|
|
|
+ } else if (getActualCps() instanceof HolonSwitch) {
|
|
|
|
+ if (mousePos.y / tableProperties.getRowHeight() == 2) {
|
|
|
|
+ Boolean bTemp = Boolean.parseBoolean(temp.toString());
|
|
|
|
+ ((HolonSwitch) getActualCps()).setManualMode(bTemp);
|
|
|
|
+ } else if (mousePos.y / tableProperties.getRowHeight() == 3) {
|
|
|
|
+ Boolean bTemp = Boolean.parseBoolean(temp.toString());
|
|
|
|
+ ((HolonSwitch) getActualCps()).setActiveAt(bTemp);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- Point mousePos = tableProperties.getMousePosition();
|
|
|
|
temp = tableModelProperties.getValueAt(mousePos.y / tableProperties.getRowHeight(),
|
|
temp = tableModelProperties.getValueAt(mousePos.y / tableProperties.getRowHeight(),
|
|
mousePos.x / (tableProperties.getWidth() / 2));
|
|
mousePos.x / (tableProperties.getWidth() / 2));
|
|
if (mousePos.y / tableProperties.getRowHeight() == 2) {
|
|
if (mousePos.y / tableProperties.getRowHeight() == 2) {
|
|
@@ -826,6 +845,7 @@ public class GUI<E> implements CategoryListener {
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
});
|
|
});
|
|
|
|
|
|
/***********************
|
|
/***********************
|
|
@@ -1099,23 +1119,28 @@ public class GUI<E> implements CategoryListener {
|
|
refreshTableHolonElement();
|
|
refreshTableHolonElement();
|
|
Object[] tempEnergy = { "Total Energy", ((HolonObject) temp).getCurrentEnergy() };
|
|
Object[] tempEnergy = { "Total Energy", ((HolonObject) temp).getCurrentEnergy() };
|
|
tableModelProperties.addRow(tempEnergy);
|
|
tableModelProperties.addRow(tempEnergy);
|
|
|
|
+ tableModelProperties.setCellEditable(0, 1, true);
|
|
|
|
+ tableModelProperties.setCellEditable(2, 1, false);
|
|
|
|
+ tableModelProperties.setCellEditable(3, 1, false);
|
|
} // For HolonSwitches is showed the actual status (active
|
|
} // For HolonSwitches is showed the actual status (active
|
|
// or inactive)
|
|
// or inactive)
|
|
else if (temp instanceof HolonSwitch) {
|
|
else if (temp instanceof HolonSwitch) {
|
|
deleteRows(tableModelHolonElementSingle);
|
|
deleteRows(tableModelHolonElementSingle);
|
|
deleteRows(tableModelHolonElementMulti);
|
|
deleteRows(tableModelHolonElementMulti);
|
|
|
|
+ Object[] tempMode = { "Mode", ((HolonSwitch) temp).getManualMode() };
|
|
|
|
+ tableModelProperties.addRow(tempMode);
|
|
Object[] tempActive = { "Active", ((HolonSwitch) temp).getActiveAt()[model.getCurIteration()] };
|
|
Object[] tempActive = { "Active", ((HolonSwitch) temp).getActiveAt()[model.getCurIteration()] };
|
|
tableModelProperties.addRow(tempActive);
|
|
tableModelProperties.addRow(tempActive);
|
|
unitGraph.repaintWithNewSwitch((HolonSwitch) temp);
|
|
unitGraph.repaintWithNewSwitch((HolonSwitch) temp);
|
|
elementGraph.setText(temp.getName());
|
|
elementGraph.setText(temp.getName());
|
|
|
|
+ tableModelProperties.setCellEditable(0, 1, true);
|
|
|
|
+ tableModelProperties.setCellEditable(2, 1, true);
|
|
|
|
+ tableModelProperties.setCellEditable(3, 1, true);
|
|
} else {
|
|
} else {
|
|
deleteRows(tableModelHolonElementSingle);
|
|
deleteRows(tableModelHolonElementSingle);
|
|
deleteRows(tableModelHolonElementMulti);
|
|
deleteRows(tableModelHolonElementMulti);
|
|
}
|
|
}
|
|
// For Objects the only editable cell is the name
|
|
// For Objects the only editable cell is the name
|
|
- tableModelProperties.setCellEditable(0, 1, true);
|
|
|
|
- tableModelProperties.setCellEditable(2, 1, false);
|
|
|
|
- tableModelProperties.setCellEditable(3, 1, false);
|
|
|
|
ArrayList<CpsEdge> temp_array = temp.getConnections();
|
|
ArrayList<CpsEdge> temp_array = temp.getConnections();
|
|
// If the clicked object has connections
|
|
// If the clicked object has connections
|
|
if (!temp_array.isEmpty()) {
|
|
if (!temp_array.isEmpty()) {
|
|
@@ -1440,16 +1465,17 @@ public class GUI<E> implements CategoryListener {
|
|
splitPane_tree_console.setRightComponent(console);
|
|
splitPane_tree_console.setRightComponent(console);
|
|
splitPane_1.setLeftComponent(canvasSP);
|
|
splitPane_1.setLeftComponent(canvasSP);
|
|
splitPane_1.setRightComponent(split_HolonEl_Pro);
|
|
splitPane_1.setRightComponent(split_HolonEl_Pro);
|
|
-
|
|
|
|
|
|
+
|
|
split_HolonEl_Pro.setDividerLocation(400);
|
|
split_HolonEl_Pro.setDividerLocation(400);
|
|
split_HolonEl_Pro.setTopComponent(split_Graph_HolonEl);
|
|
split_HolonEl_Pro.setTopComponent(split_Graph_HolonEl);
|
|
split_HolonEl_Pro.setBottomComponent(scrollProperties);
|
|
split_HolonEl_Pro.setBottomComponent(scrollProperties);
|
|
split_Graph_HolonEl.setDividerLocation(150);
|
|
split_Graph_HolonEl.setDividerLocation(150);
|
|
split_Graph_HolonEl.setTopComponent(scrollGraph);
|
|
split_Graph_HolonEl.setTopComponent(scrollGraph);
|
|
- split_Graph_HolonEl.setBottomComponent(scrollElements);
|
|
|
|
|
|
+ split_Graph_HolonEl.setBottomComponent(scrollElements);
|
|
canvasSP.setViewportView(canvas);
|
|
canvasSP.setViewportView(canvas);
|
|
canvasSP.setColumnHeaderView(simMenu);
|
|
canvasSP.setColumnHeaderView(simMenu);
|
|
- simMenu.setBackground(new Color(240, 240, 240));
|
|
|
|
|
|
+ simMenu.setBackground(new Color(240, 240, 240));
|
|
|
|
+
|
|
tabbedPane.setBorder(null);
|
|
tabbedPane.setBorder(null);
|
|
scrollProperties.setBorder(null);
|
|
scrollProperties.setBorder(null);
|
|
scrollGraph.setBorder(null);
|
|
scrollGraph.setBorder(null);
|