javafx.scene.shape.Path Java Examples

The following examples show how to use javafx.scene.shape.Path. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ObjectReferenceEdgeViewer.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void draw(Edge pEdge, GraphicsContext pGraphics)
{
	ToolGraphics.strokeSharpPath(pGraphics, (Path) getShape(pEdge), LineStyle.SOLID);
	Line connectionPoints = getConnectionPoints(pEdge);
	
	if(isSShaped(pEdge))
	{
		ArrowHead.BLACK_TRIANGLE.view().draw(pGraphics, 
				new Point(connectionPoints.getX2() - ENDSIZE, connectionPoints.getY2()), 
				new Point(connectionPoints.getX2(), connectionPoints.getY2()));      
	}
	else
	{
		ArrowHead.BLACK_TRIANGLE.view().draw(pGraphics, 
				new Point(connectionPoints.getX2() + ENDSIZE, connectionPoints.getY2()), 
				new Point(connectionPoints.getX2(), connectionPoints.getY2()));      
	}
}
 
Example #2
Source File: CallEdgeViewer.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Shape getShape(Edge pEdge)
{
	Point[] points = getPoints(pEdge);
	Path path = new Path();
	Point point = points[points.length - 1];
	MoveTo moveTo = new MoveTo(point.getX(), point.getY());
	path.getElements().add(moveTo);
	for(int i = points.length - 2; i >= 0; i--)
	{
		point = points[i];
		LineTo lineTo = new LineTo(point.getX(), point.getY());
		path.getElements().add(lineTo);
	}
	return path;
}
 
Example #3
Source File: ToolGraphics.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Strokes and fills a path, by converting the elements to integer coordinates and then
 * aligning them to the center of the pixels, so that it aligns precisely
 * with the JavaFX coordinate system. See the documentation for 
 * javafx.scene.shape.Shape for details.
 * 
 * @param pGraphics The graphics context.
 * @param pPath The path to stroke
 * @param pFill The fill color for the path.
 * @param pShadow True to include a drop shadow.
 */
public static void strokeAndFillSharpPath(GraphicsContext pGraphics, Path pPath, Paint pFill, boolean pShadow)
{
	double width = pGraphics.getLineWidth();
	Paint fill = pGraphics.getFill();
	pGraphics.setLineWidth(LINE_WIDTH);
	pGraphics.setFill(pFill);
	applyPath(pGraphics, pPath);
	
	if( pShadow )
	{
		pGraphics.setEffect(DROP_SHADOW);
	}
	pGraphics.fill();
	pGraphics.stroke();
	pGraphics.setLineWidth(width);
	pGraphics.setFill(fill);
	pGraphics.setEffect(null);
}
 
Example #4
Source File: CandleStickChart.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void dataItemRemoved(XYChart.Data<Number, Number> item, XYChart.Series<Number, Number> series) {
    if (series.getNode() instanceof Path) {
        Path seriesPath = (Path) series.getNode();
        seriesPath.getElements().clear();
    }

    final Node node = item.getNode();
    if (shouldAnimate()) {
        // fade out old candle
        FadeTransition ft = new FadeTransition(Duration.millis(500), node);
        ft.setToValue(0);
        ft.setOnFinished((ActionEvent actionEvent) -> {
            getPlotChildren().remove(node);
            removeDataItemFromDisplay(series, item);
        });
        ft.play();
    } else {
        getPlotChildren().remove(node);
        removeDataItemFromDisplay(series, item);
    }
}
 
Example #5
Source File: Paragraph.java    From Open-Lowcode with Eclipse Public License 2.0 6 votes vote down vote up
protected void displaySelection() {
	logger.finest(" - DisplaySelection - Try to print " + dragstartindex + " - " + dragendindex);
	if (this.dragstartindex >= 0)
		if (this.dragendindex >= 0)
			if (this.dragendindex > this.dragstartindex) {
				hideSelection();
				TextLayout textlayout = (TextLayout) invoke(getTextLayout, textflow);
				PathElement[] highlight = textlayout.getRange(this.dragstartindex, this.dragendindex,
						TextLayout.TYPE_TEXT, 0, 0);
				hightlightpath = new Path(highlight);
				hightlightpath.setManaged(false);
				hightlightpath.setFill(Color.web("#222235", 0.2));
				hightlightpath.setStrokeWidth(0);
				if (title)
					hightlightpath.setTranslateY(6);
				if (bulletpoint) {
					hightlightpath.setTranslateY(2);
					hightlightpath.setTranslateX(5);

				}
				textflow.getChildren().add(hightlightpath);
				textflow.requestLayout();
				textflow.requestFocus();
			}
}
 
