Browse Source

View for the properties, holonelement list and graph

Edgardo Palza 8 years ago
parent
commit
0cc9c21fdf
2 changed files with 164 additions and 46 deletions
  1. 141 27
      src/ui/view/GUI.java
  2. 23 19
      src/ui/view/MyCanvas.java

+ 141 - 27
src/ui/view/GUI.java

@@ -17,6 +17,9 @@ import javax.swing.JTabbedPane;
 import javax.swing.JTable;
 import javax.swing.tree.DefaultTreeModel;
 import javax.swing.tree.TreeCellRenderer;
+
+import com.sun.xml.internal.bind.v2.TODO;
+
 import ui.controller.Control;
 import ui.model.*;
 
@@ -91,10 +94,40 @@ public class GUI implements CategoryListener {
 	private final JEditorPane dtrpnHereWillBe = new JEditorPane();
 	private final JSplitPane splitPane_2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
 
-	private JTable table = new JTable();
-	private DefaultTableModel tableModel = new DefaultTableModel();
+	/******************************************
+	 ************* Right Container*************
+	 ******************************************/
+	// Right Container: here comes the information about the HolonObject, such
+	// as HolonElements Information, Properties and Consumption/Production graph
+
+	private final JSplitPane split_HolonEl_Pro = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+	private final JSplitPane split_Graph_HolonEl = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+
+	// In this section are all the Holonelements that correspond to the clicked
+	// HolonObject with consumption/production, name and amount.
+
+	private JTable tableHolonElement = new JTable();
+	private DefaultTableModel tableModelHolonElement = new DefaultTableModel();
+	private final JScrollPane scrollElements = new JScrollPane();
+
+	// In this section are all the properties that correspond to the clicked
+	// HolonObject, such as connections, name, Type, etc.
+
+	private JTable tableProperties = new JTable();
+	private DefaultTableModel tableModelProperties = new DefaultTableModel();
+	private final JScrollPane scrollProperties = new JScrollPane();
+
+	// In this section is the graph for the selected HolonElement of the clicked
+	// HolonObject
+
+	private JTable tableGraph = new JTable();
+	private DefaultTableModel tableModelGraph = new DefaultTableModel();
+	private final JScrollPane scrollGraph = new JScrollPane();
+
 	private final Model model;
 	private final Control controller;
+
+	// Pop up Windows
 	private AddObjectPopUp addObjectPopUP;
 	private AboutUsPopUp aboutUsPopUp;
 
@@ -192,15 +225,41 @@ public class GUI implements CategoryListener {
 
 		scrollPane_2.setViewportView(dtrpnHereWillBe);
 
-		JScrollPane scrollPane = new JScrollPane();
-		// Table Set up
+		/*
+		 * Right Container Set up
+		 */
+
+		// Set up of the HolonElements section
 		Object[] columnNames = { "Device", "Type", "Energy", "Quantity" };
-		tableModel.setColumnIdentifiers(columnNames);
-		table.setModel(tableModel);
-		scrollPane.setViewportView(table);
-		table.setFillsViewportHeight(true);
-		table.setCellSelectionEnabled(true);
-		table.setColumnSelectionAllowed(true);
+		tableModelHolonElement.setColumnIdentifiers(columnNames);
+		tableHolonElement.setModel(tableModelHolonElement);
+		tableHolonElement.setFillsViewportHeight(true);
+		tableHolonElement.setCellSelectionEnabled(true);
+		tableHolonElement.setColumnSelectionAllowed(true);
+
+		// Set up of the Properties section
+		Object[] colNames = { "Field", "Information" };
+		tableModelProperties.setColumnIdentifiers(colNames);
+		tableProperties.setModel(tableModelProperties);
+		tableProperties.setFillsViewportHeight(true);
+		tableProperties.setCellSelectionEnabled(true);
+		tableProperties.setColumnSelectionAllowed(true);
+
+		// Set up of the Graph section
+
+		Object[] tempText = { "Here comes the graph for each clicked HolonElement" };
+		tableModelGraph.setColumnIdentifiers(tempText);
+		tableGraph.setModel(tableModelGraph);
+		tableGraph.setFillsViewportHeight(true);
+		tableGraph.setCellSelectionEnabled(true);
+		tableGraph.setColumnSelectionAllowed(true);
+
+		/*
+		 * End of right container setup
+		 */
+		scrollProperties.setViewportView(tableProperties);
+		scrollElements.setViewportView(tableHolonElement);
+		scrollGraph.setViewportView(tableGraph);
 
 		frmCyberPhysical.getContentPane().setLayout(new BorderLayout(0, 0));
 
@@ -349,6 +408,10 @@ public class GUI implements CategoryListener {
 				}
 			}
 		});
