|
@@ -1,13 +1,9 @@
|
|
|
package ui.view;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.net.URL;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Enumeration;
|
|
|
-
|
|
|
import javax.swing.JFrame;
|
|
|
import javax.swing.JLabel;
|
|
|
-import javax.swing.JList;
|
|
|
import javax.swing.JMenuBar;
|
|
|
import javax.swing.JMenu;
|
|
|
import javax.swing.JMenuItem;
|
|
@@ -19,15 +15,11 @@ import javax.swing.JScrollPane;
|
|
|
import javax.swing.JTabbedPane;
|
|
|
import javax.swing.JTable;
|
|
|
import javax.swing.tree.DefaultTreeModel;
|
|
|
-import javax.swing.tree.MutableTreeNode;
|
|
|
import javax.swing.tree.TreeCellRenderer;
|
|
|
-import javax.swing.tree.TreeNode;
|
|
|
-
|
|
|
import ui.controller.Control;
|
|
|
import ui.model.*;
|
|
|
|
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
|
|
-import javax.swing.tree.DefaultTreeCellRenderer;
|
|
|
import javax.swing.JEditorPane;
|
|
|
import javax.swing.JFileChooser;
|
|
|
import javax.swing.table.DefaultTableModel;
|
|
@@ -38,17 +30,11 @@ import java.awt.Cursor;
|
|
|
import java.awt.Image;
|
|
|
import java.awt.Point;
|
|
|
import java.awt.Toolkit;
|
|
|
-import java.awt.datatransfer.Clipboard;
|
|
|
-import java.awt.datatransfer.DataFlavor;
|
|
|
-import java.awt.dnd.DragSource;
|
|
|
import java.awt.BorderLayout;
|
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
import javax.swing.JToolBar;
|
|
|
import javax.swing.JButton;
|
|
|
-import javax.swing.TransferHandler;
|
|
|
-import javax.swing.event.TreeSelectionEvent;
|
|
|
-import javax.swing.event.TreeSelectionListener;
|
|
|
import javax.swing.JComboBox;
|
|
|
import javax.swing.DefaultComboBoxModel;
|
|
|
import javax.swing.Icon;
|
|
@@ -56,18 +42,15 @@ import javax.swing.ImageIcon;
|
|
|
|
|
|
import classes.Category;
|
|
|
import classes.CpsObject;
|
|
|
-import classes.HolonElement;
|
|
|
+import classes.GlobalVariables;
|
|
|
import classes.HolonObject;
|
|
|
import classes.HolonSwitch;
|
|
|
import classes.HolonTransformer;
|
|
|
import Interfaces.CategoryListener;
|
|
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
-import java.awt.event.ComponentEvent;
|
|
|
-import java.awt.event.ComponentListener;
|
|
|
import java.awt.event.MouseAdapter;
|
|
|
import java.awt.event.MouseEvent;
|
|
|
-import java.awt.event.MouseListener;
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
|
|
public class GUI implements CategoryListener {
|
|
@@ -200,7 +183,7 @@ public class GUI implements CategoryListener {
|
|
|
splitPane_2.setDividerLocation(200);
|
|
|
|
|
|
splitPane.setLeftComponent(scrollPane_1);
|
|
|
- img = new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage().getScaledInstance(30, 30,
|
|
|
+ img = new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage().getScaledInstance(GlobalVariables.SCALE, GlobalVariables.SCALE,
|
|
|
java.awt.Image.SCALE_SMOOTH);
|
|
|
Icon icon = new ImageIcon(img);
|
|
|
|
|
@@ -214,21 +197,22 @@ public class GUI implements CategoryListener {
|
|
|
CpsObject tempCPS = null;
|
|
|
|
|
|
for (Category cat : model.getCategories()) {
|
|
|
+ if (value.toString().compareTo(cat.getCompareName()) == 0) {
|
|
|
+ label.setText(cat.getCompareName());
|
|
|
+ }
|
|
|
for (CpsObject cps : cat.getObjects()) {
|
|
|
if (value.toString().compareTo(cps.getCompareName()) == 0) {
|
|
|
tempCPS = cps;
|
|
|
- // System.out.println(tempCPS.getImage());
|
|
|
imgR = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage()
|
|
|
- .getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH);
|
|
|
+ .getScaledInstance(GlobalVariables.SCALE, GlobalVariables.SCALE, java.awt.Image.SCALE_SMOOTH);
|
|
|
if (imgR != null) {
|
|
|
label.setIcon(new ImageIcon(imgR));
|
|
|
}
|
|
|
- } else {
|
|
|
-
|
|
|
+ label.setText(cps.getName());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- label.setText(value.toString());
|
|
|
+ if(label.getText().length() == 0) label.setText(value.toString());
|
|
|
return label;
|
|
|
|
|
|
}
|
|
@@ -247,23 +231,17 @@ public class GUI implements CategoryListener {
|
|
|
public void mouseReleased(MouseEvent e) {
|
|
|
try {
|
|
|
if (dragging) {
|
|
|
-
|
|
|
- // if(){
|
|
|
- // HolonSwitch h = new HolonSwitch(actualObjectClicked);
|
|
|
- // }else if(){
|
|
|
- // HolonTransformer h = new
|
|
|
- // HolonTransformer(actualObjectClicked);
|
|
|
- // }else{
|
|
|
- HolonObject h = new HolonObject(actualObjectClicked);
|
|
|
+ CpsObject h = null;
|
|
|
+ System.out.println(tempCps.getClass().toString());
|
|
|
+ if(tempCps.getClass() == HolonObject.class) {h = new HolonObject(tempCps);}
|
|
|
+ if(tempCps.getClass() == HolonSwitch.class) {h = new HolonSwitch(tempCps);}
|
|
|
+ if(tempCps.getClass() == HolonTransformer.class) {h = new HolonTransformer(tempCps);}
|
|
|
+
|
|
|
h.setPos((int) canvas.getMousePosition().getX(), (int) canvas.getMousePosition().getY());
|
|
|
controller.addObject(h);
|
|
|
for (int i = 0; i < model.getObjectsOnCanvas().size(); i++) {
|
|
|
System.out.println("Element: " + model.getObjectsOnCanvas().get(i).getObjName()
|
|
|
- + " with ID: " + model.getObjectsOnCanvas().get(i).getID()
|
|
|
- + " and the following gadgets: Consumers: "
|
|
|
- + ((HolonObject) model.getObjectsOnCanvas().get(i)).toStringConsumers()
|
|
|
- + " and Producers: "
|
|
|
- + ((HolonObject) model.getObjectsOnCanvas().get(i)).toStringProducers());
|
|
|
+ + " with ID: " + model.getObjectsOnCanvas().get(i).getID());
|
|
|
}
|
|
|
canvas.repaint();
|
|
|
dragging = false;
|
|
@@ -277,22 +255,13 @@ public class GUI implements CategoryListener {
|
|
|
tree.addMouseListener(new MouseAdapter() {
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
try {
|
|
|
- HolonObject h = new HolonObject("test");
|
|
|
actualObjectClicked = tree.getPathForLocation(e.getX(), e.getY()).getLastPathComponent().toString();
|
|
|
- /*
|
|
|
- * //System.out.println(actualObjectClicked); if
|
|
|
- * (actualObjectClicked.compareTo("Power Plant") == 0 ||
|
|
|
- * actualObjectClicked.compareTo("House") == 0 ||
|
|
|
- * actualObjectClicked.compareTo("Switch") == 0 ||
|
|
|
- * actualObjectClicked.compareTo("Transformer") == 0) {
|
|
|
- *
|
|
|
- * }
|
|
|
- */
|
|
|
+
|
|
|
for (Category cat : model.getCategories()) {
|
|
|
for (CpsObject cps : cat.getObjects()) {
|
|
|
if (actualObjectClicked.compareTo(cps.getCompareName()) == 0) {
|
|
|
img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage()
|
|
|
- .getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH);
|
|
|
+ .getScaledInstance(GlobalVariables.SCALE, GlobalVariables.SCALE, java.awt.Image.SCALE_SMOOTH);
|
|
|
tempCps = cps;
|
|
|
dragging = true;
|
|
|
Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(0, 0),
|