Ver código fonte

Adds a Label and Textfield for local Graph periods to the UnitGraph GUI

Not linked to HolonElements/Switches yet
Andreas T. Meyer-Berg 6 anos atrás
pai
commit
17719b9a7f
2 arquivos alterados com 63 adições e 1 exclusões
  1. 44 1
      src/ui/view/GUI.java
  2. 19 0
      src/ui/view/UnitGraph.java

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

@@ -99,6 +99,7 @@ public class GUI implements CategoryListener {
 	private final JLabel medGraph = new JLabel("50%");
 	private final JLabel minGraph = new JLabel("0%");
 	private final JLabel elementGraph = new JLabel("None ");
+	private final JLabel unitGraphLocalPeriodLbl = new JLabel("Local Period:");
 	private final ArrayList<HolonElement> selectedElements = new ArrayList<>();
 	private final JTree tree = new JTree();
 	/******************************************
@@ -179,6 +180,8 @@ public class GUI implements CategoryListener {
 	private final MyCanvas canvas;
 	private final HolonCanvas holonCanvas;
 	private final UnitGraph unitGraph;
+	/** Textfield to show the period of an element */
+	private final JTextField unitGraphLocalPeriod = new JTextField();
 	private final JSplitPane splitPane3 = new JSplitPane();
 	private final JSlider sizeSlider = new JSlider();
 	private final JLabel lblImageSize = new JLabel(Languages.getLanguage()[94]);
@@ -1056,14 +1059,33 @@ public class GUI implements CategoryListener {
 
 		toolBarGraph.add(lblSelectedElement);
 		toolBarGraph.add(elementGraph);
+		
+		Component horizontalStrut = Box.createHorizontalStrut(20);
+		/*
 		Component horizontalStrut = Box.createHorizontalStrut(toolBarGraph
-				.getWidth() - resetGraphBtn.getWidth());
+				.getWidth() - resetGraphBtn.getWidth() - unitGraphLocalPeriod.getWidth()
+				-unitGraphLocalPeriodLbl.getWidth());
 
+		*/
 		toolBarGraph.add(horizontalStrut);
+
+		/** Add local Graph length Textfield an Label */
+		unitGraphLocalPeriod.setPreferredSize(new Dimension(30, 12));
+		unitGraphLocalPeriod.setText(""+unitGraph.getLocalPeriod());
+		resetGraphBtn.setHorizontalAlignment(SwingConstants.RIGHT);
+		
+		toolBarGraph.add(unitGraphLocalPeriodLbl);
+		
+		unitGraphLocalPeriodLbl.setHorizontalAlignment(SwingConstants.RIGHT);
+		toolBarGraph.add(unitGraphLocalPeriod);
+		
+		
 		resetGraphBtn.setHorizontalAlignment(SwingConstants.RIGHT);
 
 		toolBarGraph.add(resetGraphBtn);
 		toolBarGraph.setFloatable(false);
+		
+		
 		scrollGraph.setRowHeaderView(graphLabel);
 		scrollGraph.setColumnHeaderView(toolBarGraph);
 
@@ -1521,6 +1543,27 @@ public class GUI implements CategoryListener {
 		 */
 		resetGraphBtn.setBorder(new LineBorder(Color.BLACK));
 		resetGraphBtn.addActionListener(actionEvent -> unitGraph.reset());
+		
+		/*
+		 * Update Local Period of an Element Graph
+		 */
+		unitGraphLocalPeriod.addKeyListener(new KeyAdapter() {
+			@Override
+			 public void keyReleased(KeyEvent e) {
+				try{
+					int localLength = Integer.parseInt(unitGraphLocalPeriod.getText());
+					unitGraphLocalPeriod.setBackground(Color.WHITE);
+					/**
+					 * set local graph Period
+					 */
+					unitGraph.setLocalPeriod(localLength);						
+				}catch(Exception ex){
+					unitGraphLocalPeriod.setBackground(Color.RED);
+				}
+				
+			}
+		});
+		
 		/*****************************
 		 * RIGHT CONTAINER DONE
 		 *****************************/

+ 19 - 0
src/ui/view/UnitGraph.java

@@ -55,6 +55,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
 
     private int border = 4;
     private int textWidth = 0;
+    
+    private int localPeriod = 100;
 
     /**
      * Constructor.
@@ -834,4 +836,21 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
             return ele.getEnergyPerElement();
         }
     }
+    
+    /**
+     * sets the localPeriod of the Current Graph
+     * @param localPeriod
+     */
+    public void setLocalPeriod(int localPeriod){
+    	//TODO: local Graph length for each HolonElelemt
+    	this.localPeriod = localPeriod;
+    }
+    
+    /**
+     * gets the LocalPeriod of the CurrentGraph
+     * @return localPeriod of the current Element or Switch
+     */
+    public int getLocalPeriod(){
+    	return localPeriod;
+    }
 }