Quellcode durchsuchen

entfernen von graph elementen

Kevin Trometer vor 8 Jahren
Ursprung
Commit
b3b75acebb
2 geänderte Dateien mit 42 neuen und 36 gelöschten Zeilen
  1. 6 9
      src/ui/view/StatisticGraph.java
  2. 36 27
      src/ui/view/StatisticGraphPanel.java

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

@@ -94,8 +94,6 @@ public class StatisticGraph extends JPanel {
 
 			// Calculate the Maximum
 			calcMaximum();
-			((StatisticGraphPanel)this.getParent()).setMaximumLabel(maximum);
-			((StatisticGraphPanel)this.getParent()).makeLegendPanel();
 
 			// Calculate values for each set and add them
 			addValues();
@@ -136,13 +134,11 @@ public class StatisticGraph extends JPanel {
 	/**
 	 * Removes an Object from the Graph.
 	 * 
-	 * @param obj
-	 *            the Object to remove
+	 * @param id
+	 *            the id of the Object to remove
 	 */
-	public void removeObject() {
-		for (TrackedDataSet set : objects) {
-			controller.addTextToConsole("Function not available");
-		}
+	public void removeObject(int id) {
+			objects.remove(id);
 	}
 
 	/**
@@ -175,7 +171,7 @@ public class StatisticGraph extends JPanel {
 	/**
 	 * Calculate the Max Value of the Graph
 	 */
-	private void calcMaximum() {
+	public void calcMaximum() {
 		maximum = 0;
 		for (TrackedDataSet set : objects) {
 			int val = 0;
@@ -211,6 +207,7 @@ public class StatisticGraph extends JPanel {
 				maximum = val;
 			}
 		}
+		((StatisticGraphPanel)this.getParent()).setMaximumLabel(maximum);
 	}
 
 	/**

+ 36 - 27
src/ui/view/StatisticGraphPanel.java

@@ -76,9 +76,6 @@ public class StatisticGraphPanel extends JPanel {
 		maximumLabel.setVerticalAlignment(SwingConstants.TOP);
 		maximumLabel.setMinimumSize(new Dimension(30, 10));
 
-		// Legend Panel
-		makeLegendPanel();
-
 		// ******************** Component Listener ****************//
 
 		that = this;
@@ -113,6 +110,42 @@ public class StatisticGraphPanel extends JPanel {
 	 */
 	public void addObjec(TrackedDataSet set) {
 		sGraph.addObject(set);
+		String property = "";
+		switch (set.getProperty()) {
+		case TrackedDataSet.CONSUMPTION:
+			property = "consumption";
+			break;
+		case TrackedDataSet.PRODUCTION:
+			property = "production";
+			break;
+		case TrackedDataSet.ACTIVATED_ELEMENTS:
+			property = "active elements";
+			break;
+		case TrackedDataSet.ON_OFF:
+			property = "on//off";
+			break;
+		default:
+			break;
+		}
+		JLabel b = new JLabel(set.getCpsObject().getName() + ": " + property);
+		b.setBackground(Color.CYAN);
+		b.setOpaque(true);
+		b.addMouseListener(new MouseAdapter() {
+			@Override
+			public void mousePressed(MouseEvent e) {
+				if (MouseEvent.BUTTON3 == e.getButton()) {
+					for (int i = 0; i < legendPanel.getComponentCount(); i++) {
+						if (legendPanel.getComponent(i).equals(e.getComponent())) {
+							legendPanel.remove(i);
+							sGraph.removeObject(i);
+							that.updateUI();
+						}
+					}
+				}
+			}
+		});
+		legendPanel.add(b);
+		sGraph.calcMaximum();
 	}
 
 	/**
@@ -133,28 +166,4 @@ public class StatisticGraphPanel extends JPanel {
 		return this.graphName;
 	}
 
-	/**
-	 * Make the LegendPane.
-	 */
-	public void makeLegendPanel() {
-		legendPanel.removeAll();
-		for (TrackedDataSet set : sGraph.objects) {
-			JLabel b = new JLabel(set.getCpsObject().getName());
-			b.setBackground(Color.CYAN);
-			b.setOpaque(true);
-			tempP = new JPanel();
-			tempP.add(b);
-			b.addMouseListener(new MouseAdapter() {
-				@Override
-				public void mousePressed(MouseEvent e) {
-					if (e.BUTTON3 == e.getButton()) {
-						legendPanel.remove(tempP);
-						that.updateUI();
-					}
-				}
-			});
-			legendPanel.add(tempP);
-		}
-		updateUI();
-	}
 }