javafx.scene.shape.Polyline Java Examples

The following examples show how to use javafx.scene.shape.Polyline. 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: PolylineSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    Polyline polyline = new Polyline(new double[]{
        45, 10,
        10, 80,
        80, 80,
    });
    polyline.setStroke(Color.web("#b9c0c5"));
    polyline.setStrokeWidth(5);
    polyline.getStrokeDashArray().addAll(15d,15d);
    polyline.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));
    polyline.setEffect(effect);
    return polyline;
}
 
Example #2
Source File: PolylineSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    Polyline polyline = new Polyline(new double[]{
        45, 10,
        10, 80,
        80, 80,
    });
    polyline.setStroke(Color.web("#b9c0c5"));
    polyline.setStrokeWidth(5);
    polyline.getStrokeDashArray().addAll(15d,15d);
    polyline.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));
    polyline.setEffect(effect);
    return polyline;
}
 
Example #3
Source File: ShapeConverter.java    From Enzo with Apache License 2.0 5 votes vote down vote up
public static String convertPolyline(final Polyline POLYLINE) {
    final StringBuilder fxPath = new StringBuilder();
    final int           size   = POLYLINE.getPoints().size();
    if (size % 2 == 0) {
        List<Double> coordinates     = POLYLINE.getPoints();
        for (int i = 0 ; i < size ; i += 2) {
            fxPath.append(i == 0 ? "M " : "L ")
                  .append(coordinates.get(i)).append(" ").append(coordinates.get(i + 1)).append(" ");
        }
    }
    return fxPath.toString();
}
 
Example #4
Source File: ShapeConverter.java    From Enzo with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #5
Source File: PolylineSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public PolylineSample() {
    super(180,90);
    // Red stroked not closed triangle
    Polyline polyline1 = new Polyline(new double[]{
        45, 10,
        10, 80,
        80, 80,
    });
    polyline1.setFill(Color.TRANSPARENT);
    polyline1.setStroke(Color.RED);

    // Blue stroked closed triangle
    Polyline polyline2 = new Polyline(new double[]{
        135, 10,
        100, 80,
        170, 80,
        135, 10,
    });
    polyline2.setStroke(Color.DODGERBLUE);
    polyline2.setStrokeWidth(2);
    polyline2.setFill(null);

    
    // Create a group to show all the polylines);
    getChildren().add(new Group(polyline1, polyline2));
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Polyline 1 Fill", polyline1.fillProperty()),
            new SimplePropertySheet.PropDesc("Polyline 1 Stroke", polyline1.strokeProperty()),
            new SimplePropertySheet.PropDesc("Polyline 2 Stroke", polyline2.strokeProperty())
    );
    // END REMOVE ME
}
 
Example #6
Source File: PolylineSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public PolylineSample() {
    super(180,90);
    // Red stroked not closed triangle
    Polyline polyline1 = new Polyline(new double[]{
        45, 10,
        10, 80,
        80, 80,
    });
    polyline1.setFill(Color.TRANSPARENT);
    polyline1.setStroke(Color.RED);

    // Blue stroked closed triangle
    Polyline polyline2 = new Polyline(new double[]{
        135, 10,
        100, 80,
        170, 80,
        135, 10,
    });
    polyline2.setStroke(Color.DODGERBLUE);
    polyline2.setStrokeWidth(2);
    polyline2.setFill(null);

    
    // Create a group to show all the polylines);
    getChildren().add(new Group(polyline1, polyline2));
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Polyline 1 Fill", polyline1.fillProperty()),
            new SimplePropertySheet.PropDesc("Polyline 1 Stroke", polyline1.strokeProperty()),
            new SimplePropertySheet.PropDesc("Polyline 2 Stroke", polyline2.strokeProperty())
    );
    // END REMOVE ME
}
 
Example #7
Source File: PolylineRepresentation.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Group createJFXNode() throws Exception
{
    final Polyline polyline = new Polyline();
    polyline.setStrokeLineJoin(StrokeLineJoin.MITER);
    polyline.setStrokeLineCap(StrokeLineCap.BUTT);
    return new Group(polyline, new Arrow(), new Arrow());
}
 
Example #8
Source File: Shape2Geometry.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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() + ">.");
	}
}
 
