Ver código fonte

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

Teh-Hai Julian Zheng 8 anos atrás
pai
commit
0904100963

BIN
.gradle/2.2.1/taskArtifacts/cache.properties.lock


BIN
.gradle/2.2.1/taskArtifacts/fileHashes.bin


BIN
.gradle/2.2.1/taskArtifacts/fileSnapshots.bin


BIN
.gradle/2.2.1/taskArtifacts/outputFileStates.bin


BIN
.gradle/2.2.1/taskArtifacts/taskArtifacts.bin


+ 9 - 1
build.gradle

@@ -10,6 +10,9 @@
 
 // Apply the java plugin to add support for Java
 apply plugin: 'java'
+apply plugin: 'application'
+
+mainClassName = 'ui.view.Main'
 
 jar {
     manifest {
@@ -20,7 +23,7 @@ jar {
 sourceSets {
     test{
 		java{
-			srcDir 'src/tests'
+			srcDirs = ["src/tests"]
 		}
 		resources{
 			srcDir 'res'
@@ -36,8 +39,13 @@ sourceSets {
     }
 }
 
+repositories {
+ mavenCentral()
+}
+
  dependencies {   
        compile fileTree(dir: 'jars', include: ['*.jar'])
+       testCompile group: 'junit', name: 'junit', version: '4.+'
 }
 /*
 // In this section you declare where to find the dependencies of your project

BIN
gradle/wrapper/gradle-wrapper.jar


+ 6 - 0
gradle/wrapper/gradle-wrapper.properties

@@ -0,0 +1,6 @@
+#Sat Sep 24 14:38:34 CEST 2016
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-bin.zip

+ 103 - 41
src/classes/HolonObject.java

@@ -7,8 +7,19 @@ import java.util.HashMap;
 import ui.controller.MultiPurposeController;
 import ui.model.idCounter;
 
+/**
+ * The class HolonObject represents any Object on the system which capability of
+ * injecting or consuming energy on the network, for instance a house or a power
+ * plant.
+ * 
+ * @author Gruppe14
+ *
+ */
 public class HolonObject extends CpsObject {
-	
+	/*
+	 * Color of the actual state (red = no supplied, yellow = partially supplied
+	 * and green = supplied)
+	 */
 	private Color stateColor;
 	/* Array of all consumers */
 	private ArrayList<HolonElement> elements;
@@ -17,10 +28,10 @@ public class HolonObject extends CpsObject {
 	/* Total of consumption */
 	private float currentEnergy;
 
-	/**
+	/*
 	 * 0 = no energy, 1 = not supplied, 2 = supplied, 3 producer
 	 */
-	int state = 0;
+	private int state = 0;
 
 	/**
 	 * Constructor Set by default the name of the object equals to the category
@@ -33,6 +44,14 @@ public class HolonObject extends CpsObject {
 		setState();
 	}
 
+	/**
+	 * Constructor with a user-defined name
+	 * 
+	 * @param ObjName
+	 *            Type of Object
+	 * @param obj
+	 *            user-defined name
+	 */
 	public HolonObject(String ObjName, String obj) {
 		super(ObjName);
 		super.setName(obj);
@@ -41,6 +60,12 @@ public class HolonObject extends CpsObject {
 		setState();
 	}
 
+	/**
+	 * Contructor of a copy of an Object
+	 * 
+	 * @param obj
+	 *            object to be copied
+	 */
 	public HolonObject(CpsObject obj) {
 		super(obj);
 		setEleIdx(MultiPurposeController.copyHashMap(((HolonObject) obj).getEleIdx()));
@@ -60,25 +85,29 @@ public class HolonObject extends CpsObject {
 			if (getCurrentEnergy() == 0) {
 				setState(0);
 				stateColor = Color.WHITE;
-			}else {
-				if(checkIfPartiallySupplied(0)){
+			} else {
+				if (checkIfPartiallySupplied(0)) {
 					stateColor = Color.yellow;
-				}else {
-					stateColor = new Color(230,120,100);
+				} else {
+					stateColor = new Color(230, 120, 100);
 				}
-				
+
 			}
 		}
 	}
 
 	/**
-	 * @return the elements
+	 * Getter for all Elements in the HolonObject
+	 * 
+	 * @return the elements ArrayList
 	 */
 	public ArrayList<HolonElement> getElements() {
 		return elements;
 	}
 
 	/**
+	 * Set a new ArrayList with HolonElements into the HolonObject
+	 * 
 	 * @param elements
 	 *            the elements to set
 	 */
@@ -91,8 +120,9 @@ public class HolonObject extends CpsObject {
 	}
 
 	/**
-	 * doesnt take into account which timestep is watched,
-	 * calculates the max values
+	 * Doesn't take into account which timestep is watched, calculates the max
+	 * values
+	 * 
 	 * @return the currentEnergy
 	 */
 	public float getCurrentEnergy() {
@@ -106,6 +136,13 @@ public class HolonObject extends CpsObject {
 		return currentEnergy;
 	}
 
+	/**
+	 * Getter for the current energy at a given timestep
+	 * 
+	 * @param x
+	 *            timestep
+	 * @return corresponding energy
+	 */
 	public float getCurrentEnergyAtTimeStep(int x) {
 		float temp = 0;
 		for (HolonElement e : getElements()) {
@@ -118,17 +155,10 @@ public class HolonObject extends CpsObject {
 	}
 
 	/**
-	 * @param currentEnergy
-	 *            the currentEnergy to set
-	 */
-	public void setCurrentEnergy(float currentEnergy) {
-		this.currentEnergy = currentEnergy;
-	}
-
-	/**
-	 * deletes Element
+	 * deletes Element at a given index
 	 * 
 	 * @param idx
+	 *            index
 	 */
 	public void deleteElement(int idx) {
 		elements.remove(idx);
@@ -152,6 +182,8 @@ public class HolonObject extends CpsObject {
 	}
 
 	/**
+	 * Getter index of all elements in the HolonObject
+	 * 
 	 * @return the eleIdx
 	 */
 	public HashMap<String, Integer> getEleIdx() {
@@ -159,6 +191,8 @@ public class HolonObject extends CpsObject {
 	}
 
 	/**
+	 * Set the indexes of all elements
+	 * 
 	 * @param eleIdx
 	 *            the eleIdx to set
 	 */
@@ -180,36 +214,52 @@ public class HolonObject extends CpsObject {
 		return newArr;
 	}
 
-	/*
-	 * returns supplied
+	/**
+	 * Get the state of the Object
+	 * 
+	 * @return state
 	 */
 	public int getState() {
 		return this.state;
 	}
 
 	/**
+	 * Set the state of the Object
+	 * 
 	 * @param supplied
 	 *            boolean if the Object is fully supplied
 	 */
 	public void setState(int st) {
 		this.state = st;
-		switch(st){
-			case 0: stateColor = Color.WHITE;
-					break;
-			
-			case 1: stateColor = new Color(230,120,100);
-					break;
-					
-			case 2: stateColor = Color.GREEN;
-					break;
-			
-			case 3: stateColor = Color.lightGray;
-					break;
-			
-			case 4: stateColor = Color.YELLOW;
+		switch (st) {
+		case 0:
+			stateColor = Color.WHITE;
+			break;
+
+		case 1:
+			stateColor = new Color(230, 120, 100);
+			break;
+
+		case 2:
+			stateColor = Color.GREEN;
+			break;
+
+		case 3:
+			stateColor = Color.lightGray;
+			break;
+
+		case 4:
+			stateColor = Color.YELLOW;
 		}
 	}
 
+	/**
+	 * Search for the element with the name
+	 * 
+	 * @param name
+	 *            name of the object to be searched
+	 * @return the searched HolonElement
+	 */
 	public HolonElement searchElement(String name) {
 		HolonElement ele = null;
 		for (HolonElement e : getElements()) {
@@ -220,6 +270,13 @@ public class HolonObject extends CpsObject {
 		return ele;
 	}
 
+	/**
+	 * Search for the element with the id
+	 * 
+	 * @param id
+	 *            id of the element to be founded
+	 * @return the element
+	 */
 	public HolonElement searchElementById(int id) {
 		HolonElement ele = null;
 		for (HolonElement e : getElements()) {
@@ -230,6 +287,11 @@ public class HolonObject extends CpsObject {
 		return ele;
 	}
 
+	/**
+	 * 
+	 * @param x
+	 * @return
+	 */
 	public boolean checkIfPartiallySupplied(int x) {
 		if (getElements().size() == 0) {
 			return false;
@@ -248,19 +310,19 @@ public class HolonObject extends CpsObject {
 				}
 			}
 		}
-//		System.out.println("minCons: " + minConsum + " prod: " + prod);
+		// System.out.println("minCons: " + minConsum + " prod: " + prod);
 		if (minConsum < 0 && prod >= -minConsum) {
 			return true;
 		} else {
 			return false;
 		}
 	}
-	
-	public void setColor(Color color){
+
+	public void setColor(Color color) {
 		stateColor = color;
 	}
-	
-	public Color getColor(){
+
+	public Color getColor() {
 		return stateColor;
 	}
 }

+ 8 - 0
src/classes/HolonSwitch.java

@@ -65,6 +65,14 @@ public class HolonSwitch extends CpsObject {
 			this.manualActive = !manualActive;
 		}
 	}
+	
+	public boolean getState(int timeStep){
+		if(manualMode){
+			return this.manualActive;
+		} else {
+			return getActiveAt()[timeStep];
+		}
+	}
 
 	public boolean getState() {
 		if (manualMode) {

+ 1 - 3
src/tests/praktikumHolonsTestCanvasController.java

@@ -1,11 +1,9 @@
 package tests;
 
-import static org.junit.Assert.*;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertTrue;
 
 import org.junit.Before;
 import org.junit.Test;
-import com.sun.xml.internal.ws.policy.spi.AssertionCreationException;
 
 import classes.CpsEdge;
 import classes.CpsObject;

+ 2 - 2
src/ui/controller/SimulationManager.java

@@ -306,9 +306,9 @@ public class SimulationManager {
 	
 	public boolean legitState(CpsObject neighbor, CpsObject current){
 		if(current instanceof HolonSwitch){
-			if(((HolonSwitch) current).getActiveAt()[timeStep]){
+			if(((HolonSwitch) current).getState(timeStep)){
 				if(neighbor instanceof HolonSwitch){
-					if(((HolonSwitch) neighbor).getActiveAt()[timeStep]){
+					if(((HolonSwitch) neighbor).getState(timeStep)){
 						return true;
 					}else{
 						return false;

+ 36 - 15
src/ui/view/GUI.java

@@ -210,6 +210,9 @@ public class GUI<E> implements CategoryListener {
 	// Coord for all Cells with boolean values (checkbox)
 	private int yBTHIS;
 	private int xBTHIS;
+	// Coord for the Edit-Modus in the PropertieTable
+	private int yProThis;
+	private int xProThis;
 	private CpsObject temp = null;
 	private final JButton btnTest = new JButton("test");
 	private final JMenuItem mntmUndo = new JMenuItem("Undo");
@@ -843,6 +846,20 @@ public class GUI<E> implements CategoryListener {
 		/***********************
 		 * HolonElement Properties Actions
 		 **********************/
+
+		/*
+		 * Update of the mouse coord
+		 */
+		tableProperties.addMouseListener(new MouseAdapter() {
+			public void mousePressed(MouseEvent e) {
+				if (e.getClickCount() == 2) {
+					yProThis = e.getY();
+					xProThis = e.getX();
+				}
+
+			}
+		});
+
 		/*
 		 * Update any change in the Property table
 		 */
@@ -851,17 +868,21 @@ public class GUI<E> implements CategoryListener {
 			public void propertyChange(PropertyChangeEvent evt) {
 				try {
 					Object temp;
+					Object btemp;
 					Point mousePos = tableProperties.getMousePosition();
+					int selValueY = (int) Math.floor(yProThis / 16);
+					int selValueX = (int) Math.floor(xProThis / (tableProperties.getWidth() / 2));
+					temp = tableModelProperties.getValueAt(selValueY, selValueX);
 					if (getActualCps() != null) {
-						temp = tableModelProperties.getValueAt(mousePos.y / tableProperties.getRowHeight(),
-								mousePos.x / (tableProperties.getWidth() / 2));
-						if (getActualCps() instanceof HolonObject) {
-							getActualCps().setName(temp.toString());
-						} else if (getActualCps() instanceof HolonSwitch) {
-							if (mousePos.y / tableProperties.getRowHeight() == 2) {
-								Boolean bTemp = Boolean.parseBoolean(temp.toString());
-								((HolonSwitch) getActualCps()).setManualMode(bTemp);
-								if (bTemp) {
+						if (getActualCps() instanceof HolonSwitch) {
+							btemp = tableModelProperties.getValueAt(mousePos.y / tableProperties.getRowHeight(),
+									mousePos.x / (tableProperties.getWidth() / 2));
+							if (mousePos.y / tableProperties.getRowHeight() == 0) {
+								getActualCps().setName(btemp.toString());
+							} else if (mousePos.y / tableProperties.getRowHeight() == 2) {
+								Boolean bbTemp = Boolean.parseBoolean(btemp.toString());
+								((HolonSwitch) getActualCps()).setManualMode(bbTemp);
+								if (bbTemp) {
 									tableModelProperties.setCellEditable(3, 1, true);
 								} else {
 									tableModelProperties.setCellEditable(3, 1, false);
@@ -873,11 +894,12 @@ public class GUI<E> implements CategoryListener {
 									((HolonSwitch) getActualCps()).setManualState(bTemp);
 								}
 							}
+						} else if (getActualCps() instanceof HolonObject) {
+							getActualCps().setName(temp.toString());
 						}
 					} else {
-						temp = tableModelProperties.getValueAt(mousePos.y / tableProperties.getRowHeight(),
-								mousePos.x / (tableProperties.getWidth() / 2));
-						if (mousePos.y / tableProperties.getRowHeight() == 2) {
+						temp = tableModelProperties.getValueAt(selValueY, selValueX);
+						if (selValueY == 2) {
 							Float ftemp;
 							if (Float.parseFloat(temp.toString()) >= 0.0) {
 								ftemp = Float.parseFloat(temp.toString());
@@ -885,7 +907,7 @@ public class GUI<E> implements CategoryListener {
 								ftemp = model.getSelectedEdge().getCapacity();
 							}
 							model.getSelectedEdge().setCapacity(ftemp);
-						} else if (mousePos.y / tableProperties.getRowHeight() == 3) {
+						} else if (selValueY == 3) {
 							Boolean bTemp = Boolean.parseBoolean(temp.toString());
 							model.getSelectedEdge().setState(bTemp);
 						}
@@ -1005,8 +1027,7 @@ public class GUI<E> implements CategoryListener {
 					DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree
 							.getPathForLocation(e.getX(), e.getY()).getLastPathComponent();
 					if (selectedNode.getLevel() == 2) {
-						controller.searchCategoryObject(selectedNode.getParent().toString(),
-								selectedNode.toString());
+						controller.searchCategoryObject(selectedNode.getParent().toString(), selectedNode.toString());
 						deleteRows(tableModelHolonElementSingle);
 						deleteRows(tableModelHolonElementMulti);
 						// if (selected instanceof HolonObject && selected !=

+ 1 - 0
src/ui/view/TimePanel.java

@@ -119,6 +119,7 @@ public class TimePanel extends JPanel {
 			public void actionPerformed(ActionEvent ae) {
 				timeSlider.setValue(timeSlider.getMinimum());
 				controller.setCurIteration(timeSlider.getValue());
+				controller.calculateStateForCurrentTimeStep();
 			}
 		});
 		timeForwardBtn.setToolTipText("Forward");