ソースを参照

Merge remote-tracking branch 'origin/TonisBranch' into BP_master

Conflicts:
	src/ui/view/GUI.java -> used BP_master
Andreas T. Meyer-Berg 7 年 前
コミット
6abd259ee0

+ 17 - 0
src/ElementComparator/ElemCompOnEleName.java

@@ -0,0 +1,17 @@
+package ElementComparator;
+
+import classes.HolonElement;
+
+public class ElemCompOnEleName extends ElementComparator {
+
+	@Override
+	public int compare(HolonElement a, HolonElement b) {
+
+		String eleNameA = a.getEleName();
+		String eleNameB = b.getEleName();
+		
+		return eleNameA.compareTo(eleNameB);
+
+	}
+
+}

+ 25 - 0
src/ElementComparator/ElemCompOnEnergy.java

@@ -0,0 +1,25 @@
+package ElementComparator;
+
+import classes.HolonElement;
+
+/**
+ * @author Toni
+ * Bei dieser Implementierung wird nach 
+ * Energieverbrauch pro HolonElement sortiert
+ */
+public class ElemCompOnEnergy extends ElementComparator {
+
+	@Override
+	public int compare(HolonElement a, HolonElement b) {
+
+		float verbrauchA = a.getEnergyPerElement();
+		float verbrauchB = b.getEnergyPerElement();
+		if (verbrauchA < verbrauchB)
+			return -1;
+		if (verbrauchA > verbrauchB)
+			return 1;
+		return 0;
+
+	}
+
+}

+ 27 - 0
src/ElementComparator/ElemCompOnId.java

@@ -0,0 +1,27 @@
+/**
+ * 
+ */
+package ElementComparator;
+
+import classes.HolonElement;
+
+/**
+ * @author Toni
+ *Comparator zum sortieren nach HolonElementId
+ */
+public class ElemCompOnId extends ElementComparator {
+
+	@Override
+	public int compare(HolonElement a, HolonElement b) {
+
+		float idA = a.getId();
+		float idB = b.getId();
+		if (idA < idB)
+			return -1;
+		if (idA > idB)
+			return 1;
+		return 0;
+
+	}
+
+}

+ 17 - 0
src/ElementComparator/ElementComparator.java

@@ -0,0 +1,17 @@
+package ElementComparator;
+
+import java.util.Comparator;
+
+import classes.HolonElement;
+
+/**
+ * @author Toni
+ *Eine abstrakte Klasse um bei HolonObjekten den Comparator 
+ *der die HolonElemente sortiert welchseln zu können
+ */
+public abstract class ElementComparator implements Comparator<HolonElement> {
+	
+	public abstract int compare(HolonElement a, HolonElement b);
+	
+}
+	

+ 17 - 2
src/classes/HolonElement.java

@@ -15,7 +15,10 @@ public class HolonElement {
 
     /* Points on the UnitGraph */
     private LinkedList<Point> graphPoints;
-    /* Name of the gadget */
+    /* Name of the Object: House, 1 */
+    @Expose
+    private String objName;
+    /* Name of the gadget: TV */
     @Expose
     private String eleName;
     /* Quantity */
@@ -111,7 +114,19 @@ public class HolonElement {
         setFlexible(false);
     }
 
-    /**
+
+
+	
+
+	public String getObjName() {
+		return objName;
+	}
+
+	public void setObjName(String objName) {
+		this.objName = objName;
+	}
+
+	/**
      * Get the Array of energyPerElement (100 values).
      *
      * @return availableEnergyPerElementAt Array of Floats

+ 30 - 6
src/ui/controller/UpdateController.java

@@ -8,7 +8,14 @@ import ui.view.PropertyTable;
 import ui.view.UpperNodeCanvas;
 
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.HashMap;
+import java.util.LinkedList;
+
+import ElementComparator.ElemCompOnEleName;
+import ElementComparator.ElemCompOnEnergy;
+import ElementComparator.ElemCompOnId;
+import ElementComparator.ElementComparator;
 
 /**
  * This class is for all update methods and more ;)
@@ -46,6 +53,7 @@ public class UpdateController {
 		}
 	}
 
+	    
 	/**
 	 * Add the Information of the given ArrayList in the HolonElement Model as
 	 * Name,Energy and Amount.
@@ -54,23 +62,39 @@ public class UpdateController {
 	 *            ArrayList to be displayed
 	 */
 	public void fillElementTable(ArrayList<AbstractCpsObject> objects, PropertyTable table) {
+		LinkedList<HolonElement> elemList = new LinkedList<HolonElement>();
+		ElementComparator compEnergy = new ElemCompOnEnergy();
+		//ElementComparator compId = new ElemCompOnId();
+		ElementComparator compEleName = new ElemCompOnEleName();
 		if (objects.size() > 1) {
 			for (AbstractCpsObject o : objects) {
 				if (o instanceof HolonObject) {
 					for (HolonElement he : ((HolonObject) o).getElements()) {
-						Object[] temp = {o.getName() + ", " + o.getId(), he.getId(), he.getEleName(), he.getEnergyPerElement(),
-								he.getFlexibleEnergyAvailablePerElement(), he.getAmount(), he.isActive(), he.isFlexible()};
-						table.addRow(temp);
+						he.setObjName(o.getName() + ", " + o.getId());
+						elemList.add(he);
+						elemList.sort(compEleName);
+						elemList.sort(compEnergy);
 					}
 				}
 			}
+			for (HolonElement e1 : elemList) {
+				Object[] temp2 = { e1.getObjName(), e1.getId(), e1.getEleName(), e1.getEnergyPerElement(),
+						e1.getFlexibleEnergyAvailablePerElement(), e1.getAmount(), e1.isActive(), e1.isFlexible() };
+				table.addRow(temp2);
+			}
+
 		} else if (objects.size() == 1) {
 			AbstractCpsObject o = objects.get(0);
 			if (o instanceof HolonObject) {
 				for (HolonElement he : ((HolonObject) o).getElements()) {
-					Object[] temp = {he.getId(), he.getEleName(), he.getEnergyPerElement(), he.getFlexibleEnergyAvailablePerElement(), he.getAmount(),
-							he.isActive(), he.isFlexible()};
-                    table.addRow(temp);
+					elemList.add(he);
+					elemList.sort(compEleName);
+					elemList.sort(compEnergy);
+				}
+				for (HolonElement e1 : elemList) {
+					Object[] temp2 = { e1.getId(), e1.getEleName(), e1.getEnergyPerElement(),
+							e1.getFlexibleEnergyAvailablePerElement(), e1.getAmount(), e1.isActive(), e1.isFlexible() };
+					table.addRow(temp2);
 				}
 			}
 		}