Browse Source

momentane iteration beim graphen angezeigt

Kevin Trometer 8 years ago
parent
commit
6cab6fbe21
3 changed files with 35 additions and 12 deletions
  1. 19 9
      src/ui/view/GUI.java
  2. 13 1
      src/ui/view/TimePanel.java
  3. 3 2
      src/ui/view/UnitGraph.java

+ 19 - 9
src/ui/view/GUI.java

@@ -8,6 +8,7 @@ import javax.swing.JLabel;
 import javax.swing.JMenuBar;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
+import javax.swing.JSlider;
 import javax.swing.JOptionPane;
 import javax.swing.JTree;
 import javax.swing.border.LineBorder;
@@ -157,12 +158,12 @@ public class GUI implements CategoryListener {
 	private int yValueElements = 0;
 
 	private MyCanvas canvas;
-	private UnitGraph testgraph; // for testing, remove later
+	private UnitGraph unitGraph; // for testing, remove later
 	private final JSplitPane splitPane_3 = new JSplitPane();
 	private final JSlider sizeSlider = new JSlider();
 	private final JLabel lblImageSize = new JLabel("Image Size");
 	// Time Stuff
-	private final TimePanel timePanel;
+	private TimePanel timePanel;
 
 	/**
 	 * Create the application.
@@ -171,10 +172,9 @@ public class GUI implements CategoryListener {
 		this.controller = control;
 		this.model = control.getModel();
 		this.canvas = new MyCanvas(model, control);
-		this.testgraph = new UnitGraph(model, control); // for testing, remove
+		this.unitGraph = new UnitGraph(model, control); // for testing, remove
 
-		timePanel = new TimePanel(model, controller);
-		timePanel.setBorder(null);
+		
 
 		// later
 		control.initListener(this);
@@ -232,7 +232,7 @@ public class GUI implements CategoryListener {
 
 		mnHelp.add(aboutUs);
 
-		testgraph.setBackground(Color.WHITE);
+		unitGraph.setBackground(Color.WHITE);
 
 		canvas.setBackground(Color.WHITE);
 		canvas.setPreferredSize(new Dimension(10000, 10000));
@@ -285,7 +285,7 @@ public class GUI implements CategoryListener {
 		 */
 		scrollProperties.setViewportView(tableProperties);
 		tableHolonElementScrollPane.setViewportView(tableHolonElement);
-		scrollGraph.setViewportView(testgraph);
+		scrollGraph.setViewportView(unitGraph);
 		graphLabel.setLayout(new BorderLayout(0, 10));
 		graphLabel.add(maxGraph, BorderLayout.NORTH);
 		graphLabel.add(medGraph, BorderLayout.CENTER);
@@ -323,7 +323,7 @@ public class GUI implements CategoryListener {
 		resetGraphBtn.addActionListener(new ActionListener() {
 
 			public void actionPerformed(ActionEvent arg0) {
-				testgraph.reset();
+				unitGraph.reset();
 			}
 		});
 		toolBarHolonEl.add(btnDelHolEL);
@@ -347,7 +347,7 @@ public class GUI implements CategoryListener {
 				HolonElement ele = getActualHolonElement(obj, yValueElements);
 				if (ele != null) {
 					elementGraph.setText(ele.getEleName() + " ");
-					testgraph.repaintWithNewElement(ele);
+					unitGraph.repaintWithNewElement(ele);
 				} else {
 					elementGraph.setText("None ");
 				}
@@ -702,6 +702,16 @@ public class GUI implements CategoryListener {
 			}
 		});
 
+		timePanel = new TimePanel(model, controller);
+		timePanel.setBorder(null);
+		((JSlider)(timePanel.getComponent(1))).addChangeListener(new ChangeListener() {
+			
+			@Override
+			public void stateChanged(ChangeEvent e) {
+				unitGraph.repaint();
+			}
+		});
+		
 		splitPane.setRightComponent(splitPane_1);
 		splitPane.setDividerLocation(200);
 		splitPane_1.setDividerLocation(500);

+ 13 - 1
src/ui/view/TimePanel.java

@@ -13,6 +13,8 @@ import javax.swing.JPanel;
 import javax.swing.JSlider;
 import javax.swing.Timer;
 import javax.swing.border.LineBorder;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
 
 import ui.controller.Control;
 import ui.model.Model;
@@ -46,6 +48,7 @@ public class TimePanel extends JPanel {
 			@Override
 			public void actionPerformed(ActionEvent ae) {
 				timeSlider.setValue(timeSlider.getValue() + 1);
+				controller.setCurIteration(timeSlider.getValue());
 				if (timeSlider.getValue() == model.getIterations()) {
 					running = false;
 					playBtn.setIcon(new ImageIcon(new ImageIcon(this.getClass().getResource("/Button_Images/play.png"))
@@ -64,9 +67,15 @@ public class TimePanel extends JPanel {
 		timeSlider.setMinorTickSpacing(1);
 		timeSlider.setMajorTickSpacing(5);
 		timeSlider.setToolTipText("Time Slider");
-		timeSlider.setMaximum(model.getIterations());
+		timeSlider.setMaximum(model.getIterations()-1);
 		timeSlider.setValue(0);
 		timeSlider.setBackground(Color.WHITE);
+		timeSlider.addChangeListener(new ChangeListener() {
+			@Override
+			public void stateChanged(ChangeEvent e) {
+				controller.setCurIteration(timeSlider.getValue());
+			}
+		});
 
 		// Panel
 		timeBtnPanel.setBorder(null);
@@ -106,6 +115,7 @@ public class TimePanel extends JPanel {
 		timeResetBtn.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent ae) {
 				timeSlider.setValue(timeSlider.getMinimum());
+				controller.setCurIteration(timeSlider.getValue());
 			}
 		});
 		timeForwardBtn.setToolTipText("Forward");
@@ -118,6 +128,7 @@ public class TimePanel extends JPanel {
 		timeForwardBtn.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent ae) {
 				timeSlider.setValue(timeSlider.getValue() + 1);
+				controller.setCurIteration(timeSlider.getValue());
 			}
 		});
 		timeBackwardBtn.setToolTipText("Backward");
@@ -130,6 +141,7 @@ public class TimePanel extends JPanel {
 		timeBackwardBtn.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent ae) {
 				timeSlider.setValue(timeSlider.getValue() - 1);
+				controller.setCurIteration(timeSlider.getValue());
 			}
 		});
 

+ 3 - 2
src/ui/view/UnitGraph.java

@@ -124,8 +124,9 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			g2.fillOval((int) (pointList.get(i).getX() * scaleX - recSize.getX() / 2),
 					(int) (pointList.get(i).getY() * scaleY - recSize.getY() / 2), (int) recSize.getX(),
 					(int) recSize.getY());
-
 		}
+		g2.drawLine((model.getCurIteration()) * this.getWidth() / (ITERATIONS - 1), MAXIMUM, (model.getCurIteration()) * this.getWidth() / (ITERATIONS - 1),
+				this.getHeight());
 
 	}
 
@@ -272,7 +273,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	/**
 	 * converts the number to fit the canvas
 	 * 
-	 * @param int
+	 * @param double
 	 *            d, the number to convert
 	 * @return the convertet number
 	 */