Example usage for javafx.event EventHandler EventHandler

List of usage examples for javafx.event EventHandler EventHandler

Introduction

In this page you can find the example usage for javafx.event EventHandler EventHandler.

Prototype

EventHandler

Source Link

Usage

From source file:gmailclientfx.controllers.LoginController.java

public void btnLogin_click(ActionEvent e) {
    if (!txtEmail.getText().equals("")) {
        String email = txtEmail.getText();
        if (EmailValidator.getInstance().isValid(email)) {
            User user = User.getUserByEmail(email);

            if (!(user == null)) {
                try {

                    GmailClient.setRefreshToken(user.getRefreshToken());
                    GmailClient.refreshAccessToken();

                    Parent loginStage = txtEmail.getParent();
                    loginStage.getScene().getWindow().hide();
                    Parent root;/*from   ww  w . ja va  2  s  .c o  m*/
                    root = FXMLLoader
                            .load(getClass().getClassLoader().getResource("gmailclientfx/views/Home.fxml"));
                    Stage stage = new Stage();
                    stage.setTitle("Home");
                    stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
                        @Override
                        public void handle(WindowEvent e) {
                            Platform.exit();
                            System.exit(0);

                        }
                    });
                    stage.setScene(new Scene(root));
                    stage.show();
                } catch (IOException ex) {
                    Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, null, ex);
                }

            } else {
                try {
                    GmailClient.authorizeUser();
                    String noviEmail = GmailClient.getEmail();
                    String noviRefreshToken = GmailClient.getRefreshToken();
                    User u = User.getUserByEmail(noviEmail);

                    if (u == null) {
                        User.unesiUseraUBazu(new User(noviEmail, noviRefreshToken));
                    }

                    Parent loginStage = txtEmail.getParent();
                    loginStage.getScene().getWindow().hide();
                    Parent root;
                    root = FXMLLoader
                            .load(getClass().getClassLoader().getResource("gmailclientfx/views/Home.fxml"));
                    Stage stage = new Stage();
                    stage.setTitle("Home");
                    stage.setScene(new Scene(root));
                    stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
                        @Override
                        public void handle(WindowEvent e) {
                            Platform.exit();
                            System.exit(0);

                        }
                    });
                    stage.show();

                } catch (IOException ex) {
                    Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        } else {
            lblStatusMsg.setText("Uneseni email nije validan!");
        }
    } else {
        lblStatusMsg.setText("Unesite email!");
    }
}

From source file:kz.aksay.polygraph.desktop.LoginPane.java

public LoginPane() {
    GridPane grid = this;

    grid.setAlignment(Pos.CENTER);/*  www  .j  av a  2  s  . com*/
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));

    sceneTitle = new Text(" ");
    sceneTitle.setId("welcome-text");
    grid.add(sceneTitle, 0, 0, 2, 1);

    userName = new Label(":");
    grid.add(userName, 0, 1);

    userTextField = new TextField();
    grid.add(userTextField, 1, 1);

    password = new Label(":");
    grid.add(password, 0, 2);

    passwordTextBox = new PasswordField();
    grid.add(passwordTextBox, 1, 2);

    signIn = new Button("");
    HBox hbBtn = new HBox(10);
    hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
    hbBtn.getChildren().add(signIn);
    grid.add(hbBtn, 1, 4);

    final Text actionTarget = new Text();
    actionTarget.setId("action-target");
    actionTarget.setWrappingWidth(300);
    grid.add(actionTarget, 0, 6, 2, 1);

    signIn.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            if (isSignInSuccess()) {
                onSignInSuccess.handle(e);
            } else {
                actionTarget.setText(
                        "?   .   !");
            }
        }
    });
}

From source file:org.craftercms.social.migration.MigrationTool.java

@Override
public void start(final Stage primaryStage) throws Exception {
    loadProperties();//from   w  w w .j ava 2 s . c  o  m
    log.debug("Loading Fxml file");
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/scenes/Main.fxml"));
    log.debug("Fxml file Loaded, Starting scene");
    Scene scene = new Scene((VBox) loader.load());
    final MainController controller = loader.getController();
    controller.setScene(scene);
    primaryStage.setScene(scene);
    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
        @Override
        public void handle(final WindowEvent windowEvent) {
            controller.stopTasks();
        }
    });
    primaryStage.setTitle("Crafter Social/Profile Migration Tool (2.3->2.5)");
    log.debug("Showing UI. {}", new Date());
    primaryStage.show();

}

