Marker class can now store and show multiple arrows sequentially

#implement #story[1118]
This commit is contained in:
Calum
2017-08-16 14:51:05 +12:00
parent ac47e9d88a
commit 3542c646f8
2 changed files with 64 additions and 32 deletions
@@ -1,5 +1,7 @@
package seng302.visualiser.fxObjects;
import java.util.ArrayList;
import java.util.List;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.paint.Color;
@@ -7,54 +9,84 @@ import javafx.scene.paint.Paint;
import javafx.scene.shape.Circle;
/**
* Visual object for a mark.
* Visual object for a mark. Contains a coloured circle and any specified arrows.
*/
public class Marker extends Group {
Circle mark = new Circle();
Paint colour = Color.BLACK;
Group enterArrow;
Group exitArrow;
private Circle mark = new Circle();
private Paint colour = Color.BLACK;
private List<Group> enterArrows = new ArrayList<>();
private List<Group> exitArrows = new ArrayList<>();
private int enterArrowIndex = 0;
private int exitArrowIndex = 0;
/**
* Creates a new Marker containing only a circle. The default colour is black.
*/
public Marker() {
mark.setRadius(5);
mark.setCenterX(0);
mark.setCenterY(0);
Platform.runLater(() -> this.getChildren().add(mark));
Platform.runLater(() -> this.getChildren().addAll(mark, new Group())); //Empty group placeholder or arrows.
}
/**
* Creates a new Marker containing only a circle of the given colour.
* @param colour the desired colour for the marker.
*/
public Marker(Paint colour) {
this();
this.colour = colour;
mark.setFill(colour);
}
public void constructArrows(MarkArrowFactory.RoundingSide roundingSide, double entryAngle, double exitAngle) {
enterArrow = MarkArrowFactory.constructEntryArrow(roundingSide, entryAngle, exitAngle, colour);
exitArrow = MarkArrowFactory.constructExitArrow(roundingSide, exitAngle, colour);
/**
* Adds an exit and entry arrow pair to the mark. Arrows are hidden and shown in the order they
* are created by calling showNextEnterArrow() or showNextExitArrow()
* @param roundingSide the side the marker will be from the perspective of the arrow.
* @param entryAngle The angle the arrow will point towards a marker
* @param exitAngle The angle the arrow wil point from the marker.
*/
public void addArrows(MarkArrowFactory.RoundingSide roundingSide, double entryAngle,
double exitAngle) {
enterArrows.add(
MarkArrowFactory.constructEntryArrow(roundingSide, entryAngle, exitAngle, colour)
);
exitArrows.add(
MarkArrowFactory.constructExitArrow(roundingSide, exitAngle, colour)
);
}
public void showEnterArrow () {
if (!this.getChildren().contains(enterArrow)) {
/**
* Shows the next EnterArrow. Does nothing if there are no more enter arrows. Other arrows become hidden.
*/
public void showNextEnterArrow() {
showArrow(enterArrows, enterArrowIndex);
enterArrowIndex++;
}
/**
* Shows the next ExitArrow. Does nothing if there are no more enter arrows. Other arrows become hidden.
*/
public void showNextExitArrow() {
showArrow(exitArrows, exitArrowIndex);
exitArrowIndex++;
}
private void showArrow(List<Group> arrowList, int arrowListIndex) {
if (arrowListIndex < arrowList.size()) {
Platform.runLater(() -> {
this.getChildren().remove(exitArrow);
this.getChildren().add(enterArrow);
this.getChildren().remove(1);
this.getChildren().add(arrowList.get(arrowListIndex));
});
}
}
public void showExitArrow () {
if (!this.getChildren().contains(exitArrow)) {
Platform.runLater(() -> {
this.getChildren().remove(enterArrow);
this.getChildren().add(exitArrow);
});
}
}
public void hideAllArows () {
Platform.runLater(() -> {
this.getChildren().removeAll(enterArrow, exitArrow);
});
/**
* Hides all arrows.
*/
public void hideAllArrows() {
Platform.runLater(() -> this.getChildren().setAll(mark));
}
}