Edgardo Palza %!s(int64=8) %!d(string=hai) anos
pai
achega
08a93ec41a

BIN=BIN
bin/tests/Tests1.class


BIN=BIN
bin/ui/controller/Control$command.class


BIN=BIN
bin/ui/controller/Control.class


BIN=BIN
bin/ui/model/Model.class


BIN=BIN
bin/ui/view/AddElementPopUp.class


BIN=BIN
bin/ui/view/AddObjectPopUp.class


BIN=BIN
bin/ui/view/GUI$1.class


BIN=BIN
bin/ui/view/GUI$2.class


BIN=BIN
bin/ui/view/GUI$3.class


BIN=BIN
bin/ui/view/GUI$4.class


BIN=BIN
bin/ui/view/GUI$5.class


BIN=BIN
bin/ui/view/GUI$6.class


BIN=BIN
bin/ui/view/GUI.class


BIN=BIN
bin/ui/view/Main$1.class


BIN=BIN
bin/ui/view/Main.class


+ 7 - 7
src/tests/Tests1.java

@@ -12,12 +12,12 @@ public class Tests1 {
 	 * Create some CPS object and Gadgets
 	 */
 	public static void main(String[] args) {
-//		HolonObject b1 = new HolonObject();
-//		HolonObject b2 = new HolonObject();
-//		HolonSwitch s1 = new HolonSwitch();
-//		HolonTransformer t1 = new HolonTransformer();
-//		b1.setPos(20, 30);
-//		Position p = b1.getPos();
-//		System.out.println(p.x + "," + p.y);
+		// HolonObject b1 = new HolonObject();
+		// HolonObject b2 = new HolonObject();
+		// HolonSwitch s1 = new HolonSwitch();
+		// HolonTransformer t1 = new HolonTransformer();
+		// b1.setPos(20, 30);
+		// Position p = b1.getPos();
+		// System.out.println(p.x + "," + p.y);
 	}
 }

+ 16 - 0
src/ui/model/Model.java

@@ -21,10 +21,20 @@ public class Model {
 	 * categories ENERGY, BUILDINGS and COMPONENTS
 	 */
 	private ArrayList<Category> categories;
+	/*
+	 * Array of all CpsObjects in our canvas. It is set by default as an empty
+	 * list.
+	 */
 	private ArrayList<CpsObject> objectsOnCanvas;
+
 	private List<CategoryListener> categoryListeners;
 	private List<ObjectListener> objectListeners;
 
+	/*
+	 * Constructor for the model. It initializes the categories and
+	 * objectsOnCanvas by default values. Listeners are also initialized by
+	 * default values.
+	 */
 	public Model() {
 		setCategories(new ArrayList<Category>());
 		setObjectsOnCanvas(new ArrayList<CpsObject>());
@@ -47,6 +57,12 @@ public class Model {
 		this.categories = categories;
 	}
 
+	/**
+	 * Transform the Arraylist of categories into a string of all objectName
+	 * with a separation (',') between each name
+	 * 
+	 * @return String of all names separeted by ','
+	 */
 	public String toStringCat() {
 		String text = "";
 		for (int i = 0; i < categories.size(); i++) {

+ 34 - 35
src/ui/view/GUI.java

@@ -103,6 +103,7 @@ public class GUI implements CategoryListener {
 
 	// variables
 	boolean dragging = false;
+	String actualObjectClicked;
 
 	private final MyCanvas canvas;
 
@@ -204,7 +205,7 @@ public class GUI implements CategoryListener {
 			public void mouseReleased(MouseEvent e) {
 				try {
 					if (dragging) {
-						HolonObject h = new HolonObject("House");
+						HolonObject h = new HolonObject(actualObjectClicked);
 						h.setPos((int) canvas.getMousePosition().getX(), (int) canvas.getMousePosition().getY());
 						controller.addObject(h);
 						canvas.repaint();
@@ -215,40 +216,37 @@ public class GUI implements CategoryListener {
 				frmCyberPhysical.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
 			}
 		});
-		
+
 		tree.addMouseListener(new MouseAdapter() {
 			public void mousePressed(MouseEvent e) {
 				try {
-					String name = tree.getPathForLocation(e.getX(), e.getY()).getLastPathComponent().toString();
-					//System.out.println(name);
-					if (name.compareTo("Power Plant") == 0 || name.compareTo("House") == 0
-							|| name.compareTo("Switch") == 0 || name.compareTo("Transformer") == 0) {
+					actualObjectClicked = tree.getPathForLocation(e.getX(), e.getY()).getLastPathComponent().toString();
+					// System.out.println(name);
+					if (actualObjectClicked.compareTo("Power Plant") == 0 || actualObjectClicked.compareTo("House") == 0
+							|| actualObjectClicked.compareTo("Switch") == 0
+							|| actualObjectClicked.compareTo("Transformer") == 0) {
 						dragging = true;
-						Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(0, 0),"Image");
+						Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(0, 0), "Image");
 						frmCyberPhysical.setCursor(cursor);
 					}
-				} catch (Exception e2) {}
+				} catch (Exception e2) {
+				}
 			}
 		});
 
 		/*
-		tree.addTreeSelectionListener(new TreeSelectionListener() {
-			@Override
-			public void valueChanged(TreeSelectionEvent e) {
-				try {
-					String name = tree.getLastSelectedPathComponent().toString();
-					System.out.println(name);
-					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) {}
-			}
-		});*/
-	
+		 * tree.addTreeSelectionListener(new TreeSelectionListener() {
+		 * 
+		 * @Override public void valueChanged(TreeSelectionEvent e) { try {
+		 * String name = tree.getLastSelectedPathComponent().toString();
+		 * System.out.println(name); 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) {} } });
+		 */
+
 		scrollPane_1.setViewportView(tree);
 
 		scrollPane_1.setColumnHeaderView(panel);
@@ -291,31 +289,32 @@ public class GUI implements CategoryListener {
 			public void actionPerformed(ActionEvent arg0) {
 
 				Object nodeInfo = tree.getLastSelectedPathComponent();
-				if(nodeInfo != null){
+				if (nodeInfo != null) {
 					DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
 					String nodeName = selectedNode.getUserObject().toString();
 					int depthOfNode = selectedNode.getLevel();
 
 					switch (depthOfNode) {
 					case 1:
-						int dialogResult = JOptionPane.showConfirmDialog (null, "Do you realy want to delete the Category " + nodeName + "?","Warning", JOptionPane.YES_NO_OPTION);
-						if(dialogResult == JOptionPane.YES_OPTION){
+						int dialogResult = JOptionPane.showConfirmDialog(null,
+								"Do you realy want to delete the Category " + nodeName + "?", "Warning",
+								JOptionPane.YES_NO_OPTION);
+						if (dialogResult == JOptionPane.YES_OPTION) {
 							controller.deleteCategory(nodeName);
 							break;
-						}
-						else{
-						break;
+						} else {
+							break;
 						}
 					case 2:
 						DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent();
 						controller.deleteObjectInCat(nodeName, parent.getUserObject().toString());
 						break;
-				
-					default :
+
+					default:
 						JOptionPane.showMessageDialog(new JFrame(),
-							"Please select a Category or an Object in order to delete something.");
+								"Please select a Category or an Object in order to delete something.");
 					}
-				}else{
+				} else {
 					JOptionPane.showMessageDialog(new JFrame(),
 							"Please select a Category or an Object in order to delete something.");
 				}