|
@@ -4,7 +4,7 @@ import classes.*;
|
|
|
import classes.comparator.UnitGraphPointComperator;
|
|
|
import interfaces.GraphEditable;
|
|
|
import interfaces.GraphEditable.Graphtype;
|
|
|
-import interfaces.IGraphedElement;
|
|
|
+import interfaces.LocalMode;
|
|
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
|
|
import ui.controller.Control;
|
|
|
import ui.controller.SingletonControl;
|
|
@@ -82,10 +82,23 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
this.addMouseMotionListener(this);
|
|
|
this.addComponentListener(this);
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
- * Paints all Components on the Canvas.
|
|
|
- *
|
|
|
+ * When the UnitGraph should represent a new GraphEditable Element.
|
|
|
+ * Its Updates the Graph and give access to the Element.
|
|
|
+ * @param element
|
|
|
+ */
|
|
|
+ public void initNewElement(GraphEditable element)
|
|
|
+ {
|
|
|
+ overrideUnitGraph(element.getStateGraph());
|
|
|
+ actualGraphType = element.getGraphType();
|
|
|
+ actualElement = element;
|
|
|
+ repaint();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Paints the Graph, the Grid, the actual Line fro the currentIteration
|
|
|
* @param g Graphics
|
|
|
*/
|
|
|
public void paintComponent(Graphics g) {
|
|
@@ -109,6 +122,60 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
drawCurrentIterartionLine(g2D);
|
|
|
}
|
|
|
|
|
|
+ // Draw Methods only to let the User see the changes. Nothing its saved here or changed.
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * This Methods draws the UnitGraph whether its a boolGraph or a doubleGraph.
|
|
|
+ * @param g to draw.
|
|
|
+ */
|
|
|
+ private void drawUnitGraph(Graphics2D g) {
|
|
|
+ switch(actualGraphType) {
|
|
|
+ case boolGraph:
|
|
|
+ if(editMode)
|
|
|
+ drawBoolGraphInEditMode(g);
|
|
|
+ else
|
|
|
+ drawBoolGraph(g);
|
|
|
+ break;
|
|
|
+ case doubleGraph:
|
|
|
+ if(editMode)
|
|
|
+ drawDoubleGraphInEditMode(g);
|
|
|
+ else
|
|
|
+ drawDoubleGraph(g);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new UnsupportedOperationException();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * This Methods draws the UnitGraphPoints of the UnitGraph.
|
|
|
+ * @param g to draw.
|
|
|
+ */
|
|
|
+ private void drawUnitGraphPoints(Graphics2D g) {
|
|
|
+ g.setColor(dotColor);
|
|
|
+ for(UnitGraphPoint p : actualGraphPoints){
|
|
|
+ drawDot(g, p.displayedPosition);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * This Methods draws the UnitGraphPoints of the UnitGraph when its in EditMode.
|
|
|
+ * @param g to draw.
|
|
|
+ */
|
|
|
+ private void drawUnitGraphPointsReleased(Graphics2D g) {
|
|
|
+ drawUnitGraphPoints(g);
|
|
|
+ g.setColor(editDotColor);
|
|
|
+ drawDot(g, editPosition);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * This Methods draws the Grid on the Canvas.
|
|
|
+ * @param g2D to draw.
|
|
|
+ */
|
|
|
private void drawGrid(Graphics2D g2D) {
|
|
|
g2D.setStroke(new BasicStroke(1));
|
|
|
g2D.setColor(Color.lightGray);
|
|
@@ -122,16 +189,39 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * This Method draws the CurrentIterationLine.
|
|
|
+ * @param g2D to draw.
|
|
|
+ */
|
|
|
private void drawCurrentIterartionLine(Graphics2D g)
|
|
|
{
|
|
|
int cur = model.getCurIteration();
|
|
|
int max = model.getIterations();
|
|
|
- double where = ((double) cur)/((double) max - 1);
|
|
|
+ double where;
|
|
|
+ if(!this.isUsingLocalPeriod()) {
|
|
|
+ where = ((double) cur)/((double) max);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ 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);
|
|
|
drawLine(g,oben,unten);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * This Method draws a line between two Positions on the Canvas.
|
|
|
+ * @param g2D to draw.
|
|
|
+ * @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)
|
|
|
{
|
|
|
Path2D.Double path = new Path2D.Double();
|
|
@@ -140,6 +230,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
g.draw(path);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * Initialize a Cubic BezierCurve.
|
|
|
+ * @param start The Position to start the Curve.
|
|
|
+ */
|
|
|
private Path2D.Double initBezier(Position start) {
|
|
|
//Good Source for basic understanding for Bezier Curves
|
|
|
//http://www.theappguruz.com/blog/bezier-curve-in-games
|
|
@@ -147,56 +243,38 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
path.moveTo(start.x, start.y);
|
|
|
return path;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * Calculate the Path of a the Cubic BezierCurve with the special controlPoints to make the wanted behavior.
|
|
|
+ * @param path the path of the Bezier.
|
|
|
+ * @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) {
|
|
|
double mitte = (actual.x + target.x)* 0.5;
|
|
|
path.curveTo(mitte, actual.y, mitte, target.y, target.x, target.y);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * Draws a Dot at a Position.
|
|
|
+ * @param g to draw.
|
|
|
+ * @param p the position of the Dot.
|
|
|
+ */
|
|
|
private void drawDot(Graphics2D g, Position p)
|
|
|
{
|
|
|
g.fillOval(p.x -dotSize/2, p.y-dotSize/2, dotSize, dotSize);
|
|
|
}
|
|
|
- private void drawUnitGraph(Graphics2D g) {
|
|
|
- switch(actualGraphType) {
|
|
|
- case boolGraph:
|
|
|
- if(editMode)
|
|
|
- drawBoolGraphWithEditPosition(g);
|
|
|
- else
|
|
|
- drawBoolGraph(g);
|
|
|
- break;
|
|
|
- case doubleGraph:
|
|
|
- if(editMode)
|
|
|
- drawDoubleGraphWithEditPosition(g);
|
|
|
- else
|
|
|
- drawDoubleGraph(g);
|
|
|
- break;
|
|
|
- default:
|
|
|
- throw new UnsupportedOperationException();
|
|
|
- }
|
|
|
- }
|
|
|
- private void drawUnitGraphPoints(Graphics2D g) {
|
|
|
- g.setColor(dotColor);
|
|
|
- for(UnitGraphPoint p : actualGraphPoints){
|
|
|
- drawDot(g, p.displayedPosition);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- private void saveGraph() {
|
|
|
- LinkedList<Point2D.Double> actual = actualElement.getStateGraph();
|
|
|
- actual.clear();
|
|
|
- for(UnitGraphPoint p: actualGraphPoints)
|
|
|
- {
|
|
|
- actual.add(p.getPoint());
|
|
|
- }
|
|
|
- actualElement.sampleGraph();
|
|
|
- }
|
|
|
- private void drawUnitGraphPointsReleased(Graphics2D g) {
|
|
|
- drawUnitGraphPoints(g);
|
|
|
- g.setColor(editDotColor);
|
|
|
- drawDot(g, editPosition);
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * This Method draws the UnitGraph as BoolGraph.
|
|
|
+ * @param g2D to draw.
|
|
|
+ */
|
|
|
private void drawBoolGraph(Graphics2D g) {
|
|
|
- System.out.println("DoImplement");
|
|
|
if(actualGraphPoints.size() <= 1) return;
|
|
|
LinkedList<Position> cornerPoints = new LinkedList<Position>();
|
|
|
ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
|
|
@@ -222,8 +300,13 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- private void drawBoolGraphWithEditPosition(Graphics2D g) {
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * This Method draws the UnitGraph as BoolGraph in EditMode.
|
|
|
+ * @param g2D to draw.
|
|
|
+ */
|
|
|
+ private void drawBoolGraphInEditMode(Graphics2D g) {
|
|
|
LinkedList<Position> before = new LinkedList<Position>();
|
|
|
LinkedList<Position> after = new LinkedList<Position>();
|
|
|
for(UnitGraphPoint p: actualGraphPoints)
|
|
@@ -248,6 +331,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
drawSnappingHint(g);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * This Method draws a red Hint to signal the User the snapping of the hovered Point under the Cursor in EditMode.
|
|
|
+ * @param g2D to draw.
|
|
|
+ */
|
|
|
private void drawSnappingHint(Graphics2D g)
|
|
|
{
|
|
|
//ColorHint
|
|
@@ -266,7 +355,13 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * This Method draws a partial Graph from a Position List as BoolGraph.
|
|
|
+ * @param g2D to draw.
|
|
|
+ * @param list the PositionList to draw a BoolGraph
|
|
|
+ */
|
|
|
private void drawBoolGraphFromList(Graphics2D g, LinkedList<Position> list) {
|
|
|
if(list.size() <= 1) return;
|
|
|
ListIterator<Position> iter = list.listIterator();
|
|
@@ -291,7 +386,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * This Method draws the UnitGraph as DoubleGraph.
|
|
|
+ * @param g2D to draw.
|
|
|
+ */
|
|
|
private void drawDoubleGraph(Graphics2D g) {
|
|
|
if(actualGraphPoints.isEmpty()) throw new IndexOutOfBoundsException("A Graph Without Points is not supportet jet");
|
|
|
ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
|
|
@@ -306,7 +406,13 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
g.draw(path);
|
|
|
|
|
|
}
|
|
|
- private void drawDoubleGraphWithEditPosition(Graphics2D g) {
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * This Method draws the UnitGraph as DoubleGraph in EditMode.
|
|
|
+ * @param g2D to draw.
|
|
|
+ */
|
|
|
+ private void drawDoubleGraphInEditMode(Graphics2D g) {
|
|
|
LinkedList<Position> before = new LinkedList<Position>();
|
|
|
LinkedList<Position> after = new LinkedList<Position>();
|
|
|
for(UnitGraphPoint p: actualGraphPoints)
|
|
@@ -327,7 +433,14 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
g.setColor(editDotColor);
|
|
|
drawUnitGraphFromList(g, middle);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Helper Method to draw the UnitGraphPanel. {@link UnitGraph#paintComponent(Graphics)}
|
|
|
+ * <p>
|
|
|
+ * This Method draws a partial Graph from a Position List as DoubleGraph.
|
|
|
+ * @param g2D to draw.
|
|
|
+ * @param list the PositionList to draw a DoubleGraph
|
|
|
+ */
|
|
|
private void drawUnitGraphFromList(Graphics2D g, LinkedList<Position> list) {
|
|
|
if(list.size() <= 1) return;
|
|
|
ListIterator<Position> iter = list.listIterator();
|
|
@@ -342,15 +455,22 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
g.draw(path);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ //Under the hood functions to calculate and function the
|
|
|
+ /**
|
|
|
+ * A unitgraphpoint have a x and y position to store the data of a graph point.
|
|
|
+ * Also it have a displayposition to store the Position of the GraphPoints on the Canvas.
|
|
|
+ * e.g. when the canvas has 500 width and 200 height a GraphPoint with the X=0.5 and Y=1.0 should have a displayposition of (250,3) when border is 3.
|
|
|
+ */
|
|
|
private void updateRepresentativePositions()
|
|
|
{
|
|
|
for(UnitGraphPoint p : actualGraphPoints) {
|
|
|
p.calcDisplayedPosition(border, widthWithBorder, heightWithBorder);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Takes a List of GraphPoints and convert it to the actual UnitGraphPoints with displayposition in the {@link #actualGraphPoints}
|
|
|
+ * @param stateCurve the list of GraphPoint
|
|
|
+ */
|
|
|
private void overrideUnitGraph(LinkedList<Point2D.Double> stateCurve) {
|
|
|
actualGraphPoints.clear();
|
|
|
for(Point2D.Double p: stateCurve){
|
|
@@ -358,21 +478,32 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
updateRepresentativePositions();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * When the PanelSize Change the width and height to calculate the drawings have to be adjusted.
|
|
|
+ */
|
|
|
private void calculateWidthHeight()
|
|
|
{
|
|
|
widthWithBorder = this.getWidth() - 2 * border;
|
|
|
heightWithBorder = this.getHeight() - 2 * border;
|
|
|
}
|
|
|
|
|
|
- public void initNewElement(GraphEditable element)
|
|
|
- {
|
|
|
- overrideUnitGraph(element.getStateGraph());
|
|
|
- actualGraphType = element.getGraphType();
|
|
|
- actualElement = element;
|
|
|
- repaint();
|
|
|
+ /**
|
|
|
+ * Save the actualGraphPoint List to the GraphEditable Element.
|
|
|
+ */
|
|
|
+ private void saveGraph() {
|
|
|
+ LinkedList<Point2D.Double> actual = actualElement.getStateGraph();
|
|
|
+ actual.clear();
|
|
|
+ for(UnitGraphPoint p: actualGraphPoints)
|
|
|
+ {
|
|
|
+ actual.add(p.getPoint());
|
|
|
+ }
|
|
|
+ actualElement.sampleGraph();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Remove a UnitGraphPoint from the UnitGraphPoint list ({@link #actualGraphPoints} when its near a given Position.
|
|
|
+ * @param mPosition
|
|
|
+ */
|
|
|
private void removePointNearPosition(Position mPosition) {
|
|
|
ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
|
|
|
while (iter.hasNext())
|
|
@@ -385,6 +516,11 @@ 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)
|
|
|
{
|
|
|
UnitGraphPoint first = actualGraphPoints.getFirst();
|
|
@@ -394,6 +530,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
else editPoint = pointType.Normal;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Determine if a Point is near the Cursor (depends on Mode what near means). To detect if it should grab the Point or create a new Point.
|
|
|
+ * @param actual
|
|
|
+ * @param target
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private boolean near(Position actual, Position target) {
|
|
|
switch(actualGraphType)
|
|
|
{
|
|
@@ -407,6 +549,10 @@ 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) {
|
|
|
//make it in the bounds of the UnitGraph no Point out of the Border
|
|
|
Position currentPosition = setInBounds(newPosition);
|
|
@@ -415,6 +561,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
this.editPosition = currentPosition;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * No Point on the UnitGraph should exit the UnitGraph.
|
|
|
+ * @param p the Position
|
|
|
+ * @return the updated Position.
|
|
|
+ */
|
|
|
private Position setInBounds(Position p) {
|
|
|
p.clampX(border, border + widthWithBorder);
|
|
|
p.clampY(border, border + heightWithBorder);
|
|
@@ -422,6 +574,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * For Switches the Point have to be Snap to the Top or the Bottem.
|
|
|
+ * @param p the Position
|
|
|
+ * @return the updated Position.
|
|
|
+ */
|
|
|
private Position snapBoolean(Position p)
|
|
|
{
|
|
|
if (p.y < border + heightWithBorder / 2) {
|
|
@@ -433,55 +591,11 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
|
|
|
|
|
|
- private Point.Double getBezierPoint(double t, Point.Double p0, Point.Double p1,Point.Double p2,Point.Double p3) {
|
|
|
- /*
|
|
|
- * Calculate Beziér:
|
|
|
- * B(t) = (1-t)^3 * P0 + 3*(1-t)^2 * t * P1 + 3*(1-t)*t^2 * P2 + t^3 * P3 , 0 < t < 1
|
|
|
- *
|
|
|
- * Source: //http://www.theappguruz.com/blog/bezier-curve-in-games
|
|
|
- */
|
|
|
- Point.Double bezier = new Point.Double();
|
|
|
- double OneSubT = 1-t;
|
|
|
- double OneSubT2 = Math.pow(OneSubT, 2);
|
|
|
- double OneSubT3 = Math.pow(OneSubT, 3);
|
|
|
- double t2 = Math.pow(t , 2);
|
|
|
- double t3 = Math.pow(t , 3);
|
|
|
-
|
|
|
- bezier.x = OneSubT3 * p0.x + 3 * OneSubT2 * t * p1.x + 3 * OneSubT * t2 * p2.x + t3 * p3.x;
|
|
|
- bezier.y = OneSubT3 * p0.y + 3 * OneSubT2 * t * p1.y + 3 * OneSubT * t2 * p2.y + t3 * p3.y;
|
|
|
- return bezier;
|
|
|
-
|
|
|
- }
|
|
|
- private double getYBetweenTwoPoints(double t, Point.Double start, Point.Double end) {
|
|
|
-
|
|
|
- double mitte = (start.x + end.x)* 0.5;
|
|
|
- Point.Double bezier = getBezierPoint(t, start, new Point.Double(mitte, start.y), new Point.Double(mitte, end.y), end);
|
|
|
- return bezier.y;
|
|
|
- }
|
|
|
-
|
|
|
- private float[] sampleGraph(int sampleLength)
|
|
|
- {
|
|
|
- ListIterator<UnitGraphPoint> iter = actualGraphPoints.listIterator();
|
|
|
- Point.Double before = iter.next().getPoint();
|
|
|
- Point.Double after = iter.next().getPoint();
|
|
|
- float [] sampleCurve = new float[sampleLength];
|
|
|
- for(int i = 0; i<sampleLength ; i++)
|
|
|
- {
|
|
|
- double graphX = (double)i / (double) (sampleLength - 1); //from 0.0 to 1.0
|
|
|
- if(graphX > after.x)
|
|
|
- {
|
|
|
- before = after;
|
|
|
- after = iter.next().getPoint();
|
|
|
- }
|
|
|
- //inverseLerp(valueBetween, min, max) (valueBetween - min) / (max - min)
|
|
|
- // e.g. old.x = 0.4, actual.x = 0.8 and graphX = 0.6 then t is 0.5
|
|
|
- double t = (after.x -before.x > 0)? (graphX - before.x) / (after.x -before.x) : 0.0;
|
|
|
- sampleCurve[i] = (float) getYBetweenTwoPoints(t, before, after);
|
|
|
- }
|
|
|
- return sampleCurve;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ /**
|
|
|
+ * The First Point has to be at 0(LeftSide) and Last Point has to be at 1(RightSide).
|
|
|
+ * @param p the Position
|
|
|
+ * @return the updated Position.
|
|
|
+ */
|
|
|
private Position attachToBorder(Position p)
|
|
|
{
|
|
|
switch(editPoint)
|
|
@@ -497,9 +611,13 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
return p;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * Insert a Position in the UnitGraphList at the right order.
|
|
|
+ * Its sorted based on the xValues.
|
|
|
+ * @param pos The new UnitGraphPoints Position
|
|
|
+ */
|
|
|
private void insertNewGraphPoint(Position pos)
|
|
|
{
|
|
|
- System.out.println("insertNewGraphPoint");
|
|
|
setInBounds(pos);
|
|
|
ListIterator<UnitGraphPoint> iter2 = actualGraphPoints.listIterator();
|
|
|
while (iter2.hasNext())
|
|
@@ -518,7 +636,11 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
iter2.add(generateUnitGraphPoint(pos));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Generate a UnitGraphPoint from a normal Position in the UnitGraph.
|
|
|
+ * @param pos the normal pos with xValues from 0..Width and yValues from 0..Height
|
|
|
+ * @return a UnitGraphPoint
|
|
|
+ */
|
|
|
private UnitGraphPoint generateUnitGraphPoint(Position pos) {
|
|
|
UnitGraphPoint temp = new UnitGraphPoint((double) (pos.x - border) / (double) widthWithBorder,
|
|
|
1 - (double) (pos.y - border) / (double) heightWithBorder, true);
|
|
@@ -526,10 +648,11 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
return temp;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Update the Point Position
|
|
|
+ */
|
|
|
@Override
|
|
|
public void mouseDragged(MouseEvent e) {
|
|
|
- System.out.println("MouseDragged");
|
|
|
updateEditPointPosition(new Position(e.getPoint()));
|
|
|
repaint();
|
|
|
}
|
|
@@ -550,9 +673,13 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
public void mouseExited(MouseEvent e) {
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * The First Step.
|
|
|
+ * When LeftMouseButton its checks if a point is to grab under the cursor or create a new Point. Then enter EditMode.
|
|
|
+ * When RightMouseButton its delete a point if its under the Curser.
|
|
|
+ */
|
|
|
@Override
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
- System.out.println("mousePressed");
|
|
|
Position mPosition = new Position(e.getPoint());
|
|
|
if (e.getButton() == MouseEvent.BUTTON3) {
|
|
|
// RightMouseButtonEvent
|
|
@@ -573,9 +700,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * The last step to save the Changes.
|
|
|
+ * Its insert the Hovering Point and exit EditMode.
|
|
|
+ */
|
|
|
@Override
|
|
|
public void mouseReleased(MouseEvent e) {
|
|
|
- System.out.println("mouseReleased");
|
|
|
if(editMode)
|
|
|
{
|
|
|
this.insertNewGraphPoint(editPosition);
|
|
@@ -591,7 +721,6 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param e ComponentEvent
|
|
|
*/
|
|
|
public void componentResized(ComponentEvent e) {
|
|
|
- System.out.println("componentResized");
|
|
|
calculateWidthHeight();
|
|
|
updateRepresentativePositions();
|
|
|
repaint();
|
|
@@ -610,8 +739,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
public void componentShown(ComponentEvent e) {
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Resets the graph to normal.
|
|
|
+ */
|
|
|
public void reset() {
|
|
|
- System.out.println("reset");
|
|
|
if(this.actualElement != null) {
|
|
|
actualElement.reset();
|
|
|
overrideUnitGraph(actualElement.getStateGraph());
|
|
@@ -620,23 +751,52 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void update(ArrayList<AbstractCpsObject> obj) {
|
|
|
- System.out.println("update");
|
|
|
- }
|
|
|
|
|
|
- public void setStretching(boolean selected) {
|
|
|
- System.out.println("setStretching");
|
|
|
+
|
|
|
+ //LocalMode access methods...
|
|
|
+ //To access a element from the GUI for the LocalMode
|
|
|
+ public void setUseLocalPeriod(boolean state) {
|
|
|
+ if(this.actualElement != null) {
|
|
|
+ ((LocalMode) actualElement).setUseLocalPeriod(state);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void setLocalPeriod(int localLength) {
|
|
|
- System.out.println("setLocalPeriod");
|
|
|
+ if(this.actualElement != null) {
|
|
|
+ ((LocalMode) actualElement).setLocalPeriod(localLength);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getLocalPeriod() {
|
|
|
+ if(this.actualElement != null) {
|
|
|
+ return ((LocalMode) actualElement).getLocalPeriod();
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isUsingLocalPeriod() {
|
|
|
+ if(this.actualElement != null) {
|
|
|
+ return ((LocalMode) actualElement).isUsingLocalPeriod();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @deprecated
|
|
|
+ * @param cps
|
|
|
+ */
|
|
|
public void repaintGraph(AbstractCpsObject cps) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
System.out.println("repaintGraph");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @deprecated
|
|
|
+ * @param obj
|
|
|
+ */
|
|
|
+ public void update(ArrayList<AbstractCpsObject> obj) {
|
|
|
+ System.out.println("update");
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|