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
0cea9d9395

+ 110 - 110
src/ui/view/ButtonTabComponent.java

@@ -30,121 +30,121 @@ package ui.view;
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
- 
+
 import javax.swing.*;
 import javax.swing.plaf.basic.BasicButtonUI;
 import java.awt.*;
 import java.awt.event.*;
- 
+
 /**
- * Component to be used as tabComponent;
- * Contains a JLabel to show the text and 
- * a JButton to close the tab it belongs to 
+ * Component to be used as tabComponent; Contains a JLabel to show the text and
+ * a JButton to close the tab it belongs to
  */
 public class ButtonTabComponent extends JPanel {
-    private final JTabbedPane pane;
-    private final JTabbedPane pane2;
- 
-    public ButtonTabComponent(final JTabbedPane pane, final JTabbedPane pane2) {
-        //unset default FlowLayout' gaps
-        super(new FlowLayout(FlowLayout.LEFT, 0, 0));
-        if (pane == null) {
-            throw new NullPointerException("TabbedPane is null");
-        }
-        this.pane = pane;
-        this.pane2 = pane2;
-        setOpaque(false);
-         
-        //make JLabel read titles from JTabbedPane
-        JLabel label = new JLabel() {
-            public String getText() {
-                int i = pane.indexOfTabComponent(ButtonTabComponent.this);
-                if (i != -1) {
-                    return pane.getTitleAt(i);
-                }
-                return null;
-            }
-        };
-         
-        add(label);
-        //add more space between the label and the button
-        label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
-        //tab button
-        JButton button = new TabButton();
-        add(button);
-        //add more space to the top of the component
-        setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
-    }
- 
-    private class TabButton extends JButton implements ActionListener {
-        public TabButton() {
-            int size = 17;
-            setPreferredSize(new Dimension(size, size));
-            setToolTipText("close this tab");
-            //Make the button looks the same for all Laf's
-            setUI(new BasicButtonUI());
-            //Make it transparent
-            setContentAreaFilled(false);
-            //No need to be focusable
-            setFocusable(false);
-            setBorder(BorderFactory.createEtchedBorder());
-            setBorderPainted(false);
-            //Making nice rollover effect
-            //we use the same listener for all buttons
-            addMouseListener(buttonMouseListener);
-            setRolloverEnabled(true);
-            //Close the proper tab by clicking the button
-            addActionListener(this);
-        }
- 
-        public void actionPerformed(ActionEvent e) {
-            int i = pane.indexOfTabComponent(ButtonTabComponent.this);
-            if (i != -1) {
-                pane.remove(i);
-                pane2.remove(i);
-            }
-        }
- 
-        //we don't want to update UI for this button
-        public void updateUI() {
-        }
- 
-        //paint the cross
-        protected void paintComponent(Graphics g) {
-            super.paintComponent(g);
-            Graphics2D g2 = (Graphics2D) g.create();
-            //shift the image for pressed buttons
-            if (getModel().isPressed()) {
-                g2.translate(1, 1);
-            }
-            g2.setStroke(new BasicStroke(2));
-            g2.setColor(Color.BLACK);
-            if (getModel().isRollover()) {
-                g2.setColor(Color.MAGENTA);
-            }
-            int delta = 6;
-            g2.drawLine(delta, delta, getWidth() - delta - 1, getHeight() - delta - 1);
-            g2.drawLine(getWidth() - delta - 1, delta, delta, getHeight() - delta - 1);
-            g2.dispose();
-        }
-    }
- 
-    private final static MouseListener buttonMouseListener = new MouseAdapter() {
-        public void mouseEntered(MouseEvent e) {
-            Component component = e.getComponent();
-            if (component instanceof AbstractButton) {
-                AbstractButton button = (AbstractButton) component;
-                button.setBorderPainted(true);
-            }
-        }
- 
-        public void mouseExited(MouseEvent e) {
-            Component component = e.getComponent();
-            if (component instanceof AbstractButton) {
-                AbstractButton button = (AbstractButton) component;
-                button.setBorderPainted(false);
-            }
-        }
-    };
-}
+	private final JTabbedPane pane;
+	private final JTabbedPane pane2;
+
+	public ButtonTabComponent(final JTabbedPane pane, final JTabbedPane pane2) {
+		// unset default FlowLayout' gaps
+		super(new FlowLayout(FlowLayout.LEFT, 0, 0));
+		if (pane == null) {
+			throw new NullPointerException("TabbedPane is null");
+		}
+		this.pane = pane;
+		this.pane2 = pane2;
+		setOpaque(false);
+
+		// make JLabel read titles from JTabbedPane
+		JLabel label = new JLabel() {
+			public String getText() {
+				int i = pane.indexOfTabComponent(ButtonTabComponent.this);
+				if (i != -1) {
+					return pane.getTitleAt(i);
+				}
+				return null;
+			}
+		};
+
+		add(label);
+		// add more space between the label and the button
+		label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
+		// tab button
+		JButton button = new TabButton();
+		add(button);
+		// add more space to the top of the component
+		setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
+	}
 