From source file:de.chaosfisch.uploader.gui.renderer.ProgressNodeRenderer.java

@Inject
public ProgressNodeRenderer(final Configuration configuration) {

    final Label progressInfo = LabelBuilder.create().build();
    progressInfo.textProperty().bind(progressBar.progressProperty().multiply(100).asString("%.2f%%"));

    progressInfo.setAlignment(Pos.CENTER_LEFT);
    progressInfo.prefWidthProperty().bind(progressBar.widthProperty().subtract(6));

    progressEta.alignmentProperty().set(Pos.CENTER_RIGHT);
    progressEta.prefWidthProperty().bind(progressBar.widthProperty().subtract(6));
    progressFinish.alignmentProperty().set(Pos.CENTER_RIGHT);
    progressFinish.prefWidthProperty().bind(progressBar.widthProperty().subtract(6));

    progressFinish.setVisible(configuration.getBoolean(DISPLAY_PROGRESS, false));
    progressBytes.setVisible(configuration.getBoolean(DISPLAY_PROGRESS, false));
    progressSpeed.setVisible(!configuration.getBoolean(DISPLAY_PROGRESS, false));
    progressEta.setVisible(!configuration.getBoolean(DISPLAY_PROGRESS, false));

    getChildren().addAll(progressBar, progressInfo, progressEta, progressSpeed, progressFinish, progressBytes);

    setOnMouseEntered(new EventHandler<MouseEvent>() {
        @Override/*ww w. j  av a 2s  .co  m*/
        public void handle(final MouseEvent me) {
            progressFinish.setVisible(!configuration.getBoolean(DISPLAY_PROGRESS, false));
            progressBytes.setVisible(!configuration.getBoolean(DISPLAY_PROGRESS, false));
            progressSpeed.setVisible(configuration.getBoolean(DISPLAY_PROGRESS, false));
            progressEta.setVisible(configuration.getBoolean(DISPLAY_PROGRESS, false));
        }
    });

    setOnMouseExited(new EventHandler<MouseEvent>() {
        @Override
        public void handle(final MouseEvent me) {
            progressFinish.setVisible(configuration.getBoolean(DISPLAY_PROGRESS, false));
            progressBytes.setVisible(configuration.getBoolean(DISPLAY_PROGRESS, false));
            progressSpeed.setVisible(!configuration.getBoolean(DISPLAY_PROGRESS, false));
            progressEta.setVisible(!configuration.getBoolean(DISPLAY_PROGRESS, false));
        }
    });
}

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("Hello Drag And Drop");

    Group root = new Group();
    Scene scene = new Scene(root, 400, 200);
    scene.setFill(Color.LIGHTGREEN);

    final Text source = new Text(50, 100, "DRAG ME");
    source.setScaleX(2.0);/*from w w  w. j a  va2 s.  c o m*/
    source.setScaleY(2.0);

    final Text target = new Text(250, 100, "DROP HERE");
    target.setScaleX(2.0);
    target.setScaleY(2.0);

    source.setOnDragDetected(new EventHandler<MouseEvent>() {
        public void handle(MouseEvent event) {
            /* drag was detected, start drag-and-drop gesture*/
            System.out.println("onDragDetected");

            /* allow any transfer mode */
            Dragboard db = source.startDragAndDrop(TransferMode.ANY);

            /* put a string on dragboard */
            ClipboardContent content = new ClipboardContent();
            content.putString(source.getText());
            db.setContent(content);

            event.consume();
        }
    });

    target.setOnDragOver(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* data is dragged over the target */
            System.out.println("onDragOver");

            /* accept it only if it is  not dragged from the same node 
             * and if it has a string data */
            if (event.getGestureSource() != target && event.getDragboard().hasString()) {
                /* allow for both copying and moving, whatever user chooses */
                event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
            }

            event.consume();
        }
    });

    target.setOnDragEntered(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* the drag-and-drop gesture entered the target */
            System.out.println("onDragEntered");
            /* show to the user that it is an actual gesture target */
            if (event.getGestureSource() != target && event.getDragboard().hasString()) {
                target.setFill(Color.GREEN);
            }

            event.consume();
        }
    });

    target.setOnDragExited(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* mouse moved away, remove the graphical cues */
            target.setFill(Color.BLACK);

            event.consume();
        }
    });

    target.setOnDragDropped(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* data dropped */
            System.out.println("onDragDropped");
            /* if there is a string data on dragboard, read it and use it */
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasString()) {
                target.setText(db.getString());
                success = true;
            }
            /* let the source know whether the string was successfully 
             * transferred and used */
            event.setDropCompleted(success);

            event.consume();
        }
    });

    source.setOnDragDone(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* the drag-and-drop gesture ended */
            System.out.println("onDragDone");
            /* if the data was successfully moved, clear it */
            if (event.getTransferMode() == TransferMode.MOVE) {
                source.setText("");
            }

            event.consume();
        }
    });

    root.getChildren().add(source);
    root.getChildren().add(target);
    stage.setScene(scene);
    stage.show();
}

