Example usage for javafx.scene.shape SVGPath setFill

List of usage examples for javafx.scene.shape SVGPath setFill

Introduction

In this page you can find the example usage for javafx.scene.shape SVGPath setFill.

Prototype

public final void setFill(Paint value) 

Source Link

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Path pathTriangle = new Path(new MoveTo(50, 0), new LineTo(0, 50), new LineTo(100, 50), new LineTo(50, 0));

    pathTriangle.setFill(Color.LIGHTGRAY);
    pathTriangle.setStroke(Color.BLACK);

    SVGPath svgTriangle = new SVGPath();
    svgTriangle.setContent("M50, 0 L10, 20 L100, 50 Z");
    svgTriangle.setFill(Color.LIGHTGRAY);
    svgTriangle.setStroke(Color.BLACK);

    HBox root = new HBox(pathTriangle, svgTriangle);
    root.setSpacing(10);/*from  w w w .  ja va2 s .com*/
    root.setStyle("-fx-padding: 10;" + "-fx-border-style: solid inside;" + "-fx-border-width: 2;"
            + "-fx-border-insets: 5;" + "-fx-border-radius: 5;" + "-fx-border-color: blue;");

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.setTitle("2D Shapes using Path and SVGPath Classes");
    stage.show();
}

From source file:User.java

private HBox drawRow2() {
    PasswordField passwordField = new PasswordField();
    passwordField.setFont(Font.font("SanSerif", 20));
    passwordField.setPromptText("Password");
    passwordField.setStyle(/*from  www.j  a v a2 s .  c o  m*/
            "-fx-text-fill:black; " + "-fx-prompt-text-fill:gray; " + "-fx-highlight-text-fill:black; "
                    + "-fx-highlight-fill: gray; " + "-fx-background-color: rgba(255, 255, 255, .80); ");

    passwordField.prefWidthProperty().bind(primaryStage.widthProperty().subtract(55));
    user.passwordProperty().bind(passwordField.textProperty());

    // error icon
    SVGPath deniedIcon = new SVGPath();
    deniedIcon.setFill(Color.rgb(255, 0, 0, .9));
    deniedIcon.setStroke(Color.WHITE);//
    deniedIcon.setContent("M24.778,21.419 19.276,15.917 24.777,10.415 21.949,7.585 "
            + "16.447,13.08710.945,7.585 8.117,10.415 13.618,15.917 8.116,21.419 10"
            + ".946,24.248 16.447,18.746 21.948,24.248z");
    deniedIcon.setVisible(false);

    SVGPath grantedIcon = new SVGPath();
    grantedIcon.setFill(Color.rgb(0, 255, 0, .9));
    grantedIcon.setStroke(Color.WHITE);//
    grantedIcon.setContent(
            "M2.379,14.729 5.208,11.899 12.958,19.648 25.877," + "6.733 28.707,9.56112.958,25.308z");
    grantedIcon.setVisible(false);

    //
    StackPane accessIndicator = new StackPane();
    accessIndicator.getChildren().addAll(deniedIcon, grantedIcon);
    accessIndicator.setAlignment(Pos.CENTER_RIGHT);

    grantedIcon.visibleProperty().bind(GRANTED_ACCESS);

    // user hits the enter key
    passwordField.setOnAction(actionEvent -> {
        if (GRANTED_ACCESS.get()) {
            System.out.printf("User %s is granted access.\n", user.getUserName());
            System.out.printf("User %s entered the password: %s\n", user.getUserName(), user.getPassword());
            Platform.exit();
        } else {
            deniedIcon.setVisible(true);
        }

        ATTEMPTS.set(ATTEMPTS.add(1).get());
        System.out.println("Attempts: " + ATTEMPTS.get());
    });

    // listener when the user types into the password field
    passwordField.textProperty().addListener((obs, ov, nv) -> {
        boolean granted = passwordField.getText().equals(MY_PASS);
        GRANTED_ACCESS.set(granted);
        if (granted) {
            deniedIcon.setVisible(false);
        }
    });

    // listener on number of attempts
    ATTEMPTS.addListener((obs, ov, nv) -> {
        if (MAX_ATTEMPTS == nv.intValue()) {
            // failed attempts
            System.out.printf("User %s is denied access.\n", user.getUserName());
            Platform.exit();
        }
    });

    // second row
    HBox row2 = new HBox(3);
    row2.getChildren().addAll(passwordField, accessIndicator);

    return row2;
}