Browse Source

Deleteobjectoncanvas

Kevin Trometer 8 years ago
parent
commit
40d248cff1

+ 12 - 0
src/ui/controller/CanvasController.java

@@ -38,5 +38,17 @@ public class CanvasController {
 			l.onChange(MODEL.getObjectsOnCanvas());
 		}
 	}
+	
+	/**
+	 * Deletes an CpsObject on the Canvas and its connections
+	 * 
+	 * @param CpsObject
+	 */
+	public void deleteObjectOnCanvas(CpsObject obj) {
+		for (CpsObject cps : MODEL.getObjectsOnCanvas()) {
+			cps.getConnectedTo().remove(obj);
+		}
+		MODEL.getObjectsOnCanvas().remove(obj);
+	}
 
 }

+ 4 - 0
src/ui/controller/Control.java

@@ -77,6 +77,10 @@ public class Control {
 	public void setSelectedObjectID(int id) {
 		objectController.setSelectedObjectID(id);
 	}
+	
+	public void deleteObjectOnCanvas(CpsObject obj) {
+		canvasController.deleteObjectOnCanvas(obj);
+	}
 
 	/* Operations for Objects and Elements */
 	public void addElementCanvasObject(String objName, String eleName, int amount, float energy) {

+ 1 - 4
src/ui/view/MyCanvas.java

@@ -61,10 +61,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			@Override
 			public void actionPerformed(ActionEvent e) {
 				// Remove the selected Object object
-				model.getObjectsOnCanvas().remove(tempCps);
-				for (CpsObject cps : model.getObjectsOnCanvas()) {
-					cps.getConnectedTo().remove(tempCps);
-				}
+				controller.deleteObjectOnCanvas(tempCps);
 				tempCps = null;
 				selectRect.setRect(0, 0, 0, 0);
 				repaint();