Browse Source

Total Flexibility added to the HolonObj PropertyTable (4th row)

Edgardo Palza 7 years ago
parent
commit
1bc3e000cf

+ 2 - 0
src/classes/HolonElement.java

@@ -44,10 +44,12 @@ public class HolonElement {
 	/*
 	 * Flexibility
 	 */
+	@Expose
 	private float flexibility;
 	/*
 	 * Active the flexibility field
 	 */
+	@Expose
 	private boolean activeFlex;
 	/*
 	 * Energy at each point of the graph with 100 predefined points. At the

+ 29 - 0
src/classes/HolonObject.java

@@ -34,6 +34,8 @@ public class HolonObject extends AbstractCpsObject {
 	private float[] trackingProd;
 	/* Array for tracking Consumption */
 	private float[] trackingCons;
+	/* Total Flexibility */
+	private float totalFlex;
 	/*
 	 * 0 = no energy, 1 = not supplied, 2 = supplied, 3 producer, 4 Partially
 	 * Supplied
@@ -379,6 +381,33 @@ public class HolonObject extends AbstractCpsObject {
 		return this.trackingCons;
 	}
 
+	/**
+	 * Get the Array Consumption
+	 */
+	public float getTotalFlex() {
+		return totalFlex;
+	}
+
+	/**
+	 * Set the Array Consumption
+	 */
+	public void setTotalFlex(float totalFlex) {
+		this.totalFlex = totalFlex;
+	}
+
+	/**
+	 * Update the totalFlex
+	 */
+	public void updateTotalFlex() {
+		float tempFlex = 0;
+		for (HolonElement e : getElements()) {
+			if (e.getActiveFlex()) {
+				tempFlex += e.getFlexibility();
+			}
+		}
+		this.totalFlex = tempFlex;
+	}
+
 	/**
 	 * If the user track any HolonObject the tracking information will be
 	 * updated. (If the HolonObject enters into the untracked state, the array

+ 9 - 2
src/ui/controller/UpdateController.java

@@ -41,9 +41,13 @@ public class UpdateController {
 			if (tempCps != null && tempCps.getClass() == HolonObject.class) {
 				if (table.getRowCount() != 0) {
 					table.removeRow(2);
+					Object[] tempEnergy = { Languages.getLanguage()[73], ((HolonObject) tempCps).getCurrentEnergy() };
+					table.insertRow(2, tempEnergy);
+					((HolonObject) tempCps).updateTotalFlex();
+					table.removeRow(3);
+					Object[] tempFlex = { "Flexibility", ((HolonObject) tempCps).getTotalFlex() };
+					table.insertRow(3, tempFlex);
 				}
-				Object[] tempEnergy = { Languages.getLanguage()[73], ((HolonObject) tempCps).getCurrentEnergy() };
-				table.insertRow(2, tempEnergy);
 			}
 		}
 	}
@@ -238,10 +242,13 @@ public class UpdateController {
 			if (obj instanceof HolonObject) {
 				refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
 				Object[] tempEnergy = { Languages.getLanguage()[73], ((HolonObject) obj).getCurrentEnergy() };
+				Object[] tempFlex = { "Flexibility", ((HolonObject) obj).getTotalFlex() };
 				model.getPropertyTable().addRow(tempEnergy);
+				model.getPropertyTable().addRow(tempFlex);
 				model.getPropertyTable().setCellEditable(0, 1, true);
 				model.getPropertyTable().setCellEditable(2, 1, false);
 				model.getPropertyTable().setCellEditable(3, 1, false);
+				model.getPropertyTable().setCellEditable(4, 1, false);
 			} // For HolonSwitches is showed the actual status (active
 				// or inactive)
 			else if (obj instanceof HolonSwitch) {