|
@@ -1,50 +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 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;
|
|
@@ -52,26 +56,8 @@ 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 javax.swing.JList;
|
|
|
-import javax.swing.JCheckBoxMenuItem;
|
|
|
-import javax.swing.Box;
|
|
|
-import javax.swing.JPopupMenu;
|
|
|
-import javax.swing.JSeparator;
|
|
|
-import javax.swing.SwingConstants;
|
|
|
+import ui.controller.Control;
|
|
|
+import ui.model.Model;
|
|
|
|
|
|
public class GUI<E> implements CategoryListener {
|
|
|
|
|
@@ -185,9 +171,8 @@ public class GUI<E> 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());
|
|
@@ -377,18 +362,20 @@ public class GUI<E> 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) {
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -596,41 +583,42 @@ public class GUI<E> 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);
|
|
|
}
|
|
|
|
|
@@ -743,7 +731,7 @@ public class GUI<E> implements CategoryListener {
|
|
|
@Override
|
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
menuFileExitActionPerformed(evt);
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void menuFileExitActionPerformed(java.awt.event.ActionEvent evt) {
|
|
@@ -751,7 +739,7 @@ public class GUI<E> implements CategoryListener {
|
|
|
JFrame test = new JFrame();
|
|
|
if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
|
|
|
File file = fileChooser.getSelectedFile();
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
controller.loadFile(file.getAbsolutePath());
|
|
|
} catch (IOException e) {
|
|
@@ -761,13 +749,13 @@ public class GUI<E> 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) {
|
|
@@ -775,7 +763,7 @@ public class GUI<E> 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) {
|
|
@@ -973,6 +961,7 @@ public class GUI<E> implements CategoryListener {
|
|
|
tableModelProperties.insertRow(2, tempEnergy);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
private static void addPopup(Component component, final JPopupMenu popup) {
|
|
|
component.addMouseListener(new MouseAdapter() {
|
|
|
public void mousePressed(MouseEvent e) {
|
|
@@ -990,4 +979,5 @@ public class GUI<E> implements CategoryListener {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
}
|