Example #6
Source File: ShapeConverter.java    From Enzo with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #7
Source File: NotifyRegion.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    path = new Path();
    path.setStroke(Color.TRANSPARENT);

    icon = new Path();
    icon.setStroke(Color.TRANSPARENT);

    tooltip = new Tooltip("");
    
    getChildren().setAll(path, icon);
}
 
Example #8
Source File: Text3DHelper.java    From FXyzLib with GNU General Public License v3.0 6 votes vote down vote up
public Text3DHelper(String text, String font, int size){
    this.text=text;
    list=new ArrayList<>();
    
    Text textNode = new Text(text);
    textNode.setFont(new Font(font,size));
    
    // Convert Text to Path
    Path subtract = (Path)(Shape.subtract(textNode, new Rectangle(0, 0)));
    // Convert Path elements into lists of points defining the perimeter (exterior or interior)
    subtract.getElements().forEach(this::getPoints);
    
    // Group exterior polygons with their interior polygons
    polis.stream().filter(LineSegment::isHole).forEach(hole->{
        polis.stream().filter(poly->!poly.isHole())
                .filter(poly->!((Path)Shape.intersect(poly.getPath(), hole.getPath())).getElements().isEmpty())
                .filter(poly->poly.getPath().contains(new Point2D(hole.getOrigen().x,hole.getOrigen().y)))
                .forEach(poly->poly.addHole(hole));
    });        
    polis.removeIf(LineSegment::isHole);                
}
 
