|
@@ -18,7 +18,7 @@ import java.util.ListIterator;
|
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
-import classes.Position;
|
|
|
+import classes.Vector2dInt;
|
|
|
import classes.UnitGraphPoint;
|
|
|
import interfaces.GraphEditable;
|
|
|
import interfaces.GraphEditable.Graphtype;
|
|
@@ -56,7 +56,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
private LinkedList<UnitGraphPoint> actualGraphPoints = new LinkedList<UnitGraphPoint>();
|
|
|
private Graphtype actualGraphType;
|
|
|
private GraphEditable actualElement;
|
|
|
- Position editPosition;
|
|
|
+ Vector2dInt editPosition;
|
|
|
boolean editMode = false;
|
|
|
private enum pointType {Normal, StartPoint, EndPoint};
|
|
|
pointType editPoint = pointType.Normal;
|
|
@@ -213,8 +213,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
int lPeriod = this.getLocalPeriod();
|
|
|
where = ((double) cur%lPeriod)/((double) lPeriod);
|
|
|
}
|
|
|
- Position oben = new Position(border + (int)(where * widthWithBorder), 0);
|
|
|
- Position unten = new Position(border + (int)(where * widthWithBorder), 2 * border + heightWithBorder);
|
|
|
+ Vector2dInt oben = new Vector2dInt(border + (int)(where * widthWithBorder), 0);
|
|
|
+ Vector2dInt unten = new Vector2dInt(border + (int)(where * widthWithBorder), 2 * border + heightWithBorder);
|
|
|
drawLine(g,oben,unten);
|
|
|
|
|
|
}
|
|
@@ -227,7 +227,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param start the Position of one end of the line to draw.
|
|
|
* @param end the other Ends Position of the Line to draw.
|
|
|
*/
|
|
|
- private void drawLine(Graphics2D g, Position start, Position end)
|
|
|
+ private void drawLine(Graphics2D g, Vector2dInt start, Vector2dInt end)
|
|
|
{
|
|
|
Path2D.Double path = new Path2D.Double();
|
|
|
path.moveTo(start.x, start.y);
|
|
@@ -241,7 +241,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* Initialize a Cubic BezierCurve.
|
|
|
* @param start The Position to start the Curve.
|
|
|
*/
|
|
|
- private Path2D.Double initBezier(Position start) {
|
|
|
+ private Path2D.Double initBezier(Vector2dInt start) {
|
|
|
//Good Source for basic understanding for Bezier Curves
|
|
|
//http://www.theappguruz.com/blog/bezier-curve-in-games
|
|
|
Path2D.Double path = new Path2D.Double();
|
|
@@ -256,7 +256,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param actaul the actual Position of the Path.
|
|
|
* @param target the end Position of the Curve.
|
|
|
*/
|
|
|
- private void curveTo(Path2D.Double path, Position actual, Position target) {
|
|
|
+ private void curveTo(Path2D.Double path, Vector2dInt actual, Vector2dInt target) {
|
|
|
double mitte = (actual.x + target.x)* 0.5;
|
|
|
path.curveTo(mitte, actual.y, mitte, target.y, target.x, target.y);
|
|
|
}
|
|
@@ -267,7 +267,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param g to draw.
|
|
|
* @param p the position of the Dot.
|
|
|
*/
|
|
|
- private void drawDot(Graphics2D g, Position p)
|
|
|
+ private void drawDot(Graphics2D g, Vector2dInt p)
|
|
|
{
|
|
|
g.fillOval(p.x -dotSize/2, p.y-dotSize/2, dotSize, dotSize);
|
|
|
}
|
|
@@ -281,17 +281,17 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
*/
|
|
|
private void drawBoolGraph(Graphics2D g) {
|
|
|
if(actualGraphPoints.size() <= 1) return;
|
|
|
- LinkedList<Position> cornerPoints = new LinkedList<Position>();
|
|
|
+ LinkedList<Vector2dInt> cornerPoints = new LinkedList<Vector2dInt>();
|
|
|
ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
|
|
|
- Position actual = actualGraphPoints.getFirst().displayedPosition;
|
|
|
+ Vector2dInt actual = actualGraphPoints.getFirst().displayedPosition;
|
|
|
Path2D.Double path = new Path2D.Double();
|
|
|
path.moveTo(actual.x, actual.y);
|
|
|
while (iter.hasNext())
|
|
|
{
|
|
|
- Position target = iter.next().displayedPosition;
|
|
|
+ Vector2dInt target = iter.next().displayedPosition;
|
|
|
//BooleanConnection
|
|
|
path.lineTo(target.x, actual.y); //line to corner
|
|
|
- cornerPoints.add(new Position(target.x, actual.y)); //save corner
|
|
|
+ cornerPoints.add(new Vector2dInt(target.x, actual.y)); //save corner
|
|
|
path.lineTo(target.x, target.y); //line to next Point
|
|
|
|
|
|
actual = target;
|
|
@@ -299,7 +299,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
g.draw(path);
|
|
|
//Draw the Points on the Corner that dont exist in Data but should be visual
|
|
|
g.setColor(dotColor);
|
|
|
- for(Position p: cornerPoints)
|
|
|
+ for(Vector2dInt p: cornerPoints)
|
|
|
{
|
|
|
drawDot(g, p);
|
|
|
}
|
|
@@ -312,8 +312,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param g2D to draw.
|
|
|
*/
|
|
|
private void drawBoolGraphInEditMode(Graphics2D g) {
|
|
|
- LinkedList<Position> before = new LinkedList<Position>();
|
|
|
- LinkedList<Position> after = new LinkedList<Position>();
|
|
|
+ LinkedList<Vector2dInt> before = new LinkedList<Vector2dInt>();
|
|
|
+ LinkedList<Vector2dInt> after = new LinkedList<Vector2dInt>();
|
|
|
for(UnitGraphPoint p: actualGraphPoints)
|
|
|
{
|
|
|
if(p.displayedPosition.x < editPosition.x)
|
|
@@ -326,7 +326,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
g.setColor(Color.BLACK);
|
|
|
drawBoolGraphFromList(g, after);
|
|
|
//EditGraph
|
|
|
- LinkedList<Position> middle = new LinkedList<Position>();
|
|
|
+ LinkedList<Vector2dInt> middle = new LinkedList<Vector2dInt>();
|
|
|
if(!before.isEmpty()) middle.add(before.getLast());
|
|
|
middle.add(editPosition);
|
|
|
if(!after.isEmpty()) middle.add(after.getFirst());
|
|
@@ -367,25 +367,25 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param g2D to draw.
|
|
|
* @param list the PositionList to draw a BoolGraph
|
|
|
*/
|
|
|
- private void drawBoolGraphFromList(Graphics2D g, LinkedList<Position> list) {
|
|
|
+ private void drawBoolGraphFromList(Graphics2D g, LinkedList<Vector2dInt> list) {
|
|
|
if(list.size() <= 1) return;
|
|
|
- ListIterator<Position> iter = list.listIterator();
|
|
|
- LinkedList<Position> cornerPoints = new LinkedList<Position>();
|
|
|
- Position actual = list.getFirst();
|
|
|
+ ListIterator<Vector2dInt> iter = list.listIterator();
|
|
|
+ LinkedList<Vector2dInt> cornerPoints = new LinkedList<Vector2dInt>();
|
|
|
+ Vector2dInt actual = list.getFirst();
|
|
|
Path2D.Double path = new Path2D.Double();
|
|
|
path.moveTo(actual.x, actual.y);
|
|
|
while (iter.hasNext())
|
|
|
{
|
|
|
- Position target = iter.next();
|
|
|
+ Vector2dInt target = iter.next();
|
|
|
//BooleanConnection
|
|
|
path.lineTo(target.x, actual.y); //line to corner
|
|
|
- cornerPoints.add(new Position(target.x, actual.y)); //save corner
|
|
|
+ cornerPoints.add(new Vector2dInt(target.x, actual.y)); //save corner
|
|
|
path.lineTo(target.x, target.y); //line to next Point
|
|
|
actual = target;
|
|
|
}
|
|
|
g.draw(path);
|
|
|
g.setColor(dotColor);
|
|
|
- for(Position p: cornerPoints)
|
|
|
+ for(Vector2dInt p: cornerPoints)
|
|
|
{
|
|
|
drawDot(g, p);
|
|
|
}
|
|
@@ -400,11 +400,11 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
private void drawDoubleGraph(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;
|
|
|
+ Vector2dInt actual = iter.next().displayedPosition;
|
|
|
Path2D.Double path = this.initBezier(actual);
|
|
|
while (iter.hasNext())
|
|
|
{
|
|
|
- Position target = iter.next().displayedPosition;
|
|
|
+ Vector2dInt target = iter.next().displayedPosition;
|
|
|
this.curveTo(path, actual, target);
|
|
|
actual = target;
|
|
|
}
|
|
@@ -418,8 +418,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param g2D to draw.
|
|
|
*/
|
|
|
private void drawDoubleGraphInEditMode(Graphics2D g) {
|
|
|
- LinkedList<Position> before = new LinkedList<Position>();
|
|
|
- LinkedList<Position> after = new LinkedList<Position>();
|
|
|
+ LinkedList<Vector2dInt> before = new LinkedList<Vector2dInt>();
|
|
|
+ LinkedList<Vector2dInt> after = new LinkedList<Vector2dInt>();
|
|
|
for(UnitGraphPoint p: actualGraphPoints)
|
|
|
{
|
|
|
if(p.displayedPosition.x < editPosition.x)
|
|
@@ -430,7 +430,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
drawUnitGraphFromList(g, before);
|
|
|
drawUnitGraphFromList(g, after);
|
|
|
//EditGraph
|
|
|
- LinkedList<Position> middle = new LinkedList<Position>();
|
|
|
+ LinkedList<Vector2dInt> middle = new LinkedList<Vector2dInt>();
|
|
|
if(!before.isEmpty()) middle.add(before.getLast());
|
|
|
middle.add(editPosition);
|
|
|
if(!after.isEmpty()) middle.add(after.getFirst());
|
|
@@ -446,14 +446,14 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param g2D to draw.
|
|
|
* @param list the PositionList to draw a DoubleGraph
|
|
|
*/
|
|
|
- private void drawUnitGraphFromList(Graphics2D g, LinkedList<Position> list) {
|
|
|
+ private void drawUnitGraphFromList(Graphics2D g, LinkedList<Vector2dInt> list) {
|
|
|
if(list.size() <= 1) return;
|
|
|
- ListIterator<Position> iter = list.listIterator();
|
|
|
- Position actual = list.getFirst();
|
|
|
+ ListIterator<Vector2dInt> iter = list.listIterator();
|
|
|
+ Vector2dInt actual = list.getFirst();
|
|
|
Path2D.Double path = this.initBezier(actual);
|
|
|
while (iter.hasNext())
|
|
|
{
|
|
|
- Position target = iter.next();
|
|
|
+ Vector2dInt target = iter.next();
|
|
|
curveTo(path, actual, target);
|
|
|
actual = target;
|
|
|
}
|
|
@@ -509,7 +509,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* Remove a UnitGraphPoint from the UnitGraphPoint list ({@link #actualGraphPoints} when its near a given Position.
|
|
|
* @param mPosition
|
|
|
*/
|
|
|
- private void removePointNearPosition(Position mPosition) {
|
|
|
+ private void removePointNearPosition(Vector2dInt mPosition) {
|
|
|
ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
|
|
|
while (iter.hasNext())
|
|
|
{
|
|
@@ -526,7 +526,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* Determine if the Point is a StartPoint , EndPoint or a NormalPoint a.k.a. in between Points.
|
|
|
* @param mPosition The Position to check.
|
|
|
*/
|
|
|
- private void detectStartEndPoint(Position mPosition)
|
|
|
+ private void detectStartEndPoint(Vector2dInt mPosition)
|
|
|
{
|
|
|
UnitGraphPoint first = actualGraphPoints.getFirst();
|
|
|
UnitGraphPoint last = actualGraphPoints.getLast();
|
|
@@ -541,7 +541,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param target
|
|
|
* @return
|
|
|
*/
|
|
|
- private boolean near(Position actual, Position target) {
|
|
|
+ private boolean near(Vector2dInt actual, Vector2dInt target) {
|
|
|
switch(actualGraphType)
|
|
|
{
|
|
|
case boolGraph: //Distance only with X
|
|
@@ -558,9 +558,9 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* When the Mouse Drag a Point it updates each time the position.
|
|
|
* @param newPosition
|
|
|
*/
|
|
|
- private void updateEditPointPosition(Position newPosition) {
|
|
|
+ private void updateEditPointPosition(Vector2dInt newPosition) {
|
|
|
//make it in the bounds of the UnitGraph no Point out of the Border
|
|
|
- Position currentPosition = setInBounds(newPosition);
|
|
|
+ Vector2dInt currentPosition = setInBounds(newPosition);
|
|
|
if(editPoint != pointType.Normal) attachToBorder(currentPosition);
|
|
|
if(actualGraphType == Graphtype.boolGraph) snapBoolean(currentPosition);
|
|
|
this.editPosition = currentPosition;
|
|
@@ -572,7 +572,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param p the Position
|
|
|
* @return the updated Position.
|
|
|
*/
|
|
|
- private Position setInBounds(Position p) {
|
|
|
+ private Vector2dInt setInBounds(Vector2dInt p) {
|
|
|
p.clampX(border, border + widthWithBorder);
|
|
|
p.clampY(border, border + heightWithBorder);
|
|
|
return p;
|
|
@@ -585,7 +585,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param p the Position
|
|
|
* @return the updated Position.
|
|
|
*/
|
|
|
- private Position snapBoolean(Position p)
|
|
|
+ private Vector2dInt snapBoolean(Vector2dInt p)
|
|
|
{
|
|
|
if (p.y < border + heightWithBorder / 2) {
|
|
|
p.y = border;
|
|
@@ -601,7 +601,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param p the Position
|
|
|
* @return the updated Position.
|
|
|
*/
|
|
|
- private Position attachToBorder(Position p)
|
|
|
+ private Vector2dInt attachToBorder(Vector2dInt p)
|
|
|
{
|
|
|
switch(editPoint)
|
|
|
{
|
|
@@ -621,13 +621,13 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* Its sorted based on the xValues.
|
|
|
* @param pos The new UnitGraphPoints Position
|
|
|
*/
|
|
|
- private void insertNewGraphPoint(Position pos)
|
|
|
+ private void insertNewGraphPoint(Vector2dInt pos)
|
|
|
{
|
|
|
setInBounds(pos);
|
|
|
ListIterator<UnitGraphPoint> iter2 = actualGraphPoints.listIterator();
|
|
|
while (iter2.hasNext())
|
|
|
{
|
|
|
- Position tempPosition = iter2.next().displayedPosition;
|
|
|
+ Vector2dInt tempPosition = iter2.next().displayedPosition;
|
|
|
if(pos.x <= tempPosition.x)
|
|
|
{
|
|
|
//previous to go back a position to make the new point before the the Position with greater X
|
|
@@ -646,7 +646,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param pos the normal pos with xValues from 0..Width and yValues from 0..Height
|
|
|
* @return a UnitGraphPoint
|
|
|
*/
|
|
|
- private UnitGraphPoint generateUnitGraphPoint(Position pos) {
|
|
|
+ private UnitGraphPoint generateUnitGraphPoint(Vector2dInt pos) {
|
|
|
UnitGraphPoint temp = new UnitGraphPoint((double) (pos.x - border) / (double) widthWithBorder,
|
|
|
1 - (double) (pos.y - border) / (double) heightWithBorder, true);
|
|
|
temp.displayedPosition = pos;
|
|
@@ -658,7 +658,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
*/
|
|
|
@Override
|
|
|
public void mouseDragged(MouseEvent e) {
|
|
|
- updateEditPointPosition(new Position(e.getPoint()));
|
|
|
+ updateEditPointPosition(new Vector2dInt(e.getPoint()));
|
|
|
repaint();
|
|
|
}
|
|
|
|
|
@@ -685,7 +685,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
*/
|
|
|
@Override
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
- Position mPosition = new Position(e.getPoint());
|
|
|
+ Vector2dInt mPosition = new Vector2dInt(e.getPoint());
|
|
|
if (e.getButton() == MouseEvent.BUTTON3) {
|
|
|
// RightMouseButtonEvent
|
|
|
detectStartEndPoint(mPosition);
|