Browse Source

graph changes

Edgardo Palza 8 years ago
parent
commit
635dd298c2
2 changed files with 41 additions and 19 deletions
  1. 27 4
      src/ui/view/GUI.java
  2. 14 15
      src/ui/view/UnitGraph.java

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

@@ -83,6 +83,7 @@ public class GUI implements CategoryListener {
 	private final JLabel maxGraph = new JLabel("100%");
 	private final JLabel medGraph = new JLabel("50%");
 	private final JLabel minGraph = new JLabel("0%");
+	private final JLabel elementGraph = new JLabel("None ");
 
 	private final JTree tree = new JTree();
 	private final JEditorPane dtrpnHereWillBe = new JEditorPane();
@@ -128,15 +129,18 @@ public class GUI implements CategoryListener {
 	private final JPanel panel = new JPanel();
 	private final JPanel panel_HolonEl = new JPanel();
 	private final JComboBox comboBox = new JComboBox();
+	private final JComboBox comboBoxGraph = new JComboBox();
 
 	// Buttons
 	private final JButton btnAdd = new JButton("+");
 	private final JButton btnDel = new JButton("-");
 	private final JButton btnAddHolEL = new JButton("+");
 	private final JButton btnDelHolEL = new JButton("-");
+	private final JButton resetGraphBtn = new JButton("Reset");
 
 	private final JToolBar toolBar = new JToolBar();
 	private final JToolBar toolBarHolonEl = new JToolBar();
+	private final JToolBar toolBarGraph = new JToolBar();
 
 	// variables
 	private boolean dragging = false;
@@ -279,8 +283,13 @@ public class GUI implements CategoryListener {
 		graphLabel.add(maxGraph);
 		graphLabel.add(medGraph);
 		graphLabel.add(minGraph);
-
+		toolBarGraph.add(elementGraph);
+		comboBoxGraph.setModel(new DefaultComboBoxModel(new String[] { "Day", "Month", "Year" }));
+		toolBarGraph.add(comboBoxGraph);
+		toolBarGraph.add(resetGraphBtn);
+		toolBarGraph.setFloatable(false);
 		scrollGraph.setRowHeaderView(graphLabel);
+		scrollGraph.setColumnHeaderView(toolBarGraph);
 		scrollElements.setLayout(new BorderLayout(0, 0));
 		scrollElements.add(panel_HolonEl, BorderLayout.NORTH);
 		scrollElements.add(tableHolonElementScrollPane);
@@ -303,6 +312,12 @@ public class GUI implements CategoryListener {
 				}
 			}
 		});
+		resetGraphBtn.addActionListener(new ActionListener() {
+
+			public void actionPerformed(ActionEvent arg0) {
+				testgraph.reset();
+			}
+		});
 		toolBarHolonEl.add(btnDelHolEL);
 		btnDelHolEL.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent arg0) {
@@ -320,7 +335,13 @@ public class GUI implements CategoryListener {
 			public void mousePressed(MouseEvent e) {
 				HolonObject obj = (HolonObject) getActualCps();
 				yValueElements = e.getY();
-				testgraph.repaintWithNewElement(getActualHolonElement(obj, yValueElements));
+				HolonElement ele = getActualHolonElement(obj, yValueElements);
+				if (ele != null) {
+					elementGraph.setText(ele.getEleName() + " ");
+					testgraph.repaintWithNewElement(ele);
+				} else {
+					elementGraph.setText("None ");
+				}
 			}
 		});
 		frmCyberPhysical.getContentPane().setLayout(new BorderLayout(0, 0));
@@ -760,8 +781,10 @@ public class GUI implements CategoryListener {
 	}
 
 	public CpsObject getActualCps() {
-		model.setSelectedCpsObject(canvas.tempCps);
-		return canvas.tempCps;
+		int tempID = model.getSelectedObjectID();
+		CpsObject tempCps = controller.searchByID(tempID);
+		System.out.println(tempCps.getID());
+		return tempCps;
 	}
 
 	public HolonElement getActualHolonElement(HolonObject obj, int yValue) {

+ 14 - 15
src/ui/view/UnitGraph.java

@@ -41,8 +41,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	private boolean pointDrag = false;
 	private int tempP;
 	private int x1, x2, y1, y2, ctrlx1, ctrly1, ctrlx2, ctrly2;
-	private final JButton resetButton = new JButton("Reset Graph");
-	private final JLabel lblName = new JLabel("Name");
+	// private final JButton resetButton = new JButton("Reset Graph");
+	// private final JLabel lblName = new JLabel("Name");
 
 	public UnitGraph(final Model model, Control control) {
 		setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
@@ -57,20 +57,20 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		this.addMouseMotionListener(this);
 		this.addComponentListener(this);
 
-		lblName.setText("None");
-		resetButton.setToolTipText("Resets the Graph");
-		resetButton.setBackground(Color.WHITE);
-
-		resetButton.addActionListener(new ActionListener() {
-			public void actionPerformed(ActionEvent e) {
-				reset();
-			}
-		});
+		// lblName.setText("None");
+		// resetButton.setToolTipText("Resets the Graph");
+		// resetButton.setBackground(Color.WHITE);
+		//
+		// resetButton.addActionListener(new ActionListener() {
+		// public void actionPerformed(ActionEvent e) {
+		// reset();
+		// }
+		// });
 		setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
 
-		add(lblName);
-
-		add(resetButton);
+		// add(lblName);
+		//
+		// add(resetButton);
 	}
 
 	/*
@@ -193,7 +193,6 @@ 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
 	}