From source file:account.management.controller.ViewSalaryVoucherController.java

/**
 * Initializes the controller class./*from  w w  w.ja v  a  2 s . co  m*/
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    this.voucher_no.setCellValueFactory(new PropertyValueFactory("id"));
    this.date.setCellValueFactory(new PropertyValueFactory("date"));
    this.section.setCellValueFactory(new PropertyValueFactory("section"));
    this.name.setCellValueFactory(new PropertyValueFactory("name"));
    this.basis.setCellValueFactory(new PropertyValueFactory("basis"));
    this.amount.setCellValueFactory(new PropertyValueFactory("total"));

    final ContextMenu contextMenu = new ContextMenu();
    MenuItem item1 = new MenuItem("    View                  ");
    item1.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent e) {
            Data.salaryVoucher = table.getSelectionModel().getSelectedItem();

            try {
                Parent root = FXMLLoader
                        .load(getClass().getResource(MetaData.viewPath + "EditSalaryVoucher.fxml"));
                Scene scene = new Scene(root);
                Stage stage = new Stage();
                scene.setRoot(root);
                stage.setResizable(false);
                stage.setTitle("Salary Voucher");
                stage.setScene(scene);
                stage.showAndWait();
                int index = table.getSelectionModel().getSelectedIndex();
                getData();

            } catch (IOException ex) {
                Logger.getLogger(ViewSalaryVoucherController.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    });
    contextMenu.getItems().addAll(item1);
    this.table.setContextMenu(contextMenu);

}

From source file:org.openwms.client.fx.core.view.CustomerDataScreen.java

private Node createToolbar() {
    Button removeButton;/*from  w w  w . jav a  2 s .  c  o  m*/
    ToolBar toolBar = ToolBarBuilder.create()
            .items(ButtonBuilder.create().text("Add Customer").onAction(new EventHandler<ActionEvent>() {
                @Override
                public void handle(ActionEvent actionEvent) {
                    controller.addCustomer();
                }
            }).build(), removeButton = ButtonBuilder.create().text("Remove Customer")
                    .onAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent actionEvent) {
                            try {
                                controller.removeCustomer(tableView.getSelectionModel().getSelectedItem());
                                tableView.getSelectionModel()
                                        .select(Math.min(tableView.getSelectionModel().getSelectedIndex(),
                                                tableView.getItems().size() - 1));
                            } catch (AccessDeniedException e) {
                                controller.showErrorDialog();
                            }
                        }
                    }).build())
            .build();
    removeButton.disableProperty().bind(tableView.getSelectionModel().selectedItemProperty().isNull());
    return toolBar;
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Group root = new Group();
    Scene scene = new Scene(root, 260, 80);
    stage.setScene(scene);//  ww  w  .j  a  v a  2s . com
    stage.setTitle("Password Field Sample");

    VBox vb = new VBox();
    vb.setPadding(new Insets(10, 0, 0, 10));
    vb.setSpacing(10);
    HBox hb = new HBox();
    hb.setSpacing(10);
    hb.setAlignment(Pos.CENTER_LEFT);

    Label label = new Label("Password");
    final PasswordField pb = new PasswordField();

    pb.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            if (!pb.getText().equals("abc")) {
                message.setText("Your password is incorrect!");
                message.setTextFill(Color.web("red"));
            } else {
                message.setText("Your password has been confirmed");
                message.setTextFill(Color.web("black"));
            }
            pb.setText("");
        }
    });

    hb.getChildren().addAll(label, pb);
    vb.getChildren().addAll(hb, message);

    scene.setRoot(vb);
    stage.show();
}

