Browse Source

statisticgraphpanel

Kevin Trometer 8 years ago
parent
commit
d14801a722

+ 0 - 8
src/ui/view/StatisticGraph.java

@@ -58,14 +58,6 @@ public class StatisticGraph extends JPanel {
 		this.controller = control;
 		this.model = model;
 
-		// addObject(new TrackedDataSet(model.getObjectsOnCanvas().get(0),
-		// TrackedDataSet.CONSUMPTION, Color.RED));
-		// addObject(new TrackedDataSet(model.getObjectsOnCanvas().get(0),
-		// TrackedDataSet.PRODUCTION, Color.GREEN));
-		// addObject(new TrackedDataSet(model.getObjectsOnCanvas().get(0),
-		// TrackedDataSet.ACTIVATED_ELEMENTS, Color.CYAN));
-		addObject(new TrackedDataSet(model.getObjectsOnCanvas().get(0), TrackedDataSet.ON_OFF, Color.BLUE));
-
 		this.setBackground(Color.WHITE);
 
 		Timer timer = new Timer(200, new ActionListener() {

+ 83 - 0
src/ui/view/StatisticGraphPanel.java

@@ -0,0 +1,83 @@
+package ui.view;
+
+import javax.swing.JPanel;
+
+import classes.TrackedDataSet;
+import ui.controller.Control;
+import ui.model.Model;
+import javax.swing.JLabel;
+import javax.swing.BoxLayout;
+import javax.swing.SwingConstants;
+import java.awt.BorderLayout;
+
+public class StatisticGraphPanel extends JPanel {
+
+	private static final long serialVersionUID = 1L;
+
+	// Model/Controller
+	private Model model;
+	private Control controller;
+
+	// Components
+	private StatisticGraph sGraph;
+	private final JLabel graphNameLabel;
+	private final JLabel maximumLabel = new JLabel("0");
+
+	// Variables
+	String graphName;
+	private final JPanel Legendpanel = new JPanel();
+
+	/**
+	 * Constructor.
+	 * 
+	 * @param mod
+	 *            the Model
+	 * @param cont
+	 *            the Controller
+	 */
+	public StatisticGraphPanel(Model mod, Control cont, String name) {
+		super();
+		this.model = mod;
+		this.controller = cont;
+		this.sGraph = new StatisticGraph(mod, cont);
+		this.graphName = name;
+		setLayout(new BorderLayout(0, 0));
+
+		/**** add everything *****/
+		// Statistic Graph
+		this.add(sGraph);
+		// Graph Name
+		graphNameLabel = new JLabel(graphName);
+		graphNameLabel.setHorizontalAlignment(SwingConstants.CENTER);
+		this.add(graphNameLabel, BorderLayout.NORTH);
+		// Y Maximum
+		maximumLabel.setVerticalAlignment(SwingConstants.TOP);
+		this.add(maximumLabel, BorderLayout.WEST);
+		// Legend Panel
+		add(Legendpanel, BorderLayout.SOUTH);
+	}
+
+	/**
+	 * Adds the Set to the Graph.
+	 * 
+	 * @param set
+	 */
+	public void addObjec(TrackedDataSet set) {
+		sGraph.addObject(set);
+	}
+
+	/**
+	 * Repaint the Graph.
+	 * 
+	 * public void repaint() { sGraph.repaint(); }
+	 */
+
+	/**
+	 * Set the Maximum Label
+	 *
+	 * @param max
+	 */
+	public void setMaximumLabel(int max) {
+		maximumLabel.setText(Integer.toString(max));
+	}
+}

+ 1 - 1
src/ui/view/splitPane.java

@@ -339,7 +339,7 @@ public class splitPane extends JSplitPane implements GraphListener {
 		JButton btnAdd = new JButton("Add");
 		btnAdd.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent e) {
-				StatisticGraph tmp = new StatisticGraph(controller.getModel(), controller);
+				StatisticGraphPanel tmp = new StatisticGraphPanel(controller.getModel(), controller, "test");
 				graphPanel.add(tmp);
 				graphPanel.revalidate();
 				graphPanel.updateUI();