下面列出了怎么用javafx.scene.shape.Line的API类实例代码及写法,或者点击链接到github查看源代码。
private Group createTicks(double cx, double cy, int numberOfTicks, double overallAngle, double tickLength, double indent, double startingAngle, String styleClass) {
Group group = new Group();
double degreesBetweenTicks = overallAngle == 360 ?
overallAngle / numberOfTicks :
overallAngle / (numberOfTicks - 1);
double outerRadius = Math.min(cx, cy) - indent;
double innerRadius = Math.min(cx, cy) - indent - tickLength;
for (int i = 0; i < numberOfTicks; i++) {
double angle = 180 + startingAngle + i * degreesBetweenTicks;
Point2D startPoint = pointOnCircle(cx, cy, outerRadius, angle);
Point2D endPoint = pointOnCircle(cx, cy, innerRadius, angle);
Line tick = new Line(startPoint.getX(), startPoint.getY(), endPoint.getX(), endPoint.getY());
tick.getStyleClass().add(styleClass);
group.getChildren().add(tick);
}
return group;
}
public List<Line> directLines() {
List<Line> dlines = new ArrayList<>();
int lastx, lasty = -1, thisx, thisy;
for (List<DoublePoint> lineData : lines) {
lastx = -1;
for (DoublePoint linePoint : lineData) {
thisx = (int) Math.round(linePoint.getX());
thisy = (int) Math.round(linePoint.getY());
if (lastx >= 0) {
Line line = new Line(lastx, lasty, thisx, thisy);
dlines.add(line);
}
lastx = thisx;
lasty = thisy;
}
}
return dlines;
}
@Override
public boolean include(double x, double y) {
if (!isValid()) {
return false;
}
int lastx, lasty = -1, thisx, thisy;
Point2D point = new Point2D(x, y);
for (List<DoublePoint> lineData : lines) {
lastx = -1;
for (DoublePoint linePoint : lineData) {
thisx = (int) Math.round(linePoint.getX());
thisy = (int) Math.round(linePoint.getY());
if (lastx >= 0) {
Line line = new Line(lastx, lasty, thisx, thisy);
if (line.contains(point)) {
return true;
}
}
lastx = thisx;
lasty = thisy;
}
}
return false;
}
public boolean include(Point2D point) {
if (!isValid()) {
return false;
}
int lastx, lasty = -1, thisx, thisy;
for (List<DoublePoint> lineData : lines) {
lastx = -1;
for (DoublePoint linePoint : lineData) {
thisx = (int) Math.round(linePoint.getX());
thisy = (int) Math.round(linePoint.getY());
if (lastx >= 0) {
Line line = new Line(lastx, lasty, thisx, thisy);
if (line.contains(point)) {
return true;
}
}
lastx = thisx;
lasty = thisy;
}
}
return false;
}
public LineSample() {
super(180,90);
// Create line shape
Line line = new Line(5, 85, 175 , 5);
line.setFill(null);
line.setStroke(Color.RED);
line.setStrokeWidth(2);
// show the line shape;
getChildren().add(line);
// REMOVE ME
setControls(
new SimplePropertySheet.PropDesc("Line Stroke", line.strokeProperty()),
new SimplePropertySheet.PropDesc("Line Start X", line.startXProperty(), 0d, 170d),
new SimplePropertySheet.PropDesc("Line Start Y", line.startYProperty(), 0d, 90d),
new SimplePropertySheet.PropDesc("Line End X", line.endXProperty(), 10d, 180d),
new SimplePropertySheet.PropDesc("Line End Y", line.endYProperty(), 0d, 90d)
);
// END REMOVE ME
}
public LineSample() {
super(180,90);
// Create line shape
Line line = new Line(5, 85, 175 , 5);
line.setFill(null);
line.setStroke(Color.RED);
line.setStrokeWidth(2);
// show the line shape;
getChildren().add(line);
// REMOVE ME
setControls(
new SimplePropertySheet.PropDesc("Line Stroke", line.strokeProperty()),
new SimplePropertySheet.PropDesc("Line Start X", line.startXProperty(), 0d, 170d),
new SimplePropertySheet.PropDesc("Line Start Y", line.startYProperty(), 0d, 90d),
new SimplePropertySheet.PropDesc("Line End X", line.endXProperty(), 10d, 180d),
new SimplePropertySheet.PropDesc("Line End Y", line.endYProperty(), 0d, 90d)
);
// END REMOVE ME
}
@Override
protected void initUI() {
Line line1 = new Line(getAppWidth() / 3, 0, getAppWidth() / 3, 0);
Line line2 = new Line(getAppWidth() / 3 * 2, 0, getAppWidth() / 3 * 2, 0);
Line line3 = new Line(0, getAppHeight() / 3, 0, getAppHeight() / 3);
Line line4 = new Line(0, getAppHeight() / 3 * 2, 0, getAppHeight() / 3 * 2);
getGameScene().addUINodes(line1, line2, line3, line4);
// animation
KeyFrame frame1 = new KeyFrame(Duration.seconds(0.5),
new KeyValue(line1.endYProperty(), getAppHeight()));
KeyFrame frame2 = new KeyFrame(Duration.seconds(1),
new KeyValue(line2.endYProperty(), getAppHeight()));
KeyFrame frame3 = new KeyFrame(Duration.seconds(0.5),
new KeyValue(line3.endXProperty(), getAppWidth()));
KeyFrame frame4 = new KeyFrame(Duration.seconds(1),
new KeyValue(line4.endXProperty(), getAppWidth()));
Timeline timeline = new Timeline(frame1, frame2, frame3, frame4);
timeline.play();
}
/** @param toolkit
* @param group Group where snap lines are added
*/
public TrackerSnapConstraint(final JFXRepresentation toolkit, final Group group)
{
this.toolkit = toolkit;
horiz_guide = new Line();
horiz_guide.getStyleClass().add("guide_line");
horiz_guide.setVisible(false);
horiz_guide.setManaged(false);
vert_guide = new Line();
vert_guide.getStyleClass().add("guide_line");
vert_guide.setVisible(false);
vert_guide.setManaged(false);
group.getChildren().addAll(horiz_guide, vert_guide);
}
private void playWinAnimation(TileCombo combo) {
Line line = new Line();
line.setStartX(combo.getTile1().getCenter().getX());
line.setStartY(combo.getTile1().getCenter().getY());
line.setEndX(combo.getTile1().getCenter().getX());
line.setEndY(combo.getTile1().getCenter().getY());
line.setStroke(Color.YELLOW);
line.setStrokeWidth(3);
getGameScene().addUINode(line);
Timeline timeline = new Timeline();
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(1),
new KeyValue(line.endXProperty(), combo.getTile3().getCenter().getX()),
new KeyValue(line.endYProperty(), combo.getTile3().getCenter().getY())));
timeline.setOnFinished(e -> gameOver(combo.getWinSymbol()));
timeline.play();
}
private void setMzAxis() {
axes.getMzAxisLabels().getChildren().clear();
axes.getMzAxisTicks().getChildren().clear();
double mzDelta = (mzRange.upperEndpoint() - mzRange.lowerEndpoint()) / 7;
double mzScaleValue = mzRange.lowerEndpoint();
Text mzLabel = new Text("m/z");
mzLabel.setRotationAxis(Rotate.X_AXIS);
mzLabel.setRotate(-45);
mzLabel.setTranslateX(SIZE / 2);
mzLabel.setTranslateZ(-5);
mzLabel.setTranslateY(8);
axes.getMzAxisLabels().getChildren().add(mzLabel);
for (int y = 0; y <= SIZE; y += SIZE / 7) {
Line tickLineZ = new Line(0, 0, 0, 9);
tickLineZ.setRotationAxis(Rotate.X_AXIS);
tickLineZ.setRotate(-90);
tickLineZ.setTranslateY(-4);
tickLineZ.setTranslateX(y - 2);
float roundOff = (float) (Math.round(mzScaleValue * 100.0) / 100.0);
Text text = new Text("" + roundOff);
text.setRotationAxis(Rotate.X_AXIS);
text.setRotate(-45);
text.setTranslateY(8);
text.setTranslateX(y - 10);
text.setTranslateZ(20);
mzScaleValue += mzDelta;
axes.getMzAxisTicks().getChildren().add(tickLineZ);
axes.getMzAxisLabels().getChildren().add(text);
}
axes.getMzAxisLabels().setRotate(270);
axes.getMzAxisLabels().setTranslateX(SIZE / 2 + SIZE / 30);
axes.getMzAxisTicks().setTranslateX(SIZE / 2 + 10);
axes.getMzAxisTicks().setTranslateY(-1);
axes.getMzAxis().setTranslateX(SIZE);
}
private void setRtAxis() {
axes.getRtAxis().getChildren().clear();
double rtDelta = (rtRange.upperEndpoint() - rtRange.lowerEndpoint()) / 7;
double rtScaleValue = rtRange.upperEndpoint();
Text rtLabel = new Text("Retention Time");
rtLabel.setRotationAxis(Rotate.X_AXIS);
rtLabel.setRotate(-45);
rtLabel.setTranslateX(SIZE * 3 / 8);
rtLabel.setTranslateZ(-25);
rtLabel.setTranslateY(13);
axes.getRtAxis().getChildren().add(rtLabel);
for (int y = 0; y <= SIZE; y += SIZE / 7) {
Line tickLineX = new Line(0, 0, 0, 9);
tickLineX.setRotationAxis(Rotate.X_AXIS);
tickLineX.setRotate(-90);
tickLineX.setTranslateY(-5);
tickLineX.setTranslateX(y);
tickLineX.setTranslateZ(-3.5);
float roundOff = (float) (Math.round(rtScaleValue * 10.0) / 10.0);
Text text = new Text("" + roundOff);
text.setRotationAxis(Rotate.X_AXIS);
text.setRotate(-45);
text.setTranslateY(9);
text.setTranslateX(y - 5);
text.setTranslateZ(-15);
rtScaleValue -= rtDelta;
axes.getRtAxis().getChildren().addAll(text, tickLineX);
}
Line lineX = new Line(0, 0, SIZE, 0);
axes.getRtAxis().getChildren().add(lineX);
axes.getRtRotate().setAngle(180);
axes.getRtTranslate().setZ(-SIZE);
axes.getRtTranslate().setX(-SIZE);
}
private static Image createDefaultHatch(final Paint color, final double strokeWidth) {
WeakHashMap<Double, Image> checkCache = FillPatternStyleHelper.defaultHatchCacheWithStrokeWidth.get(color);
if (checkCache != null) {
final Image val = checkCache.get(Double.valueOf(strokeWidth));
if (val != null) {
// found existing Image with given parameter
return val;
}
}
// need to recompute hatch pattern image
final Pane pane = new Pane();
pane.setPrefSize(10, 10);
final Line fw = new Line(-5, -5, 25, 25);
final Line bw = new Line(-5, 25, 25, -5);
fw.setSmooth(false);
bw.setSmooth(false);
fw.setStroke(color);
bw.setStroke(color);
fw.setStrokeWidth(strokeWidth);
bw.setStrokeWidth(strokeWidth);
pane.getChildren().addAll(fw, bw);
pane.setStyle("-fx-background-color: rgba(0, 0, 0, 0.0)");
final Scene scene = new Scene(pane);
scene.setFill(Color.TRANSPARENT);
final Image retVal = pane.snapshot(null, null);
// add retVal to cache
if (checkCache == null) {
final WeakHashMap<Double, Image> temp = new WeakHashMap<>();
temp.put(Double.valueOf(strokeWidth), retVal);
FillPatternStyleHelper.defaultHatchCacheWithStrokeWidth.put(color, temp);
// checkCache = new WeakHashMap<>();
} else {
checkCache.put(Double.valueOf(strokeWidth), retVal);
}
return retVal;
}
private static ImagePattern createDefaultHatch(final Paint color, final double strokeWidth,
final boolean isHorizontal, final double[] pattern) {
final Integer hash = computeHash(color, strokeWidth, isHorizontal, pattern);
return DashPatternStyle.dashHashMap.computeIfAbsent(hash, t -> {
// need to recompute hatch pattern image
final double dashPatternLength = getPatternLength(pattern);
final double width = isHorizontal ? dashPatternLength : strokeWidth;
final double height = isHorizontal ? strokeWidth : dashPatternLength;
final double middle = (int) (strokeWidth / 2.0);
final Pane pane = new Pane();
pane.setPrefSize(width, height);
final Line fw = isHorizontal ? new Line(0, middle, dashPatternLength, middle)
: new Line(middle, 0, middle, dashPatternLength);
fw.setSmooth(false);
fw.setStroke(color);
if (pattern == null) {
fw.getStrokeDashArray().setAll(dashPatternLength);
} else {
fw.getStrokeDashArray().setAll(DoubleStream.of(pattern).boxed().collect(Collectors.toList()));
}
fw.setStrokeWidth(strokeWidth);
pane.getChildren().addAll(fw);
pane.setStyle("-fx-background-color: rgba(0, 0, 0, 0.0)");
final Scene scene = new Scene(pane);
scene.setFill(Color.TRANSPARENT);
final Image hatch = pane.snapshot(null, null);
return new ImagePattern(hatch, width, 0, width, height, false);
});
}
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
// Create a pane
Pane pane = new Pane();
// Create two circles
Circle c1 = new Circle(20 + Math.random() * 201,
20 + Math.random() * 201, 15);
c1.setFill(Color.WHITE);
c1.setStroke(Color.BLACK);
Circle c2 = new Circle(20 + Math.random() * 201,
20 + Math.random() * 201, 15);
c2.setFill(Color.WHITE);
c2.setStroke(Color.BLACK);
// Create a line
Line line = new Line(c1.getCenterX(), c1.getCenterY(),
c2.getCenterX(), c2.getCenterY());
// Add nodes to pane
pane.getChildren().addAll(line, c1, c2, new Text(c1.getCenterX(),
c1.getCenterY(), "1"), new Text(c2.getCenterX(), c2.getCenterY(), "2"));
// Create a scene and place it in the stage
Scene scene = new Scene(pane);
primaryStage.setTitle("Exercise_14_22"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
/**
* Creates a graphic to display a 'forbidden' effect in the connector.
*
* @return the new graphic
*/
private Group createForbiddenGraphic() {
final Group group = new Group();
final Line firstLine = new Line(1, 1, SIZE - 1, SIZE - 1);
final Line secondLine = new Line(1, SIZE - 1, SIZE - 1, 1);
firstLine.getStyleClass().add(STYLE_CLASS_FORBIDDEN_GRAPHIC);
secondLine.getStyleClass().add(STYLE_CLASS_FORBIDDEN_GRAPHIC);
group.getChildren().addAll(firstLine, secondLine);
group.setVisible(false);
return group;
}
protected static void applyGraphicsStyleFromLineStyle(final GraphicsContext gc, final Line style) {
gc.setStroke(style.getStroke());
gc.setLineWidth(style.getStrokeWidth());
if (style.getStrokeDashArray() == null || style.getStrokeDashArray().isEmpty()) {
gc.setLineDashes(DEFAULT_GRID_DASH_PATTERM);
} else {
final double[] dashes = style.getStrokeDashArray().stream().mapToDouble(d -> d).toArray();
gc.setLineDashes(dashes);
}
}
private void bindMouseEvents(final LineChart<?, ?> baseChart, final Double strokeWidth) {
getChildren().add(detailsWindow);
detailsWindow.prefHeightProperty().bind(heightProperty());
detailsWindow.prefWidthProperty().bind(widthProperty());
detailsWindow.setMouseTransparent(true);
setOnMouseMoved(null);
setMouseTransparent(false);
final Axis<?> xAxis = baseChart.getXAxis();
final Axis<?> yAxis = baseChart.getYAxis();
final Line xLine = new Line();
final Line yLine = new Line();
yLine.setFill(Color.GRAY);
xLine.setFill(Color.GRAY);
yLine.setStrokeWidth(strokeWidth / 2);
xLine.setStrokeWidth(strokeWidth / 2);
xLine.setVisible(false);
yLine.setVisible(false);
final Node chartBackground = baseChart.lookup(".chart-plot-background");
for (final Node n : chartBackground.getParent().getChildrenUnmodifiable()) {
if ((n != chartBackground) && (n != xAxis) && (n != yAxis)) {
n.setMouseTransparent(true);
}
}
}
@Override
public void initializeParts() {
value = new Text(0, ARTBOARD_HEIGHT * 0.5, String.format(FORMAT, getSkinnable().getValue()));
value.getStyleClass().add("value");
value.setTextOrigin(VPos.CENTER);
value.setTextAlignment(TextAlignment.CENTER);
value.setMouseTransparent(true);
value.setWrappingWidth(ARTBOARD_HEIGHT);
value.setBoundsType(TextBoundsType.VISUAL);
thumb = new Circle(ARTBOARD_HEIGHT * 0.5, ARTBOARD_HEIGHT * 0.5, ARTBOARD_HEIGHT * 0.5);
thumb.getStyleClass().add("thumb");
thumbGroup = new Group(thumb, value);
valueBar = new Line();
valueBar.getStyleClass().add("valueBar");
valueBar.setStrokeLineCap(StrokeLineCap.ROUND);
applyCss(valueBar);
strokeWidthFromCSS = valueBar.getStrokeWidth();
scale = new Line();
scale.getStyleClass().add("scale");
scale.setStrokeLineCap(StrokeLineCap.ROUND);
// always needed
drawingPane = new Pane();
}
private void initializeParts() {
double cx = ARTBOARD_WIDTH * 0.5;
separator = new Line(25, 15, 225, 15);
separator.getStyleClass().add("separator");
separator.setStrokeLineCap(StrokeLineCap.ROUND);
titleLabel = createCenteredText(cx, 19, "title");
titleLabel.setTextOrigin(VPos.TOP);
valueLabel = createCenteredText(cx, 150, "value");
unitLabel = createCenteredText(cx, 188, "unit");
unitLabel.setTextOrigin(VPos.TOP);
barBackground = new Circle(CIRCLE_CENTER_X, CIRCLE_CENTER_Y, RADIUS);
barBackground.getStyleClass().add("barBackground");
bar = new Arc(CIRCLE_CENTER_X, CIRCLE_CENTER_Y, RADIUS, RADIUS, START_ANGLE, 0);
bar.getStyleClass().add("bar");
bar.setType(ArcType.OPEN);
thumb = new Circle(7);
thumb.getStyleClass().add("thumb");
// always needed
drawingPane = new Pane();
drawingPane.setMaxSize(ARTBOARD_WIDTH, ARTBOARD_HEIGHT);
drawingPane.setMinSize(ARTBOARD_WIDTH, ARTBOARD_HEIGHT);
drawingPane.setPrefSize(ARTBOARD_WIDTH, ARTBOARD_HEIGHT);
}
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 HangmanImage() {
Circle head = new Circle(20);
head.setTranslateX(SPINE_START_X);
Line spine = new Line();
spine.setStartX(SPINE_START_X);
spine.setStartY(SPINE_START_Y);
spine.setEndX(SPINE_END_X);
spine.setEndY(SPINE_END_Y);
Line leftArm = new Line();
leftArm.setStartX(SPINE_START_X);
leftArm.setStartY(SPINE_START_Y);
leftArm.setEndX(SPINE_START_X + 40);
leftArm.setEndY(SPINE_START_Y + 10);
Line rightArm = new Line();
rightArm.setStartX(SPINE_START_X);
rightArm.setStartY(SPINE_START_Y);
rightArm.setEndX(SPINE_START_X - 40);
rightArm.setEndY(SPINE_START_Y + 10);
Line leftLeg = new Line();
leftLeg.setStartX(SPINE_END_X);
leftLeg.setStartY(SPINE_END_Y);
leftLeg.setEndX(SPINE_END_X + 25);
leftLeg.setEndY(SPINE_END_Y + 50);
Line rightLeg = new Line();
rightLeg.setStartX(SPINE_END_X);
rightLeg.setStartY(SPINE_END_Y);
rightLeg.setEndX(SPINE_END_X - 25);
rightLeg.setEndY(SPINE_END_Y + 50);
getChildren().addAll(head, spine, leftArm, rightArm, leftLeg, rightLeg);
lives.set(getChildren().size());
}
@FXML
@Override
public void clearAction() {
if (null == opType || imageView == null || imageView.getImage() == null) {
return;
}
switch (opType) {
case Polyline:
imageController.maskPane.getChildren().removeAll(imageController.maskLineLines);
imageController.maskLineLines.clear();
imageController.maskLineData.clear();
break;
case DrawLines:
case Erase:
for (List<Line> penline : imageController.maskPenLines) {
imageController.maskPane.getChildren().removeAll(penline);
}
imageController.maskPenLines.clear();
imageController.maskPenData.clear();
break;
case Mosaic:
case Frosted:
maskView.setImage(imageView.getImage());
break;
default:
imageController.initMaskControls(false);
typeGroup.selectToggle(null);
}
}
public static boolean inLine(Line line, int x, int y) {
double d = (x - line.getStartX()) * (line.getStartY() - line.getEndY())
- ((line.getStartX() - line.getEndX()) * (y - line.getStartY()));
return Math.abs(d) < 0.0001
&& (x >= Math.min(line.getStartX(), line.getEndX())
&& x <= Math.max(line.getStartX(), line.getEndX()))
&& (y >= Math.min(line.getStartY(), line.getEndY()))
&& (y <= Math.max(line.getStartY(), line.getEndY()));
}
public EdgeGraphic(Graph graph, Edge edge, StringProperty textProperty) {
group = new Group();
line = new Line();
final DoubleBinding sourceX = edge.getSource().getXAnchor(graph, edge);
final DoubleBinding sourceY = edge.getSource().getYAnchor(graph, edge);
final DoubleBinding targetX = edge.getTarget().getXAnchor(graph, edge);
final DoubleBinding targetY = edge.getTarget().getYAnchor(graph, edge);
line.startXProperty().bind(sourceX);
line.startYProperty().bind(sourceY);
line.endXProperty().bind(targetX);
line.endYProperty().bind(targetY);
group.getChildren().add(line);
final DoubleProperty textWidth = new SimpleDoubleProperty();
final DoubleProperty textHeight = new SimpleDoubleProperty();
text = new Text();
text.textProperty().bind(textProperty);
text.getStyleClass().add("edge-text");
text.xProperty().bind(line.startXProperty().add(line.endXProperty()).divide(2).subtract(textWidth.divide(2)));
text.yProperty().bind(line.startYProperty().add(line.endYProperty()).divide(2).subtract(textHeight.divide(2)));
final Runnable recalculateWidth = () -> {
textWidth.set(text.getLayoutBounds().getWidth());
textHeight.set(text.getLayoutBounds().getHeight());
};
text.parentProperty().addListener((obs, oldVal, newVal) -> recalculateWidth.run());
text.textProperty().addListener((obs, oldVal, newVal) -> recalculateWidth.run());
group.getChildren().add(text);
getChildren().add(group);
}
@Test
void testUpdateUnitCM() {
prefs.unitProperty().set(Unit.INCH);
final double x = ((Line) grid.getChildren().get(2)).getStartX();
prefs.unitProperty().set(Unit.CM);
assertThat(x).isNotEqualTo(((Line) grid.getChildren().get(2)).getStartX());
}
@ParameterizedTest
@ValueSource(ints = {15, 100})
void testUpdateGridSize(final double gap) {
prefs.gridStyleProperty().set(GridStyle.CUSTOMISED);
final double x = ((Line) grid.getChildren().get(0)).getStartX();
prefs.gridGapProperty().setValue(gap);
assertThat(x).isNotEqualTo(((Line) grid.getChildren().get(0)).getStartX());
}
private Parent createContent() {
Pane root = new Pane();
root.setPrefSize(APP_W, APP_H);
Rectangle bg = new Rectangle(APP_W, APP_H);
LoadingCircle loadingCircle = new LoadingCircle();
loadingCircle.setTranslateX(APP_W - 120);
loadingCircle.setTranslateY(APP_H - 100);
LoadingArc loadingArc = new LoadingArc();
loadingArc.setTranslateX(500);
loadingArc.setTranslateY(300);
Line loadingBarBG = new Line(100, APP_H - 70, APP_W - 100, APP_H - 70);
loadingBarBG.setStroke(Color.GREY);
loadingBar.setStartX(100);
loadingBar.setStartY(APP_H - 70);
loadingBar.setEndX(100);
loadingBar.setEndY(APP_H - 70);
loadingBar.setStroke(Color.WHITE);
task.progressProperty().addListener((obs, old, newValue) -> {
double progress = newValue.doubleValue();
loadingBar.setEndX(100 + progress * (APP_W - 200));
});
root.getChildren().addAll(bg, loadingArc, loadingBarBG, loadingBar);
return root;
}
private Group buildMarkX(double x, double y, int size) {
Group group = new Group();
group.getChildren().addAll(
new Line(
x + 10, y + 10,
x + size - 10, y + size - 10
),
new Line(
x + size - 10, y + 10,
x + 10, y + size - 10
)
);
return group;
}
public static Node createIconContent() {
Line line = new Line(0, 0, 70, 70);
line.setStroke(Color.web("#b9c0c5"));
line.setStrokeWidth(5);
line.getStrokeDashArray().addAll(15d,15d);
line.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));
line.setEffect(effect);
return line;
}
public static Node createIconContent() {
Line line = new Line(0, 0, 70, 70);
line.setStroke(Color.web("#b9c0c5"));
line.setStrokeWidth(5);
line.getStrokeDashArray().addAll(15d,15d);
line.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));
line.setEffect(effect);
return line;
}