Browse Source

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

Teh-Hai Julian Zheng 7 years ago
parent
commit
78c2cacebd

+ 17 - 0
src/ui/controller/StatsController.java

@@ -3,7 +3,9 @@ package ui.controller;
 import java.util.ArrayList;
 
 import classes.AbstractCpsObject;
+import classes.TrackedDataSet;
 import ui.model.Model;
+import ui.view.StatisticGraphPanel;
 
 public class StatsController {
 
@@ -32,5 +34,20 @@ public class StatsController {
 		objArr.remove(obj);
 		model.setTrackingObj(objArr);
 		model.addObjectsToGraphListeners();
+		//Remove the Object from the graph and the LegendPanel
+		for (StatisticGraphPanel sg : model.getGraphTable().values()) {
+			ArrayList<Integer> indexList = new ArrayList<>();
+			for (TrackedDataSet set: sg.getStatGraph().getDataSets()) {
+				if (obj == set.getCpsObject()) {
+					indexList.add(sg.getStatGraph().getDataSets().indexOf(set));
+				}
+			}
+			for (int i = indexList.size()-1; i >= 0; i--) {
+				sg.getLegendPanel().remove(sg.getLegendPanel().getComponent(indexList.get(i)));
+				sg.getStatGraph().removeObject(indexList.get(i));
+				sg.updateUI();
+				
+			}
+		}
 	}
 }

+ 11 - 4
src/ui/view/GUI.java

