下面列出了怎么用javafx.scene.shape.Ellipse的API类实例代码及写法,或者点击链接到github查看源代码。
public EllipseSample() {
super(180,90);
// Simple red filled ellipse
Ellipse ellipse1 = new Ellipse(45,45,30,45);
ellipse1.setFill(Color.RED);
// Blue stroked ellipse
Ellipse ellipse2 = new Ellipse(135,45,30,45);
ellipse2.setStroke(Color.DODGERBLUE);
ellipse2.setFill(null);
// Create a group to show all the ellipses);
getChildren().add(new Group(ellipse1,ellipse2));
// REMOVE ME
setControls(
new SimplePropertySheet.PropDesc("Ellipse 1 Fill", ellipse1.fillProperty()),
new SimplePropertySheet.PropDesc("Ellipse 1 Width", ellipse1.radiusXProperty(), 10d, 40d),
new SimplePropertySheet.PropDesc("Ellipse 1 Height", ellipse1.radiusYProperty(), 10d, 45d),
new SimplePropertySheet.PropDesc("Ellipse 2 Stroke", ellipse2.strokeProperty()),
new SimplePropertySheet.PropDesc("Ellipse 2 Stroke Width", ellipse2.strokeWidthProperty(), 1d, 5d),
new SimplePropertySheet.PropDesc("Ellipse 2 Width", ellipse2.radiusXProperty(), 10d, 40d),
new SimplePropertySheet.PropDesc("Ellipse 2 Height", ellipse2.radiusYProperty(), 10d, 45d)
);
// END REMOVE ME
}
public EllipseSample() {
super(180,90);
// Simple red filled ellipse
Ellipse ellipse1 = new Ellipse(45,45,30,45);
ellipse1.setFill(Color.RED);
// Blue stroked ellipse
Ellipse ellipse2 = new Ellipse(135,45,30,45);
ellipse2.setStroke(Color.DODGERBLUE);
ellipse2.setFill(null);
// Create a group to show all the ellipses);
getChildren().add(new Group(ellipse1,ellipse2));
// REMOVE ME
setControls(
new SimplePropertySheet.PropDesc("Ellipse 1 Fill", ellipse1.fillProperty()),
new SimplePropertySheet.PropDesc("Ellipse 1 Width", ellipse1.radiusXProperty(), 10d, 40d),
new SimplePropertySheet.PropDesc("Ellipse 1 Height", ellipse1.radiusYProperty(), 10d, 45d),
new SimplePropertySheet.PropDesc("Ellipse 2 Stroke", ellipse2.strokeProperty()),
new SimplePropertySheet.PropDesc("Ellipse 2 Stroke Width", ellipse2.strokeWidthProperty(), 1d, 5d),
new SimplePropertySheet.PropDesc("Ellipse 2 Width", ellipse2.radiusXProperty(), 10d, 40d),
new SimplePropertySheet.PropDesc("Ellipse 2 Height", ellipse2.radiusYProperty(), 10d, 45d)
);
// END REMOVE ME
}
@Override
public void init() {
double t = 0;
for (int y = 0; y < ENEMY_ROWS; y++) {
for (int x = 0; x < ENEMIES_PER_ROW; x++) {
Entity enemy = spawnEnemy(random(0, getAppWidth() - 100), random(0, getAppHeight() / 2.0));
var a = animationBuilder()
.repeatInfinitely()
.autoReverse(true)
.delay(Duration.seconds(t))
.duration(Duration.seconds(1.6))
.translate(enemy)
.alongPath(new Ellipse(getAppWidth() / 2, getAppHeight() / 2 - 200, 200, 150))
.build();
animations.add(a);
a.start();
t += 0.3;
}
}
}
@Override
public void init() {
double t = 0;
for (int y = 0; y < ENEMY_ROWS; y++) {
for (int x = 0; x < ENEMIES_PER_ROW; x++) {
Entity enemy = spawnEnemy(random(0, getAppWidth() - 100), random(0, getAppHeight() / 2.0));
var a = animationBuilder()
.repeatInfinitely()
.autoReverse(true)
.delay(Duration.seconds(t))
.duration(Duration.seconds(1.6))
.translate(enemy)
.alongPath(new Ellipse(getAppWidth() / 2, getAppHeight() / 2 - 200, 200, 150))
.build();
animations.add(a);
a.start();
t += 0.3;
}
}
}
public void setDisplayVals(int displayWidth, int displayHeight, int feedWidth, int feedHeight) {
final double scaleX = (double) displayWidth / (double) feedWidth;
final double scaleY = (double) displayHeight / (double) feedHeight;
double scaledX, scaledY;
if (displayX.isPresent()) {
scaledX = displayX.get() * scaleX;
scaledY = displayY.get() * scaleY;
}
else {
scaledX = super.getX() * scaleX;
scaledY = super.getY() * scaleY;
}
if (logger.isTraceEnabled()) {
logger.trace("setTranslation {} {} - {} {} to {} {}", scaleX, scaleY, super.getX(), super.getY(), scaledX, scaledY);
}
marker = new Ellipse(scaledX, scaledY, marker.radiusXProperty().get(), marker.radiusYProperty().get());
marker.setFill(colorMap.get(color));
displayX = Optional.of(scaledX);
displayY = Optional.of(scaledY);
}
private void unbindShowPoints() {
showPoint.getChildren().stream().filter(node -> node instanceof Ellipse).map(node -> (Ellipse) node).forEach(ell -> {
ell.fillProperty().unbind();
ell.centerXProperty().unbind();
ell.centerYProperty().unbind();
ell.radiusXProperty().unbind();
ell.radiusYProperty().unbind();
ell.visibleProperty().unbind();
});
showPoint.getChildren().stream().filter(node -> node instanceof Line).map(node -> (Line) node).forEach(line -> {
line.startXProperty().unbind();
line.startYProperty().unbind();
line.endXProperty().unbind();
line.endYProperty().unbind();
line.strokeWidthProperty().unbind();
line.strokeProperty().unbind();
});
}
/**
* Creates the view.
* @param sh The model.
*/
ViewDot(final Dot sh, final PathElementProducer pathProducer) {
super(sh);
this.pathProducer = pathProducer;
path = new Path();
dot = new Ellipse();
getChildren().addAll(dot, path);
model.styleProperty().addListener(updateDot);
model.getPosition().xProperty().addListener(updateDot);
model.getPosition().yProperty().addListener(updateDot);
model.diametreProperty().addListener(updateDot);
model.fillingColProperty().addListener(updateDot);
model.lineColourProperty().addListener(updateStrokeFill);
rotateProperty().bind(Bindings.createDoubleBinding(() -> Math.toDegrees(model.getRotationAngle()), model.rotationAngleProperty()));
updateDot();
}
@Override
public void start(Stage primaryStage) throws IOException {
Group root = new Group();
// describes the window itself: name, size
primaryStage.setTitle(" Aufgabe 10 by John Malc ");
primaryStage.setScene(new Scene(root));
// say: center on screen, user can resize, and it will in general exists
primaryStage.centerOnScreen();
primaryStage.setResizable(true);
primaryStage.show();
// Ellipse alone
Ellipse a = new Ellipse();
a.setFill(Color.RED);
a.setCenterX(205);
a.setCenterY(150);
a.setRadiusX(80);
a.setRadiusY(30);
// shows Ellipse and it will add it to the group
root.getChildren().add(new Group(a));
}
private Shape createPieceTab(double eclipseCenterX, double eclipseCenterY, double eclipseRadiusX, double eclipseRadiusY,
double rectangleX, double rectangleY, double rectangleWidth, double rectangleHeight,
double circle1CenterX, double circle1CenterY, double circle1Radius,
double circle2CenterX, double circle2CenterY, double circle2Radius) {
Ellipse e = new Ellipse(eclipseCenterX, eclipseCenterY, eclipseRadiusX, eclipseRadiusY);
Rectangle r = new Rectangle(rectangleX, rectangleY, rectangleWidth, rectangleHeight);
Shape tab = Shape.union(e, r);
Circle c1 = new Circle(circle1CenterX, circle1CenterY, circle1Radius);
tab = Shape.subtract(tab, c1);
Circle c2 = new Circle(circle2CenterX, circle2CenterY, circle2Radius);
tab = Shape.subtract(tab, c2);
return tab;
}
public static Node createIconContent() {
Ellipse ellipse = new Ellipse(57,57, 20,40);
ellipse.setStroke(Color.web("#b9c0c5"));
ellipse.setStrokeWidth(5);
ellipse.getStrokeDashArray().addAll(15d,15d);
ellipse.setFill(null);
javafx.scene.effect.InnerShadow effect = new javafx.scene.effect.InnerShadow();
effect.setOffsetX(1);
effect.setOffsetY(1);
effect.setRadius(3);
effect.setColor(Color.rgb(0,0,0,0.6));
ellipse.setEffect(effect);
return ellipse;
}
private void configureBackground() {
ImageView imageView = new ImageView();
Image image = loadImage();
imageView.setImage(image);
Circle circle1 = new Circle();
circle1.setCenterX(140);
circle1.setCenterY(140);
circle1.setRadius(120);
circle1.setFill(Color.TRANSPARENT);
circle1.setStroke(Color.web("#0A0A0A"));
circle1.setStrokeWidth(0.3);
Circle circle2 = new Circle();
circle2.setCenterX(140);
circle2.setCenterY(140);
circle2.setRadius(118);
circle2.setFill(Color.TRANSPARENT);
circle2.setStroke(Color.web("#0A0A0A"));
circle2.setStrokeWidth(0.3);
Circle circle3 = new Circle();
circle3.setCenterX(140);
circle3.setCenterY(140);
circle3.setRadius(140);
circle3.setFill(Color.TRANSPARENT);
circle3.setStroke(Color.web("#818a89"));
circle3.setStrokeWidth(1);
Ellipse ellipse = new Ellipse(140, 95, 180, 95);
Circle ellipseClip = new Circle(140, 140, 140);
ellipse.setFill(Color.web("#535450"));
ellipse.setStrokeWidth(0);
GaussianBlur ellipseEffect = new GaussianBlur();
ellipseEffect.setRadius(10);
ellipse.setEffect(ellipseEffect);
ellipse.setOpacity(0.1);
ellipse.setClip(ellipseClip);
background.getChildren().addAll(imageView, circle1, circle2, circle3, ellipse);
}
public static Node createIconContent() {
Ellipse ellipse = new Ellipse(57,57, 20,40);
ellipse.setStroke(Color.web("#b9c0c5"));
ellipse.setStrokeWidth(5);
ellipse.getStrokeDashArray().addAll(15d,15d);
ellipse.setFill(null);
javafx.scene.effect.InnerShadow effect = new javafx.scene.effect.InnerShadow();
effect.setOffsetX(1);
effect.setOffsetY(1);
effect.setRadius(3);
effect.setColor(Color.rgb(0,0,0,0.6));
ellipse.setEffect(effect);
return ellipse;
}
private void configureBackground() {
ImageView imageView = new ImageView();
Image image = loadImage();
imageView.setImage(image);
Circle circle1 = new Circle();
circle1.setCenterX(140);
circle1.setCenterY(140);
circle1.setRadius(120);
circle1.setFill(Color.TRANSPARENT);
circle1.setStroke(Color.web("#0A0A0A"));
circle1.setStrokeWidth(0.3);
Circle circle2 = new Circle();
circle2.setCenterX(140);
circle2.setCenterY(140);
circle2.setRadius(118);
circle2.setFill(Color.TRANSPARENT);
circle2.setStroke(Color.web("#0A0A0A"));
circle2.setStrokeWidth(0.3);
Circle circle3 = new Circle();
circle3.setCenterX(140);
circle3.setCenterY(140);
circle3.setRadius(140);
circle3.setFill(Color.TRANSPARENT);
circle3.setStroke(Color.web("#818a89"));
circle3.setStrokeWidth(1);
Ellipse ellipse = new Ellipse(140, 95, 180, 95);
Circle ellipseClip = new Circle(140, 140, 140);
ellipse.setFill(Color.web("#535450"));
ellipse.setStrokeWidth(0);
GaussianBlur ellipseEffect = new GaussianBlur();
ellipseEffect.setRadius(10);
ellipse.setEffect(ellipseEffect);
ellipse.setOpacity(0.1);
ellipse.setClip(ellipseClip);
background.getChildren().addAll(imageView, circle1, circle2, circle3, ellipse);
}
private void configureBackground() {
ImageView imageView = new ImageView();
Image image = loadImage();
imageView.setImage(image);
Circle circle1 = new Circle();
circle1.setCenterX(140);
circle1.setCenterY(140);
circle1.setRadius(120);
circle1.setFill(Color.TRANSPARENT);
circle1.setStroke(Color.web("#0A0A0A"));
circle1.setStrokeWidth(0.3);
Circle circle2 = new Circle();
circle2.setCenterX(140);
circle2.setCenterY(140);
circle2.setRadius(118);
circle2.setFill(Color.TRANSPARENT);
circle2.setStroke(Color.web("#0A0A0A"));
circle2.setStrokeWidth(0.3);
Circle circle3 = new Circle();
circle3.setCenterX(140);
circle3.setCenterY(140);
circle3.setRadius(140);
circle3.setFill(Color.TRANSPARENT);
circle3.setStroke(Color.web("#818a89"));
circle3.setStrokeWidth(1);
Ellipse ellipse = new Ellipse(140, 95, 180, 95);
Circle ellipseClip = new Circle(140, 140, 140);
ellipse.setFill(Color.web("#535450"));
ellipse.setStrokeWidth(0);
GaussianBlur ellipseEffect = new GaussianBlur();
ellipseEffect.setRadius(10);
ellipse.setEffect(ellipseEffect);
ellipse.setOpacity(0.1);
ellipse.setClip(ellipseClip);
background.getChildren().addAll(imageView, circle1, circle2, circle3, ellipse);
}
@Override
public int[] getBorderRadii()
{
if (led instanceof Ellipse)
return new int[]
{
model_widget.propWidth().getValue()/2,
model_widget.propHeight().getValue()/2,
};
return super.getBorderRadii();
}
@Override
public Ellipse createJFXNode() throws Exception
{
final Ellipse ellipse = new Ellipse();
updateColors();
return ellipse;
}
@Override
public ButtonBase createJFXNode() throws Exception
{
led = new Ellipse();
led.getStyleClass().add("led");
button = new Button("BoolButton", led);
button.getStyleClass().add("action_button");
button.setMnemonicParsing(false);
// Model has width/height, but JFX widget has min, pref, max size.
// updateChanges() will set the 'pref' size, so make min use that as well.
button.setMinSize(ButtonBase.USE_PREF_SIZE, ButtonBase.USE_PREF_SIZE);
// Fix initial layout
toolkit.execute(() -> Platform.runLater(button::requestLayout));
if (! toolkit.isEditMode())
{
if (model_widget.propMode().getValue() == Mode.TOGGLE)
button.setOnAction(event -> handlePress(true));
else
{
final boolean inverted = model_widget.propMode().getValue() == Mode.PUSH_INVERTED;
button.setOnMousePressed(event -> handlePress(! inverted));
button.setOnMouseReleased(event -> handlePress(inverted));
}
}
return button;
}
/**
* Returns an {@link IGeometry} that describes the geometric outline of the
* given {@link Shape}, i.e. excluding the stroke.
* <p>
* The conversion is supported for the following {@link Shape}s:
* <ul>
* <li>{@link Arc}
* <li>{@link Circle}
* <li>{@link CubicCurve}
* <li>{@link Ellipse}
* <li>{@link Line}
* <li>{@link Path}
* <li>{@link Polygon}
* <li>{@link Polyline}
* <li>{@link QuadCurve}
* <li>{@link Rectangle}
* </ul>
* The following {@link Shape}s cannot be converted, yet:
* <ul>
* <li>{@link Text}
* <li>{@link SVGPath}
* </ul>
*
* @param visual
* The {@link Shape} for which an {@link IGeometry} is
* determined.
* @return The newly created {@link IGeometry} that best describes the
* geometric outline of the given {@link Shape}.
* @throws IllegalStateException
* if the given {@link Shape} is not supported.
*/
public static IGeometry toGeometry(Shape visual) {
if (visual instanceof Arc) {
return toArc((Arc) visual);
} else if (visual instanceof Circle) {
return toEllipse((Circle) visual);
} else if (visual instanceof CubicCurve) {
return toCubicCurve((CubicCurve) visual);
} else if (visual instanceof Ellipse) {
return toEllipse((Ellipse) visual);
} else if (visual instanceof Line) {
return toLine((Line) visual);
} else if (visual instanceof Path) {
return toPath((Path) visual);
} else if (visual instanceof Polygon) {
return toPolygon((Polygon) visual);
} else if (visual instanceof Polyline) {
return toPolyline((Polyline) visual);
} else if (visual instanceof QuadCurve) {
QuadCurve quad = (QuadCurve) visual;
return toQuadraticCurve(quad);
} else if (visual instanceof Rectangle) {
Rectangle rect = (Rectangle) visual;
if (rect.getArcWidth() == 0 && rect.getArcHeight() == 0) {
// corners are not rounded => normal rectangle is sufficient
return toRectangle(rect);
}
return toRoundedRectangle((Rectangle) visual);
} else {
// Text and SVGPath shapes are currently not supported
throw new IllegalStateException(
"Cannot compute geometric outline for Shape of type <"
+ visual.getClass() + ">.");
}
}
public ArenaShot(DisplayShot shot)
{
super(shot, shot.getMarker());
if (shot instanceof ArenaShot)
{
this.arenaX = ((ArenaShot) shot).arenaX;
this.arenaY = ((ArenaShot) shot).arenaY;
}
this.arenaMarker = new Ellipse(getX(), getY(), shot.getMarker().getRadiusX(), shot.getMarker().getRadiusX());
this.arenaMarker.setFill(colorMap.get(color));
}
public void setArenaCoords(double x, double y) {
arenaX = Optional.of(x);
arenaY = Optional.of(y);
this.arenaMarker = new Ellipse(getX(), getY(), getMarker().getRadiusX(), getMarker().getRadiusX());
this.arenaMarker.setFill(colorMap.get(color));
}
public DisplayShot(Shot shot, int markerRadius) {
super(shot);
if (shot instanceof DisplayShot)
{
this.displayX = ((DisplayShot) shot).displayX;
this.displayY = ((DisplayShot) shot).displayY;
}
marker = new Ellipse(getX(), getY(), markerRadius, markerRadius);
marker.setFill(colorMap.get(color));
}
public DisplayShot(Shot shot, Ellipse marker) {
super(shot);
if (shot instanceof DisplayShot)
{
this.displayX = ((DisplayShot) shot).displayX;
this.displayY = ((DisplayShot) shot).displayY;
}
this.marker = marker;
}
public DefaultIcon(ObservableEntity oe) {
super(oe);
shape = new Ellipse(60, 60);
shape.centerXProperty().bind(getMapX());
shape.centerYProperty().bind(getMapY());
shape.fillProperty().bind(getTeamColor());
}
public HeroIcon(ObservableEntity oe) {
super(oe);
shape = new Ellipse(140, 140);
shape.fillProperty().bind(getPlayerColor());
shape.translateXProperty().bind(getMapX());
shape.translateYProperty().bind(getMapY());
}
public Piece(PieceType type, int x, int y) {
this.type = type;
move(x, y);
Ellipse bg = new Ellipse(TILE_SIZE * 0.3125, TILE_SIZE * 0.26);
bg.setFill(Color.BLACK);
bg.setStroke(Color.BLACK);
bg.setStrokeWidth(TILE_SIZE * 0.03);
bg.setTranslateX((TILE_SIZE - TILE_SIZE * 0.3125 * 2) / 2);
bg.setTranslateY((TILE_SIZE - TILE_SIZE * 0.26 * 2) / 2 + TILE_SIZE * 0.07);
Ellipse ellipse = new Ellipse(TILE_SIZE * 0.3125, TILE_SIZE * 0.26);
ellipse.setFill(type == PieceType.RED
? Color.valueOf("#c40003") : Color.valueOf("#fff9f4"));
ellipse.setStroke(Color.BLACK);
ellipse.setStrokeWidth(TILE_SIZE * 0.03);
ellipse.setTranslateX((TILE_SIZE - TILE_SIZE * 0.3125 * 2) / 2);
ellipse.setTranslateY((TILE_SIZE - TILE_SIZE * 0.26 * 2) / 2);
getChildren().addAll(bg, ellipse);
setOnMousePressed(e -> {
mouseX = e.getSceneX();
mouseY = e.getSceneY();
});
setOnMouseDragged(e -> {
relocate(e.getSceneX() - mouseX + oldX, e.getSceneY() - mouseY + oldY);
});
}
/** Return an Ellipse of specified properties */
private Ellipse getEllipse(Circle c) {
Ellipse e = new Ellipse();
e.setCenterY(c.getRadius() - c.getRadius() / 3);
e.setRadiusX(c.getRadius() / 4);
e.setRadiusY(c.getRadius() / 3 - 20);
e.setStroke(Color.BLACK);
e.setFill(Color.WHITE);
return e;
}
public static String shapeToSvgString(final Shape SHAPE) {
final StringBuilder fxPath = new StringBuilder();
if (Line.class.equals(SHAPE.getClass())) {
fxPath.append(convertLine((Line) SHAPE));
} else if (Arc.class.equals(SHAPE.getClass())) {
fxPath.append(convertArc((Arc) SHAPE));
} else if (QuadCurve.class.equals(SHAPE.getClass())) {
fxPath.append(convertQuadCurve((QuadCurve) SHAPE));
} else if (CubicCurve.class.equals(SHAPE.getClass())) {
fxPath.append(convertCubicCurve((CubicCurve) SHAPE));
} else if (Rectangle.class.equals(SHAPE.getClass())) {
fxPath.append(convertRectangle((Rectangle) SHAPE));
} else if (Circle.class.equals(SHAPE.getClass())) {
fxPath.append(convertCircle((Circle) SHAPE));
} else if (Ellipse.class.equals(SHAPE.getClass())) {
fxPath.append(convertEllipse((Ellipse) SHAPE));
} else if (Text.class.equals(SHAPE.getClass())) {
Path path = (Path)(Shape.subtract(SHAPE, new Rectangle(0, 0)));
fxPath.append(convertPath(path));
} else if (Path.class.equals(SHAPE.getClass())) {
fxPath.append(convertPath((Path) SHAPE));
} else if (Polygon.class.equals(SHAPE.getClass())) {
fxPath.append(convertPolygon((Polygon) SHAPE));
} else if (Polyline.class.equals(SHAPE.getClass())) {
fxPath.append(convertPolyline((Polyline) SHAPE));
} else if (SVGPath.class.equals(SHAPE.getClass())) {
fxPath.append(((SVGPath) SHAPE).getContent());
}
return fxPath.toString();
}
public static String convertEllipse(final Ellipse ELLIPSE) {
final StringBuilder fxPath = new StringBuilder();
final double CENTER_X = ELLIPSE.getCenterX() == 0 ? ELLIPSE.getRadiusX() : ELLIPSE.getCenterX();
final double CENTER_Y = ELLIPSE.getCenterY() == 0 ? ELLIPSE.getRadiusY() : ELLIPSE.getCenterY();
final double RADIUS_X = ELLIPSE.getRadiusX();
final double RADIUS_Y = ELLIPSE.getRadiusY();
final double CONTROL_DISTANCE_X = RADIUS_X * KAPPA;
final double CONTROL_DISTANCE_Y = RADIUS_Y * KAPPA;
// Move to first point
fxPath.append("M ").append(CENTER_X).append(" ").append(CENTER_Y - RADIUS_Y).append(" ");
// 1. quadrant
fxPath.append("C ").append(CENTER_X + CONTROL_DISTANCE_X).append(" ").append(CENTER_Y - RADIUS_Y).append(" ")
.append(CENTER_X + RADIUS_X).append(" ").append(CENTER_Y - CONTROL_DISTANCE_Y).append(" ")
.append(CENTER_X + RADIUS_X).append(" ").append(CENTER_Y).append(" ");
// 2. quadrant
fxPath.append("C ").append(CENTER_X + RADIUS_X).append(" ").append(CENTER_Y + CONTROL_DISTANCE_Y).append(" ")
.append(CENTER_X + CONTROL_DISTANCE_X).append(" ").append(CENTER_Y + RADIUS_Y).append(" ")
.append(CENTER_X).append(" ").append(CENTER_Y + RADIUS_Y).append(" ");
// 3. quadrant
fxPath.append("C ").append(CENTER_X - CONTROL_DISTANCE_X).append(" ").append(CENTER_Y + RADIUS_Y).append(" ")
.append(CENTER_X - RADIUS_X).append(" ").append(CENTER_Y + CONTROL_DISTANCE_Y).append(" ")
.append(CENTER_X - RADIUS_X).append(" ").append(CENTER_Y).append(" ");
// 4. quadrant
fxPath.append("C ").append(CENTER_X - RADIUS_X).append(" ").append(CENTER_Y - CONTROL_DISTANCE_Y).append(" ")
.append(CENTER_X - CONTROL_DISTANCE_X).append(" ").append(CENTER_Y - RADIUS_Y).append(" ")
.append(CENTER_X).append(" ").append(CENTER_Y - RADIUS_Y).append(" ");
// Close path
fxPath.append("Z");
return fxPath.toString();
}
/**
* Creates the view.
* @param model The arrow. Cannot be null.
* @throws NullPointerException if the given arrow is null.
*/
ViewArrow(final Arrow model) {
super();
setId(ID);
arrow = Objects.requireNonNull(model);
path = new Path();
ellipse = new Ellipse();
arc = new Arc();
getChildren().add(path);
getChildren().add(ellipse);
getChildren().add(arc);
enableShape(false, false, false);
}
/**
* Sub routine that creates and binds show points.
*/
private final void bindShowPoints() {
showPoint.getChildren().addAll(Stream.concat(Stream.concat(model.getPoints().stream(), model.getFirstCtrlPts().stream()),
model.getSecondCtrlPts().stream()).map(pt -> {
final Ellipse dot = new Ellipse();
dot.fillProperty().bind(Bindings.createObjectBinding(() -> model.getLineColour().toJFX(), model.lineColourProperty()));
dot.centerXProperty().bind(pt.xProperty());
dot.centerYProperty().bind(pt.yProperty());
dot.radiusXProperty().bind(Bindings.createDoubleBinding(() -> (model.getArrowAt(0).getDotSizeDim() +
model.getArrowAt(0).getDotSizeNum() * model.getFullThickness()) / 2d, model.thicknessProperty(), model.dbleBordProperty(),
model.dbleBordSepProperty(), model.getArrowAt(0).dotSizeDimProperty(), model.getArrowAt(0).dotSizeNumProperty()));
dot.radiusYProperty().bind(dot.radiusXProperty());
return dot;
}).collect(Collectors.toList()));
showPoint.getChildren().addAll(IntStream.range(0, model.getFirstCtrlPts().size()).
mapToObj(i -> createLine(model.getFirstCtrlPtAt(i), model.getSecondCtrlPtAt(i))).collect(Collectors.toList()));
showPoint.getChildren().addAll(IntStream.range(1, model.getFirstCtrlPts().size() - 1).
mapToObj(i -> createLine(model.getSecondCtrlPtAt(i), model.getFirstCtrlPtAt(i + 1))).collect(Collectors.toList()));
showPoint.getChildren().addAll(createLine(model.getFirstCtrlPtAt(0), model.getFirstCtrlPtAt(1)));
// Hiding points on arrows
showPoint.getChildren().stream().filter(node -> node instanceof Ellipse &&
MathUtils.INST.equalsDouble(((Ellipse) node).getCenterX(), model.getPtAt(0).getX(), 0.00001) &&
MathUtils.INST.equalsDouble(((Ellipse) node).getCenterY(), model.getPtAt(0).getY(), 0.00001)).findAny().
ifPresent(ell -> ell.visibleProperty().bind(model.getArrowAt(0).styleProperty().isEqualTo(ArrowStyle.NONE)));
showPoint.getChildren().stream().filter(node -> node instanceof Ellipse &&
MathUtils.INST.equalsDouble(((Ellipse) node).getCenterX(), model.getPtAt(-1).getX(), 0.00001) &&
MathUtils.INST.equalsDouble(((Ellipse) node).getCenterY(), model.getPtAt(-1).getY(), 0.00001)).findAny().
ifPresent(ell -> ell.visibleProperty().bind(model.getArrowAt(-1).styleProperty().isEqualTo(ArrowStyle.NONE)));
}