|
@@ -6,6 +6,7 @@ import java.awt.Component;
|
|
|
import java.awt.Cursor;
|
|
|
import java.awt.Dimension;
|
|
|
import java.awt.Image;
|
|
|
+import java.awt.MouseInfo;
|
|
|
import java.awt.Point;
|
|
|
import java.awt.Toolkit;
|
|
|
import java.awt.event.ActionEvent;
|
|
@@ -13,6 +14,7 @@ import java.awt.event.ActionListener;
|
|
|
import java.awt.event.KeyEvent;
|
|
|
import java.awt.event.MouseAdapter;
|
|
|
import java.awt.event.MouseEvent;
|
|
|
+import java.awt.event.MouseListener;
|
|
|
import java.beans.PropertyChangeEvent;
|
|
|
import java.beans.PropertyChangeListener;
|
|
|
import java.io.File;
|
|
@@ -55,11 +57,14 @@ import javax.swing.border.LineBorder;
|
|
|
import javax.swing.event.ChangeEvent;
|
|
|
import javax.swing.event.ChangeListener;
|
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
|
+import javax.swing.plaf.FileChooserUI;
|
|
|
import javax.swing.table.DefaultTableModel;
|
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
|
import javax.swing.tree.TreeCellRenderer;
|
|
|
|
|
|
+import com.sun.corba.se.spi.orbutil.fsm.Action;
|
|
|
+
|
|
|
import Interfaces.CategoryListener;
|
|
|
import classes.Category;
|
|
|
import classes.CpsEdge;
|
|
@@ -68,8 +73,11 @@ import classes.HolonElement;
|
|
|
import classes.HolonObject;
|
|
|
import classes.HolonSwitch;
|
|
|
import classes.HolonTransformer;
|
|
|
+import classes.Position;
|
|
|
import ui.controller.Control;
|
|
|
-import ui.model.Model;;
|
|
|
+import ui.model.Model;
|
|
|
+import javax.swing.JList;
|
|
|
+import javax.swing.Box;;
|
|
|
|
|
|
public class GUI<E> implements CategoryListener {
|
|
|
|
|
@@ -90,7 +98,7 @@ public class GUI<E> implements CategoryListener {
|
|
|
private final JSplitPane splitPane_1 = new JSplitPane();
|
|
|
private final JScrollPane scrollPane_1 = new JScrollPane();
|
|
|
private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
|
|
- private final JScrollPane scrollPane_2 = new JScrollPane();
|
|
|
+ private final JScrollPane SimulationPane = new JScrollPane();
|
|
|
private JPopupMenu popmenuEdit = new JPopupMenu();
|
|
|
private JMenuItem editItem = new JMenuItem("Edit Object");
|
|
|
private String catOfObjToBeEdited;
|
|
@@ -102,7 +110,6 @@ public class GUI<E> implements CategoryListener {
|
|
|
private final ArrayList<HolonElement> selectedElements = new ArrayList<HolonElement>();
|
|
|
private String holonEleNamesDisplayed = "None ";
|
|
|
HashMap<Integer, ArrayList<HolonElement>> eleToDelete = new HashMap<Integer, ArrayList<HolonElement>>();
|
|
|
-
|
|
|
private final JTree tree = new JTree();
|
|
|
private final JEditorPane dtrpnHereWillBe = new JEditorPane();
|
|
|
/******************************************
|
|
@@ -117,7 +124,9 @@ public class GUI<E> implements CategoryListener {
|
|
|
// In this section are all the Holonelements that correspond to the clicked
|
|
|
// HolonObject with consumption/production, name and amount.
|
|
|
|
|
|
+ // Table for HolonElements --> all cells are editable
|
|
|
private JTable tableHolonElement = new JTable();
|
|
|
+ // Model for single or multi selection
|
|
|
private PropertyTable tableModelHolonElementMulti = new PropertyTable();
|
|
|
private PropertyTable tableModelHolonElementSingle = new PropertyTable();
|
|
|
private final JPanel scrollElements = new JPanel();
|
|
@@ -125,7 +134,8 @@ public class GUI<E> implements CategoryListener {
|
|
|
|
|
|
// In this section are all the properties that correspond to the clicked
|
|
|
// HolonObject, such as connections, name, Type, etc.
|
|
|
-
|
|
|
+ // Table for Properties --> Cell with (0,1) is editable by CpsObjt and
|
|
|
+ // Cell(3,1) is editable by Edges
|
|
|
private JTable tableProperties = new JTable();
|
|
|
private JPanel graphLabel = new JPanel();
|
|
|
private DefaulTable tableModelProperties;
|
|
@@ -133,7 +143,6 @@ public class GUI<E> implements CategoryListener {
|
|
|
|
|
|
// In this section is the graph for the selected HolonElement of the clicked
|
|
|
// HolonObject
|
|
|
-
|
|
|
private JTable tableGraph = new JTable();
|
|
|
private DefaultTableModel tableModelGraph = new DefaultTableModel();
|
|
|
private final JScrollPane scrollGraph = new JScrollPane();
|
|
@@ -167,7 +176,6 @@ public class GUI<E> implements CategoryListener {
|
|
|
private String actualObjectClicked;
|
|
|
private Image img = null;
|
|
|
private CpsObject tempCps = null;
|
|
|
- private HolonElement tempElement = null;
|
|
|
private int yValueElements = 0;
|
|
|
|
|
|
private MyCanvas canvas;
|
|
@@ -179,11 +187,11 @@ public class GUI<E> implements CategoryListener {
|
|
|
private TimePanel timePanel;
|
|
|
private final JMenu mnAlgorithm = new JMenu("Algorithm");
|
|
|
private final JCheckBoxMenuItem chckbxmntmUseAlgorithm = new JCheckBoxMenuItem("Use Algorithm");
|
|
|
- private final JSplitPane splitPane_2 = new JSplitPane();
|
|
|
- private final JLabel lblSelect = new JLabel("Select");
|
|
|
private final JComboBox comboBoxAlgo = new JComboBox();
|
|
|
+ // Coord for all Cells with text
|
|
|
private int yTHIS;
|
|
|
private int xTHIS;
|
|
|
+ // Coord for all Cells with boolean values (checkbox)
|
|
|
private int yBTHIS;
|
|
|
private int xBTHIS;
|
|
|
private CpsObject temp = null;
|
|
@@ -194,6 +202,10 @@ public class GUI<E> implements CategoryListener {
|
|
|
private final JMenuItem mntmFindReplace = new JMenuItem("Find/ Replace");
|
|
|
private final JMenuItem mntmEditShowedInformation = new JMenuItem("Edit showed Information");
|
|
|
private final JMenuItem mntmResetCategory = new JMenuItem("Reset Categories");
|
|
|
+ private final JMenuItem mntmSetFolder = new JMenuItem("Set Folder");
|
|
|
+ private final JMenu mnSimulationSpeed = new JMenu("Simulation Speed");
|
|
|
+ private final JTextField simulationSpeedField = new JTextField();
|
|
|
+ private final JButton btnApply = new JButton("Apply");
|
|
|
|
|
|
/**
|
|
|
* Create the application.
|
|
@@ -214,6 +226,7 @@ public class GUI<E> implements CategoryListener {
|
|
|
*/
|
|
|
@SuppressWarnings({ "serial", "unchecked" })
|
|
|
private void initialize() {
|
|
|
+ simulationSpeedField.setColumns(10);
|
|
|
frmCyberPhysical = new JFrame();
|
|
|
frmCyberPhysical.setTitle("Cyber Physical Systems Model");
|
|
|
frmCyberPhysical.setBounds(100, 100, 1000, 800);
|
|
@@ -321,17 +334,15 @@ public class GUI<E> implements CategoryListener {
|
|
|
controller.delCanvasObject(cps);
|
|
|
}
|
|
|
model.getSelectedCpsObjects().clear();
|
|
|
- /* controller.setSelectedObjectID(0);
|
|
|
- for (int i = tableModelHolonElementMulti.getRowCount() - 1; i > -1; i--) {
|
|
|
- tableModelHolonElementMulti.removeRow(i);
|
|
|
- }
|
|
|
- for (int i = tableModelHolonElementSingle.getRowCount() - 1; i > -1; i--) {
|
|
|
- tableModelHolonElementSingle.removeRow(i);
|
|
|
- }
|
|
|
- for (int i = tableModelProperties.getRowCount() - 1; i > -1; i--) {
|
|
|
- tableModelProperties.removeRow(i);
|
|
|
- }
|
|
|
- */
|
|
|
+ /*
|
|
|
+ * controller.setSelectedObjectID(0); for (int i =
|
|
|
+ * tableModelHolonElementMulti.getRowCount() - 1; i > -1; i--) {
|
|
|
+ * tableModelHolonElementMulti.removeRow(i); } for (int i =
|
|
|
+ * tableModelHolonElementSingle.getRowCount() - 1; i > -1; i--)
|
|
|
+ * { tableModelHolonElementSingle.removeRow(i); } for (int i =
|
|
|
+ * tableModelProperties.getRowCount() - 1; i > -1; i--) {
|
|
|
+ * tableModelProperties.removeRow(i); }
|
|
|
+ */
|
|
|
canvas.repaint();
|
|
|
unitGraph.empty();
|
|
|
}
|
|
@@ -440,6 +451,10 @@ public class GUI<E> implements CategoryListener {
|
|
|
mnNewMenu_2.add(mntmEditEdges);
|
|
|
|
|
|
mnNewMenu_2.add(mntmResetCategory);
|
|
|
+
|
|
|
+ mnNewMenu_2.add(mnSimulationSpeed);
|
|
|
+
|
|
|
+ mnSimulationSpeed.add(simulationSpeedField);
|
|
|
mntmResetCategory.addActionListener(new ActionListener() {
|
|
|
|
|
|
@Override
|
|
@@ -495,13 +510,9 @@ public class GUI<E> implements CategoryListener {
|
|
|
|
|
|
menuBar.add(mnAlgorithm);
|
|
|
|
|
|
- mnAlgorithm.add(chckbxmntmUseAlgorithm);
|
|
|
-
|
|
|
- mnAlgorithm.add(splitPane_2);
|
|
|
+ mnAlgorithm.add(mntmSetFolder);
|
|
|
|
|
|
- splitPane_2.setLeftComponent(lblSelect);
|
|
|
-
|
|
|
- splitPane_2.setRightComponent(comboBoxAlgo);
|
|
|
+ mnAlgorithm.add(chckbxmntmUseAlgorithm);
|
|
|
|
|
|
canvas.setBackground(Color.WHITE);
|
|
|
canvas.setPreferredSize(new Dimension(1000, 1000));
|
|
@@ -514,21 +525,22 @@ public class GUI<E> implements CategoryListener {
|
|
|
tabbedPane.addTab("Simulation",
|
|
|
new ImageIcon(new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
|
|
|
.getScaledInstance(30, 30, Image.SCALE_SMOOTH)),
|
|
|
- scrollPane_2, "Simulate the CPS");
|
|
|
+ SimulationPane, "Simulate the CPS");
|
|
|
dtrpnHereWillBe.setText("Here will be the Simulation");
|
|
|
|
|
|
- scrollPane_2.setViewportView(dtrpnHereWillBe);
|
|
|
+ SimulationPane.setViewportView(dtrpnHereWillBe);
|
|
|
|
|
|
/********************
|
|
|
* RIGHT CONTAINER (INFORMATION)
|
|
|
**********************/
|
|
|
// Set up of the HolonElements section
|
|
|
- Object[] columnNamesMulti = { "Object", "Device", "Energy", "Quantity", "Activated" };
|
|
|
+ // Two different Models: Multi for multi-selection mode and Single for
|
|
|
+ // single-selection mode (CPS-Object)
|
|
|
+ Object[] columnNamesMulti = { "Object", "Nr.", "Device", "Energy", "Quantity", "Activated" };
|
|
|
tableModelHolonElementMulti.setColumnIdentifiers(columnNamesMulti);
|
|
|
- Object[] columnNamesSingle = { "Device", "Energy", "Quantity", "Activated" };
|
|
|
+ Object[] columnNamesSingle = { "Nr.", "Device", "Energy", "Quantity", "Activated" };
|
|
|
tableModelHolonElementSingle.setColumnIdentifiers(columnNamesSingle);
|
|
|
tableHolonElement.setBorder(null);
|
|
|
-
|
|
|
tableHolonElement.setFillsViewportHeight(true);
|
|
|
tableHolonElement.setCellSelectionEnabled(true);
|
|
|
tableHolonElement.setColumnSelectionAllowed(true);
|
|
@@ -544,7 +556,7 @@ public class GUI<E> implements CategoryListener {
|
|
|
|
|
|
// Set up of the Properties section
|
|
|
Object[] colNames = { "Field", "Information" };
|
|
|
- tableModelProperties = new DefaulTable(100, colNames.length);
|
|
|
+ tableModelProperties = new DefaulTable(1000, colNames.length);
|
|
|
tableModelProperties.setColumnIdentifiers(colNames);
|
|
|
tableProperties.setModel(tableModelProperties);
|
|
|
tableProperties.setFillsViewportHeight(true);
|
|
@@ -553,8 +565,6 @@ public class GUI<E> implements CategoryListener {
|
|
|
scrollProperties.setViewportView(tableProperties);
|
|
|
|
|
|
// Set up of the Graph section
|
|
|
- Object[] tempText = { "Here comes the graph for each clicked HolonElement" };
|
|
|
- tableModelGraph.setColumnIdentifiers(tempText);
|
|
|
tableGraph.setModel(tableModelGraph);
|
|
|
tableGraph.setFillsViewportHeight(true);
|
|
|
tableGraph.setCellSelectionEnabled(true);
|
|
@@ -596,25 +606,29 @@ public class GUI<E> implements CategoryListener {
|
|
|
}
|
|
|
});
|
|
|
/*
|
|
|
- * Delete the choosen HolonElement of the selected HolonObject
|
|
|
+ * Delete the chosen HolonElement of the selected HolonObject,
|
|
|
+ * Multi-Selection for CpsObjects as well as for HolonElements possible
|
|
|
*/
|
|
|
btnDelHolEL.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent arg0) {
|
|
|
+ // For Single Selection of CpsObject
|
|
|
if (model.getSelectedCpsObjects().size() == 1) {
|
|
|
if (getActualCps().getClass() == HolonObject.class) {
|
|
|
HolonObject obj = (HolonObject) getActualCps();
|
|
|
for (HolonElement e : selectedElements) {
|
|
|
- controller.deleteElementCanvas(obj.getID(), e.getEleName());
|
|
|
+ controller.deleteElementCanvas(obj.getID(), e.getId());
|
|
|
refreshTableHolonElement();
|
|
|
refreshTableProperties();
|
|
|
controller.calculateStateForTimeStep(model.getCurIteration());
|
|
|
// Names displayed in graph are not updated
|
|
|
}
|
|
|
+ selectedElements.clear();
|
|
|
}
|
|
|
+ // For MultiSelection of CpsObject
|
|
|
} else if (model.getSelectedCpsObjects().size() > 1) {
|
|
|
for (Integer i : eleToDelete.keySet()) {
|
|
|
for (HolonElement e : eleToDelete.get(i)) {
|
|
|
- controller.deleteElementCanvas(i, e.getEleName());
|
|
|
+ controller.deleteElementCanvas(i, e.getId());
|
|
|
}
|
|
|
}
|
|
|
refreshTableHolonElement();
|
|
@@ -623,18 +637,22 @@ public class GUI<E> implements CategoryListener {
|
|
|
}
|
|
|
});
|
|
|
/*
|
|
|
- * Communication between HolonElement Table and displayed Graph
|
|
|
+ * Communication between HolonElement Table and displayed Graph and
|
|
|
+ * Properties, as well as selection of differet HolonElements
|
|
|
*/
|
|
|
tableHolonElement.addMouseListener(new MouseAdapter() {
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
HolonObject obj = (HolonObject) getActualCps();
|
|
|
yValueElements = e.getY();
|
|
|
HolonElement ele = null;
|
|
|
+ // Search for current clicked HolonElement
|
|
|
if (model.getSelectedCpsObjects().size() == 1) {
|
|
|
ele = getActualHolonElement(obj, yValueElements, 0);
|
|
|
} else {
|
|
|
ele = getActualHolonElement(null, yValueElements, 0);
|
|
|
}
|
|
|
+ // Multi-Selection of HolonElements through control button +
|
|
|
+ // mouse click
|
|
|
if (e.isControlDown() && ele != null) {
|
|
|
if (!selectedElements.contains(ele)) {
|
|
|
selectedElements.add(ele);
|
|
@@ -646,34 +664,29 @@ public class GUI<E> implements CategoryListener {
|
|
|
unitGraph.repaintWithNewElement(selectedElements);
|
|
|
}
|
|
|
getActualHolonElement(null, yValueElements, 2);
|
|
|
- } else if (ele != null) {
|
|
|
+ } // if no control-button pressed but a HolonElement choose
|
|
|
+ else if (ele != null) {
|
|
|
selectedElements.clear();
|
|
|
selectedElements.add(ele);
|
|
|
getActualHolonElement(null, yValueElements, 1);
|
|
|
holonEleNamesDisplayed = ele.getEleName() + " ";
|
|
|
unitGraph.repaintWithNewElement(selectedElements);
|
|
|
- } else {
|
|
|
+ } // If any empty space is clicked
|
|
|
+ else {
|
|
|
elementGraph.setText("None ");
|
|
|
unitGraph.empty();
|
|
|
}
|
|
|
- // if any HolonElement is double-clicked --> Edit instance of
|
|
|
- // selected HolonElement
|
|
|
+ // if any HolonElement is double-clicked --> Edit-Mode started
|
|
|
+ // for selected HolonElement
|
|
|
if (e.getClickCount() == 2) {
|
|
|
yTHIS = e.getY();
|
|
|
xTHIS = e.getX();
|
|
|
}
|
|
|
+ // for single click and empty slot
|
|
|
if (e.getClickCount() == 1 && ele == null) {
|
|
|
selectedElements.clear();
|
|
|
holonEleNamesDisplayed = "None ";
|
|
|
}
|
|
|
- // for (int i = 0; i < selectedElements.size(); i++) {
|
|
|
- // if (i == 0) {
|
|
|
- // System.out.println("Selected Items: " +
|
|
|
- // selectedElements.get(i).getEleName());
|
|
|
- // } else {
|
|
|
- // System.out.println(selectedElements.get(i).getEleName());
|
|
|
- // }
|
|
|
- // }
|
|
|
elementGraph.setText(holonEleNamesDisplayed);
|
|
|
yBTHIS = e.getY();
|
|
|
xBTHIS = e.getX();
|
|
@@ -682,8 +695,7 @@ public class GUI<E> implements CategoryListener {
|
|
|
});
|
|
|
|
|
|
/*
|
|
|
- * If the HolonElement Table enters to editing instance, than is the
|
|
|
- * propertyChangeListener triggered
|
|
|
+ * Triggered every time a change is made
|
|
|
*/
|
|
|
tableHolonElement.addPropertyChangeListener(new PropertyChangeListener() {
|
|
|
@Override
|
|
@@ -693,57 +705,65 @@ public class GUI<E> implements CategoryListener {
|
|
|
int yBMouse = yBTHIS;
|
|
|
int selectedValueY = (int) Math.floor(yMouse / 16);
|
|
|
int selectedValueBY = (int) Math.floor(yBMouse / 16);
|
|
|
+ // for multi-selection mode
|
|
|
if (model.getSelectedCpsObjects().size() > 1) {
|
|
|
- // Multiple Selection
|
|
|
- int selectedValueX = (int) Math.floor(xTHIS / (tableHolonElement.getWidth() / 5));
|
|
|
- int selectedValueBX = (int) Math.floor(xBTHIS / (tableHolonElement.getWidth() / 5));
|
|
|
+ int selectedValueX = (int) Math.floor(xTHIS / (tableHolonElement.getWidth() / 6));
|
|
|
+ int selectedValueBX = (int) Math.floor(xBTHIS / (tableHolonElement.getWidth() / 6));
|
|
|
if (getHolonObj(yMouse) != null) {
|
|
|
- if (selectedValueBX == 4) {
|
|
|
+ // For last column (boolean with a checkbox)
|
|
|
+ if (selectedValueBX == 5) {
|
|
|
HolonElement eleBTemp = getActualHolonElement(null, yBMouse, 0);
|
|
|
String newBStuff = tableModelHolonElementMulti
|
|
|
.getValueAt(selectedValueBY, selectedValueBX).toString();
|
|
|
Boolean bTemp = Boolean.parseBoolean(newBStuff);
|
|
|
eleBTemp.setActive(bTemp);
|
|
|
} else {
|
|
|
+ // Update of HolonElement
|
|
|
HolonElement eleTemp = getActualHolonElement(null, yMouse, 0);
|
|
|
String newStuff = tableModelHolonElementMulti.getValueAt(selectedValueY, selectedValueX)
|
|
|
.toString();
|
|
|
- // Small bug, when it comes to edit the name of
|
|
|
- // the HolonElement
|
|
|
- if (selectedValueX == 1) {
|
|
|
+ // Name update
|
|
|
+ if (selectedValueX == 2) {
|
|
|
eleTemp.setEleName(newStuff);
|
|
|
- } else if (selectedValueX == 2) {
|
|
|
+ }
|
|
|
+ // Energy Update
|
|
|
+ else if (selectedValueX == 3) {
|
|
|
Float ftemp = Float.parseFloat(newStuff);
|
|
|
eleTemp.setEnergy(ftemp);
|
|
|
- } else if (selectedValueX == 3) {
|
|
|
+ }
|
|
|
+ // Amount of Elements update
|
|
|
+ else if (selectedValueX == 4) {
|
|
|
Integer iTemp = Integer.parseInt(newStuff);
|
|
|
eleTemp.setAmount(iTemp);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- } else if (model.getSelectedCpsObjects().size() == 1) {
|
|
|
- // Single Selection
|
|
|
- int selectedValueX = (int) Math.floor(xTHIS / (tableHolonElement.getWidth() / 4));
|
|
|
- int selectedValueBX = (int) Math.floor(xBTHIS / (tableHolonElement.getWidth() / 4));
|
|
|
+ } // For single-selection mode
|
|
|
+ else if (model.getSelectedCpsObjects().size() == 1) {
|
|
|
+ int selectedValueX = (int) Math.floor(xTHIS / (tableHolonElement.getWidth() / 5));
|
|
|
+ int selectedValueBX = (int) Math.floor(xBTHIS / (tableHolonElement.getWidth() / 5));
|
|
|
if (getActualCps() != null && getActualCps().getClass() == HolonObject.class) {
|
|
|
- if (selectedValueBX == 3) {
|
|
|
+ // For last column (boolean with a checkbox)
|
|
|
+ if (selectedValueBX == 4) {
|
|
|
HolonElement eleBTemp = getActualHolonElement((HolonObject) getActualCps(), yBMouse, 0);
|
|
|
String newBStuff = tableModelHolonElementSingle
|
|
|
.getValueAt(selectedValueBY, selectedValueBX).toString();
|
|
|
Boolean bTemp = Boolean.parseBoolean(newBStuff);
|
|
|
eleBTemp.setActive(bTemp);
|
|
|
} else {
|
|
|
+ // Update of HolonElement
|
|
|
HolonElement eleTemp = getActualHolonElement((HolonObject) getActualCps(), yMouse, 0);
|
|
|
String newStuff = tableModelHolonElementSingle
|
|
|
.getValueAt(selectedValueY, selectedValueX).toString();
|
|
|
- // Small bug, when it comes to edit the name of
|
|
|
- // the HolonElement
|
|
|
- if (selectedValueX == 0) {
|
|
|
+ // Name update
|
|
|
+ if (selectedValueX == 1) {
|
|
|
eleTemp.setEleName(newStuff);
|
|
|
- } else if (selectedValueX == 1) {
|
|
|
+ } // Energy Update
|
|
|
+ else if (selectedValueX == 2) {
|
|
|
Float ftemp = Float.parseFloat(newStuff);
|
|
|
eleTemp.setEnergy(ftemp);
|
|
|
- } else if (selectedValueX == 2) {
|
|
|
+ } // Amount of Elements update
|
|
|
+ else if (selectedValueX == 3) {
|
|
|
Integer iTemp = Integer.parseInt(newStuff);
|
|
|
eleTemp.setAmount(iTemp);
|
|
|
}
|
|
@@ -763,9 +783,7 @@ public class GUI<E> implements CategoryListener {
|
|
|
* HolonElement Properties Actions
|
|
|
**********************/
|
|
|
/*
|
|
|
- * If any value at the Properties Table enters to editing instance, than
|
|
|
- * is PropertyChangeListener triggered (For HolonObject, the only value
|
|
|
- * to be edited is the name and for CpsEdge the Max.flow)
|
|
|
+ * Update any change in the Property table
|
|
|
*/
|
|
|
tableProperties.addPropertyChangeListener(new PropertyChangeListener() {
|
|
|
|
|
@@ -777,13 +795,23 @@ public class GUI<E> implements CategoryListener {
|
|
|
if (getActualCps() instanceof HolonObject) {
|
|
|
temp = tableModelProperties.getValueAt(0, 1);
|
|
|
getActualCps().setName(temp.toString());
|
|
|
- } else if (getActualCps() instanceof HolonTransformer) {
|
|
|
- // get Info of the Properties for Transformer
|
|
|
}
|
|
|
} else {
|
|
|
- temp = tableModelProperties.getValueAt(2, 1);
|
|
|
- Float ftemp = Float.parseFloat(temp.toString());
|
|
|
- model.getSelectedEdge().setCapacity(ftemp);
|
|
|
+ Point mousePos = tableProperties.getMousePosition();
|
|
|
+ temp = tableModelProperties.getValueAt(mousePos.y / tableProperties.getRowHeight(),
|
|
|
+ mousePos.x / (tableProperties.getWidth() / 2));
|
|
|
+ if (mousePos.y / tableProperties.getRowHeight() == 2) {
|
|
|
+ Float ftemp;
|
|
|
+ if (Float.parseFloat(temp.toString()) >= 0.0) {
|
|
|
+ ftemp = Float.parseFloat(temp.toString());
|
|
|
+ } else {
|
|
|
+ ftemp = model.getSelectedEdge().getCapacity();
|
|
|
+ }
|
|
|
+ model.getSelectedEdge().setCapacity(ftemp);
|
|
|
+ } else if (mousePos.y / tableProperties.getRowHeight() == 3) {
|
|
|
+ Boolean bTemp = Boolean.parseBoolean(temp.toString());
|
|
|
+ model.getSelectedEdge().setState(bTemp);
|
|
|
+ }
|
|
|
}
|
|
|
canvas.repaint();
|
|
|
} catch (Exception e) {
|
|
@@ -985,7 +1013,6 @@ public class GUI<E> implements CategoryListener {
|
|
|
controller.addCategory(catName);
|
|
|
}
|
|
|
break;
|
|
|
-
|
|
|
case "Object":
|
|
|
if (selectedNode == null) {
|
|
|
JOptionPane.showMessageDialog(new JFrame(),
|
|
@@ -1022,7 +1049,8 @@ public class GUI<E> implements CategoryListener {
|
|
|
/**
|
|
|
* Update of every interaction between the user and the canvas (only on
|
|
|
* the canvas). Basically the update of all the information concerning
|
|
|
- * the clicked HolonObject
|
|
|
+ * the clicked HolonObject. For multi-selection, the propertyTable would
|
|
|
+ * be disabled
|
|
|
*/
|
|
|
canvas.addMouseListener(new MouseAdapter() {
|
|
|
|
|
@@ -1030,19 +1058,13 @@ public class GUI<E> implements CategoryListener {
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
selectedElements.clear();
|
|
|
holonEleNamesDisplayed = "None ";
|
|
|
-
|
|
|
+ // If any empty space is clicked
|
|
|
if (temp == null || temp.getID() != model.getSelectedObjectID()) {
|
|
|
unitGraph.empty();
|
|
|
elementGraph.setText("None ");
|
|
|
}
|
|
|
temp = getActualCps();
|
|
|
- // Update of the Information about the HolonElements - only for
|
|
|
- // if (temp instanceof HolonObject) {
|
|
|
- // refreshTableHolonElement();
|
|
|
- // }
|
|
|
- // Update of the Information about the Properties - only for
|
|
|
- // CpsObjects
|
|
|
- // Erase old data
|
|
|
+ // Erase old data in the PropertyTable
|
|
|
if (tableModelProperties.getRowCount() > 0) {
|
|
|
for (int i = tableModelProperties.getRowCount() - 1; i > -1; i--) {
|
|
|
tableModelProperties.removeRow(i);
|
|
@@ -1055,35 +1077,23 @@ public class GUI<E> implements CategoryListener {
|
|
|
controller.addSelectedObject(temp);
|
|
|
}
|
|
|
}
|
|
|
- // } else if (e.isShiftDown() && model.getSelectedEdge() !=
|
|
|
- // null) {
|
|
|
- // selectedObjects.add(model.getSelectedEdge());
|
|
|
- // }
|
|
|
- // boolean nothingImportant = true;
|
|
|
- // for (CpsObject c : model.getSelectedCpsObjects()) {
|
|
|
- // if (nothingImportant) {
|
|
|
- // System.out.println("Elements: " + c.getName() + " and ID: " +
|
|
|
- // c.getID());
|
|
|
- // nothingImportant = false;
|
|
|
- // } else {
|
|
|
- // System.out.println(c.getName() + " and ID: " + c.getID());
|
|
|
- // }
|
|
|
- // }
|
|
|
- // Write new data
|
|
|
+ // Write new data in the PropertyTable
|
|
|
if (temp != null) {
|
|
|
+ // Name of the CpsObject
|
|
|
Object[] tempName = { "Name", temp.getName() };
|
|
|
tableModelProperties.addRow(tempName);
|
|
|
+ // Id of the CpsObject
|
|
|
Object[] tempId = { "ID", temp.getID() };
|
|
|
tableModelProperties.addRow(tempId);
|
|
|
+ // For HolonObjects the Total Energy (production or
|
|
|
+ // consumption) is calculated
|
|
|
if (temp instanceof HolonObject) {
|
|
|
refreshTableHolonElement();
|
|
|
Object[] tempEnergy = { "Total Energy", ((HolonObject) temp).getCurrentEnergy() };
|
|
|
tableModelProperties.addRow(tempEnergy);
|
|
|
- // } else if (temp instanceof HolonTransformer) {
|
|
|
- // deleteRows();
|
|
|
- // Object[] tempRatioPerc = { "Ratio Type", true };
|
|
|
- // tableModelProperties.addRow(tempRatioPerc);
|
|
|
- } else if (temp instanceof HolonSwitch) {
|
|
|
+ } // For HolonSwitches is showed the actual status (active
|
|
|
+ // or inactive)
|
|
|
+ else if (temp instanceof HolonSwitch) {
|
|
|
deleteRows(tableModelHolonElementSingle);
|
|
|
deleteRows(tableModelHolonElementMulti);
|
|
|
Object[] tempActive = { "Active", ((HolonSwitch) temp).getActiveAt()[model.getCurIteration()] };
|
|
@@ -1094,9 +1104,12 @@ public class GUI<E> implements CategoryListener {
|
|
|
deleteRows(tableModelHolonElementSingle);
|
|
|
deleteRows(tableModelHolonElementMulti);
|
|
|
}
|
|
|
+ // 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();
|
|
|
+ // If the clicked object has connections
|
|
|
if (!temp_array.isEmpty()) {
|
|
|
boolean first = true;
|
|
|
for (CpsEdge temp2 : temp_array) {
|
|
@@ -1124,20 +1137,31 @@ public class GUI<E> implements CategoryListener {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- } else if (model.getSelectedEdge() != null) {
|
|
|
+ } // If the clicked Object is an edge
|
|
|
+ else if (model.getSelectedEdge() != null) {
|
|
|
+ // Name displayed
|
|
|
Object[] tempName = { "Name", "Edge: " + model.getSelectedEdge().getA().getName() + " to "
|
|
|
+ model.getSelectedEdge().getB().getName() };
|
|
|
tableModelProperties.addRow(tempName);
|
|
|
+ // Current Flow displayed
|
|
|
Object[] tempFlow = { "Current flow", model.getSelectedEdge().getFlow() };
|
|
|
tableModelProperties.addRow(tempFlow);
|
|
|
+ // Max Capacity displayed
|
|
|
Object[] tempCapacity = { "Max. Capacity", model.getSelectedEdge().getCapacity() };
|
|
|
tableModelProperties.addRow(tempCapacity);
|
|
|
+ // Status displayed
|
|
|
+ Object[] tempStatus = { "Status", model.getSelectedEdge().getStateEdge() };
|
|
|
+ tableModelProperties.addRow(tempStatus);
|
|
|
+ // For edges, the only possible editable cell is the max
|
|
|
+ // flow
|
|
|
tableModelProperties.setCellEditable(0, 1, false);
|
|
|
tableModelProperties.setCellEditable(2, 1, true);
|
|
|
+ tableModelProperties.setCellEditable(3, 1, true);
|
|
|
} else if (getActualCps() == null) {
|
|
|
deleteRows(tableModelHolonElementSingle);
|
|
|
deleteRows(tableModelHolonElementMulti);
|
|
|
- }
|
|
|
+ } // Update of the HolonElementTable (Single- or
|
|
|
+ // Multi-Selection)
|
|
|
if (model.getSelectedCpsObjects().size() > 1) {
|
|
|
tableHolonElement.setModel(tableModelHolonElementMulti);
|
|
|
} else if (model.getSelectedCpsObjects().size() == 1) {
|
|
@@ -1328,11 +1352,11 @@ public class GUI<E> implements CategoryListener {
|
|
|
@Override
|
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
|
|
|
- menuUndoActionPerformed(evt);
|
|
|
+ menuRedoActionPerformed(evt);
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void menuUndoActionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
+ private void menuRedoActionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
try {
|
|
|
controller.loadFile(controller.getRedoSave());
|
|
|
canvas.repaint();
|
|
@@ -1359,6 +1383,34 @@ public class GUI<E> implements CategoryListener {
|
|
|
|
|
|
});
|
|
|
|
|
|
+ mntmSetFolder.addActionListener(new java.awt.event.ActionListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
+
|
|
|
+ menuSetFolderActionPerformed(evt);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void menuSetFolderActionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
+ JFileChooser fileChooser = new JFileChooser();
|
|
|
+ JFrame test = new JFrame();
|
|
|
+ fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
|
|
+ fileChooser.setAcceptAllFileFilterUsed(false);
|
|
|
+
|
|
|
+ if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
|
|
|
+ comboBoxAlgo.removeAllItems();
|
|
|
+ File[] files = fileChooser.getSelectedFile().listFiles();
|
|
|
+ for (int i = 0; i < files.length; i++) {
|
|
|
+ if (files[i].toString().endsWith(".java") || files[i].toString().endsWith(".class")) {
|
|
|
+ comboBoxAlgo.addItem(files[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
timePanel = new TimePanel(model, controller);
|
|
|
timePanel.setBorder(null);
|
|
|
((JSlider) (timePanel.getComponent(1))).addChangeListener(new ChangeListener() {
|
|
@@ -1392,12 +1444,28 @@ public class GUI<E> implements CategoryListener {
|
|
|
splitPane_1.setBorder(null);
|
|
|
split_HolonEl_Pro.setBorder(null);
|
|
|
split_Graph_HolonEl.setBorder(null);
|
|
|
- scrollPane_2.setBorder(null);
|
|
|
+ SimulationPane.setBorder(null);
|
|
|
panel_HolonEl.setBorder(null);
|
|
|
|
|
|
tableHolonElementScrollPane.setBorder(null);
|
|
|
|
|
|
frmCyberPhysical.getContentPane().add(timePanel, BorderLayout.SOUTH);
|
|
|
+
|
|
|
+ simulationSpeedField.setText(Integer.toString(timePanel.getTimerSpeed()));
|
|
|
+ btnApply.addActionListener(new ActionListener() {
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ int speed = Integer.parseInt(simulationSpeedField.getText());
|
|
|
+ timePanel.setTimerSpeed(speed);
|
|
|
+ mnSimulationSpeed.setPopupMenuVisible(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ mnSimulationSpeed.add(btnApply);
|
|
|
+ menuBar.add(comboBoxAlgo);
|
|
|
+
|
|
|
+ Dimension height = comboBoxAlgo.getPreferredSize();
|
|
|
+ comboBoxAlgo.setPreferredSize(new Dimension(200, (int) height.getHeight()));
|
|
|
+ comboBoxAlgo.setMaximumSize(comboBoxAlgo.getPreferredSize());
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -1487,7 +1555,8 @@ public class GUI<E> implements CategoryListener {
|
|
|
* Search for actual selected HolonElement
|
|
|
*
|
|
|
* @param obj
|
|
|
- * selected HolonObject
|
|
|
+ * selected HolonObject, if obj==null means multi-selection
|
|
|
+ * active
|
|
|
* @param yValue
|
|
|
* Y-Coord in the HolonElementsTable
|
|
|
* @param toMultiHash
|
|
@@ -1497,47 +1566,64 @@ public class GUI<E> implements CategoryListener {
|
|
|
*/
|
|
|
public HolonElement getActualHolonElement(HolonObject obj, int yValue, int toMultiHash) {
|
|
|
final int yTemp = (int) Math.floor(yValue / 16);
|
|
|
- int rowsTotal = tableModelHolonElementSingle.getRowCount();
|
|
|
+ int rowsTotal = 0;
|
|
|
+ // Filter for search --> single and multi selection
|
|
|
if (obj == null) {
|
|
|
rowsTotal = tableModelHolonElementMulti.getRowCount();
|
|
|
+ } else {
|
|
|
+ rowsTotal = tableModelHolonElementSingle.getRowCount();
|
|
|
}
|
|
|
+ // search for the clicked HolonObject and HolonElement --> in the
|
|
|
+ // HolonElementTable
|
|
|
HolonObject obtTemp = null;
|
|
|
- String eleTempName = "";
|
|
|
+ HolonElement toReturnEle = null;
|
|
|
+ int id = 0;
|
|
|
if (rowsTotal != 0 && rowsTotal > yTemp) {
|
|
|
+ // Multi-Selection search
|
|
|
if (obj == null) {
|
|
|
- String temp = tableModelHolonElementMulti.getValueAt(yTemp, 0).toString();
|
|
|
- int idTemp = Integer.parseInt(temp.split(", ")[1]);
|
|
|
- obtTemp = (HolonObject) controller.searchByID(idTemp);
|
|
|
- eleTempName = tableModelHolonElementMulti.getValueAt(yTemp, 1).toString();
|
|
|
+ String tempStringObj = tableModelHolonElementMulti.getValueAt(yTemp, 0).toString();
|
|
|
+ int idTempObj = Integer.parseInt(tempStringObj.split(", ")[1]);
|
|
|
+ obtTemp = (HolonObject) controller.searchByID(idTempObj);
|
|
|
+ id = Integer.parseInt(tableModelHolonElementMulti.getValueAt(yTemp, 1).toString());
|
|
|
ArrayList<HolonElement> eleTemp = new ArrayList<HolonElement>();
|
|
|
- if (eleToDelete.containsKey(idTemp) && toMultiHash == 2) {
|
|
|
- eleTemp = eleToDelete.get(idTemp);
|
|
|
- if (!eleTemp.contains(obtTemp.searchElement(eleTempName))) {
|
|
|
- eleTemp.add(obtTemp.searchElement(eleTempName));
|
|
|
- eleToDelete.replace(idTemp, eleTemp);
|
|
|
+ if (eleToDelete.containsKey(idTempObj) && toMultiHash == 2) {
|
|
|
+ eleTemp = eleToDelete.get(idTempObj);
|
|
|
+ if (!eleTemp.contains(obtTemp.searchElementById(id))) {
|
|
|
+ eleTemp.add(obtTemp.searchElementById(id));
|
|
|
+ eleToDelete.replace(idTempObj, eleTemp);
|
|
|
}
|
|
|
} else if (toMultiHash == 2) {
|
|
|
- eleTemp.add(obtTemp.searchElement(eleTempName));
|
|
|
- eleToDelete.put(idTemp, eleTemp);
|
|
|
+ eleTemp.add(obtTemp.searchElementById(id));
|
|
|
+ eleToDelete.put(idTempObj, eleTemp);
|
|
|
} else if (toMultiHash == 1) {
|
|
|
eleToDelete = new HashMap<Integer, ArrayList<HolonElement>>();
|
|
|
- eleTemp.add(obtTemp.searchElement(eleTempName));
|
|
|
- eleToDelete.put(idTemp, eleTemp);
|
|
|
+ eleTemp.add(obtTemp.searchElementById(id));
|
|
|
+ eleToDelete.put(idTempObj, eleTemp);
|
|
|
+ } else if (toMultiHash == 0) {
|
|
|
+ toReturnEle = obtTemp.searchElementById(id);
|
|
|
}
|
|
|
- } else {
|
|
|
+ } // Single-Selection search
|
|
|
+ else {
|
|
|
eleToDelete = new HashMap<Integer, ArrayList<HolonElement>>();
|
|
|
- obtTemp = obj;
|
|
|
- eleTempName = tableModelHolonElementSingle.getValueAt(yTemp, 0).toString();
|
|
|
+ id = Integer.parseInt(tableModelHolonElementSingle.getValueAt(yTemp, 0).toString());
|
|
|
+ toReturnEle = obj.searchElementById(id);
|
|
|
}
|
|
|
- model.setSelectedHolonElement(obtTemp.searchElement(eleTempName));
|
|
|
- return obtTemp.searchElement(eleTempName);
|
|
|
- } else {
|
|
|
+ model.setSelectedHolonElement(toReturnEle);
|
|
|
+ return toReturnEle;
|
|
|
+ } // If no HolonObject selected
|
|
|
+ else {
|
|
|
eleToDelete = new HashMap<Integer, ArrayList<HolonElement>>();
|
|
|
model.setSelectedHolonElement(null);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Search for clicked HolonObject through the mouse's y-Coord
|
|
|
+ *
|
|
|
+ * @param yValue
|
|
|
+ * @return clicked HolonObject
|
|
|
+ */
|
|
|
public HolonObject getHolonObj(int yValue) {
|
|
|
final int yTemp = (int) Math.floor(yValue / 16);
|
|
|
HolonObject obtTemp = null;
|
|
@@ -1589,7 +1675,7 @@ public class GUI<E> implements CategoryListener {
|
|
|
for (CpsObject o : objects) {
|
|
|
if (o instanceof HolonObject) {
|
|
|
for (HolonElement he : ((HolonObject) o).getElements()) {
|
|
|
- Object[] temp = { o.getName() + ", " + o.getID(), he.getEleName(), he.getEnergy(),
|
|
|
+ Object[] temp = { o.getName() + ", " + o.getID(), he.getId(), he.getEleName(), he.getEnergy(),
|
|
|
he.getAmount(), he.getActive() };
|
|
|
tableModelHolonElementMulti.addRow(temp);
|
|
|
}
|
|
@@ -1599,7 +1685,7 @@ public class GUI<E> implements CategoryListener {
|
|
|
CpsObject o = objects.get(0);
|
|
|
if (o instanceof HolonObject) {
|
|
|
for (HolonElement he : ((HolonObject) o).getElements()) {
|
|
|
- Object[] temp = { he.getEleName(), he.getEnergy(), he.getAmount(), he.getActive() };
|
|
|
+ Object[] temp = { he.getId(), he.getEleName(), he.getEnergy(), he.getAmount(), he.getActive() };
|
|
|
tableModelHolonElementSingle.addRow(temp);
|
|
|
}
|
|
|
}
|