+	private class TabButton extends JButton implements ActionListener {
+		public TabButton() {
+			int size = 17;
+			setPreferredSize(new Dimension(size, size));
+			setToolTipText("close this tab");
+			// Make the button looks the same for all Laf's
+			setUI(new BasicButtonUI());
+			// Make it transparent
+			setContentAreaFilled(false);
+			// No need to be focusable
+			setFocusable(false);
+			setBorder(BorderFactory.createEtchedBorder());
+			setBorderPainted(false);
+			// Making nice rollover effect
+			// we use the same listener for all buttons
+			addMouseListener(buttonMouseListener);
+			setRolloverEnabled(true);
+			// Close the proper tab by clicking the button
+			addActionListener(this);
+		}
+
+		public void actionPerformed(ActionEvent e) {
+			int i = pane.indexOfTabComponent(ButtonTabComponent.this);
+			if (i != -1) {
+				pane.remove(i);
+				if (pane2.getTabCount() < 0) {
+					pane2.remove(i);
+				}
+			}
+		}
+
+		// we don't want to update UI for this button
+		public void updateUI() {
+		}
+
+		// paint the cross
+		protected void paintComponent(Graphics g) {
+			super.paintComponent(g);
+			Graphics2D g2 = (Graphics2D) g.create();
+			// shift the image for pressed buttons
+			if (getModel().isPressed()) {
+				g2.translate(1, 1);
+			}
+			g2.setStroke(new BasicStroke(2));
+			g2.setColor(Color.BLACK);
+			if (getModel().isRollover()) {
+				g2.setColor(Color.MAGENTA);
+			}
+			int delta = 6;
+			g2.drawLine(delta, delta, getWidth() - delta - 1, getHeight() - delta - 1);
+			g2.drawLine(getWidth() - delta - 1, delta, delta, getHeight() - delta - 1);
+			g2.dispose();
+		}
+	}
+
+	private final static MouseListener buttonMouseListener = new MouseAdapter() {
+		public void mouseEntered(MouseEvent e) {
+			Component component = e.getComponent();
+			if (component instanceof AbstractButton) {
+				AbstractButton button = (AbstractButton) component;
+				button.setBorderPainted(true);
+			}
+		}
+
+		public void mouseExited(MouseEvent e) {
+			Component component = e.getComponent();
+			if (component instanceof AbstractButton) {
+				AbstractButton button = (AbstractButton) component;
+				button.setBorderPainted(false);
+			}
+		}
+	};
+}

+ 2 - 1
src/ui/view/GUI.java

@@ -1801,9 +1801,10 @@ public class GUI<E> implements CategoryListener {
 				int i = model.getCurIteration();
 				controller.runAlgorithm(model, controller);
 				controller.calculateStateForTimeStep(i);
-				contentPane.updateUI();
 				unitGraph.repaint();
 				statSplitPane.repaintGraphs();
+				controller.addTextToConsole("test");
+				contentPane.updateUI();
 			}
 		});
 		splitPane1.setMinimumSize(new Dimension(0, 25));