Example #9
Source File: CustomNodeExample.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Group doCreateVisual() {
	ImageView ian = new ImageView(new javafx.scene.image.Image(
			getClass().getResource("ibull.jpg").toExternalForm()));
	Polyline body = new Polyline(0, 0, 0, 60, 25, 90, 0, 60, -25, 90, 0,
			60, 0, 25, 25, 0, 0, 25, -25, 0);
	body.setTranslateX(ian.getLayoutBounds().getWidth() / 2
			- body.getLayoutBounds().getWidth() / 2 - 5);
	body.setTranslateY(-15);
	labelText = new Text();
	vbox = new VBox();
	vbox.getChildren().addAll(ian, body, labelText);
	return new Group(vbox);
}
 
Example #10
Source File: JFaceCustomNodeExample.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Group doCreateVisual() {
	ImageView ian = new ImageView(new javafx.scene.image.Image(
			getClass().getResource("ibull.jpg").toExternalForm()));
	Polyline body = new Polyline(0, 0, 0, 60, 25, 90, 0, 60, -25, 90, 0,
			60, 0, 25, 25, 0, 0, 25, -25, 0);
	body.setTranslateX(ian.getLayoutBounds().getWidth() / 2
			- body.getLayoutBounds().getWidth() / 2 - 5);
	body.setTranslateY(-15);
	labelText = new Text();
	vbox = new VBox();
	vbox.getChildren().addAll(ian, body, labelText);
	return new Group(vbox);
}
 
Example #11
Source File: Overlay1Controller.java    From examples-javafx-repos1 with Apache License 2.0 5 votes vote down vote up
private void createOverlayBottomLineUp() {
    overlayBottomLineUp = new Polyline();
    overlayBottomLineUp.getPoints().addAll(
            new Double[]{
                    -10.0d, 4.0d,
                    0.0d, 0.0d,
                    10.0d, 4.0d}
    );
}
 
Example #12
Source File: EmbeddedImage.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Node createErrorNode() {
	Polyline errorNode = new Polyline(
		0, 0,  ERROR_SIZE, 0,  ERROR_SIZE, ERROR_SIZE,  0, ERROR_SIZE,  0, 0,	// rectangle
		ERROR_SIZE, ERROR_SIZE,  0, ERROR_SIZE,  ERROR_SIZE, 0);				// cross
	errorNode.setStroke(Color.RED); //TODO use CSS
	return errorNode;
}
 
Example #13
Source File: Exercise_15_09.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
	// Create a pane 
	Pane pane = new Pane();

	// Create a polyline
	Polyline polyline = new Polyline(new Double(100.0), new Double(100.0));
	polyline.setFill(Color.WHITE);
	polyline.setStroke(Color.BLACK);
	pane.getChildren().add(polyline);
	ObservableList<Double> list = polyline.getPoints();

	// Create and register handler
	pane.setOnKeyPressed(e -> {
		double x = 0, y = 0;
		double length = 10;
		switch (e.getCode()) {
			case DOWN: x = list.get(list.size() - 2);
						  y = list.get(list.size() - 1) + length; break;
			case UP: x = list.get(list.size() - 2);
						y = list.get(list.size() - 1) - length; break;
			case RIGHT: x = list.get(list.size() - 2) + length;
						  y = list.get(list.size() - 1); break;
			case LEFT: x = list.get(list.size() - 2) - length;
						  y = list.get(list.size() - 1); break;

		}
		list.add(x);
		list.add(y); 
	});

	// Create a scene and place it in the stage
	Scene scene = new Scene(pane, 200, 200);
	primaryStage.setTitle("Exercise_15_09"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage

	pane.requestFocus(); // Pane is focused to receive key input 
}
 
Example #14
Source File: DoublePolyline.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public Polyline getPolyline() {
    polyline = new Polyline();
    polyline.getPoints().addAll(getData());
    return polyline;
}
 
