Bläddra i källkod

Merge branch 'Ohne_Drag_and_Drop' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons into Ohne_Drag_and_Drop

Conflicts:
	src/ui/controller/LoadStoreController.java
Edgardo Palza 7 år sedan
förälder
incheckning
3137227cef
3 ändrade filer med 78 tillägg och 11 borttagningar
  1. 3 0
      src/classes/CpsNode.java
  2. 46 4
      src/ui/controller/LoadStoreController.java
  3. 29 7
      src/ui/view/MyCanvas.java

+ 3 - 0
src/classes/CpsNode.java

@@ -1,11 +1,14 @@
 package classes;
 
+import java.util.ArrayList;
+
 import ui.model.idCounter;
 
 public class CpsNode extends CpsObject {
 
 	public CpsNode(String objName) {
 		super(objName);
+		this.setConnections(new ArrayList<CpsEdge>());
 		this.setImage("/Images/node.png");
 		this.setID(idCounter.nextId());
 		this.setStored("Canvas");

+ 46 - 4
src/ui/controller/LoadStoreController.java

@@ -14,6 +14,8 @@ import com.sun.scenario.effect.impl.sw.java.JSWBlend_COLOR_BURNPeer;
 
 import classes.Category;
 import classes.CpsObject;
+import classes.HolonElement;
+import classes.HolonObject;
 import ui.model.Model;
 
 public class LoadStoreController {
@@ -29,8 +31,14 @@ public class LoadStoreController {
 		JSONObject jsonObj = new JSONObject();
 
 		writeCategory(jsonObj);
+		writeCategoryObjects(jsonObj);
+		writeCategoryElements(jsonObj);
 
+<<<<<<< HEAD
 		FileWriter file = new FileWriter("//Users//Edgardo//Desktop//Tesst.json");
+=======
+		FileWriter file = new FileWriter("C:/Users/krabs/Desktop/Tesst.json");
+>>>>>>> 5f1735a4d30ece2b9dc2d1e34982f17502c21d2f
 		file.write(jsonObj.toJSONString());
 
 		file.flush();
@@ -39,21 +47,24 @@ public class LoadStoreController {
 	}
 
 	public void writeCategory(JSONObject jsonObj) throws IOException {
+<<<<<<< HEAD
 
 		int objI = 1;
+=======
+>>>>>>> 5f1735a4d30ece2b9dc2d1e34982f17502c21d2f
 
 		JSONArray arr = new JSONArray();
-		for (Category cat : MODEL.getCategories()) {
+		for (Category cat : MODEL.getCategories())
 			arr.add(cat.getName());
-			writeObjects(jsonObj, cat.getObjects(), objI);
-		}
 
 		jsonObj.put("Category", arr);
 
 	}
 
-	public void writeObjects(JSONObject jsonObj, ArrayList<CpsObject> objects, int objI) {
+	public void writeCategoryObjects(JSONObject jsonObj) {
+		int i = 1;
 		JSONArray arr = new JSONArray();
+<<<<<<< HEAD
 		for (CpsObject cps : objects) {
 			arr.add(cps.getStored());
 			arr.add(cps.getObjName());
@@ -62,6 +73,37 @@ public class LoadStoreController {
 
 		}
 		jsonObj.put("CategoryObject." + objI++, arr);
+=======
+
+		for (Category cats : MODEL.getCategories())
+			for (CpsObject cps : cats.getObjects()) {
+				arr.add(cps.getStored());
+				arr.add(cps.getObjName());
+				arr.add(cps.getName());
+				arr.add(cps.getImage());
+				jsonObj.put("CategoryObject." + i++, arr);
+				arr = new JSONArray();
+			}
+
+	}
+
+	public void writeCategoryElements(JSONObject jsonObj) {
+		int i = 1;
+		JSONArray arr = new JSONArray();
+
+		for (Category cats : MODEL.getCategories())
+			for (CpsObject cps : cats.getObjects())
+				if (cps instanceof HolonObject)
+					for (HolonElement ele : ((HolonObject) cps).getElements()) {
+						arr.add(ele.getStored());
+						arr.add(ele.getEleName());
+						arr.add(ele.getAmount());
+						arr.add(ele.getEnergy());
+						jsonObj.put("CategoryElement." + i++, arr);
+						arr = new JSONArray();
+					}
+
+>>>>>>> 5f1735a4d30ece2b9dc2d1e34982f17502c21d2f
 	}
 
 	public void readFromJSON(File jsonFile) throws IOException {

+ 29 - 7
src/ui/view/MyCanvas.java

@@ -121,8 +121,8 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 		if (model.getSelectedObjectID() > 0) {
 			g2.setColor(Color.GREEN);
 			for (CpsEdge con : model.getEdgesOnCanvas()) {
-				if (con.getA().getID() == model.getSelectedObjectID() || con.getB().getID() == model.getSelectedObjectID()
-						&& con != edgeHighlight) {
+				if (con.getA().getID() == model.getSelectedObjectID()
+						|| con.getB().getID() == model.getSelectedObjectID() && con != edgeHighlight) {
 					g2.drawLine(con.getA().getPosition().x + controller.getScaleDiv2(),
 							con.getA().getPosition().y + controller.getScaleDiv2(),
 							con.getB().getPosition().x + controller.getScaleDiv2(),
@@ -322,8 +322,10 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 		boolean node = true;
 		boolean newEdge = true;
 		boolean onEdge = true;
+		boolean deleteNode = false;
 		CpsEdge e = null;
-
+		CpsObject tempCPS = null; 
+		
 		for (CpsObject cps : model.getObjectsOnCanvas()) {
 			cx = cps.getPosition().x;
 			cy = cps.getPosition().y;
@@ -337,9 +339,20 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 						e = p;
 					}
 				}
-				controller.removeEdgesOnCanvas(e);
-				tempCps.getConnections().remove(e);
-				cps.getConnections().remove(e);
+				if (!newEdge) {
+					controller.removeEdgesOnCanvas(e);
+					tempCps.getConnections().remove(e);
+					cps.getConnections().remove(e);
+					// Node ohne Edge
+					if (e.getA().getClass() == CpsNode.class && e.getA().getConnections().isEmpty()) {
+						tempCps = e.getA();
+						deleteNode = true;
+					} 
+					if (e.getB().getClass() == CpsNode.class && e.getB().getConnections().isEmpty()) {
+						tempCPS = e.getB();
+						deleteNode = true;
+					}
+				}
 				if (newEdge) {
 					e = new CpsEdge(cps, tempCps);
 					cps.AddConnection(e);
@@ -387,7 +400,8 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 				controller.AddEdgeOnCanvas(e2);
 			}
 		}
-
+		
+		//ins leere Gedragged
 		if (node) {
 			CpsNode n = new CpsNode("Node");
 			n.setPosition(x - model.getScaleDiv2(), y - model.getScaleDiv2());
@@ -400,6 +414,14 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			controller.AddEdgeOnCanvas(e);
 			System.out.println("node ID: " + n.getID());
 		}
+		
+		if(deleteNode){
+			controller.deleteObjectOnCanvas(tempCps);
+			controller.deleteObjectOnCanvas(tempCPS);
+			tempCPS = null;
+			tempCps = null;
+			objectSelectionHighlighting();
+		}
 	}
 
 	/**