Browse Source

delete properties in the statisticGraph, if the object was deleted

Kevin Trometer 7 years ago
parent
commit
b21b8d5ff4

+ 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();
+				
+			}
+		}
 	}
 }

+ 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;
+	}
+
 }

+ 1 - 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();