|
@@ -124,13 +124,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
//System.out.println("paint");
|
|
|
Graphics2D g2D = (Graphics2D) g;
|
|
|
g2D.setColor(Color.BLACK);
|
|
|
- int höhe = this.getHeight();
|
|
|
- int breite = this.getWidth();
|
|
|
-
|
|
|
g2D.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
|
|
|
g2D.setStroke(new BasicStroke(2));
|
|
|
- // g2D.drawLine(0, 0,breite, höhe);
|
|
|
- //printDebug();
|
|
|
printDebugRepresentive();
|
|
|
drawUnitGraph(g2D);
|
|
|
g2D.setColor(dotColor);
|
|
@@ -141,14 +136,6 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
{
|
|
|
drawUnitGraphPoints(g2D);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //generate Path --> maybe als Methode auslagern
|
|
|
-
|
|
|
- //Good Source for basic understanding for Bezier Curves
|
|
|
- //http://www.theappguruz.com/blog/bezier-curve-in-games
|
|
|
-
|
|
|
}
|
|
|
//TODO -> New Section
|
|
|
|
|
@@ -175,7 +162,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
break;
|
|
|
case doubleGraph:
|
|
|
if(released)
|
|
|
- drawDoubleGraphReleased(g);
|
|
|
+ drawDoubleGraphWithEditPosition(g);
|
|
|
else
|
|
|
drawDoubleGraph(g);
|
|
|
break;
|
|
@@ -184,33 +171,16 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
}
|
|
|
private void drawUnitGraphPoints(Graphics2D g) {
|
|
|
- g.setColor(Color.blue);
|
|
|
+ g.setColor(dotColor);
|
|
|
for(UnitGraphPoint p : actualGraphPoints){
|
|
|
drawDot(g, p.displayedPosition);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void drawUnitGraphPointsReleased(Graphics2D g) {
|
|
|
- ListIterator<UnitGraphPoint> iter2 = actualGraphPoints.listIterator();
|
|
|
- g.setColor(Color.blue);
|
|
|
- while (iter2.hasNext())
|
|
|
- {
|
|
|
- Position tempPosition = iter2.next().displayedPosition;
|
|
|
- if(tempPosition.x > editPosition.x)
|
|
|
- {
|
|
|
- iter2.previous();
|
|
|
- break;
|
|
|
- }
|
|
|
- drawDot(g, tempPosition);
|
|
|
- }
|
|
|
+ drawUnitGraphPoints(g);
|
|
|
g.setColor(editDotColor);
|
|
|
drawDot(g, editPosition);
|
|
|
-
|
|
|
- g.setColor(Color.blue);
|
|
|
- while (iter2.hasNext())
|
|
|
- {
|
|
|
- drawDot(g, iter2.next().displayedPosition);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
private void drawBoolGraph(Graphics2D g) {
|
|
@@ -229,43 +199,57 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
actual = target;
|
|
|
}
|
|
|
g.draw(path);
|
|
|
- }
|
|
|
- private void drawDoubleGraphReleased(Graphics2D g) {
|
|
|
- if(actualGraphPoints.isEmpty()) throw new IndexOutOfBoundsException("A Graph Without Points is not supportet jet");
|
|
|
- ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
|
|
|
- Position actual = iter.next().displayedPosition;
|
|
|
- Path2D.Double path = this.initBezier(actual);
|
|
|
- while (iter.hasNext())
|
|
|
- {
|
|
|
- Position target = iter.next().displayedPosition;
|
|
|
- if(target.x > editPosition.x)
|
|
|
- {
|
|
|
- iter.previous();
|
|
|
- break;
|
|
|
- }
|
|
|
- this.curveTo(path, actual, target);
|
|
|
- actual = target;
|
|
|
- }
|
|
|
- Position old = actual;
|
|
|
- Path2D.Double editPath = this.initBezier(actual);
|
|
|
+ //Maybe New Feature
|
|
|
+ g.setColor(Color.darkGray);
|
|
|
+ //Start
|
|
|
+ Path2D.Double path2 = new Path2D.Double();
|
|
|
+ Position startpunkt = actualGraphPoints.getFirst().displayedPosition;
|
|
|
+ path2.moveTo(0,startpunkt.y);
|
|
|
+ path2.lineTo(startpunkt.x, startpunkt.y);
|
|
|
+ g.draw(path2);
|
|
|
+ //Ende
|
|
|
+ Position endpunkt = actualGraphPoints.getLast().displayedPosition;
|
|
|
+ path2.moveTo(endpunkt.x,endpunkt.y);
|
|
|
+ path2.lineTo(2 * border + border+widthWithBorder, endpunkt.y);
|
|
|
+ g.draw(path2);
|
|
|
|
|
|
- actual = iter.next().displayedPosition;
|
|
|
- //here actual is new Position;
|
|
|
- this.curveTo(editPath, old, editPosition);
|
|
|
- this.curveTo(editPath, editPosition, actual);
|
|
|
- path.moveTo(actual.x, actual.y);
|
|
|
+ }
|
|
|
+ private void drawDoubleGraphWithEditPosition(Graphics2D g) {
|
|
|
+ LinkedList<Position> before = new LinkedList<Position>();
|
|
|
+ LinkedList<Position> after = new LinkedList<Position>();
|
|
|
+ for(UnitGraphPoint p: actualGraphPoints)
|
|
|
+ {
|
|
|
+ if(p.displayedPosition.x < editPosition.x)
|
|
|
+ before.add(p.displayedPosition);
|
|
|
+ else
|
|
|
+ after.add(p.displayedPosition);
|
|
|
+ }
|
|
|
+ drawUnitGraphFromList(g, before);
|
|
|
+ drawUnitGraphFromList(g, after);
|
|
|
+ //EditGraph
|
|
|
+ LinkedList<Position> middle = new LinkedList<Position>();
|
|
|
+ if(!before.isEmpty()) middle.add(before.getLast());
|
|
|
+ middle.add(editPosition);
|
|
|
+ if(!after.isEmpty()) middle.add(after.getFirst());
|
|
|
|
|
|
-// g.setColor(Color.blue);
|
|
|
- while (iter.hasNext())
|
|
|
+ g.setColor(editDotColor);
|
|
|
+ drawUnitGraphFromList(g, middle);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void drawUnitGraphFromList(Graphics2D g, LinkedList<Position> list) {
|
|
|
+ if(list.size() <= 1) return;
|
|
|
+ ListIterator<Position> iter = list.listIterator();
|
|
|
+ Position actual = list.getFirst();
|
|
|
+ Path2D.Double path = this.initBezier(actual);
|
|
|
+ while (iter.hasNext())
|
|
|
{
|
|
|
- Position target = iter.next().displayedPosition;
|
|
|
- this.curveTo(path, actual, target);
|
|
|
+ Position target = iter.next();
|
|
|
+ curveTo(path, actual, target);
|
|
|
actual = target;
|
|
|
}
|
|
|
- g.draw(path);
|
|
|
- g.setColor(editDotColor);
|
|
|
- g.draw(editPath);
|
|
|
- }
|
|
|
+ g.draw(path);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
private void updateRepresentativePositions()
|
|
@@ -349,6 +333,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ if(!iter2.hasNext()) //if behind last point
|
|
|
+ {
|
|
|
+ iter2.add(generateUnitGraphPoint(pos));
|
|
|
+ }
|
|
|
}
|
|
|
private UnitGraphPoint generateUnitGraphPoint(Position pos) {
|
|
|
UnitGraphPoint temp = new UnitGraphPoint((double)(pos.x - border)/(double)widthWithBorder,1 - (double) (pos.y - border)/(double)heightWithBorder,true);
|