public static Node createIconContent() { Path path = new Path(); path.getElements().addAll( new MoveTo(25, 25), new HLineTo(45), new ArcTo(20, 20, 0, 80, 25, true, true) ); path.setStroke(Color.web("#b9c0c5")); path.setStrokeWidth(5); path.getStrokeDashArray().addAll(15d,15d); path.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)); path.setEffect(effect); return path; }
@FXML private void drawingAreaMouseClicked(MouseEvent e) { polyline.getPoints().addAll(e.getX(), e.getY()); polygon.getPoints().addAll(e.getX(), e.getY()); // if path is empty, move to first click position and close path if (path.getElements().isEmpty()) { path.getElements().add(new MoveTo(e.getX(), e.getY())); path.getElements().add(new ClosePath()); } else // insert a new path segment before the ClosePath element { // create an arc segment and insert it in the path ArcTo arcTo = new ArcTo(); arcTo.setX(e.getX()); arcTo.setY(e.getY()); arcTo.setRadiusX(100.0); arcTo.setRadiusY(100.0); arcTo.setSweepFlag(sweepFlag); sweepFlag = !sweepFlag; path.getElements().add(path.getElements().size() - 1, arcTo); } }
private Path initializeHalfCircle() { final Path halfCircle = new Path(); halfCircle.setStroke(Color.BLACK); MoveTo p1 = new MoveTo(); ArcTo p2 = new ArcTo(); p1.xProperty().bind(xProperty().add(CIRCLE_RADIUS)); p1.yProperty().bind(yProperty()); p2.xProperty().bind(xProperty().subtract(CIRCLE_RADIUS)); p2.yProperty().bind(yProperty()); p2.setRadiusX(CIRCLE_RADIUS); p2.setRadiusY(CIRCLE_RADIUS); halfCircle.getElements().add(p1); halfCircle.getElements().add(p2); return halfCircle; }
private Path initializeLargeCircle() { final Path largeCircle = new Path(); largeCircle.setStroke(Color.BLACK); MoveTo p1 = new MoveTo(); ArcTo p2 = new ArcTo(); p1.xProperty().bind(xProperty().add(LARGE_CIRCLE_RADIUS)); p1.yProperty().bind(yProperty()); p2.xProperty().bind(xProperty().subtract(LARGE_CIRCLE_RADIUS)); p2.yProperty().bind(yProperty()); p2.setRadiusX(LARGE_CIRCLE_RADIUS); p2.setRadiusY(LARGE_CIRCLE_RADIUS); largeCircle.getElements().add(p1); largeCircle.getElements().add(p2); return largeCircle; }
private Path initializeMediumCircle() { final Path mediumCircle = new Path(); mediumCircle.setStroke(Color.BLACK); MoveTo p1 = new MoveTo(); ArcTo p2 = new ArcTo(); p1.xProperty().bind(xProperty().add(MEDIUM_CIRCLE_RADIUS)); p1.yProperty().bind(yProperty()); p2.xProperty().bind(xProperty().subtract(MEDIUM_CIRCLE_RADIUS)); p2.yProperty().bind(yProperty()); p2.setRadiusX(MEDIUM_CIRCLE_RADIUS); p2.setRadiusY(MEDIUM_CIRCLE_RADIUS); mediumCircle.getElements().add(p1); mediumCircle.getElements().add(p2); return mediumCircle; }
private Path initializeSmallCircle() { final Path smallCircle = new Path(); smallCircle.setStroke(Color.BLACK); MoveTo p1 = new MoveTo(); ArcTo p2 = new ArcTo(); p1.xProperty().bind(xProperty().add(SMALL_CIRCLE_RADIUS)); p1.yProperty().bind(yProperty()); p2.xProperty().bind(xProperty().subtract(SMALL_CIRCLE_RADIUS)); p2.yProperty().bind(yProperty()); p2.setRadiusX(SMALL_CIRCLE_RADIUS); p2.setRadiusY(SMALL_CIRCLE_RADIUS); smallCircle.getElements().add(p1); smallCircle.getElements().add(p2); return smallCircle; }
/** * Draws the arrow-head for its current size and position values. */ public void draw() { getElements().clear(); getElements().add(new MoveTo(x, y + length / 2)); getElements().add(new LineTo(x + width / 2, y - length / 2)); if (radius > 0) { final ArcTo arcTo = new ArcTo(); arcTo.setX(x - width / 2); arcTo.setY(y - length / 2); arcTo.setRadiusX(radius); arcTo.setRadiusY(radius); arcTo.setSweepFlag(true); getElements().add(arcTo); } else { getElements().add(new LineTo(x - width / 2, y - length / 2)); } getElements().add(new ClosePath()); }
private static Path processPath(final List<String> PATH_LIST, final PathReader READER) { final Path PATH = new Path(); PATH.setFillRule(FillRule.EVEN_ODD); while (!PATH_LIST.isEmpty()) { if ("M".equals(READER.read())) { PATH.getElements().add(new MoveTo(READER.nextX(), READER.nextY())); } else if ("L".equals(READER.read())) { PATH.getElements().add(new LineTo(READER.nextX(), READER.nextY())); } else if ("C".equals(READER.read())) { PATH.getElements().add(new CubicCurveTo(READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY())); } else if ("Q".equals(READER.read())) { PATH.getElements().add(new QuadCurveTo(READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY())); } else if ("H".equals(READER.read())) { PATH.getElements().add(new HLineTo(READER.nextX())); } else if ("L".equals(READER.read())) { PATH.getElements().add(new VLineTo(READER.nextY())); } else if ("A".equals(READER.read())) { PATH.getElements().add(new ArcTo(READER.nextX(), READER.nextY(), 0, READER.nextX(), READER.nextY(), false, false)); } else if ("Z".equals(READER.read())) { PATH.getElements().add(new ClosePath()); } } return PATH; }
private Path createSegment(final double START_ANGLE, final double END_ANGLE, final double INNER_RADIUS, final double OUTER_RADIUS, final Color FILL, final Color STROKE, final TreeNode NODE) { double startAngleRad = Math.toRadians(START_ANGLE + 90); double endAngleRad = Math.toRadians(END_ANGLE + 90); boolean largeAngle = Math.abs(END_ANGLE - START_ANGLE) > 180.0; double x1 = centerX + INNER_RADIUS * Math.sin(startAngleRad); double y1 = centerY - INNER_RADIUS * Math.cos(startAngleRad); double x2 = centerX + OUTER_RADIUS * Math.sin(startAngleRad); double y2 = centerY - OUTER_RADIUS * Math.cos(startAngleRad); double x3 = centerX + OUTER_RADIUS * Math.sin(endAngleRad); double y3 = centerY - OUTER_RADIUS * Math.cos(endAngleRad); double x4 = centerX + INNER_RADIUS * Math.sin(endAngleRad); double y4 = centerY - INNER_RADIUS * Math.cos(endAngleRad); MoveTo moveTo1 = new MoveTo(x1, y1); LineTo lineTo2 = new LineTo(x2, y2); ArcTo arcTo3 = new ArcTo(OUTER_RADIUS, OUTER_RADIUS, 0, x3, y3, largeAngle, true); LineTo lineTo4 = new LineTo(x4, y4); ArcTo arcTo1 = new ArcTo(INNER_RADIUS, INNER_RADIUS, 0, x1, y1, largeAngle, false); Path path = new Path(moveTo1, lineTo2, arcTo3, lineTo4, arcTo1); path.setFill(FILL); path.setStroke(STROKE); String tooltipText = new StringBuilder(NODE.getData().getName()).append("\n").append(String.format(Locale.US, formatString, NODE.getData().getValue())).toString(); Tooltip.install(path, new Tooltip(tooltipText)); path.setOnMousePressed(new WeakEventHandler<>(e -> NODE.getTreeRoot().fireTreeNodeEvent(new TreeNodeEvent(NODE, EventType.NODE_SELECTED)))); return path; }
public PathSample() { super(180,90); // Create path shape - square Path path1 = new Path(); path1.getElements().addAll( new MoveTo(25, 25), new HLineTo(65), new VLineTo(65), new LineTo(25, 65), new ClosePath() ); path1.setFill(null); path1.setStroke(Color.RED); path1.setStrokeWidth(2); // Create path shape - curves Path path2 = new Path(); path2.getElements().addAll( new MoveTo(100, 45), new CubicCurveTo(120, 20, 130, 80, 140, 45), new QuadCurveTo(150, 0, 160, 45), new ArcTo(20, 40, 0, 180, 45, true, true) ); path2.setFill(null); path2.setStroke(Color.DODGERBLUE); path2.setStrokeWidth(2); // show the path shapes; getChildren().add(new Group(path1, path2)); // REMOVE ME setControls( new SimplePropertySheet.PropDesc("Path 1 Stroke", path1.strokeProperty()), new SimplePropertySheet.PropDesc("Path 2 Stroke", path2.strokeProperty()) ); // END REMOVE ME }
private Path createSegment(final double START_ANGLE, final double END_ANGLE, final double INNER_RADIUS, final double OUTER_RADIUS, final Paint FILL, final Color STROKE, final TreeNode NODE) { double startAngleRad = Math.toRadians(START_ANGLE + 90); double endAngleRad = Math.toRadians(END_ANGLE + 90); boolean largeAngle = Math.abs(END_ANGLE - START_ANGLE) > 180.0; double x1 = centerX + INNER_RADIUS * Math.sin(startAngleRad); double y1 = centerY - INNER_RADIUS * Math.cos(startAngleRad); double x2 = centerX + OUTER_RADIUS * Math.sin(startAngleRad); double y2 = centerY - OUTER_RADIUS * Math.cos(startAngleRad); double x3 = centerX + OUTER_RADIUS * Math.sin(endAngleRad); double y3 = centerY - OUTER_RADIUS * Math.cos(endAngleRad); double x4 = centerX + INNER_RADIUS * Math.sin(endAngleRad); double y4 = centerY - INNER_RADIUS * Math.cos(endAngleRad); MoveTo moveTo1 = new MoveTo(x1, y1); LineTo lineTo2 = new LineTo(x2, y2); ArcTo arcTo3 = new ArcTo(OUTER_RADIUS, OUTER_RADIUS, 0, x3, y3, largeAngle, true); LineTo lineTo4 = new LineTo(x4, y4); ArcTo arcTo1 = new ArcTo(INNER_RADIUS, INNER_RADIUS, 0, x1, y1, largeAngle, false); Path path = new Path(moveTo1, lineTo2, arcTo3, lineTo4, arcTo1); path.setFill(FILL); path.setStroke(STROKE); String tooltipText = new StringBuilder(NODE.getItem().getName()).append("\n").append(String.format(Locale.US, formatString, NODE.getItem().getValue())).toString(); Tooltip.install(path, new Tooltip(tooltipText)); path.setOnMousePressed(new WeakEventHandler<>(e -> NODE.getTreeRoot().fireTreeNodeEvent(new TreeNodeEvent(NODE, EventType.NODE_SELECTED)))); return path; }
/** arc from current position, using the specified center coordinates, radius, and angle */ public void arcRel(double xc, double yc, double radius, double angle) { // arcTo seems to fail if sweep angle is greater than 360 if(angle >= FX.TWO_PI) { angle = FX.TWO_PI - 0.0000001; } else if(angle <= -FX.TWO_PI) { angle = - FX.TWO_PI + 0.0000001; } Point2D p = currentPos(); double a = Math.atan2(yc + yorigin - p.getY(), p.getX() - xc - xorigin); double b = a - angle; double xe = xorigin + xc + radius * Math.cos(b); double ye = yorigin - yc - radius * Math.sin(b); // arcTo sweep is explained here: // https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/ArcTo.html boolean large = (angle >= Math.PI); boolean sweep = (angle > 0); add(new ArcTo(radius, radius, 0, xe, ye, large, sweep)); }
/** * Create a transition * * @param sourceElements * the source elements * @param targetElements * the target elements * @param duation * the duration * @param pathNode * the path not the morph is done on */ public PathMorphTransition(List<PathElement> sourceElements, List<PathElement> targetElements, Duration duation, Path pathNode) { this.pathNode = pathNode; setCycleDuration(duation); if (sourceElements.size() != targetElements.size()) { throw new IllegalArgumentException("Only equal paths are allowed"); //$NON-NLS-1$ } for (int i = 0; i < sourceElements.size(); i++) { PathElement sourceElement = sourceElements.get(i); PathElement targetElement = targetElements.get(i); if (sourceElement.getClass() != targetElement.getClass()) { throw new IllegalArgumentException("Only equal paths are allowed"); //$NON-NLS-1$ } if (sourceElement instanceof ArcTo) { this.interpolateList.add(new ArcToInterpolatable((ArcTo) sourceElement)); } else if (sourceElement instanceof CubicCurveTo) { this.interpolateList.add(new CubicCurveToInterpolatable((CubicCurveTo) sourceElement)); } else if (sourceElement instanceof HLineTo) { this.interpolateList.add(new HLineToInterpolatable((HLineTo) sourceElement)); } else if (sourceElement instanceof LineTo) { this.interpolateList.add(new LineToInterpolatable((LineTo) sourceElement)); } else if (sourceElement instanceof MoveTo) { this.interpolateList.add(new MoveToInterpolatable((MoveTo) sourceElement)); } else if (sourceElement instanceof QuadCurveTo) { this.interpolateList.add(new QuadCurveToInterpolatable((QuadCurveTo) sourceElement)); } else if (sourceElement instanceof VLineTo) { this.interpolateList.add(new VLineToInterpolatable((VLineTo) sourceElement)); } } this.sourceElements = sourceElements; this.targetElements = targetElements; }
@Override public ArcTo interpolate(ArcTo endValue, double t) { ArcTo rv = new ArcTo(this.source.getRadiusX() + (endValue.getRadiusX() - this.source.getRadiusX()) * t, this.source.getRadiusY() + (endValue.getRadiusY() - this.source.getRadiusY()) * t, this.source.getXAxisRotation() + (endValue.getXAxisRotation() - this.source.getXAxisRotation()) * t, this.source.getX() + (endValue.getX() - this.source.getX()) * t, this.source.getY() + (endValue.getY() - this.source.getY()) * t, this.source.isLargeArcFlag(), this.source.isSweepFlag()); rv.setAbsolute(this.source.isAbsolute()); return rv; }
/** * Adds a circular detour arc to the path, to the given position. * * @param x the final x position of the arc * @param y the final y position of the arc */ private void addArcTo(final double x, final double y) { final ArcTo arcTo = new ArcTo(); arcTo.setRadiusX(DETOUR_RADIUS); arcTo.setRadiusY(DETOUR_RADIUS); arcTo.setSweepFlag(sign > 0); arcTo.setX(GeometryUtils.moveOffPixel(x)); arcTo.setY(GeometryUtils.moveOffPixel(y)); getPathElements().add(arcTo); }
/** * @param touchPoint that is the center of new active touch area, or null if the mouse */ private TouchArea(TouchPoint touchPoint) { super(); this.setLayoutX(DrawWire.this.getEndX()); this.setLayoutY(DrawWire.this.getEndY()); this.touchID = touchPoint == null ? -1 : touchPoint.getId(); this.dragStarted = true; this.nearbyAnchors = new ArrayList<>(); this.lastNearbyUpdate = Point2D.ZERO; this.disapperance = new Timeline(new KeyFrame(Duration.millis(2000), e -> DrawWire.this.remove(), new KeyValue(this.opacityProperty(), 0.3), new KeyValue(DrawWire.this.opacityProperty(), 0.2))); // a circle with hole is built from a path of round arcs with a very thick stroke ArcTo arc1 = new ArcTo(100, 100, 0, 100, 0, true, true); ArcTo arc2 = new ArcTo(100, 100, 0, -100, 0, true, true); this.getElements().addAll(new MoveTo(-100, 0), arc1, arc2, new ClosePath()); this.setStroke(Color.web("#0066FF")); this.setStrokeType(StrokeType.INSIDE); this.setStrokeWidth(90); this.setStroke(Color.web("#0066FF")); this.setStrokeType(StrokeType.INSIDE); this.setOpacity(0); if (touchPoint != null) { touchPoint.grab(this); } this.addEventHandler(TouchEvent.TOUCH_PRESSED, this::handleTouchPress); this.addEventHandler(TouchEvent.TOUCH_MOVED, this::handleTouchDrag); this.addEventHandler(TouchEvent.TOUCH_RELEASED, this::handleTouchRelease); this.addEventHandler(MouseEvent.MOUSE_PRESSED, this::handleMousePress); this.addEventHandler(MouseEvent.MOUSE_DRAGGED, this::handleMouseDrag); this.addEventHandler(MouseEvent.MOUSE_RELEASED, this::handleMouseRelease); }
@Override protected Shape[] Thumbnail() { return new Shape[] { new Path(new PathElement[] { new MoveTo(0, 20), new ArcTo(15, 15, 0, 30, 20, false, true), new LineTo(0, 20) }) }; }
@Override public void Draw(Pane canvas) { double x = canvas.getWidth() * GetDoubleAttribute("X") / MaximumX; double y = canvas.getHeight() * GetDoubleAttribute("Y") / MaximumY; double radX = canvas.getWidth() * (GetDoubleAttribute("Width") / MaximumX) / 2; double radY = canvas.getHeight() * GetDoubleAttribute("Height") / MaximumY; double angle = 2 * Math.PI * GetDoubleAttribute("Rotation") / MaximumX; double xOffset = radX - radX * Math.cos(angle); double yOffset = radX * Math.sin(angle); double x1 = x - radX + xOffset; double x2 = x + radX - xOffset; double y1 = y - yOffset; double y2 = y + yOffset; Path path = new Path(new PathElement[] { new MoveTo(x1, y1), new ArcTo(radX, radY, angle * 180 / Math.PI, x2, y2, true, true), new LineTo(x1, y1) }); path.setFill(GetColorAttribute("Color")); path.setStrokeWidth(0); canvas.getChildren().add(path); }
private static Path processPath(final List<String> PATH_LIST, final PathReader READER) { final Path PATH = new Path(); PATH.setFillRule(FillRule.EVEN_ODD); while (!PATH_LIST.isEmpty()) { if ("M".equals(READER.read())) { PATH.getElements().add(new MoveTo(READER.nextX(), READER.nextY())); } else if ("L".equals(READER.read())) { PATH.getElements().add(new LineTo(READER.nextX(), READER.nextY())); } else if ("C".equals(READER.read())) { PATH.getElements().add(new CubicCurveTo( READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY())); } else if ("Q".equals(READER.read())) { PATH.getElements().add(new QuadCurveTo(READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY())); } else if ("H".equals(READER.read())) { PATH.getElements().add(new HLineTo(READER.nextX())); } else if ("L".equals(READER.read())) { PATH.getElements().add(new VLineTo(READER.nextY())); } else if ("A".equals(READER.read())) { PATH.getElements().add( new ArcTo(READER.nextX(), READER.nextY(), 0, READER.nextX(), READER.nextY(), false, false)); } else if ("Z".equals(READER.read())) { PATH.getElements().add(new ClosePath()); } } return PATH; }
@Override public void arcRel(float rx, float ry, float xAxisRotation, boolean largeArcFlag, boolean sweepFlag, float x, float y) throws ParseException { lastX = x; lastY = y; path.getElements().add(new ArcTo(rx, ry, xAxisRotation, x, y, largeArcFlag, sweepFlag)); }
private Path createLogoPath() { Path path = new Path(); path.setStrokeWidth(10); path.setStroke(javafx.scene.paint.Color.valueOf("#808080")); path.setFill(javafx.scene.paint.Color.valueOf("#2e7cdb")); path.getElements().add(new MoveTo( CENTER_X + E_RADIUS_INT - SMALL_DELTA_B, CENTER_Y + SMALL_DELTA_A)); path.getElements().add(new ArcTo(E_RADIUS_INT, E_RADIUS_INT, 0, CENTER_X - SMALL_DELTA_A, CENTER_Y - E_RADIUS_INT + SMALL_DELTA_B, true, true)); path.getElements().add(new ArcTo(RADIUS, RADIUS, 0, CENTER_X - BIG_DELTA_A, CENTER_Y - E_RADIUS_EXT + BIG_DELTA_B, false, false)); path.getElements().add(new ArcTo(E_RADIUS_EXT, E_RADIUS_EXT, 0, CENTER_X + E_RADIUS_EXT - BIG_DELTA_B, CENTER_Y + BIG_DELTA_A, true, false)); path.getElements().add(new ArcTo(RADIUS, RADIUS, 0, CENTER_X + E_RADIUS_INT - SMALL_DELTA_B, CENTER_Y + SMALL_DELTA_A, false, false)); path.getElements().add(new MoveTo( CENTER_X + G_RADIUS_INT / Math.sqrt(2.0) + 39, CENTER_Y - G_RADIUS_INT / Math.sqrt(2.0) + 42 )); path.getElements().add(new ArcTo(G_RADIUS_INT, G_RADIUS_INT, 0, CENTER_X - SMALL_DELTA_A, CENTER_Y - G_RADIUS_INT + SMALL_DELTA_B - 3, true, true)); path.getElements().add(new ArcTo(RADIUS, RADIUS, 0, CENTER_X - BIG_DELTA_A, CENTER_Y - G_RADIUS_EXT + BIG_DELTA_B - 3, false, false)); path.getElements().add(new ArcTo(G_RADIUS_EXT, G_RADIUS_EXT, 0, CENTER_X + G_RADIUS_EXT / Math.sqrt(2.0) - 22, CENTER_Y - G_RADIUS_EXT / Math.sqrt(2.0) - 22, true, false)); path.getElements().add(new ArcTo(30, 30, 0, CENTER_X + G_RADIUS_EXT / Math.sqrt(2.0) - 68, CENTER_Y - G_RADIUS_EXT / Math.sqrt(2.0) - 22, false, false)); path.getElements().add(new LineTo(CENTER_X - BIG_DELTA_A, CENTER_Y - SMALL_DELTA_A + 16)); path.getElements().add(new ArcTo(RADIUS, RADIUS, 0, CENTER_X + 20, CENTER_Y + SMALL_DELTA_A + 4, false, false)); path.getElements().add(new LineTo( CENTER_X + G_RADIUS_INT / Math.sqrt(2.0) + 39, CENTER_Y - G_RADIUS_INT / Math.sqrt(2.0) + 42)); path.setScaleX(.3); path.setScaleY(.3); path.setLayoutY(-400); path.setLayoutX(-400); return path; }
@Override public void start(Stage palco) throws Exception { StackPane painelEmpilhador = new StackPane(); Rectangle retangulo = new Rectangle(220, 120); retangulo.setFill(Color.GREEN); Polygon losango = new Polygon(); losango.getPoints().addAll(new Double[]{ 50.0, 50.0, 150.0, 0.0, 250.0, 50.0, 150.0, 100.0, 50.0, 50.0 }); losango.setFill(Color.YELLOW); Path arco = new Path(); MoveTo moveTo = new MoveTo(); moveTo.setX(0.0); moveTo.setY(0.0); ArcTo arcTo = new ArcTo(); arcTo.setX(55.0); arcTo.setY(0.0); arcTo.setRadiusX(50.0); arcTo.setRadiusY(50.0); arco.getElements().add(moveTo); arco.getElements().add(arcTo); arco.setStroke(Color.WHITE); arco.setRotate(180); arco.setStrokeWidth(5); Circle circulo = new Circle(30, Color.BLUE); painelEmpilhador.getChildren().addAll(retangulo, losango, circulo, arco); Scene cena = new Scene(painelEmpilhador, 250, 100); palco.setTitle("Testando StackPane"); palco.setScene(cena); palco.show(); }
/** * Creates a semi-circle with in the specified location. * * layer starts at 0 * * @param layer * The layer to place this element at, the first child of root is * layer 0. * @param angle * The start and end points of this ring * @param center * the coordinates of the center of the circle * @param scale * the scaling factor * @return a semi-circle with the specified dimensions */ private Shape createRing(final int layer, final DegreeRange angle, final Point2D center, final double scale) { Path result = new Path(); result.setFill(createColor(angle.getStartAngle(), layer)); result.setFillRule(FillRule.EVEN_ODD); // check if this is a large arc boolean largeArc = angle.angle() > AbstractSunburstNode.CIRCLEDEGREES / 2; // calculate the radii of the two arcs double innerRadius = scale * (CENTER_RADIUS + (layer * RING_WIDTH)); double outerRadius = innerRadius + scale * RING_WIDTH; // convert degrees to radians for Math.sin and Math.cos double angleAlpha = Math.toRadians(angle.getStartAngle()); double angleAlphaNext = Math.toRadians(angle.getEndAngle()); // draw the semi-circle // first go to the start point double startX = center.getX() + innerRadius * Math.sin(angleAlpha); double startY = center.getY() - innerRadius * Math.cos(angleAlpha); MoveTo move1 = new MoveTo(startX, startY); // draw a line from point 1 to point 2 LineTo line1To2 = createLine(outerRadius, center, angleAlpha); // draw an arc from point 2 to point 3 ArcTo arc2To3 = createArc(outerRadius, center, angleAlphaNext, true, largeArc); // draw a line from point 3 to point 4 LineTo line3To4 = createLine(innerRadius, center, angleAlphaNext); // draw an arc from point 4 back to point 1 ArcTo arc4To1 = createArc(innerRadius, center, angleAlpha, false, largeArc); // add all elements to the path result.getElements() .addAll(move1, line1To2, arc2To3, line3To4, arc4To1); return result; }
/** * Creates an {@link ArcTo} with the specified parameters. * * Coordinates of the end point of the arc are given in polar form relative * to the center of the arcs. * * @param radius * The radius of the arc. * @param center * The center coordinates of the arc. * @param angle * The angle of the end point. * @param sweep * The draw direction of the arc. * @param largeArc * if true draw an arc larger than 180 degrees. * @return an ArcTo with the specified parameters. */ private ArcTo createArc(final double radius, final Point2D center, final double angle, final boolean sweep, final boolean largeArc) { // calculate the end point of the arc double endX = center.getX() + radius * Math.sin(angle); double endY = center.getY() - radius * Math.cos(angle); // create the arc ArcTo result = new ArcTo(); result.setRadiusX(radius); result.setRadiusY(radius); result.setX(endX); result.setY(endY); result.setSweepFlag(sweep); result.setLargeArcFlag(largeArc); return result; }
public static String convertPath(final Path PATH) { final StringBuilder fxPath = new StringBuilder(); for (PathElement element : PATH.getElements()) { if (MoveTo.class.equals(element.getClass())) { fxPath.append("M ") .append(((MoveTo) element).getX()).append(" ") .append(((MoveTo) element).getY()).append(" "); } else if (LineTo.class.equals(element.getClass())) { fxPath.append("L ") .append(((LineTo) element).getX()).append(" ") .append(((LineTo) element).getY()).append(" "); } else if (CubicCurveTo.class.equals(element.getClass())) { fxPath.append("C ") .append(((CubicCurveTo) element).getControlX1()).append(" ") .append(((CubicCurveTo) element).getControlY1()).append(" ") .append(((CubicCurveTo) element).getControlX2()).append(" ") .append(((CubicCurveTo) element).getControlY2()).append(" ") .append(((CubicCurveTo) element).getX()).append(" ") .append(((CubicCurveTo) element).getY()).append(" "); } else if (QuadCurveTo.class.equals(element.getClass())) { fxPath.append("Q ") .append(((QuadCurveTo) element).getControlX()).append(" ") .append(((QuadCurveTo) element).getControlY()).append(" ") .append(((QuadCurveTo) element).getX()).append(" ") .append(((QuadCurveTo) element).getY()).append(" "); } else if (ArcTo.class.equals(element.getClass())) { fxPath.append("A ") .append(((ArcTo) element).getX()).append(" ") .append(((ArcTo) element).getY()).append(" ") .append(((ArcTo) element).getRadiusX()).append(" ") .append(((ArcTo) element).getRadiusY()).append(" "); } else if (HLineTo.class.equals(element.getClass())) { fxPath.append("H ") .append(((HLineTo) element).getX()).append(" "); } else if (VLineTo.class.equals(element.getClass())) { fxPath.append("V ") .append(((VLineTo) element).getY()).append(" "); } else if (ClosePath.class.equals(element.getClass())) { fxPath.append("Z"); } } return fxPath.toString(); }
public static String convertPath(final Path PATH) { final StringBuilder fxPath = new StringBuilder(); for (PathElement element : PATH.getElements()) { if (MoveTo.class.equals(element.getClass())) { fxPath .append("M ") .append(((MoveTo) element).getX()) .append(" ") .append(((MoveTo) element).getY()) .append(" "); } else if (LineTo.class.equals(element.getClass())) { fxPath .append("L ") .append(((LineTo) element).getX()) .append(" ") .append(((LineTo) element).getY()) .append(" "); } else if (CubicCurveTo.class.equals(element.getClass())) { fxPath .append("C ") .append(((CubicCurveTo) element).getControlX1()) .append(" ") .append(((CubicCurveTo) element).getControlY1()) .append(" ") .append(((CubicCurveTo) element).getControlX2()) .append(" ") .append(((CubicCurveTo) element).getControlY2()) .append(" ") .append(((CubicCurveTo) element).getX()) .append(" ") .append(((CubicCurveTo) element).getY()) .append(" "); } else if (QuadCurveTo.class.equals(element.getClass())) { fxPath .append("Q ") .append(((QuadCurveTo) element).getControlX()) .append(" ") .append(((QuadCurveTo) element).getControlY()) .append(" ") .append(((QuadCurveTo) element).getX()) .append(" ") .append(((QuadCurveTo) element).getY()) .append(" "); } else if (ArcTo.class.equals(element.getClass())) { fxPath .append("A ") .append(((ArcTo) element).getX()) .append(" ") .append(((ArcTo) element).getY()) .append(" ") .append(((ArcTo) element).getRadiusX()) .append(" ") .append(((ArcTo) element).getRadiusY()) .append(" "); } else if (HLineTo.class.equals(element.getClass())) { fxPath.append("H ").append(((HLineTo) element).getX()).append(" "); } else if (VLineTo.class.equals(element.getClass())) { fxPath.append("V ").append(((VLineTo) element).getY()).append(" "); } else if (ClosePath.class.equals(element.getClass())) { fxPath.append("Z"); } } return fxPath.toString(); }
@Override public void arcAbs(float rx, float ry, float xAxisRotation, boolean largeArcFlag, boolean sweepFlag, float x, float y) throws ParseException { lastX = x; lastY = y; path.getElements().add(new ArcTo(rx, ry, xAxisRotation, x, y, largeArcFlag, sweepFlag)); }
/** * computes the circular ring segments specified by segmentCount * through translation of vector coordinates into local coordinate-space at * application runtime <br> * Each segment and its associated symbol will be added to a * group-node which will be put into an ObservableList of type Group: segments <br> * @see {@link segments}, {@link getSegments}, {@link setSegments} */ private void createOuterCircleSegments() { double segmentRadians = 360/segmentCount*Math.PI/180; for(int i = 2; i <= segmentCount+1; i++) { Group g = new Group(); Path p = new Path(); p.setFill(fillColor); p.setStroke(strokeColor); p.setFillRule(FillRule.EVEN_ODD); MoveTo firstPoint = new MoveTo(); firstPoint.setX(centerX + innerRadius*Math.cos(segmentRadians*(i-1))); firstPoint.setY(centerY + innerRadius*Math.sin(segmentRadians*(i-1))); p.getElements().add(firstPoint); LineTo nextLine = new LineTo(); nextLine.setX(centerX + outerRadius*Math.cos(segmentRadians*(i-1))); nextLine.setY(centerY + outerRadius*Math.sin(segmentRadians*(i-1))); ArcTo outerArc = new ArcTo(); outerArc.setSweepFlag(true); outerArc.setAbsolute(true); outerArc.setX(centerX + outerRadius*Math.cos(2*Math.PI + segmentRadians*i)); outerArc.setY(centerY + outerRadius*Math.sin(2*Math.PI + segmentRadians*i)); outerArc.setRadiusX(outerRadius); outerArc.setRadiusY(outerRadius); LineTo line2 = new LineTo(); line2.setX(centerX + innerRadius*Math.cos(segmentRadians*(i))); line2.setY(centerY + innerRadius*Math.sin(segmentRadians*(i))); ArcTo innerArc = new ArcTo(); innerArc.setSweepFlag(false); innerArc.setAbsolute(true); innerArc.setX(centerX + innerRadius*Math.cos(2*Math.PI + segmentRadians*(i-1))); innerArc.setY(centerY + innerRadius*Math.sin(2*Math.PI + segmentRadians*(i-1))); innerArc.setRadiusX(innerRadius); innerArc.setRadiusY(innerRadius); MoveTo end = new MoveTo(); end.setX(centerX + innerRadius*Math.cos(segmentRadians*(i))); end.setY(centerY + innerRadius*Math.sin(segmentRadians*(i))); p.getElements().add(nextLine); p.getElements().add(outerArc); p.getElements().add(line2); p.getElements().add(innerArc); p.getElements().add(end); g.getChildren().add(p); // temporary: for button layout injection Rectangle rect = new Rectangle(); rect.setX(centerX-((outerRadius-innerRadius)*0.35) + (innerRadius + (outerRadius - innerRadius)/2)*Math.cos(segmentRadians*(i-.5))); rect.setY(centerY-((outerRadius-innerRadius)*0.35) + (innerRadius + (outerRadius - innerRadius)/2)*Math.sin(segmentRadians*(i-.5))); rect.setWidth(((outerRadius-innerRadius)*0.7)); rect.setHeight(((outerRadius-innerRadius)*0.7)); rect.setRotate(Math.toDegrees(segmentRadians*(i-.5))); rect.setFill(Color.RED); g.getChildren().add(rect); segments.add(g); } }
@Override protected void unbindChild(RuleNode<?> node) { maxWidth.removeExpression(node.widthProperty()); Path path1 = getPath(node, 0); MoveTo moveLeft = (MoveTo) path1.getElements().get(0); moveLeft.yProperty().unbind(); ArcTo arcSourceLeft = (ArcTo) path1.getElements().get(1); arcSourceLeft.radiusXProperty().unbind(); arcSourceLeft.radiusYProperty().unbind(); arcSourceLeft.xProperty().unbind(); arcSourceLeft.yProperty().unbind(); arcSourceLeft.sweepFlagProperty().unbind(); VLineTo leftVertical = (VLineTo) path1.getElements().get(2); leftVertical.yProperty().unbind(); ArcTo arcDestinationLeft = (ArcTo) path1.getElements().get(3); arcDestinationLeft.radiusXProperty().unbind(); arcDestinationLeft.radiusYProperty().unbind(); arcDestinationLeft.xProperty().unbind(); arcDestinationLeft.yProperty().unbind(); arcDestinationLeft.sweepFlagProperty().unbind(); HLineTo leftHorizontal = (HLineTo) path1.getElements().get(4); leftHorizontal.xProperty().unbind(); removePath(path1, node); Path path2 = getPath(node, 1); MoveTo moveRight = (MoveTo) path1.getElements().get(0); moveRight.xProperty().unbind(); moveRight.yProperty().unbind(); HLineTo rightHorizontal = (HLineTo) path1.getElements().get(1); rightHorizontal.xProperty().unbind(); ArcTo arcSourceRight = (ArcTo) path1.getElements().get(2); arcSourceRight.radiusXProperty().unbind(); arcSourceRight.radiusYProperty().unbind(); arcSourceRight.xProperty().unbind(); arcSourceRight.yProperty().unbind(); arcSourceRight.sweepFlagProperty().unbind(); VLineTo rightVertical = (VLineTo) path1.getElements().get(3); rightVertical.yProperty().unbind(); ArcTo arcDestinationRight = (ArcTo) path1.getElements().get(4); arcDestinationRight.radiusXProperty().unbind(); arcDestinationRight.radiusYProperty().unbind(); arcDestinationRight.xProperty().unbind(); arcDestinationRight.yProperty().unbind(); arcDestinationRight.sweepFlagProperty().unbind(); removePath(path2, node); }