+ 2 - 0
src/ui/view/SplitPane.java

@@ -812,6 +812,8 @@ public class SplitPane extends JSplitPane implements GraphListener {
 
 	public void repaintGraphs() {
 		for (StatisticGraphPanel sg : graphHashtable.values()) {
+			sg.calcMaximum();
+			sg.addValues();
 			sg.repaint();
 		}
 	}

+ 2 - 0
src/ui/view/StatPanel2.java

@@ -771,6 +771,8 @@ public class StatPanel2 extends JSplitPane implements GraphListener {
 
 	public void repaintGraphs() {
 		for (StatisticGraphPanel sg : graphHashtable.values()) {
+			sg.calcMaximum();
+			sg.addValues();
 			sg.repaint();
 		}
 	}

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

@@ -90,10 +90,10 @@ public class StatisticGraph extends JPanel {
 			g2.setStroke(new BasicStroke(3));
 
 			// Calculate the Maximum
-			calcMaximum();
+			// calcMaximum();
 
 			// Calculate values for each set and add them
-			addValues();
+			// addValues();
 
 			// Create Paths and draw them
 			for (TrackedDataSet set : dataSets) {
@@ -329,7 +329,7 @@ public class StatisticGraph extends JPanel {
 	/**
 	 * Add the Current Values to each set
 	 */
-	private void addValues() {
+	public void addValues() {
 		for (TrackedDataSet set : dataSets) {
 			float val = 0;
 			switch (set.getProperty()) {
@@ -547,8 +547,10 @@ public class StatisticGraph extends JPanel {
 				path.lineTo((i + 1) * this.getWidth() / model.getIterations(),
 						convertToCanvasY(set.getValues()[i + 1]));
 			} else {
-				path.moveTo((i + 2) * this.getWidth() / model.getIterations(),
-						convertToCanvasY(set.getValues()[i + 2]));
+				if (i + 2 < model.getCurIteration()) {
+					path.moveTo((i + 2) * this.getWidth() / model.getIterations(),
+							convertToCanvasY(set.getValues()[i + 2]));
+				}
 			}
 		}
 	}
@@ -571,8 +573,10 @@ public class StatisticGraph extends JPanel {
 				path.lineTo((i + 1) * this.getWidth() / model.getIterations(),
 						convertToCanvasY((float) (set.getValues()[i + 1] * (maximum / 3 * 2)) + (maximum / 6)));
 			} else {
-				path.moveTo((i + 2) * this.getWidth() / model.getIterations(),
-						convertToCanvasY((float) (set.getValues()[i + 2] * (maximum / 3 * 2)) + (maximum / 6)));
+				if (i + 2 < model.getCurIteration()) {
+					path.moveTo((i + 2) * this.getWidth() / model.getIterations(),
+							convertToCanvasY((float) (set.getValues()[i + 2] * (maximum / 3 * 2)) + (maximum / 6)));
+				}
 			}
 		}
 	}
@@ -593,8 +597,10 @@ public class StatisticGraph extends JPanel {
 				path.lineTo((i + 1) * this.getWidth() / model.getIterations(),
 						convertToCanvasY(set.getValues()[i + 1] * maximum));
 			} else {
-				path.moveTo((i + 2) * this.getWidth() / model.getIterations(),
-						convertToCanvasY(set.getValues()[i + 2] * maximum));
+				if (i + 2 < model.getCurIteration()) {
+					path.moveTo((i + 2) * this.getWidth() / model.getIterations(),
+							convertToCanvasY(set.getValues()[i + 2] * maximum));
+				}
 			}
 
 		}

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

@@ -274,5 +274,19 @@ public class StatisticGraphPanel extends JPanel {
 	public String getGraphName() {
 		return this.graphName;
 	}
+	
+	/**
+	 * Calls the addValue function of the sGraph
+	 */
+	public void addValues(){
+		sGraph.addValues();
+	}
 
+	/**
+	 * Calls the calcMaximum function of the sGraph
+	 */
+	public void calcMaximum(){
+		sGraph.calcMaximum();
+	}
+	
 }