Java Code Examples for javafx.scene.shape.Polygon#setStroke()

The following examples show how to use javafx.scene.shape.Polygon#setStroke() . 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: PolygonSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    Polygon polygon = new Polygon(new double[]{
        45 , 10 ,
        10 , 80 ,
        80 , 80 ,
    });
    polygon.setStroke(Color.web("#b9c0c5"));
    polygon.setStrokeWidth(5);
    polygon.getStrokeDashArray().addAll(15d,15d);
    polygon.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));
    polygon.setEffect(effect);
    return polygon;
}
 
Example 2
Source File: PolygonSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    Polygon polygon = new Polygon(new double[]{
        45 , 10 ,
        10 , 80 ,
        80 , 80 ,
    });
    polygon.setStroke(Color.web("#b9c0c5"));
    polygon.setStrokeWidth(5);
    polygon.getStrokeDashArray().addAll(15d,15d);
    polygon.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));
    polygon.setEffect(effect);
    return polygon;
}
 
Example 3
Source File: Exercise_18_36.java    From Intro-to-Java-Programming with MIT License 6 votes vote down vote up
private void displayTriangles(int order, Point2D p1,
		Point2D p2, Point2D p3) {
	if (order == 0) {
		// Draw a triangle to connect three points
		Polygon triangle = new Polygon();
		triangle.getPoints().addAll(p1.getX(), p1.getY(), p2.getX(),
			p2.getY(), p3.getX(), p3.getY());
		triangle.setStroke(Color.BLACK);
		triangle.setFill(Color.BLACK);

		this.getChildren().add(triangle);
	}
	else {
		//Get the midpoint on each edge in the triangle
		Point2D p12= p1.midpoint(p2);
		Point2D p23= p2.midpoint(p3);
		Point2D p31= p3.midpoint(p1);

		// Recursively display three triangles
		displayTriangles(order - 1, p1, p12, p31);
		displayTriangles(order - 1, p12, p2, p23);
		displayTriangles(order - 1, p31, p23, p3);
	}
}
 
Example 4
Source File: PolygonLayoutBoundsBug.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
	final Polygon p = new Polygon(10, 30, 20, 20, 20, 40);
	p.setFill(Color.RED);
	p.setStroke(Color.BLACK);

	final Rectangle r = new Rectangle();
	r.setFill(new Color(0, 0, 1, 0.5));
	r.setX(p.getLayoutBounds().getMinX());
	r.setY(p.getLayoutBounds().getMinY());
	r.setWidth(p.getLayoutBounds().getWidth());
	r.setHeight(p.getLayoutBounds().getHeight());

	Group g = new Group(r, p);
	g.getTransforms().add(new Scale(10, 10));
	Scene scene = new Scene(g, 500, 500);
	primaryStage.setScene(scene);
	primaryStage.sizeToScene();
	primaryStage.show();
}
 
Example 5
Source File: CreationMenuOnClickHandler.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
private Node createArrow(final boolean left) {
	// shape
	final Polygon arrow = new Polygon();
	arrow.getPoints().addAll(left ? LEFT_ARROW_POINTS : RIGHT_ARROW_POINTS);
	// style
	arrow.setStrokeWidth(ARROW_STROKE_WIDTH);
	arrow.setStroke(ARROW_STROKE);
	arrow.setFill(ARROW_FILL);
	// effect
	effectOnHover(arrow, new DropShadow(DROP_SHADOW_RADIUS, getHighlightColor()));
	// action
	arrow.setOnMouseClicked(new EventHandler<MouseEvent>() {
		@Override
		public void handle(MouseEvent event) {
			traverse(left);
		}
	});
	return arrow;
}
 
Example 6
Source File: TriangleCell.java    From fxgraph with Do What The F*ck You Want To Public License 6 votes vote down vote up
@Override
public Region getGraphic(Graph graph) {
	final double width = 50;
	final double height = 50;

	final Polygon view = new Polygon(width / 2, 0, width, height, 0, height);

	view.setStroke(Color.RED);
	view.setFill(Color.RED);

	final Pane pane = new Pane(view);
	pane.setPrefSize(50, 50);
	final Scale scale = new Scale(1, 1);
	view.getTransforms().add(scale);
	scale.xProperty().bind(pane.widthProperty().divide(50));
	scale.yProperty().bind(pane.heightProperty().divide(50));
	CellGestures.makeResizable(pane);

	return pane;
}
 
Example 7
Source File: Exercise_18_19.java    From Intro-to-Java-Programming with MIT License 6 votes vote down vote up
private void displayTriangles(int order, Point2D p1,
		Point2D p2, Point2D p3) {
	if (order == 0) {
		// Draw a triangle to connect three points
		Polygon triangle = new Polygon();
		triangle.getPoints().addAll(p1.getX(), p1.getY(), p2.getX(),
			p2.getY(), p3.getX(), p3.getY());
		triangle.setStroke(Color.BLACK);
		triangle.setFill(Color.WHITE);

		this.getChildren().add(triangle);
	}
	else {
		//Get the midpoint on each edge in the triangle
		Point2D p12= p1.midpoint(p2);
		Point2D p23= p2.midpoint(p3);
		Point2D p31= p3.midpoint(p1);

		// Recursively display three triangles
		displayTriangles(order - 1, p1, p12, p31);
		displayTriangles(order - 1, p12, p2, p23);
		displayTriangles(order - 1, p31, p23, p3);
	}
}
 