Example #9
Source File: LowerRightRegion.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
private void initGraphics() {
    if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 ||
        Double.compare(getHeight(), 0.0) <= 0) {
        if (getPrefWidth() > 0 && getPrefHeight() > 0) {
            setPrefSize(getPrefWidth(), getPrefHeight());
        } else {
            setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    path = new Path();
    path.setStroke(Color.TRANSPARENT);

    icon = new Path();
    icon.setStroke(Color.TRANSPARENT);

    tooltip = new Tooltip("");

    getChildren().setAll(path, icon);
}
 
Example #10
Source File: OrganView.java    From narjillos with MIT License 6 votes vote down vote up
private Shape getShape(double zoomLevel, boolean effectsOn) {

		segment.setWidth(organ.getLength() + getOverlap() * 2);
		segment.setHeight(organ.getThickness());

		segment.getTransforms().clear();
		// overlap slightly and shift to center based on thickness
		double widthCenter = organ.getThickness() / 2;
		segment.getTransforms().add(moveToStartPoint());
		segment.getTransforms().add(new Translate(-getOverlap(), -widthCenter));
		segment.getTransforms().add(new Rotate(organ.getAbsoluteAngle(), getOverlap(), widthCenter));

		boolean isHighDetail = hasJoint && zoomLevel >= VERY_HIGH_MAGNIFICATION && effectsOn;

		if (!isHighDetail)
			return segment;

		joint.setRadius(getJointRadius(organ.getThickness()));

		joint.getTransforms().clear();
		joint.getTransforms().add(moveToStartPoint());
		joint.getTransforms().add(new Translate(organ.getLength(), 0));
		joint.getTransforms().add(new Rotate(organ.getAbsoluteAngle(), -organ.getLength(), 0));

		return Path.union(segment, joint);
	}
 
Example #11
Source File: ObjectReferenceEdgeViewer.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private Path getCShape(Line pConnectionPoints)
{
	final int x1 = Math.max(pConnectionPoints.getX1(), pConnectionPoints.getX2()) + ENDSIZE;
	final int y1 = pConnectionPoints.getY1();
	final int x2 = x1 + ENDSIZE;
	final int y2 = pConnectionPoints.getY2();
	final int ymid = (pConnectionPoints.getY1() + pConnectionPoints.getY2()) / 2;
	
	MoveTo moveTo = new MoveTo(pConnectionPoints.getX1(), y1);
	LineTo lineTo1 = new LineTo(x1, y1);
	QuadCurveTo quadTo1 = new QuadCurveTo(x2, y1, x2, ymid);
	QuadCurveTo quadTo2 = new QuadCurveTo(x2, y2, x1, y2);
	LineTo lineTo2 = new LineTo(pConnectionPoints.getX2(), y2);
	
	Path path = new Path();
	path.getElements().addAll(moveTo, lineTo1, quadTo1, quadTo2, lineTo2);
	return path;
}
 
Example #12
Source File: ParagraphText.java    From RichTextFX with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Bounds getRangeBoundsOnScreen(int from, int to) {
    layout(); // ensure layout, is a no-op if not dirty
    PathElement[] rangeShape = getRangeShapeSafely(from, to);

    Path p = new Path();
    p.setManaged(false);
    p.setLayoutX(getInsets().getLeft());
    p.setLayoutY(getInsets().getTop());

    getChildren().add(p);

    p.getElements().setAll(rangeShape);
    Bounds localBounds = p.getBoundsInLocal();
    Bounds rangeBoundsOnScreen = p.localToScreen(localBounds);

    getChildren().remove(p);

    return rangeBoundsOnScreen;
}
 
Example #13
Source File: ObjectReferenceEdgeViewer.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private Path getSShape(Line pConnectionPoints)
{
	final int x1 = pConnectionPoints.getX1() + ENDSIZE;
	final int y1 = pConnectionPoints.getY1();
	final int x2 = pConnectionPoints.getX2() - ENDSIZE;
	final int y2 = pConnectionPoints.getY2();
	final int xmid = (pConnectionPoints.getX1() + pConnectionPoints.getX2()) / 2;
	final int ymid = (pConnectionPoints.getY1() + pConnectionPoints.getY2()) / 2;
    
	MoveTo moveTo = new MoveTo(pConnectionPoints.getX1(), y1);
	LineTo lineTo1 = new LineTo(x1, y1);
	QuadCurveTo quadTo1 = new QuadCurveTo((x1 + xmid) / 2, y1, xmid, ymid);
	QuadCurveTo quadTo2 = new QuadCurveTo((x2 + xmid) / 2, y2, x2, y2);
	LineTo lineTo2 = new LineTo(pConnectionPoints.getX2(), y2);
	
	Path path = new Path();
	path.getElements().addAll(moveTo, lineTo1, quadTo1, quadTo2, lineTo2);
	return path;
}
 
Example #14
Source File: GameElimniationController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
protected void shake(int i1, int j1) {
    try {
        VBox vbox = chessBoard.get(i1 + "-" + j1);
        double x = vbox.getLayoutX();
        double y = vbox.getLayoutY();
        Path path = new Path();
        path.getElements().add(new LineTo(x - 20, y + 18));
        path.getElements().add(new LineTo(x + 20, y + 18));
        path.getElements().add(new LineTo(x - 20, y + 18));
        path.getElements().add(new LineTo(x + 20, y + 18));
        path.getElements().add(new LineTo(x, y));

        PathTransition pathTransition = new PathTransition(Duration.millis(200), path, vbox);
        pathTransition.setCycleCount(3);
        pathTransition.setAutoReverse(true);
        pathTransition.play();

    } catch (Exception e) {
        logger.debug(e.toString());
    }
}
 
Example #15
Source File: AdvCandleStickChartSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Override protected void seriesAdded(Series<Number, Number> series, int seriesIndex) {
    // handle any data already in series
    for (int j = 0; j < series.getData().size(); j++) {
        Data item = series.getData().get(j);
        Node candle = createCandle(seriesIndex, item, j);
        if (shouldAnimate()) {
            candle.setOpacity(0);
            getPlotChildren().add(candle);
            // fade in new candle
            FadeTransition ft = new FadeTransition(Duration.millis(500), candle);
            ft.setToValue(1);
            ft.play();
        } else {
            getPlotChildren().add(candle);
        }
    }
    // create series path
    Path seriesPath = new Path();
    seriesPath.getStyleClass().setAll("candlestick-average-line", "series" + seriesIndex);
    series.setNode(seriesPath);
    getPlotChildren().add(seriesPath);
}
 
Example #16
Source File: AdvCandleStickChartSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Override protected void seriesAdded(Series<Number, Number> series, int seriesIndex) {
    // handle any data already in series
    for (int j = 0; j < series.getData().size(); j++) {
        Data item = series.getData().get(j);
        Node candle = createCandle(seriesIndex, item, j);
        if (shouldAnimate()) {
            candle.setOpacity(0);
            getPlotChildren().add(candle);
            // fade in new candle
            FadeTransition ft = new FadeTransition(Duration.millis(500), candle);
            ft.setToValue(1);
            ft.play();
        } else {
            getPlotChildren().add(candle);
        }
    }
    // create series path
    Path seriesPath = new Path();
    seriesPath.getStyleClass().setAll("candlestick-average-line", "series" + seriesIndex);
    series.setNode(seriesPath);
    getPlotChildren().add(seriesPath);
}
 
Example #17
Source File: AbstractInterpolator.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Adjusts the curveClip so that the curve node does not paint through the
 * given decoration.
 *
 * @param curveShape
 *            A shape describing the {@link ICurve} geometry, which is used
 *            for clipping.
 *
 * @param curveClip
 *            A shape that represents the clip of the curve node,
 *            interpreted in scene coordinates.
 * @param decoration
 *            The decoration to clip the curve node from.
 * @return A shape representing the resulting clip, interpreted in scene
 *         coordinates.
 */
protected Shape clipAtDecoration(Shape curveShape, Shape curveClip,
		Shape decoration) {
	// first intersect curve shape with decoration layout bounds,
	// then subtract the curve shape from the result, and the decoration
	// from that
	Path decorationShapeBounds = new Path(
			Geometry2Shape.toPathElements(NodeUtils
					.localToScene(decoration,
							NodeUtils.getShapeBounds(decoration))
					.toPath()));
	decorationShapeBounds.setFill(Color.RED);
	Shape clip = Shape.intersect(decorationShapeBounds, curveShape);
	clip = Shape.subtract(clip, decoration);
	clip = Shape.subtract(curveClip, clip);
	return clip;
}
 
Example #18
Source File: SmoothedChart.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public void setSeriesColor(final XYChart.Series<X, Y> SERIES, final Paint STROKE, final Paint FILL, final Background SYMBOL_BACKGROUND, final Paint LEGEND_SYMBOL_FILL) {
    if (getData().isEmpty()) { return; }
    if (!getData().contains(SERIES)) { return; }
    if (null != FILL)               { ((Path) ((Group) SERIES.getNode()).getChildren().get(0)).setFill(FILL); }
    if (null != STROKE)             { ((Path) ((Group) SERIES.getNode()).getChildren().get(1)).setStroke(STROKE); }
    if (null != SYMBOL_BACKGROUND)  { setSymbolFill(SERIES, SYMBOL_BACKGROUND); }
    // If enabled the following line won't work in Java 9 because it makes use of com.sun packages!!!
    //if (null != LEGEND_SYMBOL_FILL) { setLegendSymbolFill(SERIES, LEGEND_SYMBOL_FILL); }
}
 
Example #19
Source File: Text3DHelper.java    From FXyzLib with GNU General Public License v3.0 5 votes vote down vote up
private Path generatePath(){
    Path path = new Path(new MoveTo(list.get(0).x,list.get(0).y));
    list.stream().skip(1).forEach(p->path.getElements().add(new LineTo(p.x,p.y)));
    path.getElements().add(new ClosePath());
    path.setStroke(Color.GREEN);
    // Path must be filled to allow Shape.intersect
    path.setFill(Color.RED);
    return path;
}
 
Example #20
Source File: TagBoard.java    From OpenLabeler with Apache License 2.0 5 votes vote down vote up
private ObjectTag addObjectTag(String label, ShapeItem.Type type, Path path) {
   var bounds = path.getBoundsInLocal();
   ObjectModel om = new ObjectModel(label, bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds.getMaxY());
   if (type == POLYGON) {
      om.setPolygon(AppUtils.getPolygonPoints(path));
   }
   return addObjectTag(om, bundle.getString("menu.create"));
}
 
Example #21
Source File: InteractiveGaugeSkin.java    From medusademo with Apache License 2.0 5 votes vote down vote up
private void updateMarkers() {
    markerMap.clear();
    for (Marker marker : getSkinnable().getMarkers()) {
        switch(marker.getMarkerType()) {
            case TRIANGLE: markerMap.put(marker, new Path()); break;
            case DOT     : markerMap.put(marker, new Circle()); break;
            case STANDARD:
            default:       markerMap.put(marker, new Path()); break;
        }
    }
}
 
Example #22
Source File: AmpSkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
private void updateMarkers() {
    markerMap.clear();
    for (Marker marker : gauge.getMarkers()) {
        switch(marker.getMarkerType()) {
            case TRIANGLE: markerMap.put(marker, new Path()); break;
            case DOT     : markerMap.put(marker, new Circle()); break;
            case STANDARD:
            default:       markerMap.put(marker, new Path()); break;
        }
    }
}
 
Example #23
Source File: RotationHandler.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The constructor by default.
 * @param border The selection border.
 */
public RotationHandler(final @NotNull Rectangle border) {
	super();
	final Arc arc = new Arc();
	arc.setCenterX(DEFAULT_SIZE / 2d);
	arc.setRadiusX(DEFAULT_SIZE / 2d);
	arc.setRadiusY(DEFAULT_SIZE / 2d);
	arc.setType(ArcType.OPEN);
	arc.setLength(270d);
	arc.setStroke(DEFAULT_COLOR);
	arc.setStrokeWidth(2.5d);
	arc.setStrokeLineCap(StrokeLineCap.BUTT);
	arc.setFill(new Color(1d, 1d, 1d, 0d));
	getChildren().add(arc);

	final Path arrows = new Path();
	arrows.setStroke(null);
	arrows.setFill(new Color(0d, 0d, 0d, 0.4));
	arrows.getElements().add(new MoveTo(DEFAULT_SIZE + DEFAULT_SIZE / 4d, 0d));
	arrows.getElements().add(new LineTo(DEFAULT_SIZE, DEFAULT_SIZE / 2d));
	arrows.getElements().add(new LineTo(DEFAULT_SIZE - DEFAULT_SIZE / 4d, 0d));
	arrows.getElements().add(new ClosePath());
	getChildren().add(arrows);

	translateXProperty().bind(Bindings.createDoubleBinding(() -> border.getLayoutX() + border.getWidth(), border.xProperty(),
		border.widthProperty(), border.layoutXProperty()));
	translateYProperty().bind(Bindings.createDoubleBinding(() -> border.getLayoutY() + DEFAULT_SIZE, border.yProperty(),
		border.heightProperty(), border.layoutYProperty()));
}
 
Example #24
Source File: QuarterSkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
private void updateMarkers() {
    markerMap.clear();
    for (Marker marker : gauge.getMarkers()) {
        switch(marker.getMarkerType()) {
            case TRIANGLE: markerMap.put(marker, new Path()); break;
            case DOT     : markerMap.put(marker, new Circle()); break;
            case STANDARD:
            default:       markerMap.put(marker, new Path()); break;
        }
    }
}
 
Example #25
Source File: VSkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
private void updateMarkers() {
    markerMap.clear();
    for (Marker marker : gauge.getMarkers()) {
        switch(marker.getMarkerType()) {
            case TRIANGLE: markerMap.put(marker, new Path()); break;
            case DOT     : markerMap.put(marker, new Circle()); break;
            case STANDARD:
            default:       markerMap.put(marker, new Path()); break;
        }
    }
}
 
Example #26
Source File: SunburstChart.java    From charts with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #27
Source File: BatterySkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
private void initGraphics() {
    // Set initial size
    if (Double.compare(gauge.getPrefWidth(), 0.0) <= 0 || Double.compare(gauge.getPrefHeight(), 0.0) <= 0 ||
        Double.compare(gauge.getWidth(), 0.0) <= 0 || Double.compare(gauge.getHeight(), 0.0) <= 0) {
        if (gauge.getPrefWidth() > 0 && gauge.getPrefHeight() > 0) {
            gauge.setPrefSize(gauge.getPrefWidth(), gauge.getPrefHeight());
        } else {
            gauge.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    batteryBackground = new Path();
    batteryBackground.setFillRule(FillRule.EVEN_ODD);
    batteryBackground.setStroke(null);

    battery = new Path();
    battery.setFillRule(FillRule.EVEN_ODD);
    battery.setStroke(null);

    valueText = new Text(String.format(locale, "%.0f%%", gauge.getCurrentValue()));
    valueText.setVisible(gauge.isValueVisible());
    valueText.setManaged(gauge.isValueVisible());

    // Add all nodes
    pane = new Pane();
    pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(1))));
    pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), CornerRadii.EMPTY, Insets.EMPTY)));
    pane.getChildren().setAll(batteryBackground, battery, valueText);

    getChildren().setAll(pane);
}
 
