Edgardo Palza 8 years ago
parent
commit
a763193152

+ 1 - 1
src/ui/controller/Control.java

@@ -127,7 +127,7 @@ public class Control {
 	
 	
 	/* Operations for Loading and Storing */
-	public void writeFile() throws IOException{
+	public void writeFile() throws IOException {
 		loadStoreController.writeJSONFile();
 	}
 	////////// etc

+ 5 - 5
src/ui/controller/LoadStoreController.java

@@ -30,7 +30,7 @@ public class LoadStoreController {
 
 		writeCategory(jsonObj);
 
-		FileWriter file = new FileWriter("//Users//zheng//Desktop//Tesst.json");
+		FileWriter file = new FileWriter("//Users//Edgardo//Desktop//Tesst.json");
 		file.write(jsonObj.toJSONString());
 
 		file.flush();
@@ -39,7 +39,7 @@ public class LoadStoreController {
 	}
 
 	public void writeCategory(JSONObject jsonObj) throws IOException {
-		
+
 		int objI = 1;
 
 		JSONArray arr = new JSONArray();
@@ -55,11 +55,11 @@ public class LoadStoreController {
 	public void writeObjects(JSONObject jsonObj, ArrayList<CpsObject> objects, int objI) {
 		JSONArray arr = new JSONArray();
 		for (CpsObject cps : objects) {
-			arr.add(cps.getStored() );
+			arr.add(cps.getStored());
 			arr.add(cps.getObjName());
-			arr.add( cps.getName());
+			arr.add(cps.getName());
 			arr.add(cps.getImage());
-			
+
 		}
 		jsonObj.put("CategoryObject." + objI++, arr);
 	}

+ 43 - 26
src/ui/model/Model.java

@@ -10,16 +10,20 @@ import java.util.List;
 import classes.Category;
 import classes.CpsEdge;
 import classes.CpsObject;
+import classes.HolonElement;
 import ui.controller.*;
 
 public class Model {
 
-	//Global Variables
-	private static int SCALE = 50;	//Picture Scale
-	private static int SCALE_DIV2 = SCALE/2;
+	// Global Variables
+	private static int SCALE = 50; // Picture Scale
+	private static int SCALE_DIV2 = SCALE / 2;
 	private static final int ITERATIONS = 50;
-	
+
 	// ID of the Selected Object
+	private CpsObject selectedCpsObject;
+	private HolonElement selectedHolonElement;
+
 	private int selectedID = 0;
 	// eventuell wenn Canvasgröße gewählt werden kann
 	private int HEIGHT;
@@ -45,7 +49,6 @@ public class Model {
 	 */
 	private List<CategoryListener> categoryListeners;
 	private List<ObjectListener> objectListeners;
-	
 
 	/*
 	 * Constructor for the model. It initializes the categories and
@@ -107,7 +110,7 @@ public class Model {
 	public void setObjectsOnCanvas(ArrayList<CpsObject> objectsOnCanvas) {
 		this.objectsOnCanvas = objectsOnCanvas;
 	}
-	
+
 	/**
 	 * @return the objectsOnCanvas
 	 */
@@ -122,7 +125,7 @@ public class Model {
 	public void addEdgeOnCanvas(CpsEdge edge) {
 		this.edgesOnCanvas.add(edge);
 	}
-	
+
 	/**
 	 * @param edgesOnCanvas
 	 *            the edge to remove
@@ -130,7 +133,7 @@ public class Model {
 	public void removeEdgesOnCanvas(CpsEdge edge) {
 		this.edgesOnCanvas.remove(edge);
 	}
-	
+
 	/**
 	 * @param EdgesOnCanvas
 	 *            the edgesOnCanvas to set
@@ -138,7 +141,7 @@ public class Model {
 	public void setEdgesOnCanvas(ArrayList<CpsEdge> arrayList) {
 		this.edgesOnCanvas = arrayList;
 	}
-	
+
 	/**
 	 * @return the objectListeners
 	 */
@@ -168,57 +171,71 @@ public class Model {
 	public void setCategoryListeners(LinkedList<CategoryListener> linkedList) {
 		this.categoryListeners = linkedList;
 	}
-	
+
 	/**
-	 * Set the ID of the selected Object
-	 * 0 = no Object is selected
+	 * Set the ID of the selected Object 0 = no Object is selected
 	 * 
 	 * @param ID
 	 * 
 	 */
-	public void setSelectedObjectID(int id){
+	public void setSelectedObjectID(int id) {
 		this.selectedID = id;
 	}
-	
+
 	/**
-	 * Returns the ID of the selected Object
-	 * 0 = no Object is selected
+	 * Returns the ID of the selected Object 0 = no Object is selected
 	 * 
 	 * @return ID
 	 */
-	public int getSelectedObjectID(){
+	public int getSelectedObjectID() {
 		return selectedID;
 	}
-	
+
+	public CpsObject getSelectedCpsObject() {
+		return selectedCpsObject;
+	}
+
+	public void setSelectedCpsObject(CpsObject selectedCpsObject) {
+		this.selectedCpsObject = selectedCpsObject;
+	}
+
+	public HolonElement getSelectedHolonElement() {
+		return selectedHolonElement;
+	}
+
+	public void setSelectedHolonElement(HolonElement selectedHolonElement) {
+		this.selectedHolonElement = selectedHolonElement;
+	}
+
 	/**
 	 * Returns SCALE
 	 * 
 	 * @return SCALE
 	 */
-	public int getScale(){
+	public int getScale() {
 		return SCALE;
 	}
-	
+
 	/**
 	 * Returns SCALE_DIV2
 	 * 
 	 * @return SCALE_DIV2
 	 */
-	public int getScaleDiv2(){
+	public int getScaleDiv2() {
 		return SCALE_DIV2;
 	}
-	
-	public void setScale(int scale){
+
+	public void setScale(int scale) {
 		SCALE = scale;
-		SCALE_DIV2 = SCALE/2;
+		SCALE_DIV2 = SCALE / 2;
 	}
-	
+
 	/**
 	 * Returns ITERATIONS
 	 * 
 	 * @return ITERATIONS
 	 */
-	public int getIterations(){
+	public int getIterations() {
 		return ITERATIONS;
 	}
 

+ 3 - 0
src/ui/view/GUI.java

@@ -747,6 +747,7 @@ public class GUI implements CategoryListener {
 	}
 
 	public CpsObject getActualCps() {
+		model.setSelectedCpsObject(canvas.tempCps);
 		return canvas.tempCps;
 	}
 
@@ -755,8 +756,10 @@ public class GUI implements CategoryListener {
 		final int yTemp = (int) Math.floor(yValue / 16);
 		int rowsTotal = tableModelHolonElement.getRowCount();
 		if (rowsTotal != 0 && rowsTotal > yTemp) {
+			model.setSelectedHolonElement(obj.getElements().get(yTemp));
 			return obj.getElements().get(yTemp);
 		} else {
+			model.setSelectedHolonElement(null);
 			return null;
 		}
 	}

+ 2 - 2
src/ui/view/Main.java

@@ -31,8 +31,8 @@ public class Main {
 					GUI VIEW = new GUI(CONTROL);
 
 					VIEW.getFrmCyberPhysical().setVisible(true);
-					
-					CONTROL.writeFile();
+
+					// CONTROL.writeFile();
 
 				} catch (Exception e) {
 					e.printStackTrace();

+ 3 - 1
src/ui/view/UnitGraph.java

@@ -23,6 +23,8 @@ import java.awt.event.ActionListener;
 import java.awt.event.ActionEvent;
 import java.awt.FlowLayout;
 import javax.swing.SwingConstants;
+
+import classes.HolonElement;
 import javax.swing.JLabel;
 import java.awt.Cursor;
 
@@ -35,6 +37,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	private CubicCurve2D c = new CubicCurve2D.Double();
 	private Point[] pointList;
 
+	private HolonElement temp = null;
 	private boolean pointDrag = false;
 	private int tempP;
 	private int x1, x2, y1, y2, ctrlx1, ctrly1, ctrlx2, ctrly2;
@@ -45,7 +48,6 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
 		this.controller = control;
 		this.model = model;
-
 		this.pointList = new Point[model.getIterations()];
 		for (int i = 0; i < pointList.length; i++) {
 			pointList[i] = new Point(0, 0);