|
@@ -6,12 +6,14 @@ 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;
|
|
|
import java.awt.event.ActionListener;
|
|
|
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;
|
|
@@ -34,6 +36,7 @@ import javax.swing.JMenuItem;
|
|
|
import javax.swing.JOptionPane;
|
|
|
import javax.swing.JPanel;
|
|
|
import javax.swing.JPopupMenu;
|
|
|
+import javax.swing.JRadioButton;
|
|
|
import javax.swing.JScrollPane;
|
|
|
import javax.swing.JSlider;
|
|
|
import javax.swing.JSplitPane;
|
|
@@ -48,6 +51,8 @@ import javax.swing.tree.DefaultMutableTreeNode;
|
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
|
import javax.swing.tree.TreeCellRenderer;
|
|
|
|
|
|
+import com.sun.javafx.geom.Edge;
|
|
|
+
|
|
|
import Interfaces.CategoryListener;
|
|
|
import classes.Category;
|
|
|
import classes.CpsEdge;
|
|
@@ -130,7 +135,7 @@ public class GUI<E> implements CategoryListener {
|
|
|
private final JPanel panel = new JPanel();
|
|
|
private final JPanel panel_HolonEl = new JPanel();
|
|
|
private final JComboBox comboBox = new JComboBox();
|
|
|
- private final JComboBox comboBoxGraph = new JComboBox();
|
|
|
+ // private final JComboBox comboBoxGraph = new JComboBox();
|
|
|
|
|
|
// Buttons
|
|
|
private final JButton btnAdd = new JButton("+");
|
|
@@ -228,15 +233,15 @@ public class GUI<E> implements CategoryListener {
|
|
|
menuBar.add(mnHelp);
|
|
|
|
|
|
mnHelp.add(aboutUs);
|
|
|
-
|
|
|
+
|
|
|
menuBar.add(mnAlgorithm);
|
|
|
-
|
|
|
+
|
|
|
mnAlgorithm.add(chckbxmntmUseAlgorithm);
|
|
|
-
|
|
|
+
|
|
|
mnAlgorithm.add(splitPane_2);
|
|
|
-
|
|
|
+
|
|
|
splitPane_2.setLeftComponent(lblSelect);
|
|
|
-
|
|
|
+
|
|
|
splitPane_2.setRightComponent(comboBoxAlgo);
|
|
|
|
|
|
unitGraph.setBackground(Color.WHITE);
|
|
@@ -248,7 +253,7 @@ public class GUI<E> implements CategoryListener {
|
|
|
|
|
|
tabbedPane.addTab("Modeling", new ImageIcon(new ImageIcon(this.getClass().getResource("/Images/home.png"))
|
|
|
.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH)), canvasSP, "Model a CPS");
|
|
|
-
|
|
|
+
|
|
|
tabbedPane.addTab("New tab", null, label_1, null);
|
|
|
|
|
|
tabbedPane.addTab("Simulation",
|
|
@@ -300,8 +305,9 @@ public class GUI<E> implements CategoryListener {
|
|
|
graphLabel.add(medGraph, BorderLayout.CENTER);
|
|
|
graphLabel.add(minGraph, BorderLayout.SOUTH);
|
|
|
toolBarGraph.add(elementGraph);
|
|
|
- comboBoxGraph.setModel(new DefaultComboBoxModel(new String[] { "Day", "Month", "Year" }));
|
|
|
- toolBarGraph.add(comboBoxGraph);
|
|
|
+ // comboBoxGraph.setModel(new DefaultComboBoxModel(new String[] { "Day",
|
|
|
+ // "Month", "Year" }));
|
|
|
+ // toolBarGraph.add(comboBoxGraph);
|
|
|
toolBarGraph.add(resetGraphBtn);
|
|
|
toolBarGraph.setFloatable(false);
|
|
|
scrollGraph.setRowHeaderView(graphLabel);
|
|
@@ -374,12 +380,42 @@ public class GUI<E> implements CategoryListener {
|
|
|
} else {
|
|
|
temp = tableModelProperties.getValueAt(2, 1);
|
|
|
Float ftemp = Float.parseFloat(temp.toString());
|
|
|
- System.out.println(ftemp);
|
|
|
model.getSelectedEdge().setCapacity(ftemp);
|
|
|
}
|
|
|
- for (CpsEdge c : getActualCps().getConnections()) {
|
|
|
- System.out.println(c.getA().getName() + " conected to " + c.getB().getName());
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ tableHolonElement.addPropertyChangeListener(new PropertyChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void propertyChange(PropertyChangeEvent evt) {
|
|
|
+ try {
|
|
|
+ int xMouse = tableHolonElement.getMousePosition().x;
|
|
|
+ int yMouse = tableHolonElement.getMousePosition().y;
|
|
|
+ int xSizeCell = tableHolonElement.getWidth() / 3;
|
|
|
+ int selectedValueX = (int) Math.floor(xMouse / xSizeCell);
|
|
|
+ int selectedValueY = (int) Math.floor(yMouse / 16);
|
|
|
+ if (getActualCps() != null && getActualCps().getClass() == HolonObject.class) {
|
|
|
+ HolonElement eleTemp = getActualHolonElement((HolonObject) getActualCps(), yMouse);
|
|
|
+ String newStuff = tableModelHolonElement.getValueAt(selectedValueY, selectedValueX).toString();
|
|
|
+ if (selectedValueX == 0) {
|
|
|
+ System.out.println("Changin Name");
|
|
|
+ eleTemp.setEleName(newStuff);
|
|
|
+ } else if (selectedValueX == 1) {
|
|
|
+ System.out.println("Changin Energy");
|
|
|
+ Float ftemp = Float.parseFloat(newStuff);
|
|
|
+ eleTemp.setEnergy(ftemp);
|
|
|
+ } else if (selectedValueX == 2) {
|
|
|
+ System.out.println("Changin Amount");
|
|
|
+ Integer iTemp = Integer.parseInt(newStuff);
|
|
|
+ eleTemp.setAmount(iTemp);
|
|
|
+ tableHolonElement.firePropertyChange("amount", iTemp, iTemp);
|
|
|
+ }
|
|
|
+ System.out.println(newStuff);
|
|
|
}
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
}
|
|
@@ -601,30 +637,30 @@ public class GUI<E> implements CategoryListener {
|
|
|
}
|
|
|
tableModelProperties.setCellEditable(0, 1, true);
|
|
|
tableModelProperties.setCellEditable(2, 1, false);
|
|
|
- ArrayList<CpsEdge> temp_array = temp.getConnectedTo();
|
|
|
+ ArrayList<CpsEdge> temp_array = temp.getConnections();
|
|
|
if (!temp_array.isEmpty()) {
|
|
|
boolean first = true;
|
|
|
for (CpsEdge temp2 : temp_array) {
|
|
|
if (first) {
|
|
|
first = false;
|
|
|
- if (temp.getName().compareTo(temp2.getA().getCompareName()) == 0) {
|
|
|
+ if (temp.getID() != temp2.getA().getID()) {
|
|
|
Object[] tempConnection = { temp.getName() + " is connected to",
|
|
|
- temp2.getB().getName() + " with ID: " + temp2.getB().getID() };
|
|
|
+ temp2.getA().getName() + " with ID: " + temp2.getA().getID() };
|
|
|
tableModelProperties.addRow(tempConnection);
|
|
|
} else {
|
|
|
Object[] tempConnection = { temp.getName() + " is connected to",
|
|
|
- temp2.getA().getName() + " with ID: " + temp2.getA().getID() };
|
|
|
+ temp2.getB().getName() + " with ID: " + temp2.getB().getID() };
|
|
|
tableModelProperties.addRow(tempConnection);
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
- if (temp.getName().compareTo(temp2.getA().getCompareName()) == 0) {
|
|
|
+ if (temp.getID() != temp2.getA().getID()) {
|
|
|
Object[] tempConnection = { "",
|
|
|
- temp2.getB().getName() + " with ID: " + temp2.getB().getID() };
|
|
|
+ temp2.getA().getName() + " with ID: " + temp2.getA().getID() };
|
|
|
tableModelProperties.addRow(tempConnection);
|
|
|
+
|
|
|
} else {
|
|
|
Object[] tempConnection = { "",
|
|
|
- temp2.getA().getName() + " with ID: " + temp2.getA().getID() };
|
|
|
+ temp2.getB().getName() + " with ID: " + temp2.getB().getID() };
|
|
|
tableModelProperties.addRow(tempConnection);
|
|
|
}
|
|
|
|
|
@@ -646,52 +682,6 @@ public class GUI<E> implements CategoryListener {
|
|
|
|
|
|
});
|
|
|
|
|
|
- tableHolonElement.addPropertyChangeListener(new PropertyChangeListener() {
|
|
|
- @Override
|
|
|
- public void propertyChange(PropertyChangeEvent evt) {
|
|
|
- try {
|
|
|
-
|
|
|
- tempCps = controller.searchByID(model.getSelectedObjectID());
|
|
|
- if (tempCps != null) {
|
|
|
- // System.out.println("change: " + tempCps.toString());
|
|
|
- for (int r = 0; r < tableModelHolonElement.getRowCount(); r++) {
|
|
|
- ArrayList<Object> temp = new ArrayList<>();
|
|
|
- for (int c = 0; c < tableModelHolonElement.getColumnCount(); c++) {
|
|
|
- temp.add(tableHolonElement.getValueAt(r, c));
|
|
|
- }
|
|
|
- // float ch;
|
|
|
- // if (temp.get(1).toString().compareTo("-") == 0) {
|
|
|
- // ch = -1;
|
|
|
- // } else {
|
|
|
- // ch = 1;
|
|
|
- // }
|
|
|
- float fa = Float.parseFloat(temp.get(1).toString());
|
|
|
- int i = Integer.parseInt(temp.get(2).toString());
|
|
|
- ((HolonObject) tempCps).getElements().get(r).setEleName((String) temp.get(0));
|
|
|
- // ((HolonObject)
|
|
|
- // tempCps).getElements().get(r).setSign(ch);
|
|
|
- ((HolonObject) tempCps).getElements().get(r).setEnergy(fa);
|
|
|
- ((HolonObject) tempCps).getElements().get(r).setAmount(i);
|
|
|
- // System.out.println(tableHolonElement.getRowCount()
|
|
|
- // + " " + temp.get(0) + " " + ch + " " + fa
|
|
|
- // + " " + i);
|
|
|
- }
|
|
|
- if (tableModelHolonElement.getRowCount() > 0) {
|
|
|
- for (int i = tableModelHolonElement.getRowCount() - 1; i > -1; i--) {
|
|
|
- tableModelHolonElement.removeRow(i);
|
|
|
- }
|
|
|
- }
|
|
|
- for (HolonElement he : canvas.dataSelected) {
|
|
|
- Object[] temp = { he.getEleName(), he.getEnergy(), he.getAmount() };
|
|
|
- tableModelHolonElement.addRow(temp);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
toolBar.add(btnAdd);
|
|
|
|
|
|
// Del Button
|
|
@@ -934,11 +924,10 @@ public class GUI<E> implements CategoryListener {
|
|
|
deleteRows();
|
|
|
if (canvas.dataSelected != null) {
|
|
|
fillElementTable(canvas.dataSelected);
|
|
|
- }
|
|
|
- /**
|
|
|
- * hinzugef�gt damit man auch nach dem objekt platziert wurde elemente
|
|
|
- * von Objekten in Kategorien ansehen kann
|
|
|
- */
|
|
|
+ } /**
|
|
|
+ * hinzugef�gt damit man auch nach dem objekt platziert wurde
|
|
|
+ * elemente von Objekten in Kategorien ansehen kann
|
|
|
+ */
|
|
|
canvas.dataSelected = null;
|
|
|
|
|
|
}
|
|
@@ -963,13 +952,13 @@ public class GUI<E> implements CategoryListener {
|
|
|
*/
|
|
|
public void refreshTableProperties() {
|
|
|
CpsObject tempCps = getActualCps();
|
|
|
- if (tempCps.getClass() == HolonObject.class && tempCps != null) {
|
|
|
+ if (tempCps != null && tempCps.getClass() == HolonObject.class) {
|
|
|
tableModelProperties.removeRow(2);
|
|
|
- Object[] tempEnergy = { "Total Energy", ((HolonObject) canvas.tempCps).getCurrentEnergy() };
|
|
|
+ Object[] tempEnergy = { "Total Energy", ((HolonObject) tempCps).getCurrentEnergy() };
|
|
|
tableModelProperties.insertRow(2, tempEnergy);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private static void addPopup(Component component, final JPopupMenu popup) {
|
|
|
component.addMouseListener(new MouseAdapter() {
|
|
|
public void mousePressed(MouseEvent e) {
|
|
@@ -977,15 +966,17 @@ public class GUI<E> implements CategoryListener {
|
|
|
showMenu(e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
public void mouseReleased(MouseEvent e) {
|
|
|
if (e.isPopupTrigger()) {
|
|
|
showMenu(e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
private void showMenu(MouseEvent e) {
|
|
|
popup.show(e.getComponent(), e.getX(), e.getY());
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|