Example #28
Source File: TransitionPath.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void init(Stage primaryStage) {
    Group root = new Group();
    primaryStage.setResizable(false);
    primaryStage.setScene(new Scene(root, 400,260));
    Rectangle rect = new Rectangle (0, 0, 40, 40);
    rect.setArcHeight(10);
    rect.setArcWidth(10);
    rect.setFill(Color.ORANGE);
    root.getChildren().add(rect);
    Path path = PathBuilder.create()
            .elements(
                new MoveTo(20,20),
                new CubicCurveTo(380, 0, 380, 120, 200, 120),
                new CubicCurveTo(0, 120, 0, 240, 380, 240)
            )
            .build();
    path.setStroke(Color.DODGERBLUE);
    path.getStrokeDashArray().setAll(5d,5d);
    root.getChildren().add(path);
    
    pathTransition = PathTransitionBuilder.create()
            .duration(Duration.seconds(4))
            .path(path)
            .node(rect)
            .orientation(OrientationType.ORTHOGONAL_TO_TANGENT)
            .cycleCount(Timeline.INDEFINITE)
            .autoReverse(true)
            .build();
}
 
Example #29
Source File: ToolGraphics.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Strokes a path, by converting the elements to integer coordinates and then
 * aligning them to the center of the pixels, so that it aligns precisely
 * with the JavaFX coordinate system. See the documentation for 
 * javafx.scene.shape.Shape for details.
 * 
 * @param pGraphics The graphics context.
 * @param pPath The path to stroke
 * @param pStyle The line style for the path.
 */
