Quellcode durchsuchen

graph removable

Kevin Trometer vor 8 Jahren
Ursprung
Commit
aa072629e1
2 geänderte Dateien mit 31 neuen und 11 gelöschten Zeilen
  1. 30 10
      src/ui/view/StatisticGraphPanel.java
  2. 1 1
      src/ui/view/splitPane.java

+ 30 - 10
src/ui/view/StatisticGraphPanel.java

@@ -12,6 +12,9 @@ import javax.swing.SwingConstants;
 import java.awt.BorderLayout;
 import javax.swing.border.LineBorder;
 import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 
 public class StatisticGraphPanel extends JPanel {
 
@@ -49,20 +52,37 @@ public class StatisticGraphPanel extends JPanel {
 		this.graphName = name;
 		setLayout(new BorderLayout(0, 0));
 
-		//********** add everything **********//
-		// Statistic Graph
-		this.add(sGraph);
-		// Graph Name and Close Button
+		// ******************** Component Propertys ***************//
+		//Graph Name
 		graphNameLabel = new JLabel(graphName);
-		topPanel.add(graphNameLabel);
-		topPanel.add(closeButton);
+		graphNameLabel.setHorizontalTextPosition(JLabel.CENTER);
+
+		//Panel on top (Name and Close Button)
+		topPanel.setLayout(new BorderLayout(0, 0));
+		topPanel.add(graphNameLabel, BorderLayout.CENTER);
+		topPanel.add(closeButton, BorderLayout.EAST);
 		topPanel.setBorder(null);
-		this.add(topPanel, BorderLayout.NORTH);
-		// Y Maximum
+		
+		//Maximum Label
 		maximumLabel.setVerticalAlignment(SwingConstants.TOP);
+		maximumLabel.setPreferredSize(new Dimension(30,10));
+		// ******************** Component Listener ****************//
+		
+		JPanel that = this;
+		closeButton.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				JPanel parent = (JPanel) that.getParent();
+				parent.remove(that);
+				parent.revalidate();
+			}
+		});
+		
+		// ******************** add everything ********************//
+		this.add(sGraph);
+		this.add(topPanel, BorderLayout.NORTH);
 		this.add(maximumLabel, BorderLayout.WEST);
-		// Legend Panel
-		add(Legendpanel, BorderLayout.SOUTH);
+		this.add(Legendpanel, BorderLayout.SOUTH);
 	}
 
 	/**

+ 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) {
-				StatisticGraphPanel tmp = new StatisticGraphPanel(controller.getModel(), controller, "test");
+				StatisticGraphPanel tmp = new StatisticGraphPanel(controller.getModel(), controller, graphNrTxtField.getText());
 				graphPanel.add(tmp);
 				graphPanel.revalidate();
 				graphPanel.updateUI();