|
@@ -50,7 +50,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
|
|
|
private boolean pointDrag = false;
|
|
|
private boolean init = false;
|
|
|
- private Point tempP = null, p1 = null, p2 = null;
|
|
|
+ private Point tempP = null;
|
|
|
private double x = 0, y = 0;
|
|
|
private int x1, x2, y1, y2, ctrlx1, ctrly1, ctrlx2, ctrly2;
|
|
|
|
|
@@ -60,6 +60,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
this.model = model;
|
|
|
|
|
|
this.pointList = new LinkedList<>();
|
|
|
+ this.setBackground(Color.WHITE);
|
|
|
|
|
|
this.addMouseListener(this);
|
|
|
this.addMouseMotionListener(this);
|
|
@@ -203,6 +204,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //New Point
|
|
|
if (!pointDrag && e.getButton() != MouseEvent.BUTTON3 && e.getX() != 0
|
|
|
&& e.getX() != this.getWidth() / scaleX) {
|
|
|
for (int i = 0; i < pointList.size(); i++) {
|
|
@@ -218,6 +220,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ //Delete a Point
|
|
|
if (deletePoint && tempP.getX() != 0
|
|
|
&& (tempP.getX() != this.getWidth() / scaleX || tempP != pointList.getLast())) {
|
|
|
pointList.remove(tempP);
|
|
@@ -236,10 +239,11 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
}
|
|
|
|
|
|
public void componentResized(ComponentEvent e) {
|
|
|
+ //Wenn ein anderes Element genommen wird
|
|
|
if (init) {
|
|
|
MAXIMUM = tempElement.getEnergy();
|
|
|
init = false;
|
|
|
- // for scale
|
|
|
+ // for scale on the first initialisation
|
|
|
if (width == -1 && height == -1) {
|
|
|
width = this.getWidth();
|
|
|
height = this.getHeight();
|
|
@@ -247,12 +251,15 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
|
|
|
scaleX = this.getWidth() / width;
|
|
|
scaleY = this.getHeight() / height;
|
|
|
-
|
|
|
+
|
|
|
+ //First time clicked on the Element
|
|
|
if (pointList.isEmpty()) {
|
|
|
pointList.addFirst(new Point(0, 0));
|
|
|
pointList.addLast(new Point((int) (this.getWidth() / scaleX), 0));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //Scale
|
|
|
scaleX = this.getWidth() / width;
|
|
|
scaleY = this.getHeight() / height;
|
|
|
repaint();
|
|
@@ -341,6 +348,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
y1 = (int) p1.getY();
|
|
|
x2 = (int) p2.getX();
|
|
|
y2 = (int) p2.getY();
|
|
|
+
|
|
|
+ //calculate the controllpoints
|
|
|
ctrlx1 = (int) p1.getX() + ((int) p2.getX() - (int) p1.getX()) / 2;
|
|
|
ctrlx2 = (int) p2.getX() - ((int) p2.getX() - (int) p1.getX()) / 2;
|
|
|
if (y1 < y2) {
|
|
@@ -351,6 +360,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
ctrly2 = (int) p2.getY() + ((int) p1.getY() - (int) p2.getY()) / 10;
|
|
|
}
|
|
|
|
|
|
+ //set the curve
|
|
|
c.setCurve(x1 * scaleX, y1 * scaleY, ctrlx1 * scaleX, ctrly1 * scaleY, ctrlx2 * scaleX, ctrly2 * scaleY,
|
|
|
x2 * scaleX, y2 * scaleY);
|
|
|
return c;
|
|
@@ -376,7 +386,6 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
Line2D l1 = new Line2D.Double(pointList.get(i).getX(), pointList.get(i).getY(),
|
|
|
pointList.get(i + 1).getX(), pointList.get(i + 1).getY());
|
|
|
Line2D l2 = new Line2D.Double(xVal, 0, xVal, height);
|
|
|
-
|
|
|
return (float) getIntersectionPoint(l1, l2).getY();
|
|
|
}
|
|
|
}
|