+		/**
+		 * Pop up - About Us with some important information about the
+		 * developers, source and programming stuff
+		 */
 		aboutUs.addMouseListener(new MouseAdapter() {
 			@Override
 			public void mousePressed(MouseEvent e) {
@@ -356,24 +419,64 @@ public class GUI implements CategoryListener {
 				aboutUsPopUp.setVisible(true);
 			}
 		});
+
+		/**
+		 * Update of every interaction between the user and the canvas (only on
+		 * the canvas). Basically the update of all the information concerning
+		 * the clicked HolonObject
+		 */
 		canvas.addMouseListener(new MouseAdapter() {
 			@Override
 			public void mousePressed(MouseEvent e) {
-				if (tableModel.getRowCount() > 0) {
-					for (int i = tableModel.getRowCount() - 1; i > -1; i--) {
-						tableModel.removeRow(i);
+
+				// Update of the Information about the HolonElements
+				if (tableModelHolonElement.getRowCount() > 0) {
+					for (int i = tableModelHolonElement.getRowCount() - 1; i > -1; i--) {
+						tableModelHolonElement.removeRow(i);
 					}
 				}
 				if (canvas.dataSelected != null) {
 					for (HolonElement he : canvas.dataSelected) {
 						Object[] temp = { he.getEleName(), he.getSign(), he.getEnergy(), he.getAmount() };
-						tableModel.addRow(temp);
+						tableModelHolonElement.addRow(temp);
+					}
+				}
+
+				// Update of the Information about the Properties
+				if (tableModelProperties.getRowCount() > 0) {
+					for (int i = tableModelProperties.getRowCount() - 1; i > -1; i--) {
+						tableModelProperties.removeRow(i);
+					}
+				}
+				if (canvas.dataSelected != null) {
+					Object[] tempName = { "Name", canvas.tempCps.getName() };
+					tableModelProperties.addRow(tempName);
+					Object[] tempId = { "ID", canvas.tempCps.getID() };
+					tableModelProperties.addRow(tempId);
+					if (canvas.tempCps.getClass() == HolonObject.class) {
+						Object[] tempEnergy = { "Total Energy", ((HolonObject) canvas.tempCps).getCurrentEnergy() };
+						tableModelProperties.addRow(tempEnergy);
+					}
+					ArrayList<CpsObject> temp_array = canvas.tempCps.getConnectedTo();
+					if (!temp_array.isEmpty()) {
+						boolean first = true;
+						for (CpsObject temp : temp_array) {
+							if (first) {
+								first = false;
+								Object[] tempConnection = { canvas.tempCps.getName() + " is connected to",
+										temp.getName() + " with ID: " + temp.getID() };
+								tableModelProperties.addRow(tempConnection);
+							} else {
+								Object[] tempConnection = { "", temp.getName() + " with ID: " + temp.getID() };
+								tableModelProperties.addRow(tempConnection);
+							}
+						}
 					}
 				}
 			}
 		});
 
-		table.addPropertyChangeListener(new PropertyChangeListener() {
+		tableHolonElement.addPropertyChangeListener(new PropertyChangeListener() {
 			@Override
 			public void propertyChange(PropertyChangeEvent evt) {
 				try {
@@ -381,34 +484,38 @@ public class GUI implements CategoryListener {
 					tempCps = controller.searchByID(model.getSelectedObjectID());
 					if (tempCps != null) {
 						System.out.println("change: " + tempCps.toString());
-						for (int r = 0; r < tableModel.getRowCount(); r++) {
+						for (int r = 0; r < tableModelHolonElement.getRowCount(); r++) {
 							ArrayList<Object> temp = new ArrayList<>();
-							for (int c = 0; c < tableModel.getColumnCount(); c++) {
-								temp.add(table.getValueAt(r, c));
+							for (int c = 0; c < tableModelHolonElement.getColumnCount(); c++) {
+								temp.add(tableHolonElement.getValueAt(r, c));
 							}
 							float ch;
-							if(temp.get(1).toString().compareTo("-")==0) {ch = -1;} else {ch = 1;}
+							if (temp.get(1).toString().compareTo("-") == 0) {
+								ch = -1;
+							} else {
+								ch = 1;
+							}
 							float fa = Float.parseFloat(temp.get(2).toString());
 							int i = Integer.parseInt(temp.get(3).toString());
 							((HolonObject) tempCps).getElements().get(r).setEleName((String) temp.get(0));
 							((HolonObject) tempCps).getElements().get(r).setSign(ch);
 							((HolonObject) tempCps).getElements().get(r).setEnergy(fa);
 							((HolonObject) tempCps).getElements().get(r).setAmount(i);
-							System.out.println(table.getRowCount() + " " + temp.get(0) + " " + ch + " "
-									+ fa + " " + i);
+							System.out.println(tableHolonElement.getRowCount() + " " + temp.get(0) + " " + ch + " " + fa
+									+ " " + i);
 						}
-						if (tableModel.getRowCount() > 0) {
-							for (int i = tableModel.getRowCount() - 1; i > -1; i--) {
-								tableModel.removeRow(i);
+						if (tableModelHolonElement.getRowCount() > 0) {
+							for (int i = tableModelHolonElement.getRowCount() - 1; i > -1; i--) {
+								tableModelHolonElement.removeRow(i);
 							}
 						}
 						for (HolonElement he : canvas.dataSelected) {
 							Object[] temp = { he.getEleName(), he.getSign(), he.getEnergy(), he.getAmount() };
-							tableModel.addRow(temp);
+							tableModelHolonElement.addRow(temp);
 						}
 					}
 				} catch (Exception e) {
-					
+
 				}
 			}
 		});
@@ -476,7 +583,14 @@ public class GUI implements CategoryListener {
 		splitPane_1.setDividerLocation(500);
 		splitPane.setLeftComponent(scrollPane_1);
 		splitPane_1.setLeftComponent(tabbedPane);
-		splitPane_1.setRightComponent(scrollPane);
+		splitPane_1.setRightComponent(split_HolonEl_Pro);
+		split_HolonEl_Pro.setDividerLocation(600);
+		split_HolonEl_Pro.setTopComponent(split_Graph_HolonEl);
+		split_HolonEl_Pro.setBottomComponent(scrollProperties);
+		split_Graph_HolonEl.setDividerLocation(150);
+		split_Graph_HolonEl.setTopComponent(scrollGraph);
+		split_Graph_HolonEl.setBottomComponent(scrollElements);
+
 	}
 
 	/*

+ 23 - 19
src/ui/view/MyCanvas.java

@@ -43,7 +43,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 	private boolean dragging = false; // for dragging
 	private boolean drawEdge = false; // for drawing edges
 	private boolean click = false; // for double click
-	private CpsObject tempCps = null;
+	public CpsObject tempCps = null;
 	private Rectangle selectRect = new Rectangle();
 
 	// PopUpMenu
@@ -168,10 +168,11 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
 				tempCps = cps;
 				// If drawing an Edge (CTRL down)
-				if (e.isControlDown()){
+				if (e.isControlDown()) {
 					drawEdge = true;
 					controller.deleteElementCanvas(1, "Rehab");
-					System.out.println(((HolonObject)model.getCategories().get(0).getObjects().get(0)).getElements().get(2).getAmount());
+					System.out.println(((HolonObject) model.getCategories().get(0).getObjects().get(0)).getElements()
+							.get(2).getAmount());
 				}
 				if (tempCps.getClass() == HolonObject.class) {
 					HolonObject tempObj = ((HolonObject) tempCps);
@@ -215,31 +216,34 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 
 	@Override
 	public void mouseDragged(MouseEvent e) {
-		//If Edge is drawn
+		// If Edge is drawn
 		if (drawEdge) {
 			x = e.getX();
 			y = e.getY();
 			repaint();
 		} else {
 			try {
-				//Au�erhalb des Randes gedragged?
-				x = e.getX()-controller.getScaleDiv2();
-				y = e.getY()-controller.getScaleDiv2();
-				if(e.getX()<controller.getScaleDiv2())x = 0;
-				else if(e.getX()>this.getWidth()-controller.getScaleDiv2())x = this.getWidth()-controller.getScale();
-				if(e.getY()<controller.getScaleDiv2())y = 0;
-				else if(e.getY()>this.getHeight()-controller.getScaleDiv2())y = this.getHeight()-controller.getScale();
-				//Drag Position
+				// Au�erhalb des Randes gedragged?
+				x = e.getX() - controller.getScaleDiv2();
+				y = e.getY() - controller.getScaleDiv2();
+				if (e.getX() < controller.getScaleDiv2())
+					x = 0;
+				else if (e.getX() > this.getWidth() - controller.getScaleDiv2())
+					x = this.getWidth() - controller.getScale();
+				if (e.getY() < controller.getScaleDiv2())
+					y = 0;
+				else if (e.getY() > this.getHeight() - controller.getScaleDiv2())
+					y = this.getHeight() - controller.getScale();
+				// Drag Position
 				tempCps.setPosition(x, y);
-				//Highlighting Position
-				selectRect.setLocation(x - (controller.getScale() / 20),y - (controller.getScale() / 20)); 
-				//TipText Position and name
+				// Highlighting Position
+				selectRect.setLocation(x - (controller.getScale() / 20), y - (controller.getScale() / 20));
+				// TipText Position and name
 				objectTT.setTipText(tempCps.getName());
-				objectTT.setLocation(x, y+controller.getScale());
+				objectTT.setLocation(x, y + controller.getScale());
 				repaint();
-				}
-			catch (Exception e2) {
-			
+			} catch (Exception e2) {
+
 			}
 		}
 	}