|
@@ -75,8 +75,6 @@ public class GUI implements CategoryListener {
|
|
private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
|
private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
|
private final JScrollPane scrollPane_2 = new JScrollPane();
|
|
private final JScrollPane scrollPane_2 = new JScrollPane();
|
|
|
|
|
|
- private final MyCanvas canvas = new MyCanvas();
|
|
|
|
-
|
|
|
|
private final JTree tree = new JTree();
|
|
private final JTree tree = new JTree();
|
|
private final JEditorPane dtrpnHereWillBe = new JEditorPane();
|
|
private final JEditorPane dtrpnHereWillBe = new JEditorPane();
|
|
private final JSplitPane splitPane_2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
|
|
private final JSplitPane splitPane_2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
|
|
@@ -95,10 +93,11 @@ public class GUI implements CategoryListener {
|
|
private final JButton btnDel = new JButton("-");
|
|
private final JButton btnDel = new JButton("-");
|
|
|
|
|
|
private final JToolBar toolBar = new JToolBar();
|
|
private final JToolBar toolBar = new JToolBar();
|
|
-
|
|
|
|
- //variables
|
|
|
|
|
|
+
|
|
|
|
+ // variables
|
|
boolean dragging = false;
|
|
boolean dragging = false;
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ private final MyCanvas canvas;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Create the application.
|
|
* Create the application.
|
|
@@ -106,6 +105,7 @@ public class GUI implements CategoryListener {
|
|
public GUI(Control control) {
|
|
public GUI(Control control) {
|
|
this.controller = control;
|
|
this.controller = control;
|
|
this.model = control.getModel();
|
|
this.model = control.getModel();
|
|
|
|
+ this.canvas = new MyCanvas(model);
|
|
control.initListener(this);
|
|
control.initListener(this);
|
|
initialize();
|
|
initialize();
|
|
}
|
|
}
|
|
@@ -171,8 +171,11 @@ public class GUI implements CategoryListener {
|
|
scrollPane_3.setViewportView(table_2);
|
|
scrollPane_3.setViewportView(table_2);
|
|
|
|
|
|
table_2.setFillsViewportHeight(true);
|
|
table_2.setFillsViewportHeight(true);
|
|
- table_2.setModel(new DefaultTableModel(new Object[][] { { "Solar", "23", "10" }, { "Generator", "24", "1" },
|
|
|
|
- { "Something Else", "25", "3" }, }, new String[] { "Producer", "Units", "Number" }));
|
|
|
|
|
|
+ table_2.setModel(
|
|
|
|
+ new DefaultTableModel(
|
|
|
|
+ new Object[][] { { "Solar", "23", "10" }, { "Generator", "24", "1" },
|
|
|
|
+ { "Something Else", "25", "3" }, },
|
|
|
|
+ new String[] { "Gadget", "Production", "Quantity" }));
|
|
table_2.getColumnModel().getColumn(0).setPreferredWidth(103);
|
|
table_2.getColumnModel().getColumn(0).setPreferredWidth(103);
|
|
table_2.getColumnModel().getColumn(1).setPreferredWidth(107);
|
|
table_2.getColumnModel().getColumn(1).setPreferredWidth(107);
|
|
table_2.getColumnModel().getColumn(2).setPreferredWidth(125);
|
|
table_2.getColumnModel().getColumn(2).setPreferredWidth(125);
|
|
@@ -180,72 +183,68 @@ public class GUI implements CategoryListener {
|
|
splitPane_2.setDividerLocation(200);
|
|
splitPane_2.setDividerLocation(200);
|
|
|
|
|
|
splitPane.setLeftComponent(scrollPane_1);
|
|
splitPane.setLeftComponent(scrollPane_1);
|
|
- final Image img = new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage().getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH);
|
|
|
|
|
|
+ final Image img = new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
|
|
|
|
+ .getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH);
|
|
Icon icon = new ImageIcon(img);
|
|
Icon icon = new ImageIcon(img);
|
|
- DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer)tree.getCellRenderer();
|
|
|
|
- renderer.setLeafIcon(icon);
|
|
|
|
- //renderer.setClosedIcon(icon);
|
|
|
|
- //renderer.setOpenIcon(icon);
|
|
|
|
- tree.setRowHeight(icon.getIconHeight());
|
|
|
|
|
|
+ DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();
|
|
|
|
+ renderer.setLeafIcon(icon);
|
|
|
|
+ // renderer.setClosedIcon(icon);
|
|
|
|
+ // renderer.setOpenIcon(icon);
|
|
|
|
+ tree.setRowHeight(icon.getIconHeight());
|
|
tree.setCellRenderer(renderer);
|
|
tree.setCellRenderer(renderer);
|
|
-
|
|
|
|
- //Tree Drag and Drop
|
|
|
|
|
|
+
|
|
|
|
+ // Tree Drag and Drop
|
|
TransferHandler transfer = new TransferHandler("text");
|
|
TransferHandler transfer = new TransferHandler("text");
|
|
-
|
|
|
|
- //add a MouseListener to initiate the Drag on the appropriate
|
|
|
|
- //MouseEvent
|
|
|
|
- /*tree.addMouseMotionListener(new MouseAdapter(){
|
|
|
|
- public void mouseDragged(MouseEvent e) {
|
|
|
|
- System.out.println("Drag");
|
|
|
|
- Image img = null;
|
|
|
|
- try {
|
|
|
|
- URL url = new URL("https://cdn4.iconfinder.com/data/icons/buildings-filled-1/60/house-home-building-construction-32.png");
|
|
|
|
- img = ImageIO.read(url);
|
|
|
|
- } catch (IOException e1) {
|
|
|
|
- System.out.println("Failed to load the Image!");
|
|
|
|
- }
|
|
|
|
- JTree treep = (JTree)e.getSource();
|
|
|
|
- TransferHandler handle = treep.getTransferHandler();
|
|
|
|
- handle.setDragImage(img);
|
|
|
|
- handle.exportAsDrag(treep, e, TransferHandler.MOVE);
|
|
|
|
- }
|
|
|
|
- });*/
|
|
|
|
- tree.addMouseListener(new MouseAdapter(){
|
|
|
|
- public void mouseReleased(MouseEvent e){
|
|
|
|
- try {
|
|
|
|
- if(dragging){
|
|
|
|
- HolonObject h = new HolonObject("House");
|
|
|
|
- h.setPos((int)canvas.getMousePosition().getX(),(int)canvas.getMousePosition().getY());
|
|
|
|
- canvas.choords.add(h);
|
|
|
|
- canvas.repaint();
|
|
|
|
-
|
|
|
|
- System.out.println(model.getObjectsOnCanvas());
|
|
|
|
- dragging = false;
|
|
|
|
- }
|
|
|
|
- } catch (Exception e2) {}
|
|
|
|
- frmCyberPhysical.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ // add a MouseListener to initiate the Drag on the appropriate
|
|
|
|
+ // MouseEvent
|
|
|
|
+ /*
|
|
|
|
+ * tree.addMouseMotionListener(new MouseAdapter(){ public void
|
|
|
|
+ * mouseDragged(MouseEvent e) { System.out.println("Drag"); Image img =
|
|
|
|
+ * null; try { URL url = new URL(
|
|
|
|
+ * "https://cdn4.iconfinder.com/data/icons/buildings-filled-1/60/house-home-building-construction-32.png"
|
|
|
|
+ * ); img = ImageIO.read(url); } catch (IOException e1) {
|
|
|
|
+ * System.out.println("Failed to load the Image!"); } JTree treep =
|
|
|
|
+ * (JTree)e.getSource(); TransferHandler handle =
|
|
|
|
+ * treep.getTransferHandler(); handle.setDragImage(img);
|
|
|
|
+ * handle.exportAsDrag(treep, e, TransferHandler.MOVE); } });
|
|
|
|
+ */
|
|
|
|
+ tree.addMouseListener(new MouseAdapter() {
|
|
|
|
+ public void mouseReleased(MouseEvent e) {
|
|
|
|
+ try {
|
|
|
|
+ if (dragging) {
|
|
|
|
+ HolonObject h = new HolonObject("House");
|
|
|
|
+ h.setPos((int) canvas.getMousePosition().getX(), (int) canvas.getMousePosition().getY());
|
|
|
|
+ controller.addObject(h);
|
|
|
|
+ canvas.repaint();
|
|
|
|
+ dragging = false;
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e2) {
|
|
|
|
+ }
|
|
|
|
+ frmCyberPhysical.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
tree.addTreeSelectionListener(new TreeSelectionListener() {
|
|
tree.addTreeSelectionListener(new TreeSelectionListener() {
|
|
@Override
|
|
@Override
|
|
public void valueChanged(TreeSelectionEvent e) {
|
|
public void valueChanged(TreeSelectionEvent e) {
|
|
try {
|
|
try {
|
|
String name = tree.getLastSelectedPathComponent().toString();
|
|
String name = tree.getLastSelectedPathComponent().toString();
|
|
System.out.println(name);
|
|
System.out.println(name);
|
|
- tree.clearSelection();
|
|
|
|
- if(name.compareTo("Power Plant")==0 || name.compareTo("House")==0 || name.compareTo("Switch")==0 || name.compareTo("Transformer")==0){
|
|
|
|
- dragging = true;
|
|
|
|
- Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(0,0), "red Cursor");
|
|
|
|
- frmCyberPhysical.setCursor(cursor);
|
|
|
|
- }
|
|
|
|
|
|
+ tree.clearSelection();
|
|
|
|
+ if (name.compareTo("Power Plant") == 0 || name.compareTo("House") == 0
|
|
|
|
+ || name.compareTo("Switch") == 0 || name.compareTo("Transformer") == 0) {
|
|
|
|
+ dragging = true;
|
|
|
|
+ Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(0, 0),
|
|
|
|
+ "red Cursor");
|
|
|
|
+ frmCyberPhysical.setCursor(cursor);
|
|
|
|
+ }
|
|
} catch (Exception e2) {
|
|
} catch (Exception e2) {
|
|
// TODO: handle exception
|
|
// TODO: handle exception
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
scrollPane_1.setViewportView(tree);
|
|
scrollPane_1.setViewportView(tree);
|
|
|
|
|
|
scrollPane_1.setColumnHeaderView(panel);
|
|
scrollPane_1.setColumnHeaderView(panel);
|
|
@@ -263,25 +262,25 @@ public class GUI implements CategoryListener {
|
|
Object nodeInfo = tree.getLastSelectedPathComponent();
|
|
Object nodeInfo = tree.getLastSelectedPathComponent();
|
|
String selectedOption = comboBox.getSelectedItem().toString();
|
|
String selectedOption = comboBox.getSelectedItem().toString();
|
|
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
|
|
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
|
|
-
|
|
|
|
- switch(selectedOption){
|
|
|
|
-
|
|
|
|
- case "Category":
|
|
|
|
- String catName = JOptionPane.showInputDialog("Please enter a Name for Category ");
|
|
|
|
- if(catName.length() != 0){
|
|
|
|
|
|
+
|
|
|
|
+ switch (selectedOption) {
|
|
|
|
+
|
|
|
|
+ case "Category":
|
|
|
|
+ String catName = JOptionPane.showInputDialog("Please enter a Name for Category ");
|
|
|
|
+ if (catName.length() != 0) {
|
|
controller.addNewCategory(catName);
|
|
controller.addNewCategory(catName);
|
|
- }
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- default :
|
|
|
|
- addObjectPopUP = new AddObjectPopUp();
|
|
|
|
- addObjectPopUP.setVisible(true);
|
|
|
|
- addObjectAction(selectedOption, selectedNode);
|
|
|
|
- break;
|
|
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ addObjectPopUP = new AddObjectPopUp();
|
|
|
|
+ addObjectPopUP.setVisible(true);
|
|
|
|
+ addObjectAction(selectedOption, selectedNode);
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
toolBar.add(btnAdd);
|
|
toolBar.add(btnAdd);
|
|
|
|
|
|
// Del Button
|
|
// Del Button
|
|
@@ -292,18 +291,16 @@ public class GUI implements CategoryListener {
|
|
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
|
|
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
|
|
String nodeName = selectedNode.getUserObject().toString();
|
|
String nodeName = selectedNode.getUserObject().toString();
|
|
int depthOfNode = selectedNode.getLevel();
|
|
int depthOfNode = selectedNode.getLevel();
|
|
-
|
|
|
|
- switch(depthOfNode){
|
|
|
|
|
|
+
|
|
|
|
+ switch (depthOfNode) {
|
|
case 1:
|
|
case 1:
|
|
controller.deleteCategory(nodeName);
|
|
controller.deleteCategory(nodeName);
|
|
break;
|
|
break;
|
|
case 2:
|
|
case 2:
|
|
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent();
|
|
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent();
|
|
- controller.deleteObjectInCat(nodeName,parent.getUserObject().toString());
|
|
|
|
|
|
+ controller.deleteObjectInCat(nodeName, parent.getUserObject().toString());
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -327,36 +324,37 @@ public class GUI implements CategoryListener {
|
|
});
|
|
});
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/*
|
|
/*
|
|
- * adds a specific object type to selected Category
|
|
|
|
- * also handles input windows and illegal inputs
|
|
|
|
|
|
+ * adds a specific object type to selected Category also handles input
|
|
|
|
+ * windows and illegal inputs
|
|
*/
|
|
*/
|
|
- public void addObjectAction(String objType, DefaultMutableTreeNode selectedNode){
|
|
|
|
- if(selectedNode == null){
|
|
|
|
- JOptionPane.showMessageDialog(new JFrame(), "Please select a Category first before adding " + objType + ".");
|
|
|
|
|
|
+ public void addObjectAction(String objType, DefaultMutableTreeNode selectedNode) {
|
|
|
|
+ if (selectedNode == null) {
|
|
|
|
+ JOptionPane.showMessageDialog(new JFrame(),
|
|
|
|
+ "Please select a Category first before adding " + objType + ".");
|
|
}
|
|
}
|
|
- //if selected node is a directory for Categories
|
|
|
|
- else{
|
|
|
|
- if(selectedNode.getLevel()==1){
|
|
|
|
|
|
+ // if selected node is a directory for Categories
|
|
|
|
+ else {
|
|
|
|
+ if (selectedNode.getLevel() == 1) {
|
|
String objname = JOptionPane.showInputDialog("Please enter a Name for the " + objType);
|
|
String objname = JOptionPane.showInputDialog("Please enter a Name for the " + objType);
|
|
Category cat = controller.searchCategory(selectedNode.getUserObject().toString());
|
|
Category cat = controller.searchCategory(selectedNode.getUserObject().toString());
|
|
- switch(objType){
|
|
|
|
-
|
|
|
|
- case "Object":
|
|
|
|
- controller.addNewObject( cat , objname);
|
|
|
|
|
|
+ switch (objType) {
|
|
|
|
+
|
|
|
|
+ case "Object":
|
|
|
|
+ controller.addNewObject(cat, objname);
|
|
break;
|
|
break;
|
|
-
|
|
|
|
- case "Switch" :
|
|
|
|
|
|
+
|
|
|
|
+ case "Switch":
|
|
controller.addNewSwitch(cat, objname);
|
|
controller.addNewSwitch(cat, objname);
|
|
-
|
|
|
|
- case "Transformer" :
|
|
|
|
|
|
+
|
|
|
|
+ case "Transformer":
|
|
controller.addNewTransformer(cat, objname);
|
|
controller.addNewTransformer(cat, objname);
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ JOptionPane.showMessageDialog(new JFrame(),
|
|
|
|
+ "Objects can not be added to Objects. Please select a Category.");
|
|
}
|
|
}
|
|
- else{
|
|
|
|
- JOptionPane.showMessageDialog(new JFrame(), "Objects can not be added to Objects. Please select a Category.");
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|