Browse Source

Status of Edges updated (read comment on edge class)

Edgardo Palza 7 years ago
parent
commit
38d08f4e7f
3 changed files with 64 additions and 35 deletions
  1. 31 19
      src/classes/CpsEdge.java
  2. 14 10
      src/classes/HolonElement.java
  3. 19 6
      src/ui/view/GUI.java

+ 31 - 19
src/classes/CpsEdge.java

@@ -5,11 +5,15 @@ public class CpsEdge {
 	float maxCapacity;
 	float flow;
 	boolean isWorking;
-	
+	//State represents the real status of the edge
+	//If it breaks --> stay ruin no matter the actual scenario
+	//The only way to repair it is through manual change (setStateEdge) 
+	boolean state = true;
+
 	CpsObject A;
 	CpsObject B;
 
-	public CpsEdge(CpsObject A, CpsObject B){
+	public CpsEdge(CpsObject A, CpsObject B) {
 		setA(A);
 		setB(B);
 		this.A.AddConnection(this);
@@ -18,8 +22,8 @@ public class CpsEdge {
 		flow = 0;
 		isWorking = true;
 	}
-	
-	public CpsEdge(CpsObject A, CpsObject B, float maxCap){
+
+	public CpsEdge(CpsObject A, CpsObject B, float maxCap) {
 		setA(A);
 		setB(B);
 		this.A.AddConnection(this);
@@ -28,8 +32,7 @@ public class CpsEdge {
 		flow = 0;
 		isWorking = true;
 	}
-	
-	
+
 	/**
 	 * @return the capacity
 	 */
@@ -38,7 +41,8 @@ public class CpsEdge {
 	}
 
 	/**
-	 * @param cap the Capacity to set
+	 * @param cap
+	 *            the Capacity to set
 	 */
 	public void setCapacity(float cap) {
 		this.maxCapacity = cap;
@@ -51,18 +55,28 @@ public class CpsEdge {
 		return flow;
 	}
 
+	public boolean getStateEdge() {
+		return state;
+	}
+
 	/**
-	 * @param flow the flow to set
+	 * @param flow
+	 *            the flow to set
 	 */
 	public void setFlow(float flow) {
 		this.flow = flow;
-		if(flow <= maxCapacity || flow == -1){
+		if (flow <= maxCapacity || flow == -1) {
 			isWorking = true;
-		}else{
+		} else {
 			isWorking = false;
+			state = false;
 		}
 	}
-	
+
+	public void setState(boolean isActive) {
+		state = isActive;
+	}
+
 	/**
 	 * @return the a
 	 */
@@ -70,15 +84,14 @@ public class CpsEdge {
 		return A;
 	}
 
-
 	/**
-	 * @param a the a to set
+	 * @param a
+	 *            the a to set
 	 */
 	public void setA(CpsObject a) {
 		A = a;
 	}
 
-
 	/**
 	 * @return the b
 	 */
@@ -86,17 +99,16 @@ public class CpsEdge {
 		return B;
 	}
 
-
 	/**
-	 * @param b the b to set
+	 * @param b
+	 *            the b to set
 	 */
 	public void setB(CpsObject b) {
 		B = b;
 	}
-	
-	public boolean getState(){
+
+	public boolean getState() {
 		return isWorking;
 	}
-	
 
 }

+ 14 - 10
src/classes/HolonElement.java

@@ -19,16 +19,16 @@ public class HolonElement {
 	String image;
 	/* +: for Consumers and -: Producers */
 	char sign;
-	/* Place where the Object is Stored*/
+	/* Place where the Object is Stored */
 	String sav;
-	/* Object where the Element is Stored*/
+	/* Object where the Element is Stored */
 	String obj;
 	/*
 	 * Energy at each point of the graph with 100 predefined points. At the
 	 * beginning, it starts with all values at energy
 	 */
 	float[] energyAt = new float[100];
-	//Points on the UnitGraph
+	// Points on the UnitGraph
 	LinkedList<Point> graphPoints = new LinkedList<>();
 
 	public HolonElement(String eleName, int amount, float energy) {
@@ -59,7 +59,8 @@ public class HolonElement {
 	}
 
 	/**
-	 * @param energy, the value
+	 * @param energy,
+	 *            the value
 	 */
 	public void setEnergyAt(float energy) {
 		for (int i = 0; i < energyAt.length; i++) {
@@ -157,8 +158,8 @@ public class HolonElement {
 		totalEnergy = ((float) amount) * energy;
 		return totalEnergy;
 	}
-	
-	public float getTotalEnergyAtTimeStep(int x){
+
+	public float getTotalEnergyAtTimeStep(int x) {
 		float result = ((float) amount) * energyAt[x];
 		return result;
 	}
@@ -189,7 +190,8 @@ public class HolonElement {
 	}
 
 	/**
-	 * @param stored the stored to set
+	 * @param stored
+	 *            the stored to set
 	 */
 	public void setSav(String sav) {
 		this.sav = sav;
@@ -203,12 +205,13 @@ public class HolonElement {
 	}
 
 	/**
-	 * @param obj the obj to set
+	 * @param obj
+	 *            the obj to set
 	 */
 	public void setObj(String obj) {
 		this.obj = obj;
 	}
-	
+
 	/**
 	 * @return the Graph Points
 	 */
@@ -217,7 +220,8 @@ public class HolonElement {
 	}
 
 	/**
-	 * @param points, the Graph points
+	 * @param points,
+	 *            the Graph points
 	 */
 	public void setGraphPoints(LinkedList<Point> points) {
 		this.graphPoints = points;

+ 19 - 6
src/ui/view/GUI.java

@@ -6,6 +6,7 @@ import java.awt.Component;
 import java.awt.Cursor;
 import java.awt.Dimension;
 import java.awt.Image;
+import java.awt.MouseInfo;
 import java.awt.Point;
 import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
@@ -13,6 +14,7 @@ import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.io.File;
@@ -68,6 +70,7 @@ import classes.HolonElement;
 import classes.HolonObject;
 import classes.HolonSwitch;
 import classes.HolonTransformer;
+import classes.Position;
 import ui.controller.Control;
 import ui.model.Model;;
 
@@ -736,6 +739,7 @@ public class GUI<E> implements CategoryListener {
 								// Small bug, when it comes to edit the name of
 								// the HolonElement
 								if (selectedValueX == 0) {
+									System.out.println(eleTemp.getEleName());
 									eleTemp.setEleName(newStuff);
 								} else if (selectedValueX == 1) {
 									Float ftemp = Float.parseFloat(newStuff);
@@ -774,13 +778,18 @@ public class GUI<E> implements CategoryListener {
 						if (getActualCps() instanceof HolonObject) {
 							temp = tableModelProperties.getValueAt(0, 1);
 							getActualCps().setName(temp.toString());
-						} else if (getActualCps() instanceof HolonTransformer) {
-							// get Info of the Properties for Transformer
 						}
 					} else {
-						temp = tableModelProperties.getValueAt(2, 1);
-						Float ftemp = Float.parseFloat(temp.toString());
-						model.getSelectedEdge().setCapacity(ftemp);
+						Point mousePos = tableProperties.getMousePosition();
+						temp = tableModelProperties.getValueAt(mousePos.y / tableProperties.getRowHeight(),
+								mousePos.x / (tableProperties.getWidth() / 2));
+						if (mousePos.y / tableProperties.getRowHeight() == 2) {
+							Float ftemp = Float.parseFloat(temp.toString());
+							model.getSelectedEdge().setCapacity(ftemp);
+						} else if (mousePos.y / tableProperties.getRowHeight() == 3) {
+							Boolean bTemp = Boolean.parseBoolean(temp.toString());
+							model.getSelectedEdge().setState(bTemp);
+						}
 					}
 					canvas.repaint();
 				} catch (Exception e) {
@@ -1093,6 +1102,7 @@ public class GUI<E> implements CategoryListener {
 					}
 					tableModelProperties.setCellEditable(0, 1, true);
 					tableModelProperties.setCellEditable(2, 1, false);
+					tableModelProperties.setCellEditable(3, 1, false);
 					ArrayList<CpsEdge> temp_array = temp.getConnections();
 					if (!temp_array.isEmpty()) {
 						boolean first = true;
@@ -1129,8 +1139,11 @@ public class GUI<E> implements CategoryListener {
 					tableModelProperties.addRow(tempFlow);
 					Object[] tempCapacity = { "Max. Capacity", model.getSelectedEdge().getCapacity() };
 					tableModelProperties.addRow(tempCapacity);
+					Object[] tempStatus = { "Status", model.getSelectedEdge().getStateEdge() };
+					tableModelProperties.addRow(tempStatus);
 					tableModelProperties.setCellEditable(0, 1, false);
 					tableModelProperties.setCellEditable(2, 1, true);
+					tableModelProperties.setCellEditable(3, 1, true);
 				} else if (getActualCps() == null) {
 					deleteRows(tableModelHolonElementSingle);
 					deleteRows(tableModelHolonElementMulti);
@@ -1512,7 +1525,7 @@ public class GUI<E> implements CategoryListener {
 					if (!eleTemp.contains(obtTemp.searchElement(eleTempName))) {
 						eleTemp.add(obtTemp.searchElement(eleTempName));
 						eleToDelete.replace(idTemp, eleTemp);
-				
+
 					}
 				} else if (toMultiHash == 2) {
 					eleTemp.add(obtTemp.searchElement(eleTempName));