|
@@ -18,13 +18,13 @@ import java.util.ListIterator;
|
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
-import classes.Vector2dInt;
|
|
|
import classes.UnitGraphPoint;
|
|
|
import interfaces.GraphEditable;
|
|
|
import interfaces.GraphEditable.Graphtype;
|
|
|
import interfaces.LocalMode;
|
|
|
import ui.controller.Control;
|
|
|
import ui.model.Model;
|
|
|
+import utility.Vector2Int;
|
|
|
|
|
|
/**
|
|
|
* This Class represents a Graph where the User can model the behavior of
|
|
@@ -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;
|
|
|
- Vector2dInt editPosition;
|
|
|
+ Vector2Int 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);
|
|
|
}
|
|
|
- Vector2dInt oben = new Vector2dInt(border + (int)(where * widthWithBorder), 0);
|
|
|
- Vector2dInt unten = new Vector2dInt(border + (int)(where * widthWithBorder), 2 * border + heightWithBorder);
|
|
|
+ Vector2Int oben = new Vector2Int(border + (int)(where * widthWithBorder), 0);
|
|
|
+ Vector2Int unten = new Vector2Int(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, Vector2dInt start, Vector2dInt end)
|
|
|
+ private void drawLine(Graphics2D g, Vector2Int start, Vector2Int end)
|
|
|
{
|
|
|
Path2D.Double path = new Path2D.Double();
|
|
|
path.moveTo(start.getX(), start.getY());
|
|
@@ -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(Vector2dInt start) {
|
|
|
+ private Path2D.Double initBezier(Vector2Int 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, Vector2dInt actual, Vector2dInt target) {
|
|
|
+ private void curveTo(Path2D.Double path, Vector2Int actual, Vector2Int target) {
|
|
|
double mitte = (actual.getX() + target.getX())* 0.5;
|
|
|
path.curveTo(mitte, actual.getY(), mitte, target.getY(), target.getX(), target.getY());
|
|
|
}
|
|
@@ -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, Vector2dInt p)
|
|
|
+ private void drawDot(Graphics2D g, Vector2Int p)
|
|
|
{
|
|
|
g.fillOval(p.getX() -dotSize/2, p.getY()-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<Vector2dInt> cornerPoints = new LinkedList<Vector2dInt>();
|
|
|
+ LinkedList<Vector2Int> cornerPoints = new LinkedList<Vector2Int>();
|
|
|
ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
|
|
|
- Vector2dInt actual = actualGraphPoints.getFirst().displayedPosition;
|
|
|
+ Vector2Int actual = actualGraphPoints.getFirst().displayedPosition;
|
|
|
Path2D.Double path = new Path2D.Double();
|
|
|
path.moveTo(actual.getX(), actual.getY());
|
|
|
while (iter.hasNext())
|
|
|
{
|
|
|
- Vector2dInt target = iter.next().displayedPosition;
|
|
|
+ Vector2Int target = iter.next().displayedPosition;
|
|
|
//BooleanConnection
|
|
|
path.lineTo(target.getX(), actual.getY()); //line to corner
|
|
|
- cornerPoints.add(new Vector2dInt(target.getX(), actual.getY())); //save corner
|
|
|
+ cornerPoints.add(new Vector2Int(target.getX(), actual.getY())); //save corner
|
|
|
path.lineTo(target.getX(), target.getY()); //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(Vector2dInt p: cornerPoints)
|
|
|
+ for(Vector2Int 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<Vector2dInt> before = new LinkedList<Vector2dInt>();
|
|
|
- LinkedList<Vector2dInt> after = new LinkedList<Vector2dInt>();
|
|
|
+ LinkedList<Vector2Int> before = new LinkedList<Vector2Int>();
|
|
|
+ LinkedList<Vector2Int> after = new LinkedList<Vector2Int>();
|
|
|
for(UnitGraphPoint p: actualGraphPoints)
|
|
|
{
|
|
|
if(p.displayedPosition.getX() < editPosition.getX())
|
|
@@ -326,7 +326,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
g.setColor(Color.BLACK);
|
|
|
drawBoolGraphFromList(g, after);
|
|
|
//EditGraph
|
|
|
- LinkedList<Vector2dInt> middle = new LinkedList<Vector2dInt>();
|
|
|
+ LinkedList<Vector2Int> middle = new LinkedList<Vector2Int>();
|
|
|
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<Vector2dInt> list) {
|
|
|
+ private void drawBoolGraphFromList(Graphics2D g, LinkedList<Vector2Int> list) {
|
|
|
if(list.size() <= 1) return;
|
|
|
- ListIterator<Vector2dInt> iter = list.listIterator();
|
|
|
- LinkedList<Vector2dInt> cornerPoints = new LinkedList<Vector2dInt>();
|
|
|
- Vector2dInt actual = list.getFirst();
|
|
|
+ ListIterator<Vector2Int> iter = list.listIterator();
|
|
|
+ LinkedList<Vector2Int> cornerPoints = new LinkedList<Vector2Int>();
|
|
|
+ Vector2Int actual = list.getFirst();
|
|
|
Path2D.Double path = new Path2D.Double();
|
|
|
path.moveTo(actual.getX(), actual.getY());
|
|
|
while (iter.hasNext())
|
|
|
{
|
|
|
- Vector2dInt target = iter.next();
|
|
|
+ Vector2Int target = iter.next();
|
|
|
//BooleanConnection
|
|
|
path.lineTo(target.getX(), actual.getY()); //line to corner
|
|
|
- cornerPoints.add(new Vector2dInt(target.getX(), actual.getY())); //save corner
|
|
|
+ cornerPoints.add(new Vector2Int(target.getX(), actual.getY())); //save corner
|
|
|
path.lineTo(target.getX(), target.getY()); //line to next Point
|
|
|
actual = target;
|
|
|
}
|
|
|
g.draw(path);
|
|
|
g.setColor(dotColor);
|
|
|
- for(Vector2dInt p: cornerPoints)
|
|
|
+ for(Vector2Int 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();
|
|
|
- Vector2dInt actual = iter.next().displayedPosition;
|
|
|
+ Vector2Int actual = iter.next().displayedPosition;
|
|
|
Path2D.Double path = this.initBezier(actual);
|
|
|
while (iter.hasNext())
|
|
|
{
|
|
|
- Vector2dInt target = iter.next().displayedPosition;
|
|
|
+ Vector2Int 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<Vector2dInt> before = new LinkedList<Vector2dInt>();
|
|
|
- LinkedList<Vector2dInt> after = new LinkedList<Vector2dInt>();
|
|
|
+ LinkedList<Vector2Int> before = new LinkedList<Vector2Int>();
|
|
|
+ LinkedList<Vector2Int> after = new LinkedList<Vector2Int>();
|
|
|
for(UnitGraphPoint p: actualGraphPoints)
|
|
|
{
|
|
|
if(p.displayedPosition.getX() < editPosition.getX())
|
|
@@ -430,7 +430,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
drawUnitGraphFromList(g, before);
|
|
|
drawUnitGraphFromList(g, after);
|
|
|
//EditGraph
|
|
|
- LinkedList<Vector2dInt> middle = new LinkedList<Vector2dInt>();
|
|
|
+ LinkedList<Vector2Int> middle = new LinkedList<Vector2Int>();
|
|
|
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<Vector2dInt> list) {
|
|
|
+ private void drawUnitGraphFromList(Graphics2D g, LinkedList<Vector2Int> list) {
|
|
|
if(list.size() <= 1) return;
|
|
|
- ListIterator<Vector2dInt> iter = list.listIterator();
|
|
|
- Vector2dInt actual = list.getFirst();
|
|
|
+ ListIterator<Vector2Int> iter = list.listIterator();
|
|
|
+ Vector2Int actual = list.getFirst();
|
|
|
Path2D.Double path = this.initBezier(actual);
|
|
|
while (iter.hasNext())
|
|
|
{
|
|
|
- Vector2dInt target = iter.next();
|
|
|
+ Vector2Int 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(Vector2dInt mPosition) {
|
|
|
+ private void removePointNearPosition(Vector2Int 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(Vector2dInt mPosition)
|
|
|
+ private void detectStartEndPoint(Vector2Int 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(Vector2dInt actual, Vector2dInt target) {
|
|
|
+ private boolean near(Vector2Int actual, Vector2Int 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(Vector2dInt newPosition) {
|
|
|
+ private void updateEditPointPosition(Vector2Int newPosition) {
|
|
|
//make it in the bounds of the UnitGraph no Point out of the Border
|
|
|
- Vector2dInt currentPosition = setInBounds(newPosition);
|
|
|
+ Vector2Int 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 Vector2dInt setInBounds(Vector2dInt p) {
|
|
|
+ private Vector2Int setInBounds(Vector2Int 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 Vector2dInt snapBoolean(Vector2dInt p)
|
|
|
+ private Vector2Int snapBoolean(Vector2Int p)
|
|
|
{
|
|
|
if (p.getY() < border + heightWithBorder / 2) {
|
|
|
p.setY(border);
|
|
@@ -601,7 +601,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param p the Position
|
|
|
* @return the updated Position.
|
|
|
*/
|
|
|
- private Vector2dInt attachToBorder(Vector2dInt p)
|
|
|
+ private Vector2Int attachToBorder(Vector2Int 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(Vector2dInt pos)
|
|
|
+ private void insertNewGraphPoint(Vector2Int pos)
|
|
|
{
|
|
|
setInBounds(pos);
|
|
|
ListIterator<UnitGraphPoint> iter2 = actualGraphPoints.listIterator();
|
|
|
while (iter2.hasNext())
|
|
|
{
|
|
|
- Vector2dInt tempPosition = iter2.next().displayedPosition;
|
|
|
+ Vector2Int tempPosition = iter2.next().displayedPosition;
|
|
|
if(pos.getX() <= tempPosition.getX())
|
|
|
{
|
|
|
//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(Vector2dInt pos) {
|
|
|
+ private UnitGraphPoint generateUnitGraphPoint(Vector2Int pos) {
|
|
|
UnitGraphPoint temp = new UnitGraphPoint((double) (pos.getX() - border) / (double) widthWithBorder,
|
|
|
1 - (double) (pos.getY() - 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 Vector2dInt(e.getPoint().x, e.getPoint().y));
|
|
|
+ updateEditPointPosition(new Vector2Int(e.getPoint().x, e.getPoint().y));
|
|
|
repaint();
|
|
|
}
|
|
|
|
|
@@ -685,7 +685,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
*/
|
|
|
@Override
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
- Vector2dInt mPosition = new Vector2dInt(e.getPoint().x, e.getPoint().y);
|
|
|
+ Vector2Int mPosition = new Vector2Int(e.getPoint().x, e.getPoint().y);
|
|
|
if (e.getButton() == MouseEvent.BUTTON3) {
|
|
|
// RightMouseButtonEvent
|
|
|
detectStartEndPoint(mPosition);
|