Browse Source

Merge branches 'master' and 'master' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons

Edgardo Palza 8 years ago
parent
commit
57f0b0b748

+ 25 - 16
src/ui/controller/Control.java

@@ -62,7 +62,7 @@ public class Control {
 		this.consoleController = new ConsoleController(model);
 		this.consoleController = new ConsoleController(model);
 		autoPath = System.getProperty("user.home") + "/HolonGUI/Autosave/";
 		autoPath = System.getProperty("user.home") + "/HolonGUI/Autosave/";
 		File dest = new File(autoPath);
 		File dest = new File(autoPath);
-		//deleteDirectory(dest);
+		// deleteDirectory(dest);
 		dest.mkdirs();
 		dest.mkdirs();
 		try {
 		try {
 			autoSave();
 			autoSave();
@@ -97,7 +97,8 @@ public class Control {
 	/**
 	/**
 	 * Search for Object by ID.
 	 * Search for Object by ID.
 	 * 
 	 * 
-	 * @param id the id of the Object
+	 * @param id
+	 *            the id of the Object
 	 * @return the CpsObject
 	 * @return the CpsObject
 	 */
 	 */
 	public AbstractCpsObject searchByID(int id) {
 	public AbstractCpsObject searchByID(int id) {
@@ -120,7 +121,8 @@ public class Control {
 	/**
 	/**
 	 * search for category.
 	 * search for category.
 	 * 
 	 * 
-	 * @param cat name of the Category
+	 * @param cat
+	 *            name of the Category
 	 * @return the Category
 	 * @return the Category
 	 */
 	 */
 	public Category searchCategory(String cat) {
 	public Category searchCategory(String cat) {
@@ -128,7 +130,7 @@ public class Control {
 	}
 	}
 
 
 	/* Operations for Categories and Objects */
 	/* Operations for Categories and Objects */
-	
+
 	/**
 	/**
 	 * init default category and objects.
 	 * init default category and objects.
 	 */
 	 */
@@ -153,7 +155,8 @@ public class Control {
 	 *            Category
 	 *            Category
 	 * @param obj
 	 * @param obj
 	 *            New Object Name
 	 *            New Object Name
-	 *            @param ele Array of Elements
+	 * @param ele
+	 *            Array of Elements
 	 * @param img
 	 * @param img
 	 *            the image Path
 	 *            the image Path
 	 */
 	 */
@@ -468,7 +471,9 @@ public class Control {
 	public void calculateStateForCurrentTimeStep() {
 	public void calculateStateForCurrentTimeStep() {
 		simulationManager.reset();
 		simulationManager.reset();
 		simulationManager.calculateStateForTimeStep(model.getCurIteration());
 		simulationManager.calculateStateForTimeStep(model.getCurIteration());
-		runAlgorithm(model, this);
+		if (model.getIsSimulation()) {
+			runAlgorithm(model, this);
+		}
 	}
 	}
 
 
 	/**
 	/**
@@ -480,7 +485,9 @@ public class Control {
 	public void calculateStateForTimeStep(int x) {
 	public void calculateStateForTimeStep(int x) {
 		simulationManager.reset();
 		simulationManager.reset();
 		simulationManager.calculateStateForTimeStep(x);
 		simulationManager.calculateStateForTimeStep(x);
-		runAlgorithm(model, this);
+		if (model.getIsSimulation()) {
+			runAlgorithm(model, this);
+		}
 	}
 	}
 
 
 	/**
 	/**
@@ -644,42 +651,44 @@ public class Control {
 	public void setIsSimulation(boolean b) {
 	public void setIsSimulation(boolean b) {
 		globalController.setIsSimulation(b);
 		globalController.setIsSimulation(b);
 	}
 	}
-	
+
 	/**
 	/**
 	 * Set the Canvas X Size.
 	 * Set the Canvas X Size.
 	 * 
 	 * 
-	 * @param canvasX the cANVAS_X to set
+	 * @param canvasX
+	 *            the cANVAS_X to set
 	 */
 	 */
 	public void setCanvasX(int canvasX) {
 	public void setCanvasX(int canvasX) {
 		globalController.setCanvasX(canvasX);
 		globalController.setCanvasX(canvasX);
 	}
 	}
 
 
-
 	/**
 	/**
 	 * Set the Canvas Y Size.
 	 * Set the Canvas Y Size.
 	 * 
 	 * 
-	 * @param canvasY the cANVAS_Y to set
+	 * @param canvasY
+	 *            the cANVAS_Y to set
 	 */
 	 */
 	public void setCanvasY(int canvasY) {
 	public void setCanvasY(int canvasY) {
 		globalController.setCanvasY(canvasY);
 		globalController.setCanvasY(canvasY);
 	}
 	}
-	
+
 	/**
 	/**
 	 * Set the Algorithm.
 	 * Set the Algorithm.
 	 * 
 	 * 
-	 * @param obj the Algorithm
+	 * @param obj
+	 *            the Algorithm
 	 */
 	 */
 	public void setAlgorithm(Object obj) {
 	public void setAlgorithm(Object obj) {
 		multiPurposeController.setAlgorithm(obj);
 		multiPurposeController.setAlgorithm(obj);
 	}
 	}
-	
+
 	/**
 	/**
 	 * Run the Algorithm.
 	 * Run the Algorithm.
 	 */
 	 */
 	public void runAlgorithm(Model model, Control controller) {
 	public void runAlgorithm(Model model, Control controller) {
 		if (model.getAlgorithm() != null) {
 		if (model.getAlgorithm() != null) {
-			((interfaceTest)model.getAlgorithm()).RunAlgorithm(model, controller);
+			((interfaceTest) model.getAlgorithm()).RunAlgorithm(model, controller);
 		}
 		}
 	}
 	}
-	
+
 }
 }

+ 0 - 8
src/ui/controller/SimulationManager.java

@@ -135,11 +135,9 @@ public class SimulationManager {
 		ArrayList<AbstractCpsObject> producers = new ArrayList<AbstractCpsObject>();
 		ArrayList<AbstractCpsObject> producers = new ArrayList<AbstractCpsObject>();
 		AbstractCpsObject tmp = null;
 		AbstractCpsObject tmp = null;
 		tagTable = new HashMap<Integer, Float>();
 		tagTable = new HashMap<Integer, Float>();
-		System.out.println("producers:");
 		for (HolonObject hl : sN.getObjects()) {
 		for (HolonObject hl : sN.getObjects()) {
 			float energy = hl.getCurrentEnergyAtTimeStep(timeStep);
 			float energy = hl.getCurrentEnergyAtTimeStep(timeStep);
 			if (energy > 0) {
 			if (energy > 0) {
-				System.out.println(hl.getID());
 				tagTable.put(hl.getID(), energy);
 				tagTable.put(hl.getID(), energy);
 				hl.addTag(hl.getID());
 				hl.addTag(hl.getID());
 				for (CpsEdge edge : hl.getConnections()) {
 				for (CpsEdge edge : hl.getConnections()) {
@@ -168,7 +166,6 @@ public class SimulationManager {
 				}
 				}
 			}
 			}
 		}
 		}
-		printNodes(producers);
 		setFlowSimRec(producers, 0);
 		setFlowSimRec(producers, 0);
 	}
 	}
 
 
@@ -181,7 +178,6 @@ public class SimulationManager {
 	 *            the Iteration
 	 *            the Iteration
 	 */
 	 */
 	public void setFlowSimRec(ArrayList<AbstractCpsObject> nodes, int iter) {
 	public void setFlowSimRec(ArrayList<AbstractCpsObject> nodes, int iter) {
-		System.out.println("iteration: " + iter);
 		ArrayList<AbstractCpsObject> newNodes = new ArrayList<AbstractCpsObject>();
 		ArrayList<AbstractCpsObject> newNodes = new ArrayList<AbstractCpsObject>();
 		ArrayList<CpsEdge> changedEdges = new ArrayList<CpsEdge>();
 		ArrayList<CpsEdge> changedEdges = new ArrayList<CpsEdge>();
 		AbstractCpsObject tmp;
 		AbstractCpsObject tmp;
@@ -189,9 +185,6 @@ public class SimulationManager {
 			for(AbstractCpsObject cps: nodes){
 			for(AbstractCpsObject cps: nodes){
 				if(legitState(cps)){
 				if(legitState(cps)){
 					for(CpsEdge edge: cps.getConnections()){
 					for(CpsEdge edge: cps.getConnections()){
-						if(edge.getPseudoTags() == null){
-							System.out.println("edge null");
-						}
 						if(edge.getState() && (!(edge.containsTags(edge.getTags(), cps.getTag())))){
 						if(edge.getState() && (!(edge.containsTags(edge.getTags(), cps.getTag())))){
 							if(edge.getA().getID() == cps.getID()){
 							if(edge.getA().getID() == cps.getID()){
 								tmp = edge.getB();
 								tmp = edge.getB();
@@ -223,7 +216,6 @@ public class SimulationManager {
 				}
 				}
 			}
 			}
 			setPseudoTags(newNodes, changedEdges);
 			setPseudoTags(newNodes, changedEdges);
-			printNodes(newNodes);
 			setFlowSimRec(newNodes, iter+1);
 			setFlowSimRec(newNodes, iter+1);
 		}
 		}
 	}
 	}

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

@@ -894,6 +894,7 @@ public class GUI<E> implements CategoryListener {
 						}
 						}
 					} else {
 					} else {
 						temp = tableModelProperties.getValueAt(selValueY, selValueX);
 						temp = tableModelProperties.getValueAt(selValueY, selValueX);
+						System.out.println(temp.toString());
 						if (selValueY == 2) {
 						if (selValueY == 2) {
 							Float ftemp;
 							Float ftemp;
 							if (Float.parseFloat(temp.toString()) >= 0.0) {
 							if (Float.parseFloat(temp.toString()) >= 0.0) {

+ 20 - 2
src/ui/view/SimulationMenu.java

@@ -41,6 +41,8 @@ import java.awt.Dimension;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagConstraints;
 import java.awt.Insets;
 import java.awt.Insets;
 import java.awt.event.ActionListener;
 import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseEvent;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeEvent;
@@ -93,6 +95,18 @@ public class SimulationMenu extends JMenuBar {
 		this.model = mod;
 		this.model = mod;
 		this.controller = cont;
 		this.controller = cont;
 
 
+		// Algorithm ComboBox Action
+		algoCombo.addItemListener(new ItemListener() {
+
+			@Override
+			public void itemStateChanged(ItemEvent e) {
+
+				setAlgorithm(algosHash.get(e.getItem()));
+				controller.addTextToConsole("" + e.getItem());
+
+			}
+		});
+
 		// algoFolderButton Action
 		// algoFolderButton Action
 		algoFolderButton.addActionListener(new ActionListener() {
 		algoFolderButton.addActionListener(new ActionListener() {
 
 
@@ -110,6 +124,10 @@ public class SimulationMenu extends JMenuBar {
 				if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
 				if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
 					algoCombo.removeAllItems();
 					algoCombo.removeAllItems();
 					File[] files = fileChooser.getSelectedFile().listFiles();
 					File[] files = fileChooser.getSelectedFile().listFiles();
+					//Set Root Folder Path
+					root = new File(fileChooser.getCurrentDirectory().getPath());
+					controller.addTextToConsole("roor Path" + root.getPath());
+					
 					for (int i = 0; i < files.length; i++) {
 					for (int i = 0; i < files.length; i++) {
 						if (files[i].toString()
 						if (files[i].toString()
 								.endsWith(".java") /*
 								.endsWith(".java") /*
@@ -121,10 +139,10 @@ public class SimulationMenu extends JMenuBar {
 							name = name.substring(0, tmpB);
 							name = name.substring(0, tmpB);
 							algosHash.put(name, files[i]);
 							algosHash.put(name, files[i]);
 							algoCombo.addItem(name);
 							algoCombo.addItem(name);
-							root = new File(fileChooser.getCurrentDirectory().getPath());
-							setAlgorithm(files[i]);
+
 						}
 						}
 					}
 					}
+
 				}
 				}
 			}
 			}