Browse Source

Small changes in the design of the GUI

Edgardo Palza 8 years ago
parent
commit
b8e3fb5427
1 changed files with 37 additions and 9 deletions
  1. 37 9
      src/ui/view/GUI.java

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

@@ -59,6 +59,7 @@ import java.beans.PropertyChangeListener;
 import java.awt.event.ActionEvent;
 import javax.swing.JSlider;
 import javax.swing.event.ChangeListener;
+import javax.swing.event.TableModelEvent;
 import javax.swing.event.ChangeEvent;
 
 public class GUI implements CategoryListener {
@@ -109,6 +110,7 @@ public class GUI implements CategoryListener {
 	// HolonObject, such as connections, name, Type, etc.
 
 	private JTable tableProperties = new JTable();
+	private JPanel graphLabel = new JPanel();
 	private DefaultTableModel tableModelProperties = new DefaultTableModel();
 	private final JScrollPane scrollProperties = new JScrollPane();
 
@@ -281,12 +283,10 @@ public class GUI implements CategoryListener {
 		scrollProperties.setViewportView(tableProperties);
 		tableHolonElementScrollPane.setViewportView(tableHolonElement);
 		scrollGraph.setViewportView(testgraph);
-		JPanel graphLabel = new JPanel();
-		graphLabel.setLayout(new BoxLayout(graphLabel, BoxLayout.Y_AXIS));
-		minGraph.setBounds(0, 150, 10, 10);
-		graphLabel.add(maxGraph);
-		graphLabel.add(medGraph);
-		graphLabel.add(minGraph);
+		graphLabel.setLayout(new BorderLayout(0, 10));
+		graphLabel.add(maxGraph, BorderLayout.NORTH);
+		graphLabel.add(medGraph, BorderLayout.CENTER);
+		graphLabel.add(minGraph, BorderLayout.SOUTH);
 		toolBarGraph.add(elementGraph);
 		comboBoxGraph.setModel(new DefaultComboBoxModel(new String[] { "Day", "Month", "Year" }));
 		toolBarGraph.add(comboBoxGraph);
@@ -313,6 +313,7 @@ public class GUI implements CategoryListener {
 					controller.addElementCanvasObject(tempCpsObject.getID(), addElementPopUp.getElement().getEleName(),
 							addElementPopUp.getElement().getAmount(), addElementPopUp.getElement().getEnergy());
 					refreshTableHolonElement();
+					refreshTableProperties();
 				}
 			}
 		});
@@ -331,11 +332,11 @@ public class GUI implements CategoryListener {
 					if (tempElement != null && obj.getClass() == HolonObject.class && obj.getID() != 0) {
 						controller.deleteElementCanvas(obj.getID(), tempElement.getEleName());
 						refreshTableHolonElement();
+						refreshTableProperties();
 					}
 				}
 			}
 		});
-
 		tableHolonElement.addMouseListener(new MouseAdapter() {
 			public void mousePressed(MouseEvent e) {
 				HolonObject obj = (HolonObject) getActualCps();
@@ -777,14 +778,27 @@ public class GUI implements CategoryListener {
 		return frmCyberPhysical;
 	}
 
+	/**
+	 * Getter for selected CpsObject
+	 * 
+	 * @return selected CpsObject
+	 */
 	public CpsObject getActualCps() {
 		int tempID = model.getSelectedObjectID();
 		CpsObject tempCps = controller.searchByID(tempID);
 		return tempCps;
 	}
 
+	/**
+	 * Search for actual selected HolonElement
+	 * 
+	 * @param obj
+	 *            selected HolonObject
+	 * @param yValue
+	 *            Y-Coord in the HolonElementsTable
+	 * @return the selected HolonElement
+	 */
 	public HolonElement getActualHolonElement(HolonObject obj, int yValue) {
-		HolonObject tempCps = obj;
 		final int yTemp = (int) Math.floor(yValue / 16);
 		int rowsTotal = tableModelHolonElement.getRowCount();
 		if (rowsTotal != 0 && rowsTotal > yTemp) {
@@ -797,7 +811,7 @@ public class GUI implements CategoryListener {
 	}
 
 	/*
-	 * Refresh the Table displaying the Holon Elements
+	 * Refresh the Table displaying the HolonElements
 	 */
 	public void refreshTableHolonElement() {
 		// Update of the Information about the HolonElements - only for
@@ -812,6 +826,20 @@ public class GUI implements CategoryListener {
 				Object[] temp = { he.getEleName(), he.getEnergy(), he.getAmount() };
 				tableModelHolonElement.addRow(temp);
 			}
+
+		}
+
+	}
+
+	/**
+	 * Update the information about properties of the selected CpsObject
+	 */
+	public void refreshTableProperties() {
+		CpsObject tempCps = getActualCps();
+		if (tempCps.getClass() == HolonObject.class && tempCps != null) {
+			tableModelProperties.removeRow(2);
+			Object[] tempEnergy = { "Total Energy", ((HolonObject) canvas.tempCps).getCurrentEnergy() };
+			tableModelProperties.insertRow(2, tempEnergy);
 		}
 	}
 }