Browse Source

Small changes im Graph

Edgardo Palza 8 years ago
parent
commit
a9ac089715
2 changed files with 46 additions and 23 deletions
  1. 17 4
      src/ui/view/GUI.java
  2. 29 19
      src/ui/view/UnitGraph.java

+ 17 - 4
src/ui/view/GUI.java

@@ -80,6 +80,10 @@ public class GUI implements CategoryListener {
 	private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
 	private final JScrollPane scrollPane_2 = new JScrollPane();
 
+	private final JLabel maxGraph = new JLabel("100%");
+	private final JLabel medGraph = new JLabel("50%");
+	private final JLabel minGraph = new JLabel("0%");
+
 	private final JTree tree = new JTree();
 	private final JEditorPane dtrpnHereWillBe = new JEditorPane();
 	/******************************************
@@ -239,7 +243,7 @@ public class GUI implements CategoryListener {
 		 */
 
 		// Set up of the HolonElements section
-		Object[] columnNames = { "Device", "Type", "Energy", "Quantity" };
+		Object[] columnNames = { "Device", "Energy", "Quantity" };
 		tableModelHolonElement.setColumnIdentifiers(columnNames);
 		tableHolonElement.setModel(tableModelHolonElement);
 		tableHolonElement.setFillsViewportHeight(true);
@@ -269,7 +273,14 @@ 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);
+
+		scrollGraph.setRowHeaderView(graphLabel);
 		scrollElements.setLayout(new BorderLayout(0, 0));
 		scrollElements.add(panel_HolonEl, BorderLayout.NORTH);
 		scrollElements.add(tableHolonElementScrollPane);
@@ -307,7 +318,9 @@ public class GUI implements CategoryListener {
 
 		tableHolonElement.addMouseListener(new MouseAdapter() {
 			public void mousePressed(MouseEvent e) {
+				HolonObject obj = (HolonObject) getActualCps();
 				yValueElements = e.getY();
+				testgraph.repaintWithNewElement(getActualHolonElement(obj, yValueElements));
 			}
 		});
 		frmCyberPhysical.getContentPane().setLayout(new BorderLayout(0, 0));
@@ -486,7 +499,7 @@ public class GUI implements CategoryListener {
 				}
 				if (canvas.dataSelected != null) {
 					for (HolonElement he : canvas.dataSelected) {
-						Object[] temp = { he.getEleName(), he.getSign(), he.getEnergy(), he.getAmount() };
+						Object[] temp = { he.getEleName(), he.getEnergy(), he.getAmount() };
 						tableModelHolonElement.addRow(temp);
 					}
 				}
@@ -579,7 +592,7 @@ public class GUI implements CategoryListener {
 							}
 						}
 						for (HolonElement he : canvas.dataSelected) {
-							Object[] temp = { he.getEleName(), he.getSign(), he.getEnergy(), he.getAmount() };
+							Object[] temp = { he.getEleName(), he.getEnergy(), he.getAmount() };
 							tableModelHolonElement.addRow(temp);
 						}
 					}

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

@@ -42,7 +42,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	private int tempP;
 	private int x1, x2, y1, y2, ctrlx1, ctrly1, ctrlx2, ctrly2;
 	private final JButton resetButton = new JButton("Reset Graph");
-	private final JLabel lblMaximum = new JLabel("Maximum");
+	private final JLabel lblName = new JLabel("Name");
 
 	public UnitGraph(final Model model, Control control) {
 		setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
@@ -57,7 +57,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		this.addMouseMotionListener(this);
 		this.addComponentListener(this);
 
-		lblMaximum.setText(lblMaximum.getText() + ": 100");
+		lblName.setText("None");
 		resetButton.setToolTipText("Resets the Graph");
 		resetButton.setBackground(Color.WHITE);
 
@@ -68,7 +68,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		});
 		setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
 
-		add(lblMaximum);
+		add(lblName);
 
 		add(resetButton);
 	}
@@ -130,22 +130,24 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 	@Override
 	public void mouseDragged(MouseEvent e) {
-		if (pointDrag && e.getY() >= this.getHeight() / 3 && tempP != -1) {
-			pointList[tempP].setLocation(pointList[tempP].getX(), e.getY());
-			if (tempP != 0 && pointList[tempP - 1].getY() < pointList[tempP].getY()
-					- (pointList[tempP].getY() - this.getHeight() / 3) / 2) {
-				pointList[tempP - 1].setLocation(pointList[tempP - 1].getX(),
-						pointList[tempP].getY() - (pointList[tempP].getY() - this.getHeight() / 3) / 2);
+		if (temp != null) {
+			if (pointDrag && e.getY() >= this.getHeight() / 3 && tempP != -1) {
+				pointList[tempP].setLocation(pointList[tempP].getX(), e.getY());
+				if (tempP != 0 && pointList[tempP - 1].getY() < pointList[tempP].getY()
+						- (pointList[tempP].getY() - this.getHeight() / 3) / 2) {
+					pointList[tempP - 1].setLocation(pointList[tempP - 1].getX(),
+							pointList[tempP].getY() - (pointList[tempP].getY() - this.getHeight() / 3) / 2);
+				}
+				if (tempP != model.getIterations() - 1 && pointList[tempP + 1].getY() < pointList[tempP].getY()
+						- (pointList[tempP].getY() - this.getHeight() / 3) / 2) {
+					pointList[tempP + 1].setLocation(pointList[tempP + 1].getX(),
+							pointList[tempP].getY() - (pointList[tempP].getY() - this.getHeight() / 3) / 2);
+				}
+			} else if (tempP != -1) {
+				pointList[tempP].setLocation(pointList[tempP].getX(), this.getHeight() / 3);
 			}
-			if (tempP != model.getIterations() - 1 && pointList[tempP + 1].getY() < pointList[tempP].getY()
-					- (pointList[tempP].getY() - this.getHeight() / 3) / 2) {
-				pointList[tempP + 1].setLocation(pointList[tempP + 1].getX(),
-						pointList[tempP].getY() - (pointList[tempP].getY() - this.getHeight() / 3) / 2);
-			}
-		} else if (tempP != -1) {
-			pointList[tempP].setLocation(pointList[tempP].getX(), this.getHeight() / 3);
+			repaint();
 		}
-		repaint();
 	}
 
 	@Override
@@ -188,11 +190,19 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		}
 	}
 
+	public void repaintWithNewElement(HolonElement ele) {
+		reset();
+		float[] arrayOfValue = ele.getEnergyAt();
+		lblName.setText(ele.getEleName());
+		temp = ele;
+		// TODO
+	}
+
 	// resize listener
 	public void componentResized(ComponentEvent e) {
-		if (pointList[0].getY() != 0)
+		if (pointList[0].getY() != 0) {
 			reset();
-		else {
+		} else {
 			for (int i = 0; i < pointList.length; i++) {
 				pointList[i] = new Point((i) * this.getWidth() / (model.getIterations() - 1), this.getHeight() / 3);
 			}