|
@@ -120,7 +120,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
(int) (pointList.get(i).getY() * scaleY - recSize.getY() / 2), (int) recSize.getX(),
|
|
|
(int) recSize.getY());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Iteration Value
|
|
|
if (arrayOfFloats != null) {
|
|
|
g2.drawString("" + arrayOfFloats[model.getCurIteration()],
|
|
@@ -146,22 +146,23 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
g2.setStroke(new BasicStroke(2));
|
|
|
g2.setColor(Color.BLACK);
|
|
|
for (int i = 0; i < pointList.size() - 1; i++) {
|
|
|
- line = new Line2D.Double(pointList.get(i).getX()*scaleX, pointList.get(i).getY()*scaleY, pointList.get(i+1).getX()*scaleX,pointList.get(i+1).getY()*scaleY);
|
|
|
+ line = new Line2D.Double(pointList.get(i).getX() * scaleX, pointList.get(i).getY() * scaleY,
|
|
|
+ pointList.get(i + 1).getX() * scaleX, pointList.get(i + 1).getY() * scaleY);
|
|
|
graphCurve.append(line, true);
|
|
|
}
|
|
|
g2.draw(graphCurve);
|
|
|
|
|
|
- // Draw the Points
|
|
|
- g2.setColor(Color.BLUE);
|
|
|
- for (int i = 0; i < pointList.size() - 0; i++) {
|
|
|
- g2.fillOval((int) (pointList.get(i).getX() * scaleX - recSize.getX() / 2),
|
|
|
- (int) (pointList.get(i).getY() * scaleY - recSize.getY() / 2), (int) recSize.getX(),
|
|
|
- (int) recSize.getY());
|
|
|
- }
|
|
|
-
|
|
|
+ /*
|
|
|
+ * // Draw the Points g2.setColor(Color.BLUE); for (int i = 0; i
|
|
|
+ * < pointList.size() - 0; i++) { g2.fillOval((int)
|
|
|
+ * (pointList.get(i).getX() * scaleX - recSize.getX() / 2),
|
|
|
+ * (int) (pointList.get(i).getY() * scaleY - recSize.getY() /
|
|
|
+ * 2), (int) recSize.getX(), (int) recSize.getY()); }
|
|
|
+ */
|
|
|
+
|
|
|
// Iteration Value
|
|
|
- if (arrayOfFloats != null) {
|
|
|
- g2.drawString("" + arrayOfFloats[model.getCurIteration()],
|
|
|
+ if (arrayOfBooleans != null) {
|
|
|
+ g2.drawString("" + arrayOfBooleans[model.getCurIteration()],
|
|
|
(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1) + 2,
|
|
|
this.getHeight() - 10);
|
|
|
}
|
|
@@ -216,7 +217,26 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
* @param e
|
|
|
*/
|
|
|
public void switchDragged(MouseEvent e) {
|
|
|
- // TODO Switch dragged zeugs kommt hier hin
|
|
|
+ if (pointDrag && tempP != null && tempP != pointList.getFirst() && tempP != pointList.getLast()) {
|
|
|
+ int i = pointList.indexOf(tempP);
|
|
|
+ x = e.getX() / scaleX;
|
|
|
+
|
|
|
+ if (pointList.get(i + 1).getY() == tempP.getY()) {
|
|
|
+ // x
|
|
|
+ if (pointList.get(i + 1).getX() <= x+1 || pointList.get(i - 2).getX() >= x-1) {
|
|
|
+ x = tempP.getX();
|
|
|
+ }
|
|
|
+ pointList.get(i - 1).setLocation(x, pointList.get(i - 1).getY());
|
|
|
+ } else {
|
|
|
+ // x
|
|
|
+ if (pointList.get(i + 2).getX() <= x+1 || pointList.get(i - 1).getX() >= x-1) {
|
|
|
+ x = tempP.getX();
|
|
|
+ }
|
|
|
+ pointList.get(i + 1).setLocation(x, pointList.get(i + 1).getY());
|
|
|
+ }
|
|
|
+ tempP.setLocation(x, tempP.getY());
|
|
|
+ repaint();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -260,6 +280,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
// Click on Point
|
|
|
tempP = null;
|
|
|
if (pointList != null) {
|
|
|
+ // look if a point was clicked
|
|
|
for (Point p : pointList) {
|
|
|
if (x >= p.getX() - recSize.getX() / 2 && y >= p.getY() - recSize.getY() / 2
|
|
|
&& x <= p.getX() + recSize.getX() / 2 && y <= p.getY() * scaleY + recSize.getY() / 2) {
|
|
@@ -304,6 +325,58 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
* @param e
|
|
|
*/
|
|
|
public void switchPressed(MouseEvent e) {
|
|
|
+ boolean added = false;
|
|
|
+ boolean deletePoint = false;
|
|
|
+
|
|
|
+ double x = e.getX() / scaleX;
|
|
|
+ double y = e.getY() / scaleY;
|
|
|
+
|
|
|
+ // Halbe Iterations Distanz
|
|
|
+ double dist = (width / (model.getIterations() - 1)) / 2;
|
|
|
+
|
|
|
+ // Click on Point
|
|
|
+ tempP = null;
|
|
|
+ if (pointList != null) {
|
|
|
+ for (Point p : pointList) {
|
|
|
+ if (x >= p.getX() - dist && x <= p.getX() + dist) {
|
|
|
+ if (e.getButton() == MouseEvent.BUTTON3) {
|
|
|
+ tempP = p;
|
|
|
+ deletePoint = true;
|
|
|
+ } else {
|
|
|
+ pointDrag = true;
|
|
|
+ tempP = p;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // New Point
|
|
|
+ if (!pointDrag && e.getButton() != MouseEvent.BUTTON3 && x != 0 && x != width) {
|
|
|
+ for (int i = 0; i < pointList.size() && !added; i++) {
|
|
|
+ if (x < pointList.get(i).getX() - dist) {
|
|
|
+ // Punkt hinzufügen, je nachdem ob es oberhalb oder
|
|
|
+ // unterhalb der hälfte ist
|
|
|
+ if (y < height / 2 && (pointList.get(i - 1).getY() == height - 1
|
|
|
+ && pointList.get(i).getY() == height - 1)) {
|
|
|
+ pointList.add(i, new Point((int) (x + dist), (int) height - 1));
|
|
|
+ pointList.add(i, new Point((int) (x + dist), 0));
|
|
|
+ pointList.add(i, new Point((int) (x - dist), 0));
|
|
|
+ pointList.add(i, new Point((int) (x - dist), (int) height - 1));
|
|
|
+ added = true;
|
|
|
+ } else if (y >= height / 2 && (pointList.get(i - 1).getY() != height - 1
|
|
|
+ && pointList.get(i).getY() != height - 1)) {
|
|
|
+ pointList.add(i, new Point((int) (x + dist), 0));
|
|
|
+ pointList.add(i, new Point((int) (x + dist), (int) height - 1));
|
|
|
+ pointList.add(i, new Point((int) (x - dist), (int) height - 1));
|
|
|
+ pointList.add(i, new Point((int) (x - dist), 0));
|
|
|
+ added = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (int i = 0; i < pointList.size(); i++) {
|
|
|
+ System.out.println(pointList.get(i).getX()+", "+pointList.get(i).getY());
|
|
|
+ }
|
|
|
+ repaint();
|
|
|
+ }
|
|
|
// TODO Siwtch pressed zeugs hier hin
|
|
|
}
|
|
|
|
|
@@ -429,8 +502,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
isElement = false;
|
|
|
// First time clicked on the Element
|
|
|
if (pointList.isEmpty()) {
|
|
|
- pointList.addFirst(new Point(0, (int) (this.getHeight()/scaleY)));
|
|
|
- pointList.addLast(new Point((int) (this.getWidth() / scaleX), (int) (this.getHeight()/scaleY)));
|
|
|
+ pointList.addFirst(new Point(0, 0));
|
|
|
+ pointList.addLast(new Point((int) (width), 0));
|
|
|
}
|
|
|
repaint();
|
|
|
}
|
|
@@ -471,10 +544,16 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
*/
|
|
|
public void fillArrayofBooleans() {
|
|
|
for (int i = 0; i < arrayOfBooleans.length; i++) {
|
|
|
- arrayOfBooleans[i] = true;
|
|
|
+ int t = (int) getYValueAt_2((int) (i * width / (model.getIterations() - 1)));
|
|
|
+ if (t == 0) {
|
|
|
+ arrayOfBooleans[i] = true;
|
|
|
+ } else {
|
|
|
+ arrayOfBooleans[i] = false;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Fills the Arrays of each HolonElement
|
|
|
*/
|