Example #15
Source File: Exercise_14_17.java    From Intro-to-Java-Programming with MIT License 4 votes vote down vote up
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
	// Create a pane
	Pane pane = new Pane();

	// Create three polylines and set their properties
	Polyline polyline1 = new Polyline();
	pane.getChildren().add(polyline1);
	polyline1.setStroke(Color.BLACK);
	ObservableList<Double> list = polyline1.getPoints();
	double x1 = 40.0;
	double y1 = 190.0;
	double y2 = 20.0;
	double x3 = 125.0;
	list.addAll(x1, y1, x1, y2, x3, y2, x3, y1 * .60);

	Polyline polyline2 = new Polyline();
	pane.getChildren().add(polyline2);
	polyline2.setStroke(Color.BLACK);
	ObservableList<Double> list2 = polyline2.getPoints();
	list2.addAll((x1 + x3) * .5, y1 * .5, x3, y1 * .25,
		x3 + (x3 - x1) * .5, y1 * .5);

	Polyline polyline3 = new Polyline();
	pane.getChildren().add(polyline3);
	polyline3.setStroke(Color.BLACK);
	ObservableList<Double> list3 = polyline3.getPoints();
	list3.addAll((x1 + x3) * .6, y1 * .80, x3, y1 * .60,
		x3 + (x3 - x1) * .3, y1 * .80);

	// Create a circle and set its properties
	Circle circle = new Circle(x3, y1 * .25, 15);
	circle.setFill(Color.WHITE);
	circle.setStroke(Color.BLACK);
	pane.getChildren().add(circle);

	// Create an arc and set its properties
	Arc arc = new Arc(x1, y1 + 1, 25, 15, 0, 180);
	arc.setFill(Color.WHITE);
	arc.setStroke(Color.BLACK);
	pane.getChildren().add(arc);

	// Create a scene and place it in the stage
	Scene scene = new Scene(pane, 200, 200);
	primaryStage.setTitle("Exercise_14_17"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}
 
Example #16
Source File: Exercise_14_18.java    From Intro-to-Java-Programming with MIT License 4 votes vote down vote up
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
	// Create two panes
	Pane pane1 = new Pane();
	pane1.setRotate(180);
	pane1.setPadding(new Insets(72, 0, 0, 75));
	Pane pane2 = new Pane();

	// Create a polyline
	Polyline polyline1 = new Polyline();
	pane1.getChildren().add(polyline1);             
	ObservableList<Double> list = polyline1.getPoints();
	double scaleFactor = 0.0125;                       
	for (int x = -100; x <= 100; x++) {                
		list.add(x + 200.0);                            
		list.add(scaleFactor * x * x);                  
	}  

	// Create two lines
	Line lineX = new Line(10, 200, 350, 200);                                                
	//pane.getChildren().addAll(stackPane, lineX);

	Line lineY = new Line(lineX.getEndX() / 2, 250, lineX.getEndX() / 2, 30);                                                
	pane2.getChildren().addAll(pane1, lineX, lineY);

	// Create two polylines
	Polyline polyline2 = new Polyline();
	pane2.getChildren().add(polyline2);
	ObservableList<Double> list2 = polyline2.getPoints();
	list2.addAll(lineY.getEndX() - 10, lineY.getEndY() + 20, 
		lineY.getEndX(), lineY.getEndY(), lineY.getEndX() + 10, 
		lineY. getEndY() + 20);

	Polyline polyline3 = new Polyline();
	pane2.getChildren().add(polyline3);
	ObservableList<Double> list3 = polyline3.getPoints();
	list3.addAll(lineX.getEndX() - 20, lineX.getEndY() - 10, 
		lineX.getEndX(), lineX.getEndY(), lineX.getEndX() - 20, 
		lineX. getEndY() + 10);

	// Create two text objects
	Text textX = new Text(lineX.getEndX() - 10, lineX.getEndY() - 20, "X");
	Text textY = new Text(lineY.getEndX() + 20, lineY.getEndY() + 10, "Y");
	pane2.getChildren().addAll(textX, textY);

	// Create a scene and place it in the stage
	Scene scene = new Scene(pane2);
	primaryStage.setTitle("Exercise_14_18"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}
 
Example #17
Source File: DoublePolyline.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public void setPolyline(Polyline polyline) {
    this.polyline = polyline;
}
 
Example #18
Source File: DoublePolyline.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public void clear() {
    points.clear();
    polyline = new Polyline();
}
 
Example #19
Source File: DoublePolyline.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public DoublePolyline() {
    points = new ArrayList<>();
    polyline = new Polyline();
}
 
Example #20
Source File: Shape2Geometry.java    From gef with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Converts the given JavaFX {@link Polyline} to a
 * {@link org.eclipse.gef.geometry.planar.Polyline}.
 *
 * @param polyline
 *            The JavaFX {@link Polyline} to convert.
 * @return The newly created
 *         {@link org.eclipse.gef.geometry.planar.Polyline} that describes
 *         the given {@link Polyline}.
 */
public static org.eclipse.gef.geometry.planar.Polyline toPolyline(
		Polyline polyline) {
	double[] coords = new double[polyline.getPoints().size()];
	for (int i = 0; i < coords.length; i++) {
		coords[i] = polyline.getPoints().get(i).doubleValue();
	}
	return new org.eclipse.gef.geometry.planar.Polyline(coords);
}