Example 8
Source File: MenuItem.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public MenuItem(String name, int width) {
    	int n = name.length();
//        Polygon bg = new Polygon(
//                0, 0,
//                220, 0,
//                245, 25,
//                220, 50,
//                0, 50
//        );
        Polygon bg = new Polygon(
                0, 0,
                width - 20 , 0,
                width, 25,
                width - 20, 50,
                0, 50
        );

        bg.setStroke(Color.color(1, 1, 1, 0.1));//75));
        //bg.setEffect(new GaussianBlur());
        bg.fillProperty().bind(
                Bindings.when(pressedProperty())
                        .then(Color.color(1, 1, 1, 0.35))//Color.color(139D/255D, 69D/255D, 19D/255D, 0.35))
                        .otherwise(Color.color(1, 1, 1, 0.15))
        );

        text = new Text(name);
        text.setTranslateX((18 - n) * 6.5);
        text.setTranslateY(34);
        text.setFont(Font.loadFont(MenuApp.class.getResource("/fonts/Penumbra-HalfSerif-Std_35114.ttf").toExternalForm(), 22));
        text.setFill(Color.LIGHTGOLDENRODYELLOW);//.CORAL);//.WHITE);
        text.effectProperty().bind(
                Bindings.when(hoverProperty())
                        .then(shadow)
                        .otherwise(blur)
        );

        getChildren().addAll(bg, text);
    }
 
Example 9
Source File: Exercise_14_11.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
/** Return a Polygon of specified properties */
private Polygon getPolygon(Circle c) {
	double length = c.getRadius() / 4;
	Polygon p = new Polygon(c.getCenterX(), c.getCenterY() - length,
		c.getCenterX() - length, c.getCenterY() + length, c.getCenterX() + length, 
		c.getCenterY() + length);
	p.setFill(Color.WHITE);
	p.setStroke(Color.BLACK);
	return p;
}
 
Example 10
Source File: Exercise_15_14.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 polygon and set it properties
	Polygon polygon = new Polygon();
	pane.getChildren().add(polygon);
	ObservableList<Double> list = polygon.getPoints();
	list.addAll(40.0, 20.0, 70.0, 40.0, 60.0, 80.0, 45.0, 45.0, 20.0, 60.0);
	polygon.setFill(Color.WHITE);
	polygon.setStroke(Color.BLACK);

	// Create and register the handle
	pane.setOnMouseMoved(e -> {
		pane.getChildren().clear();
		Text text = new Text(e.getX(), e.getY(), "Mouse point is " +
			(polygon.contains(e.getX(), e.getY()) ? "inside " : "outside ") +
			"the polygon");
		pane.getChildren().addAll(polygon, text);
	});

	// Create a scene and place it in the stage
	Scene scene = new Scene(pane, 300, 150);
	primaryStage.setTitle("Exercise_15_14"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}
 
Example 11
Source File: Exercise_15_20.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
/** Create a polygon */
private void drawTriangle(Pane pane, ArrayList<Circle> p) {
	Polygon polygon = new Polygon();
	pane.getChildren().add(polygon);
	ObservableList<Double> points = polygon.getPoints();
	for (int i = 0; i < p.size(); i++) {
		points.add(p.get(i).getCenterX());
		points.add(p.get(i).getCenterY());
	}
	polygon.setFill(Color.WHITE);
	polygon.setStroke(Color.BLACK);
}
 
Example 12
Source File: Civ6MenuItem.java    From FXTutorials with MIT License 5 votes vote down vote up
public Civ6MenuItem(String name) {
    Polygon bg = new Polygon(
            0, 0,
            200, 0,
            215, 15,
            200, 30,
            0, 30
    );
    bg.setStroke(Color.color(1, 1, 1, 0.75));
    bg.setEffect(new GaussianBlur());

    bg.fillProperty().bind(
            Bindings.when(pressedProperty())
                    .then(Color.color(0, 0, 0, 0.75))
                    .otherwise(Color.color(0, 0, 0, 0.25))
    );

    text = new Text(name);
    text.setTranslateX(5);
    text.setTranslateY(20);
    text.setFont(Font.loadFont(Civ6MenuApp.class.getResource("res/Penumbra-HalfSerif-Std_35114.ttf").toExternalForm(), 14));
    text.setFill(Color.WHITE);

    text.effectProperty().bind(
            Bindings.when(hoverProperty())
                    .then(shadow)
                    .otherwise(blur)
    );

    getChildren().addAll(bg, text);
}
 
Example 13
Source File: CustomNodeSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static Polygon createUMLArrow() {
    Polygon polygon = new Polygon(new double[]{
        7.5, 0,
        15, 15,
        7.51, 15,
        7.51, 40,
        7.49, 40,
        7.49, 15,
        0, 15
    });
    polygon.setFill(Color.WHITE);
    polygon.setStroke(Color.BLACK);
    return polygon;
}
 
