|
@@ -1,52 +1,54 @@
|
|
|
package ui.view;
|
|
|
|
|
|
+import java.awt.BorderLayout;
|
|
|
+import java.awt.Color;
|
|
|
+import java.awt.Component;
|
|
|
+import java.awt.Cursor;
|
|
|
+import java.awt.Dimension;
|
|
|
+import java.awt.Image;
|
|
|
+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.beans.PropertyChangeEvent;
|
|
|
+import java.beans.PropertyChangeListener;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
+import javax.swing.BoxLayout;
|
|
|
+import javax.swing.DefaultComboBoxModel;
|
|
|
+import javax.swing.ImageIcon;
|
|
|
+import javax.swing.JButton;
|
|
|
+import javax.swing.JCheckBoxMenuItem;
|
|
|
+import javax.swing.JComboBox;
|
|
|
+import javax.swing.JEditorPane;
|
|
|
+import javax.swing.JFileChooser;
|
|
|
import javax.swing.JFrame;
|
|
|
import javax.swing.JLabel;
|
|
|
-import javax.swing.JMenuBar;
|
|
|
import javax.swing.JMenu;
|
|
|
+import javax.swing.JMenuBar;
|
|
|
import javax.swing.JMenuItem;
|
|
|
-import javax.swing.JSlider;
|
|
|
import javax.swing.JOptionPane;
|
|
|
-import javax.swing.JTree;
|
|
|
-import javax.swing.border.LineBorder;
|
|
|
-import javax.swing.BoxLayout;
|
|
|
-import javax.swing.JSplitPane;
|
|
|
+import javax.swing.JPanel;
|
|
|
+import javax.swing.JPopupMenu;
|
|
|
import javax.swing.JScrollPane;
|
|
|
+import javax.swing.JSlider;
|
|
|
+import javax.swing.JSplitPane;
|
|
|
import javax.swing.JTabbedPane;
|
|
|
import javax.swing.JTable;
|
|
|
+import javax.swing.JToolBar;
|
|
|
+import javax.swing.JTree;
|
|
|
+import javax.swing.event.ChangeEvent;
|
|
|
+import javax.swing.event.ChangeListener;
|
|
|
+import javax.swing.table.DefaultTableModel;
|
|
|
+import javax.swing.tree.DefaultMutableTreeNode;
|
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
|
import javax.swing.tree.TreeCellRenderer;
|
|
|
|
|
|
-import com.sun.javafx.geom.Edge;
|
|
|
-
|
|
|
-import ui.controller.Control;
|
|
|
-import ui.model.*;
|
|
|
-
|
|
|
-import javax.swing.tree.DefaultMutableTreeNode;
|
|
|
-import javax.swing.JEditorPane;
|
|
|
-import javax.swing.JFileChooser;
|
|
|
-import javax.swing.table.DefaultTableModel;
|
|
|
-
|
|
|
-import java.awt.Color;
|
|
|
-import java.awt.Component;
|
|
|
-import java.awt.Cursor;
|
|
|
-import java.awt.Dimension;
|
|
|
-import java.awt.Image;
|
|
|
-import java.awt.Point;
|
|
|
-import java.awt.Toolkit;
|
|
|
-import java.awt.BorderLayout;
|
|
|
-
|
|
|
-import javax.swing.JPanel;
|
|
|
-import javax.swing.JToolBar;
|
|
|
-import javax.swing.JButton;
|
|
|
-import javax.swing.JComboBox;
|
|
|
-import javax.swing.DefaultComboBoxModel;
|
|
|
-import javax.swing.ImageIcon;
|
|
|
-
|
|
|
+import Interfaces.CategoryListener;
|
|
|
import classes.Category;
|
|
|
import classes.CpsEdge;
|
|
|
import classes.CpsObject;
|
|
@@ -54,22 +56,10 @@ import classes.HolonElement;
|
|
|
import classes.HolonObject;
|
|
|
import classes.HolonSwitch;
|
|
|
import classes.HolonTransformer;
|
|
|
-import Interfaces.CategoryListener;
|
|
|
-
|
|
|
-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.awt.event.ActionEvent;
|
|
|
-
|
|
|
-import javax.swing.JSlider;
|
|
|
-import javax.swing.event.ChangeListener;
|
|
|
-import javax.swing.event.TableModelEvent;
|
|
|
-import javax.swing.event.ChangeEvent;
|
|
|
+import ui.controller.Control;
|
|
|
+import ui.model.Model;
|
|
|
|
|
|
-public class GUI implements CategoryListener {
|
|
|
+public class GUI<E> implements CategoryListener {
|
|
|
|
|
|
private JFrame frmCyberPhysical;
|
|
|
|
|
@@ -167,6 +157,12 @@ public class GUI implements CategoryListener {
|
|
|
private final JLabel lblImageSize = new JLabel("Image Size");
|
|
|
// Time Stuff
|
|
|
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 label_1 = new JLabel("New label");
|
|
|
+ private final JLabel lblSelect = new JLabel("Select");
|
|
|
+ private final JComboBox comboBoxAlgo = new JComboBox();
|
|
|
|
|
|
/**
|
|
|
* Create the application.
|
|
@@ -175,9 +171,8 @@ public class GUI implements CategoryListener {
|
|
|
this.controller = control;
|
|
|
this.model = control.getModel();
|
|
|
this.canvas = new MyCanvas(model, control);
|
|
|
- this.unitGraph = new UnitGraph(model, control); // for testing, remove
|
|
|
+ this.unitGraph = new UnitGraph(model, control);
|
|
|
|
|
|
- // later
|
|
|
control.initListener(this);
|
|
|
initialize();
|
|
|
updateCategories(model.getCategories());
|
|
@@ -232,6 +227,16 @@ public class GUI 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);
|
|
|
|
|
@@ -242,6 +247,8 @@ public class GUI 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",
|
|
|
new ImageIcon(new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
|
|
@@ -355,18 +362,20 @@ public class GUI implements CategoryListener {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- tableProperties.addMouseListener(new MouseAdapter() {
|
|
|
- public void mousePressed(MouseEvent e) {
|
|
|
- int selectedX = (int) Math
|
|
|
- .floor(e.getX() / (tableProperties.getColumnModel().getTotalColumnWidth() / 2));
|
|
|
- int selectedY = (int) Math.floor(e.getY() / 16);
|
|
|
- if (tableModelProperties.isCellEditable(selectedY, selectedX) && e.getClickCount() == 2) {
|
|
|
+ tableProperties.addPropertyChangeListener(new PropertyChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void propertyChange(PropertyChangeEvent evt) {
|
|
|
+ try {
|
|
|
if (getActualCps() != null) {
|
|
|
-
|
|
|
- tableModelProperties.fireTableCellUpdated(selectedY, selectedX);
|
|
|
+ String newName = tableModelProperties.getValueAt(0, 1).toString();
|
|
|
+ getActualCps().setName(newName);
|
|
|
} else {
|
|
|
- System.out.println("Edge");
|
|
|
+ float newCap = (float) tableModelProperties.getValueAt(2, 1);
|
|
|
+ System.out.println(newCap);
|
|
|
+ model.getSelectedEdge().setCapacity(newCap);
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -574,41 +583,42 @@ public class GUI implements CategoryListener {
|
|
|
}
|
|
|
}
|
|
|
// Write new data
|
|
|
- if (canvas.tempCps != null) {
|
|
|
- Object[] tempName = { "Name", canvas.tempCps.getName() };
|
|
|
+ CpsObject temp = getActualCps();
|
|
|
+ if (temp != null) {
|
|
|
+ Object[] tempName = { "Name", temp.getName() };
|
|
|
tableModelProperties.addRow(tempName);
|
|
|
- Object[] tempId = { "ID", canvas.tempCps.getID() };
|
|
|
+ Object[] tempId = { "ID", temp.getID() };
|
|
|
tableModelProperties.addRow(tempId);
|
|
|
- if (canvas.tempCps.getClass() == HolonObject.class) {
|
|
|
- Object[] tempEnergy = { "Total Energy", ((HolonObject) canvas.tempCps).getCurrentEnergy() };
|
|
|
+ if (temp.getClass() == HolonObject.class) {
|
|
|
+ Object[] tempEnergy = { "Total Energy", ((HolonObject) temp).getCurrentEnergy() };
|
|
|
tableModelProperties.addRow(tempEnergy);
|
|
|
}
|
|
|
tableModelProperties.setCellEditable(0, 1, true);
|
|
|
tableModelProperties.setCellEditable(2, 1, false);
|
|
|
- ArrayList<CpsEdge> temp_array = canvas.tempCps.getConnectedTo();
|
|
|
+ ArrayList<CpsEdge> temp_array = temp.getConnectedTo();
|
|
|
if (!temp_array.isEmpty()) {
|
|
|
boolean first = true;
|
|
|
- for (CpsEdge temp : temp_array) {
|
|
|
+ for (CpsEdge temp2 : temp_array) {
|
|
|
if (first) {
|
|
|
first = false;
|
|
|
- if (canvas.tempCps.getName().compareTo(temp.getA().getCompareName()) == 0) {
|
|
|
- Object[] tempConnection = { canvas.tempCps.getName() + " is connected to",
|
|
|
- temp.getB().getName() + " with ID: " + temp.getB().getID() };
|
|
|
+ if (temp.getName().compareTo(temp2.getA().getCompareName()) == 0) {
|
|
|
+ Object[] tempConnection = { temp.getName() + " is connected to",
|
|
|
+ temp2.getB().getName() + " with ID: " + temp2.getB().getID() };
|
|
|
tableModelProperties.addRow(tempConnection);
|
|
|
} else {
|
|
|
- Object[] tempConnection = { canvas.tempCps.getName() + " is connected to",
|
|
|
- temp.getA().getName() + " with ID: " + temp.getA().getID() };
|
|
|
+ Object[] tempConnection = { temp.getName() + " is connected to",
|
|
|
+ temp2.getA().getName() + " with ID: " + temp2.getA().getID() };
|
|
|
tableModelProperties.addRow(tempConnection);
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
- if (canvas.tempCps.getName().compareTo(temp.getA().getCompareName()) == 0) {
|
|
|
+ if (temp.getName().compareTo(temp2.getA().getCompareName()) == 0) {
|
|
|
Object[] tempConnection = { "",
|
|
|
- temp.getB().getName() + " with ID: " + temp.getB().getID() };
|
|
|
+ temp2.getB().getName() + " with ID: " + temp2.getB().getID() };
|
|
|
tableModelProperties.addRow(tempConnection);
|
|
|
} else {
|
|
|
Object[] tempConnection = { "",
|
|
|
- temp.getA().getName() + " with ID: " + temp.getA().getID() };
|
|
|
+ temp2.getA().getName() + " with ID: " + temp2.getA().getID() };
|
|
|
tableModelProperties.addRow(tempConnection);
|
|
|
}
|
|
|
|
|
@@ -721,7 +731,7 @@ public class GUI implements CategoryListener {
|
|
|
@Override
|
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
menuFileExitActionPerformed(evt);
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void menuFileExitActionPerformed(java.awt.event.ActionEvent evt) {
|
|
@@ -729,7 +739,7 @@ public class GUI implements CategoryListener {
|
|
|
JFrame test = new JFrame();
|
|
|
if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
|
|
|
File file = fileChooser.getSelectedFile();
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
controller.loadFile(file.getAbsolutePath());
|
|
|
canvas.repaint();
|
|
@@ -741,13 +751,13 @@ public class GUI implements CategoryListener {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
mntmSave.addActionListener(new java.awt.event.ActionListener() {
|
|
|
@Override
|
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
-
|
|
|
+
|
|
|
menuSaveActionPerformed(evt);
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void menuSaveActionPerformed(java.awt.event.ActionEvent evt) {
|
|
@@ -755,7 +765,7 @@ public class GUI implements CategoryListener {
|
|
|
JFrame test = new JFrame();
|
|
|
if (fileChooser.showSaveDialog(test) == JFileChooser.APPROVE_OPTION) {
|
|
|
File file = fileChooser.getSelectedFile();
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
controller.saveFile(file.getAbsolutePath());
|
|
|
} catch (IOException e) {
|
|
@@ -953,4 +963,23 @@ public class GUI implements CategoryListener {
|
|
|
tableModelProperties.insertRow(2, tempEnergy);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private static void addPopup(Component component, final JPopupMenu popup) {
|
|
|
+ component.addMouseListener(new MouseAdapter() {
|
|
|
+ public void mousePressed(MouseEvent e) {
|
|
|
+ if (e.isPopupTrigger()) {
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
}
|