|
@@ -7,6 +7,7 @@ import holeg.model.HolonElement;
|
|
|
import holeg.model.Model;
|
|
|
import holeg.preferences.ColorPreference;
|
|
|
import holeg.ui.controller.Control;
|
|
|
+import holeg.utility.listener.ResizeListener;
|
|
|
import holeg.utility.math.Maths;
|
|
|
import holeg.utility.math.vector.Vec2f;
|
|
|
import holeg.utility.math.vector.Vec2i;
|
|
@@ -35,11 +36,8 @@ import javax.swing.JPanel;
|
|
|
|
|
|
* This Class represents a Graph where the User can model the behavior of elements and switches over
|
|
|
* time.
|
|
|
- *
|
|
|
- * @author Tom Troppmann
|
|
|
*/
|
|
|
-public class UnitGraph extends JPanel implements MouseListener, MouseMotionListener,
|
|
|
- ComponentListener {
|
|
|
+public class UnitGraph extends JPanel implements MouseListener, MouseMotionListener{
|
|
|
|
|
|
private static final Logger log = Logger.getLogger(UnitGraph.class.getName());
|
|
|
|
|
@@ -77,17 +75,19 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
this.control = control;
|
|
|
this.addMouseListener(this);
|
|
|
this.addMouseMotionListener(this);
|
|
|
- this.addComponentListener(this);
|
|
|
+ this.addComponentListener((ResizeListener) e -> {
|
|
|
+ calculateWidthHeight();
|
|
|
+ updateRepresentativePositions();
|
|
|
+ repaint();
|
|
|
+ });
|
|
|
control.OnCanvasUpdate.addListener(this::repaint);
|
|
|
}
|
|
|
|
|
|
- ;
|
|
|
-
|
|
|
|
|
|
* When the UnitGraph should represent a new GraphEditable Element. Its Updates the Graph and give
|
|
|
* access to the Element.
|
|
|
*
|
|
|
- * @param element
|
|
|
+ * @param element a series
|
|
|
*/
|
|
|
public void addNewSeries(TimelineDependent element) {
|
|
|
Series series = new Series();
|
|
@@ -100,6 +100,9 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
repaint();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Removes all series from the graph.
|
|
|
+ */
|
|
|
public void clearSeries() {
|
|
|
seriesList.clear();
|
|
|
repaint();
|
|
@@ -387,7 +390,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
if (series.points.size() <= 1) {
|
|
|
return;
|
|
|
}
|
|
|
- LinkedList<Vec2i> cornerPoints = new LinkedList<Vec2i>();
|
|
|
+ LinkedList<Vec2i> cornerPoints = new LinkedList<>();
|
|
|
ListIterator<UnitGraphPoint> iter = series.points.listIterator();
|
|
|
Vec2i actual = series.points.getFirst().displayedPosition;
|
|
|
Path2D.Double path = new Path2D.Double();
|
|
@@ -418,8 +421,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param g to draw.
|
|
|
*/
|
|
|
private void drawBoolGraphInEditMode(Graphics2D g, Series series) {
|
|
|
- LinkedList<Vec2i> before = new LinkedList<Vec2i>();
|
|
|
- LinkedList<Vec2i> after = new LinkedList<Vec2i>();
|
|
|
+ LinkedList<Vec2i> before = new LinkedList<>();
|
|
|
+ LinkedList<Vec2i> after = new LinkedList<>();
|
|
|
for (UnitGraphPoint p : series.points) {
|
|
|
if (p.displayedPosition.getX() < editPosition.getX()) {
|
|
|
before.add(p.displayedPosition);
|
|
@@ -432,7 +435,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
g.setColor(series.color);
|
|
|
drawBoolGraphFromList(g, after);
|
|
|
|
|
|
- LinkedList<Vec2i> middle = new LinkedList<Vec2i>();
|
|
|
+ LinkedList<Vec2i> middle = new LinkedList<>();
|
|
|
if (!before.isEmpty()) {
|
|
|
middle.add(before.getLast());
|
|
|
}
|
|
@@ -458,7 +461,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
|
|
|
g.setColor(Color.RED);
|
|
|
|
|
|
- final float dash1[] = {10.0f};
|
|
|
+ final float[] dash1 = {10.0f};
|
|
|
final BasicStroke dashed = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
|
|
|
10.0f, dash1,
|
|
|
0.0f);
|
|
@@ -483,7 +486,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
return;
|
|
|
}
|
|
|
ListIterator<Vec2i> iter = list.listIterator();
|
|
|
- LinkedList<Vec2i> cornerPoints = new LinkedList<Vec2i>();
|
|
|
+ LinkedList<Vec2i> cornerPoints = new LinkedList<>();
|
|
|
Vec2i actual = list.getFirst();
|
|
|
Path2D.Double path = new Path2D.Double();
|
|
|
path.moveTo(actual.getX(), actual.getY());
|
|
@@ -533,8 +536,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* @param g to draw.
|
|
|
*/
|
|
|
private void drawDoubleGraphInEditMode(Graphics2D g, Series series) {
|
|
|
- LinkedList<Vec2i> before = new LinkedList<Vec2i>();
|
|
|
- LinkedList<Vec2i> after = new LinkedList<Vec2i>();
|
|
|
+ LinkedList<Vec2i> before = new LinkedList<>();
|
|
|
+ LinkedList<Vec2i> after = new LinkedList<>();
|
|
|
for (UnitGraphPoint p : series.points) {
|
|
|
if (p.displayedPosition.getX() < editPosition.getX()) {
|
|
|
before.add(p.displayedPosition);
|
|
@@ -545,7 +548,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
drawUnitGraphFromList(g, before);
|
|
|
drawUnitGraphFromList(g, after);
|
|
|
|
|
|
- LinkedList<Vec2i> middle = new LinkedList<Vec2i>();
|
|
|
+ LinkedList<Vec2i> middle = new LinkedList<>();
|
|
|
if (!before.isEmpty()) {
|
|
|
middle.add(before.getLast());
|
|
|
}
|
|
@@ -647,7 +650,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
* Remove a UnitGraphPoint from the UnitGraphPoint list ({@link #seriesList} when its near a given
|
|
|
* Position.
|
|
|
*
|
|
|
- * @param mPosition
|
|
|
+ * @param mPosition the position
|
|
|
*/
|
|
|
private void removePointNearPosition(Series series, Vec2i mPosition) {
|
|
|
ListIterator<UnitGraphPoint> iter = series.points.listIterator();
|
|
@@ -743,35 +746,25 @@ 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 Vec2i snapBoolean(Vec2i p) {
|
|
|
+ private void snapBoolean(Vec2i p) {
|
|
|
if (p.getY() < border + heightWithBorder / 2) {
|
|
|
p.setY(border);
|
|
|
} else {
|
|
|
p.setY(border + heightWithBorder);
|
|
|
}
|
|
|
- return p;
|
|
|
}
|
|
|
|
|
|
|
|
|
* 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 Vec2i attachToBorder(Vec2i p, EditPointType editPointType) {
|
|
|
+ private void attachToBorder(Vec2i p, EditPointType editPointType) {
|
|
|
switch (editPointType) {
|
|
|
- case StartPoint:
|
|
|
- p.setX(border);
|
|
|
- break;
|
|
|
- case EndPoint:
|
|
|
- p.setX(border + widthWithBorder);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ case StartPoint -> p.setX(border);
|
|
|
+ case EndPoint -> p.setX(border + widthWithBorder);
|
|
|
}
|
|
|
- return p;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -889,30 +882,6 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
repaint();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * When the Component is Resized.
|
|
|
- *
|
|
|
- * @param e ComponentEvent
|
|
|
- */
|
|
|
- public void componentResized(ComponentEvent e) {
|
|
|
- calculateWidthHeight();
|
|
|
- updateRepresentativePositions();
|
|
|
- repaint();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void componentHidden(ComponentEvent e) {
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void componentMoved(ComponentEvent e) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void componentShown(ComponentEvent e) {
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
* Resets the graph to normal.
|
|
|
*/
|
|
@@ -924,21 +893,37 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
repaint();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * set the local period of all selected series elements.
|
|
|
+ * @param period the period
|
|
|
+ */
|
|
|
public void setPeriod(LocalMode.Period period) {
|
|
|
for (Series series : seriesList) {
|
|
|
series.element.setPeriod(new LocalMode.Period(period));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Check if selected series are different from another.
|
|
|
+ * @return true or false
|
|
|
+ */
|
|
|
public boolean isLocalPeriedDifferentInSeries() {
|
|
|
return seriesList.stream().map(series -> series.element.getPeriod().getInterval()).distinct()
|
|
|
.count() > 1;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Returns the local period of the first series
|
|
|
+ * @return the first series local period
|
|
|
+ */
|
|
|
public int getFirstLocalPeriod() {
|
|
|
return seriesList.isEmpty() ? 0 : seriesList.get(0).element.getPeriod().getInterval();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * Check if using the local period of the series.
|
|
|
+ * @return true or false
|
|
|
+ */
|
|
|
public boolean isUsingLocalPeriod() {
|
|
|
return seriesList.stream().anyMatch(
|
|
|
series -> series.element.getPeriod().getType() != LocalMode.Period.PeriodType.Global);
|
|
@@ -951,7 +936,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
|
|
|
private static class Series {
|
|
|
|
|
|
- public LinkedList<UnitGraphPoint> points = new LinkedList<UnitGraphPoint>();
|
|
|
+ public LinkedList<UnitGraphPoint> points = new LinkedList<>();
|
|
|
public TimelineDependent element;
|
|
|
public GraphType type;
|
|
|
public Color color;
|
|
@@ -959,10 +944,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
|
|
|
private static class GlobalCurve {
|
|
|
|
|
|
- public LinkedList<UnitGraphPoint> points = new LinkedList<UnitGraphPoint>();
|
|
|
+ public LinkedList<UnitGraphPoint> points = new LinkedList<>();
|
|
|
public float minEnergy;
|
|
|
public float maxEnergy;
|
|
|
- public LinkedList<UnitGraphPoint> zeroLinePoints = new LinkedList<UnitGraphPoint>();
|
|
|
+ public LinkedList<UnitGraphPoint> zeroLinePoints = new LinkedList<>();
|
|
|
}
|
|
|
|
|
|
}
|