|
@@ -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);
|
|
|
}
|