@@ -266,7 +266,7 @@ public class GUI<E> implements CategoryListener {
 	private AbstractCpsObject temp = null;
 	private final JMenuItem mntmUndo = new JMenuItem("Undo");
 	private final JMenuItem mntmRedo = new JMenuItem("Redo");
-	private final JMenuItem mntmEditEdges = new JMenuItem("Edit Edges");
+	private final JMenuItem mntmEditEdges = new JMenuItem("Edge Properties");
 	private final JMenuItem mntmFindReplace = new JMenuItem("Find/ Replace");
 	private final JMenuItem mntmEditShowedInformation = new JMenuItem("Edit showed Information");
 	private final JMenuItem mntmResetCategory = new JMenuItem("Reset Categories");
@@ -406,6 +406,7 @@ public class GUI<E> implements CategoryListener {
 					for (AbstractCpsObject cps : uNC.upperNode.getNodes()) {
 						controller.addSelectedObject(cps);
 					}
+					controller.getObjectsInDepth();
 					uNC.repaint();
 					// or Canvas?
 				} else if (((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
@@ -413,6 +414,7 @@ public class GUI<E> implements CategoryListener {
 					for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
 						controller.addSelectedObject(cps);
 					}
+					controller.getObjectsInDepth();
 					canvas.repaint();
 				}
 				controller.getObjectsInDepth();
@@ -443,6 +445,7 @@ public class GUI<E> implements CategoryListener {
 						controller.removeTrackingObj(cps);
 						if (uNC.upperNode.getNodes().contains(cps)) {
 							controller.delObjUpperNode(cps, uNC.upperNode);
+							unc.setToolTip(false);
 							// Remove UpperNodeTab if UpperNode deleted
 							if (cps instanceof CpsUpperNode) {
 								boolean splitView = false;
@@ -481,6 +484,7 @@ public class GUI<E> implements CategoryListener {
 						if (j < model.getSelectedCpsObjects().size() - 1)
 							save = true;
 						controller.delCanvasObject(cps, save);
+						canvas.setToolTip(false);
 						// Remove UpperNodeTab if UpperNode deleted
 						if (cps instanceof CpsUpperNode) {
 							boolean splitView = false;
@@ -688,8 +692,7 @@ public class GUI<E> implements CategoryListener {
 		});
 
 		mnNewMenuEdit.add(mntmEditShowedInformation);
-
-		menuBar.add(mnNewMenuOptions);
+		mnNewMenuEdit.add(mntmEditEdges);
 		mntmEditEdges.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent e) {
 				EditEdgesPopUp edgePopUp = new EditEdgesPopUp();
@@ -699,7 +702,7 @@ public class GUI<E> implements CategoryListener {
 			}
 		});
 
-		mnNewMenuOptions.add(mntmEditEdges);
+		menuBar.add(mnNewMenuOptions);
 
 		mnNewMenuOptions.add(mntmResetCategory);
 		mntmResetCategory.addActionListener(new ActionListener() {
@@ -1415,6 +1418,8 @@ public class GUI<E> implements CategoryListener {
 
 								controller.addObjUpperNode(h, unc.upperNode);
 								unc.invalidate();
+								unc.setXY((int) canvas.getMousePosition().getX(),
+										(int) canvas.getMousePosition().getY());
 								unc.repaint();
 							}
 						} else {
@@ -1436,6 +1441,8 @@ public class GUI<E> implements CategoryListener {
 
 							controller.addObjectCanvas(h);
 							canvas.invalidate();
+							canvas.setXY((int) canvas.getMousePosition().getX(),
+									(int) canvas.getMousePosition().getY());
 							canvas.repaint();
 						}
 						controller.calculateStateForCurrentTimeStep();

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

@@ -761,7 +761,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 			}
 		}
 
-		if (edgeHighlight == null && tempCps == null) {
+		if (edgeHighlight == null && tempCps == null ) {
 			sx = e.getX();
 			sy = e.getY();
 			doMark = true;
@@ -1160,4 +1160,23 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 	public boolean[] getShowedInformation() {
 		return showedInformation;
 	}
+	
+	/**
+	 * set toolTip
+	 * @param bool
+	 */
+	public void setToolTip(boolean bool){
+		this.toolTip = bool;
+	}
+	
+	/**
+	 * Set the Mouse
+	 * @param x
+	 * @param y
+	 */
+	public void setXY(int x, int y){
+		this.x = x;
+		this.y = y;
+	}
+	
 }

+ 23 - 15
src/ui/view/StatisticGraphPanel.java

@@ -75,11 +75,11 @@ public class StatisticGraphPanel extends JPanel {
 
 		// ******************** Component Propertys ***************//
 		// Graph
-		//this.setPreferredSize(new Dimension(300, 200));
+		// this.setPreferredSize(new Dimension(300, 200));
 		sGraph.setPreferredSize(new Dimension(200, 200));
 		sGraph.setMinimumSize(new Dimension(100, 150));
-		//this.setMaximumSize(new Dimension(700, 200));
-		//this.setMinimumSize(new Dimension(300, 200));
+		// this.setMaximumSize(new Dimension(700, 200));
+		// this.setMinimumSize(new Dimension(300, 200));
 
 		// Graph Name
 		graphNameLabel = new JLabel(graphName);
@@ -87,7 +87,7 @@ public class StatisticGraphPanel extends JPanel {
 
 		// Panel on top (Name and Close Button)
 		topPanel.setLayout(new BorderLayout(0, 0));
-		JPanel topPanelHelp = new JPanel(new BorderLayout(0,0));
+		JPanel topPanelHelp = new JPanel(new BorderLayout(0, 0));
 		topPanelHelp.add(graphNameLabel, BorderLayout.CENTER);
 		topPanelHelp.add(savImgButton, BorderLayout.EAST);
 		topPanel.add(topPanelHelp, BorderLayout.CENTER);
@@ -234,7 +234,7 @@ public class StatisticGraphPanel extends JPanel {
 		} else {
 			b = new JLabel(property);
 		}
-		//b.setBackground(set.getColor());
+		// b.setBackground(set.getColor());
 		b.setBorder(BorderFactory.createLineBorder(set.getColor()));
 		int color = Math.max(Math.max(set.getColor().getRed(), set.getColor().getGreen()), set.getColor().getBlue());
 
@@ -276,34 +276,42 @@ public class StatisticGraphPanel extends JPanel {
 	public String getGraphName() {
 		return this.graphName;
 	}
-	
+
 	/**
 	 * Calls the addValue function of the sGraph
 	 */
-	public void addValues(){
+	public void addValues() {
 		sGraph.addValues();
 	}
 
 	/**
 	 * Calls the calcMaximum function of the sGraph
 	 */
-	public void calcMaximum(){
+	public void calcMaximum() {
 		sGraph.calcMaximum();
 	}
-	
-	public StatisticGraph getStatGraph(){
+
+	public StatisticGraph getStatGraph() {
 		return sGraph;
 	}
-	
-	public void setStatisticGraph(StatisticGraph sG){
+
+	public void setStatisticGraph(StatisticGraph sG) {
 		this.sGraph = sG;
 	}
+
 	/**
-	 *	Reset the Graph. Delete all calculated values.
+	 * Reset the Graph. Delete all calculated values.
 	 */
-	public void resetGraph(){
+	public void resetGraph() {
 		sGraph.resetGraph();
 	}
 
-	
+	/**
+	 * Returns the Legend Panel.
+	 * @return legendPanel
+	 */
+	public JPanel getLegendPanel(){
+		return legendPanel;
+	}
+
 }

+ 21 - 0
src/ui/view/UpperNodeCanvas.java

@@ -396,6 +396,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 						}
 					}
 				}
+				toolTip = false;
 				model.getSelectedCpsObjects().clear();
 				tempCps = null;
 				repaint();
@@ -1572,4 +1573,24 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 		upperNode.setBackgroundImage(imagePath, mode, width, height);
 	}
 
+	/**
+	 * set tooltIp
+	 * 
+	 * @param bool
+	 */
+	public void setToolTip(boolean bool) {
+		this.toolTip = bool;
+	}
+
+	/**
+	 * Set the Mouse Position on the UpperNodeCanvas;
+	 * 
+	 * @param x
+	 * @param y
+	 */
+	public void setXY(int x, int y) {
+		this.x = x;
+		this.y = y;
+	}
+
 }