public static void strokeSharpPath(GraphicsContext pGraphics, Path pPath, LineStyle pStyle)
{
	double[] oldDash = pGraphics.getLineDashes();
	pGraphics.setLineDashes(pStyle.getLineDashes());
	double width = pGraphics.getLineWidth();
	pGraphics.setLineWidth(LINE_WIDTH);
	applyPath(pGraphics, pPath);
	pGraphics.stroke();
	pGraphics.setLineDashes(oldDash);
	pGraphics.setLineWidth(width);
}
 
Example #30
Source File: BatterySkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
private Path createHorizontalBattery(final Path PATH) {
    PATH.getElements().clear();
    PATH.getElements().add(new MoveTo(0.825 * size, 0.25 * size));
    PATH.getElements().add(new CubicCurveTo(0.825 * size, 0.25 * size,
                                                  0.075 * size, 0.25 * size,
                                                  0.075 * size, 0.25 * size));
    PATH.getElements().add(new CubicCurveTo(0.03125 * size, 0.25 * size,
                                                  0.0, 0.28125 * size,
                                                  0.0, 0.325 * size));
    PATH.getElements().add(new CubicCurveTo(0.0, 0.325 * size,
                                                  0.0, 0.675 * size,
                                                  0.0, 0.675 * size));
    PATH.getElements().add(new CubicCurveTo(0.0, 0.71875 * size,
                                                  0.03125 * size, 0.75 * size,
                                                  0.075 * size, 0.75 * size));
    PATH.getElements().add(new CubicCurveTo(0.075 * size, 0.75 * size,
                                                  0.825 * size, 0.75 * size,
                                                  0.825 * size, 0.75 * size));
    PATH.getElements().add(new CubicCurveTo(0.86875 * size, 0.75 * size,
                                                  0.9 * size, 0.71875 * size,
                                                  0.9 * size, 0.675 * size));
    PATH.getElements().add(new CubicCurveTo(0.9 * size, 0.675 * size,
                                                  0.9 * size, 0.6 * size,
                                                  0.9 * size, 0.6 * size));
    PATH.getElements().add(new LineTo(size, 0.6 * size));
    PATH.getElements().add(new LineTo(size, 0.4 * size));
    PATH.getElements().add(new LineTo(0.9 * size, 0.4 * size));
    PATH.getElements().add(new CubicCurveTo(0.9 * size, 0.4 * size,
                                                  0.9 * size, 0.325 * size,
                                                  0.9 * size, 0.325 * size));
    PATH.getElements().add(new CubicCurveTo(0.9 * size, 0.28125 * size,
                                                  0.86875 * size, 0.25 * size,
                                                  0.825 * size, 0.25 * size));
    PATH.getElements().add(new ClosePath());
    return PATH;
}