From source file:com.properned.application.LocaleListCell.java

private MenuItem getDeleteMenu(Locale locale) {
    MenuItem deleteMenu = new MenuItem(MessageReader.getInstance().getMessage("action.deleteMessageKey"));
    deleteMenu.setOnAction(new EventHandler<ActionEvent>() {
        @Override/*from ww w .ja  va2s. c o m*/
        public void handle(ActionEvent event) {
            logger.info("Clic on delete button for locale '" + locale.toString() + "'");

            String fileName = properties.getMapPropertiesFileByLocale().get(locale).getAbsolutePath();

            Alert alert = new Alert(AlertType.CONFIRMATION);
            alert.setTitle(MessageReader.getInstance().getMessage("manageLocale.confirmDelete.title"));
            alert.setHeaderText(MessageReader.getInstance().getMessage("manageLocale.confirmDelete.header"));
            alert.setContentText(
                    MessageReader.getInstance().getMessage("manageLocale.confirmDelete.content", fileName));
            Optional<ButtonType> result = alert.showAndWait();
            if (result.isPresent() && result.get() == ButtonType.OK) {
                logger.info("User say OK to the confirm");
                properties.deleteLocale(locale);

                // Reload list
                controller.initializeList();
            }

        }
    });

    if (properties.getMapPropertiesByLocale().keySet().size() <= 1) {
        // We can delete only if there is more than the current locale
        deleteMenu.setDisable(true);
    }

    return deleteMenu;
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250);
    root.getChildren().addAll(source, target);

    source.setOnDragDetected(new EventHandler<MouseEvent>() {
        public void handle(MouseEvent event) {
            /* drag was detected, start a drag-and-drop gesture*/
            /* allow any transfer mode */
            Dragboard db = source.startDragAndDrop(TransferMode.ANY);

            /* Put a string on a dragboard */
            ClipboardContent content = new ClipboardContent();
            content.putString(source.getText());
            db.setContent(content);/* w  ww.  j av a 2  s .c  o m*/

            event.consume();
        }
    });
    target.setOnDragOver(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* data is dragged over the target */
            /* accept it only if it is not dragged from the same node 
             * and if it has a string data */
            if (event.getGestureSource() != target && event.getDragboard().hasString()) {
                /* allow for moving */
                event.acceptTransferModes(TransferMode.MOVE);
            }

            event.consume();
        }
    });
    target.setOnDragEntered(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* the drag-and-drop gesture entered the target */
            /* show to the user that it is an actual gesture target */
            if (event.getGestureSource() != target && event.getDragboard().hasString()) {
                target.setFill(Color.GREEN);
            }

            event.consume();
        }
    });
    target.setOnDragExited(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* mouse moved away, remove the graphical cues */
            target.setFill(Color.BLACK);

            event.consume();
        }
    });
    target.setOnDragDropped(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* data dropped */
            /* if there is a string data on dragboard, read it and use it */
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasString()) {
                target.setText(db.getString());
                success = true;
            }
            /* let the source know whether the string was successfully 
             * transferred and used */
            event.setDropCompleted(success);

            event.consume();
        }
    });
    source.setOnDragDone(new EventHandler<DragEvent>() {
        public void handle(DragEvent event) {
            /* the drag and drop gesture ended */
            /* if the data was successfully moved, clear it */
            if (event.getTransferMode() == TransferMode.MOVE) {
                source.setText("");
            }
            event.consume();
        }
    });

    primaryStage.setScene(scene);
    primaryStage.show();
}