Example 14
Source File: PolygonSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public PolygonSample() {
    super(180,90);
    // Simple red filled triangle
    Polygon polygon1 = new Polygon(new double[]{
        45 , 10 ,
        10 , 80 ,
        80 , 80 ,
    });
    polygon1.setFill(Color.RED);

    // Blue stroked polygon
    Polygon polygon2 = new Polygon(new double[]{
        135, 15,
        160, 30,
        160, 60,
        135, 75,
        110, 60,
        110, 30
    });
    polygon2.setStroke(Color.DODGERBLUE);
    polygon2.setStrokeWidth(2);
    polygon2.setFill(null);

    
    // Create a group to show all the polygons);
    getChildren().add(new Group(polygon1, polygon2));
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Polygon 1 Fill", polygon1.fillProperty()),
            new SimplePropertySheet.PropDesc("Polygon 2 Stroke", polygon2.strokeProperty())
    );
    // END REMOVE ME
}
 
Example 15
Source File: CustomNodeSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static Polygon createUMLArrow() {
    Polygon polygon = new Polygon(new double[]{
        7.5, 0,
        15, 15,
        7.51, 15,
        7.51, 40,
        7.49, 40,
        7.49, 15,
        0, 15
    });
    polygon.setFill(Color.WHITE);
    polygon.setStroke(Color.BLACK);
    return polygon;
}
 
Example 16
Source File: PolygonSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public PolygonSample() {
    super(180,90);
    // Simple red filled triangle
    Polygon polygon1 = new Polygon(new double[]{
        45 , 10 ,
        10 , 80 ,
        80 , 80 ,
    });
    polygon1.setFill(Color.RED);

    // Blue stroked polygon
    Polygon polygon2 = new Polygon(new double[]{
        135, 15,
        160, 30,
        160, 60,
        135, 75,
        110, 60,
        110, 30
    });
    polygon2.setStroke(Color.DODGERBLUE);
    polygon2.setStrokeWidth(2);
    polygon2.setFill(null);

    
    // Create a group to show all the polygons);
    getChildren().add(new Group(polygon1, polygon2));
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Polygon 1 Fill", polygon1.fillProperty()),
            new SimplePropertySheet.PropDesc("Polygon 2 Stroke", polygon2.strokeProperty())
    );
    // END REMOVE ME
}
 
Example 17
Source File: Exercise_14_24.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 scanner
	Scanner input = new Scanner(System.in);

	// Create a pane
	Pane pane = new Pane();

	// Create a polygon
	Polygon polygon = new Polygon();
	polygon.setFill(Color.WHITE);
	polygon.setStroke(Color.BLACK);
	pane.getChildren().add(polygon);
	ObservableList<Double> list = polygon.getPoints();

	// Prompt the user to enter the coordinates of five points
	System.out.print("Enter five points: ");
	for (int i = 0; i < 8; i++) {
		list.add(input.nextDouble());
	}
	double x = input.nextDouble();
	double y = input.nextDouble();

	// Create a circle
	Circle circle = new Circle(x, y, 5);
	pane.getChildren().add(circle);

	// Create a Text
	Text text = new Text("        The point is " + 
		(polygon.contains(x, y) ? "" : "not ") + "inside the polygon  ");

	// Create a vbox
	VBox vbox = new VBox(5);
	vbox.getChildren().addAll(pane, text);

	// Create a Scene and place it in the stage
	Scene scene = new Scene(vbox);
	primaryStage.setTitle("Exercise_14_24"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}
 
Example 18
Source File: Exercise_14_25.java    From Intro-to-Java-Programming with MIT License 4 votes vote down vote up
public void start(Stage primaryStage) {
	// Create a pane
	Pane pane = new Pane();
	pane.setPadding(new Insets(10, 10, 10, 10));

	// Create a circle
	Circle circle = new Circle(60, 60, 40);
	circle.setFill(Color.WHITE);
	circle.setStroke(Color.BLACK);
	pane.getChildren().addAll(circle);

	// Create a polygon
	Polygon polygon = new Polygon();
	pane.getChildren().add(polygon);
	polygon.setFill(Color.WHITE);
	polygon.setStroke(Color.BLACK);
	ObservableList<Double> list = polygon.getPoints();

	// Generate random angles in radians between 0 and 2PI
	ArrayList<Double> angles = new ArrayList<>();
	for (int i = 0; angles.size() < 5; i++) {
		double angle = (Math.random() * (2 * Math.PI));
		if (!angles.contains(angle)) {
			angles.add(angle);
		}
	}

	// Sort angles clockwise
	java.util.Collections.sort(angles);

	// Get 5 points on the circle
	for (int i = 0; i < angles.size(); i++) {
		list.add(circle.getCenterX() + circle.getRadius() * 
			Math.cos(angles.get(i)));
		list.add(circle.getCenterY() - circle.getRadius() * 
			Math.sin(angles.get(i)));
	}

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