Example usage for javafx.scene.effect Blend Blend

List of usage examples for javafx.scene.effect Blend Blend

Introduction

In this page you can find the example usage for javafx.scene.effect Blend Blend.

Prototype

public Blend(BlendMode mode) 

Source Link

Document

Creates a new instance of Blend with the specified mode.

Usage

From source file:com.github.vatbub.tictactoe.view.Main.java

@FXML
// This method is called by the FXMLLoader when initialization is complete
void initialize() {
    // modify the default exception handler to show a good error message on every uncaught exception
    final Thread.UncaughtExceptionHandler currentUncaughtExceptionHandler = Thread
            .getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler((thread, exception) -> {
        if (currentUncaughtExceptionHandler != null) {
            // execute current handler as we only want to append it
            currentUncaughtExceptionHandler.uncaughtException(thread, exception);
        }/*  w  ww .ja  v  a 2 s.c o  m*/
        Platform.runLater(() -> new ExceptionAlert(exception).showAndWait());
    });

    opponentsTurnHBox.heightProperty()
            .addListener((observable, oldValue, newValue) -> updateOpponentsTurnHBox(false));

    aiLevelLabelClipRectangle = new Rectangle(0, 0, 0, 0);
    aiLevelLabelClipRectangle.setEffect(new MotionBlur(0, 10));
    aiLevelLabelPane.setClip(aiLevelLabelClipRectangle);
    aiLevelLabelClipRectangle.heightProperty().bind(aiLevelLabelPane.heightProperty());
    aiLevelLabelPane.widthProperty().addListener((observable, oldValue, newValue) -> updateAILevelLabel(true));

    Rectangle menuSubBoxClipRectangle = new Rectangle(0, 0, 0, 0);
    menuSubBox.setClip(menuSubBoxClipRectangle);
    menuSubBoxClipRectangle.heightProperty().bind(menuSubBox.heightProperty());
    menuSubBoxClipRectangle.widthProperty().bind(menuSubBox.widthProperty());

    Rectangle playOnlineClipRectangle = new Rectangle(0, 0, 0, 0);
    playOnlineClipAnchorPane.setClip(playOnlineClipRectangle);
    playOnlineClipRectangle.heightProperty().bind(playOnlineClipAnchorPane.heightProperty());
    playOnlineClipRectangle.widthProperty().bind(playOnlineClipAnchorPane.widthProperty());

    player1SetSampleName();
    player2SetSampleName();

    gameTable.heightProperty()
            .addListener((observable, oldValue, newValue) -> refreshedNodes.refreshAll(gameTable.getWidth(),
                    oldValue.doubleValue(), gameTable.getWidth(), newValue.doubleValue()));
    gameTable.widthProperty()
            .addListener((observable, oldValue, newValue) -> refreshedNodes.refreshAll(oldValue.doubleValue(),
                    gameTable.getHeight(), newValue.doubleValue(), gameTable.getHeight()));

    player1AIToggle.selectedProperty().addListener((observable, oldValue, newValue) -> {
        showHideAILevelSlider(newValue, player2AIToggle.isSelected());
        player1SetSampleName();
    });
    player2AIToggle.selectedProperty().addListener((observable, oldValue, newValue) -> {
        showHideAILevelSlider(player1AIToggle.isSelected(), newValue);
        player2SetSampleName();
    });

    gameTable.setSelectionModel(null);
    gameTable.heightProperty().addListener((observable, oldValue, newValue) -> {
        Pane header = (Pane) gameTable.lookup("TableHeaderRow");
        if (header.isVisible()) {
            header.setMaxHeight(0);
            header.setMinHeight(0);
            header.setPrefHeight(0);
            header.setVisible(false);
        }
        renderRows();
    });
    gameTable.setRowFactory(param -> {
        TableRow<Row> row = new TableRow<>();
        row.styleProperty().bind(style);

        if (rowFont == null) {
            rowFont = new SimpleObjectProperty<>();
            rowFont.bind(row.fontProperty());
        }

        return row;
    });

    looseImage.fitHeightProperty().bind(looserPane.heightProperty());
    looseImage.fitWidthProperty().bind(looserPane.widthProperty());
    looseImage.fitHeightProperty().addListener((observable, oldValue, newValue) -> reloadImage(looseImage,
            getClass().getResource("loose.png").toString(), looseImage.getFitWidth(), newValue.doubleValue()));
    looseImage.fitWidthProperty().addListener((observable, oldValue, newValue) -> reloadImage(looseImage,
            getClass().getResource("loose.png").toString(), newValue.doubleValue(), looseImage.getFitWidth()));

    confetti.fitHeightProperty().bind(winPane.heightProperty());
    confetti.fitWidthProperty().bind(winPane.widthProperty());
    confetti.fitHeightProperty().addListener((observable, oldValue, newValue) -> reloadImage(confetti,
            getClass().getResource("confetti.png").toString(), confetti.getFitWidth(), newValue.doubleValue()));
    confetti.fitWidthProperty().addListener((observable, oldValue, newValue) -> reloadImage(confetti,
            getClass().getResource("confetti.png").toString(), newValue.doubleValue(), confetti.getFitWidth()));

    aiLevelSlider.valueProperty().addListener((observable, oldValue, newValue) -> updateAILevelLabel());

    playOnlineHyperlink.widthProperty().addListener((observable, oldValue, newValue) -> {
        if (playOnlineAnchorPane.isVisible()) {
            setLowerRightAnchorPaneDimensions(playOnlineHyperlink, currentPlayerLabel, true);
        }
    });
    playOnlineHyperlink.heightProperty().addListener((observable, oldValue, newValue) -> {
        if (playOnlineAnchorPane.isVisible()) {
            setLowerRightAnchorPaneDimensions(playOnlineHyperlink, currentPlayerLabel, true);
        }
    });
    playOnlineHyperlink.textProperty().addListener((observable, oldValue, newValue) -> {
        if (!newValue.equals(oldValue)) {
            if (newValue.contains("ff")) {
                setLowerRightAnchorPaneDimensions(playOnlineHyperlink, currentPlayerLabel, true, 1);
            } else {
                setLowerRightAnchorPaneDimensions(playOnlineHyperlink, currentPlayerLabel, true, -1);
            }
        }
    });

    // Kunami code
    root.setOnKeyPressed(event -> {
        if (KunamiCode.isCompleted(event.getCode())) {
            if (root.getEffect() != null && root.getEffect() instanceof Blend) {
                BlendMode currentMode = ((Blend) root.getEffect()).getMode();
                BlendMode nextMode;
                if (currentMode == BlendMode.values()[BlendMode.values().length - 1]) {
                    nextMode = BlendMode.values()[0];
                } else {
                    nextMode = BlendMode.values()[Arrays.asList(BlendMode.values()).indexOf(currentMode) + 1];
                }
                ((Blend) root.getEffect()).setMode(nextMode);
            } else {
                root.setEffect(new Blend(BlendMode.EXCLUSION));
            }
        }
    });

    // prompt text of the my username field in the online multiplayer menu
    onlineMyUsername.promptTextProperty().bind(player1Name.promptTextProperty());
    onlineMyUsername.textProperty().bindBidirectional(player1Name.textProperty());

    setAccessibleTextsForNodesThatDoNotChange();
    updateAccessibleTexts();

    initBoard();
    initNewGame();
}