Quellcode durchsuchen

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

dominik.rieder vor 8 Jahren
Ursprung
Commit
67da183392

+ 35 - 2
src/ui/controller/MultiPurposeController.java

@@ -115,7 +115,7 @@ public class MultiPurposeController {
 	public HolonElement searchEleById(HolonObject object, int idEle) {
 		return object.searchElementById(idEle);
 	}
-	
+
 	/**
 	 * 
 	 * @param upperNode
@@ -123,7 +123,7 @@ public class MultiPurposeController {
 	 * @return
 	 */
 	public AbstractCpsObject searchIDUpperNode(CpsUpperNode upperNode, int id) {
-		
+
 		Integer idx;
 
 		if ((idx = upperNode.getNodesIdx().get(id)) == null || upperNode.getNodesIdx().size() < 1)
@@ -176,6 +176,39 @@ public class MultiPurposeController {
 		}
 	}
 
+	/**
+	 * Adjust Indices before porting them from one map to another
+	 * 
+	 * @param key
+	 *            the Key
+	 * @param <T>
+	 *            key type
+	 * @param map
+	 *            the Map
+	 */
+	public <T> void adjustIdx(int x, HashMap<T, Integer> map) {
+
+		for (Entry<T, Integer> i : map.entrySet()) {
+			i.setValue(i.getValue() + x + 1);
+		}
+	}
+
+	/**
+	 * Returns the highest Id
+	 * @param map
+	 * @return
+	 */
+	public <T> int getHighestIdx(HashMap<T, Integer> map) {
+		int max = 0;
+
+		for (T i : map.keySet()) {
+			if (map.get(i) > max)
+				max = map.get(i);
+		}
+		
+		return max;
+	}
+
 	/**
 	 * Copies a HashMap into a new One.
 	 * 

+ 2 - 0
src/ui/controller/NodeController.java

@@ -118,6 +118,8 @@ public class NodeController {
 		// TODO Auto-generated method stub
 		// add all nodes into upperNode
 		(upperNode == null ? model.getObjectsOnCanvas() : upperNode.getNodes()).addAll(node.getNodes());
+		// change the indices accordingly the higher layer
+		mpC.adjustIdx(mpC.getHighestIdx((upperNode == null ? model.getCvsObjIdx() : upperNode.getNodesIdx())), node.getNodesIdx());
 		// add all indices of nodes into upperNode
 		(upperNode == null ? model.getCvsObjIdx() : upperNode.getNodesIdx()).putAll(node.getNodesIdx());
 		// add all Edges of node into upperNode

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

@@ -472,7 +472,6 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		dataSelected = null;
 		edgeHighlight = null;
 		controller.setSelecteEdge(null);
-		// System.out.println(model.getEdgesOnCanvas().size());
 		// Object Selection
 		for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
 			cx = cps.getPosition().x;

+ 3 - 6
src/ui/view/StatisticGraph.java

@@ -57,8 +57,6 @@ public class StatisticGraph extends JPanel {
 	public StatisticGraph(final Model model, Control control) {
 		this.controller = control;
 		this.model = model;
-
-		
 	
 		this.setBackground(Color.WHITE);
 	}
@@ -274,9 +272,8 @@ public class StatisticGraph extends JPanel {
 	private void createPathFloats(TrackedDataSet set) {
 		boolean init = true;
 		path.moveTo(0, 0);
-		for (int i = 0; i < model.getCurIteration() - 1; i++) {
-			controller.addTextToConsole(path.getCurrentPoint().getX() + ", " + path.getCurrentPoint().getY());
-			if (init /* && set.getValues()[i] != -1 */) {
+		for (int i = 0; i < model.getCurIteration(); i++) {
+			if (init && set.getValues()[i] != -1 ) {
 				path.moveTo(i * this.getWidth() / model.getIterations() - 1, convertToCanvasY(set.getValues()[i]));
 				init = false;
 			}
@@ -299,7 +296,7 @@ public class StatisticGraph extends JPanel {
 	 */
 	private void createPathBooleans(TrackedDataSet set) {
 		boolean init = true;
-		for (int i = 0; i < model.getCurIteration() - 1; i++) {
+		for (int i = 0; i < model.getCurIteration(); i++) {
 			if (init && set.getValues()[i] != -1) {
 				path.moveTo(i * this.getWidth() / model.getIterations() - 1,
 						convertToCanvasY((float) (set.getValues()[i] * maximum)));

+ 21 - 2
src/ui/view/StatisticGraphPanel.java

@@ -9,6 +9,8 @@ import ui.model.Model;
 import javax.swing.JLabel;
 import javax.swing.JButton;
 import javax.swing.SwingConstants;
+import javax.swing.Timer;
+
 import java.awt.BorderLayout;
 import javax.swing.border.LineBorder;
 
@@ -79,7 +81,7 @@ public class StatisticGraphPanel extends JPanel {
 				JPanel parent = (JPanel) that.getParent();
 				for (int i = 0; i < parent.getComponentCount(); i++) {
 					if (parent.getComponent(i).equals(that)) {
-						parent.remove(parent.getComponent(i+1));
+						parent.remove(parent.getComponent(i + 1));
 						break;
 					}
 				}
@@ -94,7 +96,15 @@ public class StatisticGraphPanel extends JPanel {
 		this.add(topPanel, BorderLayout.NORTH);
 		this.add(maximumLabel, BorderLayout.WEST);
 		this.add(Legendpanel, BorderLayout.SOUTH);
-		
+
+		Timer t = new Timer(200, new ActionListener() {
+
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				that.repaint();
+			}
+		});
+		t.start();
 
 	}
 
@@ -122,4 +132,13 @@ public class StatisticGraphPanel extends JPanel {
 	public void setMaximumLabel(int max) {
 		maximumLabel.setText(Integer.toString(max));
 	}
+
+	/**
+	 * Get the name of the Graph.
+	 * 
+	 * @return the name of the Graph
+	 */
+	public String getGraphName() {
+		return this.graphName;
+	}
 }