Example usage for javafx.scene.control Button Button

List of usage examples for javafx.scene.control Button Button

Introduction

In this page you can find the example usage for javafx.scene.control Button Button.

Prototype

public Button(String text) 

Source Link

Document

Creates a button with the specified text as its label.

Usage

From source file:ijfx.ui.canvas.FxCanvasTester.java

@Override
public void start(Stage primaryStage) {

    final SCIFIO scifio = new SCIFIO();
    MenuBar menuBar = new MenuBar();
    InputControl parameterInput = null;//w  ww .  j  av  a 2  s.co  m
    try {
        System.setProperty("imagej.legacy.sync", "true");
        //reader.getContext().inject(this);
        ImageJ imagej = new ImageJ();
        context = imagej.getContext();
        CommandInfo command = imagej.command().getCommand(GaussianBlur.class);

        CommandModuleItem input = command.getInput("sigma");
        Class<?> type = input.getType();
        if (type == double.class) {
            type = Double.class;
        }

        context.inject(this);

        GaussianBlur module = new GaussianBlur();

        imagej.ui().showUI();

        //reader = scifio.initializer().initializeReader("./stack.tif");
        commandService.run(OpenFile.class, true, new HashMap<String, Object>());

        menuBar = new MenuBar();
        menuService.createMenus(new FxMenuCreator(), menuBar);
        ObjectMapper mapper = new ObjectMapper();
        SimpleModule simpleModule = new SimpleModule("ModuleSerializer");
        // simpleModule.addSerializer(ModuleItem<?>.class,new ModuleItemSerializer());
        simpleModule.addSerializer(ModuleInfo.class, new ModuleSerializer());
        simpleModule.addSerializer(ModuleItem.class, new ModuleItemSerializer());
        mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
        mapper.registerModule(simpleModule);

        mapper.writeValue(new File("modules.json"), moduleService.getModules());

    } catch (Exception ex) {
        ImageJFX.getLogger();
    }

    //imageView.fitImageToScreen();
    Button reset = new Button("Reset");

    reset.setOnAction(event -> update());

    BorderPane pane = new BorderPane();

    Button test = new Button("Test");

    AnchorPane root = new AnchorPane();
    root.getChildren().add(pane);
    root.getStylesheets().add(ArcMenu.class.getResource("arc-default.css").toExternalForm());
    root.getStylesheets().add(ImageJFX.class.getResource(("flatterfx.css")).toExternalForm());
    AnchorPane.setTopAnchor(pane, 0.0);
    AnchorPane.setBottomAnchor(pane, 0.0);
    AnchorPane.setLeftAnchor(pane, 0.0);
    AnchorPane.setRightAnchor(pane, 0.0);
    pane.setTop(menuBar);

    HBox vbox = new HBox();
    vbox.getChildren().addAll(reset, test, parameterInput);
    vbox.setSpacing(10);
    vbox.setPadding(new Insets(10, 10, 10, 10));
    // update();
    pane.setCenter(ImageWindowContainer.getInstance());
    // pane.setPrefSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
    pane.setBottom(vbox);

    Scene scene = new Scene(root, 600, 600);

    test.setOnAction(event -> {

        test();
    });

    primaryStage.setTitle("ImageCanvasTest");
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:dsfixgui.view.DSFHudPane.java

private void initialize() {

    //Basic layout
    this.setFitToWidth(true);

    spacerColumn = new ColumnConstraints();
    spacerColumn.setFillWidth(true);//from   w  w  w. j  ava2 s .  c  om
    spacerColumn.setPercentWidth(3.0);
    primaryColumn = new ColumnConstraints();
    primaryColumn.setFillWidth(true);
    primaryColumn.setPercentWidth(95.0);
    primaryPane = new GridPane();
    primaryPane.getColumnConstraints().addAll(spacerColumn, primaryColumn);
    primaryVBox = new VBox();
    primaryVBox.getStyleClass().add("spacing_15");
    primaryPane.add(primaryVBox, 1, 0);
    titleLabel = new Label(HUD.toUpperCase() + " " + SETTINGS.toUpperCase());
    titleLabel.getStyleClass().add("settings_title");
    titleBar = new HBox();
    titleBar.setAlignment(Pos.CENTER);
    titleBar.getChildren().add(titleLabel);
    restoreDefaultsBar = new HBox();
    restoreDefaultsBar.setAlignment(Pos.CENTER);
    restoreDefaultsBar.setSpacing(5.0);
    applySettingsButton = new Button(APPLY_SETTINGS);
    restoreDefaultsButton = new Button(RESTORE_DEFAULTS);
    applySettingsButton.getStyleClass().add("translate_y_4");
    restoreDefaultsButton.getStyleClass().add("translate_y_4");
    restoreDefaultsBar.getChildren().addAll(applySettingsButton, restoreDefaultsButton);
    spacerHBox = new HBox();
    spacerHBox.setMinHeight(10.0);
    bottomSpacerHBox = new HBox();
    bottomSpacerHBox.setMinHeight(10.0);

    /////////////////////SETTINGS PANES/////////////////////
    //
    //
    //Toggle HUD Modifications
    hudModsPane = new FlowPane();
    hudModsPane.getStyleClass().add("settings_pane");
    hudModsLabel = new Label(HUD_MODS_LABEL + "  ");
    hudModsLabel.getStyleClass().addAll("bold_text", "font_12_pt");
    hudModsLabel.setTooltip(new Tooltip(HUD_MODS_TT));
    hudModsPicker = new ComboBox(FXCollections.observableArrayList(DISABLE_ENABLE));
    if (config.enableHudMod.get() == 0) {
        hudModsPicker.setValue(hudModsPicker.getItems().get(0));
    } else {
        hudModsPicker.setValue(hudModsPicker.getItems().get(1));
    }
    hudModsPane.getChildren().addAll(hudModsLabel, hudModsPicker);
    //
    //Minimal HUD
    minimalHUDPane = new FlowPane();
    minimalHUDPane.getStyleClass().add("settings_pane");
    minimalHUDLabel = new Label(MINIMAL_HUD_LABEL + "  ");
    minimalHUDLabel.getStyleClass().addAll("bold_text", "font_12_pt");
    minimalHUDLabel.setTooltip(new Tooltip(MIN_HUD_TT));
    minimalHUDPicker = new ComboBox(FXCollections.observableArrayList(DISABLE_ENABLE));
    if (config.enableMinimalHud.get() == 0) {
        minimalHUDPicker.setValue(minimalHUDPicker.getItems().get(0));
    } else {
        minimalHUDPicker.setValue(minimalHUDPicker.getItems().get(1));
    }
    minimalHUDPane.getChildren().addAll(minimalHUDLabel, minimalHUDPicker);
    //
    //HUD Scale
    hudScalePane = new FlowPane();
    hudScalePane.getStyleClass().add("settings_pane");
    hudScaleLabel = new Label(HUD_SCALE_LABEL + "  ");
    hudScaleLabel.getStyleClass().addAll("bold_text", "font_12_pt");
    hudScaleLabel.setTooltip(new Tooltip(HUD_SCALE_TT));
    hudScaleField = new TextField(config.hudScaleFactor.toString());
    hudScaleField.getStyleClass().add("settings_med_text_field");
    hudScalePane.getChildren().addAll(hudScaleLabel, hudScaleField);
    //
    //HUD Opacities Parent Label
    hudOpacitiesPane = new FlowPane();
    hudOpacitiesPane.getStyleClass().add("settings_pane");
    hudOpacitiesLabel = new Label(HUD_OPACITIES_LABEL + "  ");
    hudOpacitiesLabel.getStyleClass().addAll("bold_text", "font_14_pt");
    hudOpacitiesLabel.setTooltip(new Tooltip(HUD_OPS_TT));
    hudOpacitiesPane.getChildren().addAll(hudOpacitiesLabel);
    //
    //Top Left HUD Opacity
    topLeftHUDOpPane = new FlowPane();
    topLeftHUDOpPane.getStyleClass().add("settings_pane");
    topLeftHUDOpLabel = new Label(TOP_LEFT_HUD_OP_LABEL + "  ");
    topLeftHUDOpLabel.getStyleClass().addAll("bold_text", "font_12_pt");
    topLeftHUDOpLabel.setTooltip(new Tooltip(TOP_LEFT_HUD_TT));
    topLeftHUDOpField = new TextField(
            config.hudTopLeftOpacity.toString().substring(0, config.hudTopLeftOpacity.length() - 1));
    topLeftHUDOpField.getStyleClass().add("settings_med_text_field");
    topLeftHUDOpPane.getChildren().addAll(topLeftHUDOpLabel, topLeftHUDOpField);
    //
    //Bottom Left HUD Opacity
    bottomLeftHUDOpPane = new FlowPane();
    bottomLeftHUDOpPane.getStyleClass().add("settings_pane");
    bottomLeftHUDOpLabel = new Label(BOTTOM_LEFT_HUD_OP_LABEL + "  ");
    bottomLeftHUDOpLabel.getStyleClass().addAll("bold_text", "font_12_pt");
    bottomLeftHUDOpLabel.setTooltip(new Tooltip(BOTTOM_LEFT_HUD_TT));
    bottomLeftHUDOpField = new TextField(
            config.hudBottomLeftOpacity.toString().substring(0, config.hudBottomLeftOpacity.length() - 1));
    bottomLeftHUDOpField.getStyleClass().add("settings_med_text_field");
    bottomLeftHUDOpPane.getChildren().addAll(bottomLeftHUDOpLabel, bottomLeftHUDOpField);
    //
    //Bottom Riht HUD Opacity
    bottomRightHUDOpPane = new FlowPane();
    bottomRightHUDOpPane.getStyleClass().add("settings_pane");
    bottomRightHUDOpLabel = new Label(BOTTOM_RIGHT_HUD_OP_LABEL + "  ");
    bottomRightHUDOpLabel.getStyleClass().addAll("bold_text", "font_12_pt");
    bottomRightHUDOpLabel.setTooltip(new Tooltip(BOTTOM_RIGHT_HUD_TT));
    bottomRightHUDOpField = new TextField(
            config.hudBottomRightOpacity.toString().substring(0, config.hudBottomRightOpacity.length() - 1));
    bottomRightHUDOpField.getStyleClass().add("settings_med_text_field");
    bottomRightHUDOpPane.getChildren().addAll(bottomRightHUDOpLabel, bottomRightHUDOpField);

    if (config.enableHudMod.get() == 0) {
        minimalHUDPicker.setDisable(true);
        hudScaleField.setDisable(true);
        topLeftHUDOpField.setDisable(true);
        bottomLeftHUDOpField.setDisable(true);
        bottomRightHUDOpField.setDisable(true);
    }

    primaryVBox.getChildren().addAll(titleBar, restoreDefaultsBar, spacerHBox, hudModsPane, minimalHUDPane,
            hudScalePane, hudOpacitiesPane, topLeftHUDOpPane, bottomLeftHUDOpPane, bottomRightHUDOpPane,
            bottomSpacerHBox);

    initializeEventHandlers();

    this.setContent(primaryPane);
}

From source file:RemoveDuplicateFiles.java

public static Scene makeScene() {
    //Setup the main BorderPane (Holds all the things)
    BorderPane backPane = new BorderPane();

    //----------------------------------------------------------------------
    //Setup the Main Menu Buttons & Pane
    sortFilesButton = new Button("Sort Files");
    batchRenameButton = new Button("Batch Rename Files");

    HBox mainButtons = new HBox();
    mainButtons.setPadding(new Insets(15, 12, 15, 12));
    mainButtons.setSpacing(10);//from w ww.  jav  a 2 s .c  om
    mainButtons.setStyle(BUTTON_STYLE);

    mainButtons.getChildren().add(sortFilesButton);
    mainButtons.getChildren().add(batchRenameButton);

    backPane.setTop(mainButtons);

    //----------------------------------------------------------------------
    //Setup the filetypes box
    HBox fileTypePane = GUIFactories.getFileTypeBox(fileTypes);
    backPane.setBottom(fileTypePane);

    //----------------------------------------------------------------------
    //Setup the FileType Pre-set Buttons
    VBox preSets = GUIFactories.getPresets(fileTypes);
    backPane.setRight(preSets);

    //----------------------------------------------------------------------
    //Setup the center GridPane
    rmvButton = new Button("Remove Duplicates");
    actionTarget = new Text();

    GridPane grid = GUIFactories.getCenterPane(address, rmvButton, actionTarget);
    backPane.setCenter(grid);

    //----------------------------------------------------------------------
    Scene scene = new Scene(backPane, WIDTH, HEIGHT);
    return scene;

}

From source file:com.bdb.weather.display.freeplot.FreePlot.java

/**
 * Create the panel that allows the user to select what series are displayed
 * /*from w  ww.  ja va 2s. c o m*/
 * @param controls The series display controls
 * 
 * @return The JavaFX Node
 */
private Node createDataSelectionPanel(Collection<SeriesGroupControl> controls) {
    BorderPane p = new BorderPane();

    VBox box = new VBox();

    Button b = new Button(LOAD_DATA_BUTTON);
    b.setOnAction((event) -> {
        loadData();
        displayData();
    });
    //b.setActionCommand(LOAD_DATA_BUTTON);
    //b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    box.getChildren().add(b);

    for (SeriesGroupControl control : controls) {
        Node collectionPanel = control;
        box.getChildren().add(collectionPanel);
    }

    //box.getChildren().add(VBox.createVerticalGlue());

    p.setTop(box);
    p.setCenter(new FlowPane());

    return p;
}

From source file:uk.co.everywheremusic.viewcontroller.SetupScene.java

private void startSetupWindow(Stage primaryStage) {
    try {//  w ww .  ja  v a 2 s  .  c om
        installFolder = new File(".").getCanonicalPath() + Globals.INSTALL_EXT;
    } catch (IOException ex) {
        Logger.getLogger(SetupScene.class.getName()).log(Level.SEVERE, null, ex);
        installFolder = System.getProperty("user.dir") + Globals.INSTALL_EXT;
    }

    primaryStage.setTitle(Globals.APP_NAME);

    grid = new GridPane();
    grid.setAlignment(Pos.CENTER);
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));

    column1 = new ColumnConstraints(100, 100, Double.MAX_VALUE);
    column1.setHgrow(Priority.ALWAYS);
    column2 = new ColumnConstraints(100, 100, Double.MAX_VALUE);
    column2.setHgrow(Priority.ALWAYS);
    column3 = new ColumnConstraints(100, 100, Double.MAX_VALUE);
    column3.setHgrow(Priority.ALWAYS);
    column4 = new ColumnConstraints(100, 100, Double.MAX_VALUE);
    column4.setHgrow(Priority.ALWAYS);
    grid.getColumnConstraints().addAll(column1, column2, column3, column4);

    sceneTitle = new Label(Globals.SETUP_FRAME_TITLE);
    sceneTitle.setId(Globals.CSS_TITLE_ID);
    sceneTitle.setPrefWidth(Double.MAX_VALUE);
    sceneTitle.setAlignment(Pos.CENTER);

    ImageView imageView = null;
    try {

        imageView = new ImageView();
        String img = new File(Globals.IC_LOGO).toURI().toURL().toString();
        imgLogo = new Image(img);

        imageView.setImage(imgLogo);

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

    GridPane titlePane = new GridPane();
    ColumnConstraints c1 = new ColumnConstraints(50);
    ColumnConstraints c2 = new ColumnConstraints(400);
    titlePane.getColumnConstraints().addAll(c1, c2);
    titlePane.add(imageView, 0, 0);
    titlePane.add(sceneTitle, 1, 0);
    titlePane.setAlignment(Pos.CENTER);
    grid.add(titlePane, 0, 0, 4, 1);

    lblFolder = new Label(Globals.SETUP_LBL_MUSIC_FOLDER);
    grid.add(lblFolder, 0, 2, 3, 1);

    txtFolder = new TextField();
    txtFolder.setText("/home/kyle/Music/Test music");
    grid.add(txtFolder, 0, 3, 3, 1);

    btnFolder = new Button(Globals.SETUP_BTN_MUSIC_FOLDER);
    btnFolder.setPrefWidth(Double.MAX_VALUE);
    grid.add(btnFolder, 3, 3);

    final DirectoryChooser dirChooser = new DirectoryChooser();

    btnFolder.setOnAction((ActionEvent event) -> {
        File dir = dirChooser.showDialog(primaryStage);
        if (dir != null) {
            txtFolder.setText(dir.getAbsolutePath());
        }
    });

    lblPassword = new Label("Choose a password:");
    grid.add(lblPassword, 0, 4, 2, 1);

    lblConfirmPassword = new Label("Confirm your password:");
    grid.add(lblConfirmPassword, 2, 4, 2, 1);

    txtPassword = new PasswordField();
    grid.add(txtPassword, 0, 5, 2, 1);

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

    textArea = new TextArea();
    textArea.setPrefHeight(Double.MAX_VALUE);
    textArea.setDisable(true);
    textArea.setWrapText(true);
    grid.add(textArea, 0, 7, 4, 2);

    StackPane progressPane = new StackPane();
    lblProgress = new Label(Globals.SETUP_LBL_PERCENT);
    lblProgress.setId(Globals.CSS_PROGBAR_LBL_ID);
    lblProgress.setVisible(false);
    progressBar = new ProgressBar(0);
    progressBar.setPrefWidth(Double.MAX_VALUE);
    progressBar.setVisible(false);
    progressPane.getChildren().addAll(progressBar, lblProgress);
    progressPane.setAlignment(Pos.CENTER_RIGHT);
    grid.add(progressPane, 0, 11, 3, 1);

    StackPane buttonPane = new StackPane();
    btnInstall = new Button(Globals.SETUP_BTN_INSTALL);
    btnInstall.setPrefWidth(Double.MAX_VALUE);
    btnDone = new Button(Globals.SETUP_BTN_DONE);
    btnDone.setPrefWidth(Double.MAX_VALUE);
    btnDone.setVisible(false);
    buttonPane.getChildren().addAll(btnInstall, btnDone);
    grid.add(buttonPane, 3, 11);

    btnInstall.setOnAction((ActionEvent event) -> {

        boolean valid = validateForm();
        if (valid) {

            lblFolder.setDisable(true);
            txtFolder.setDisable(true);
            btnFolder.setDisable(true);
            lblPassword.setDisable(true);
            txtPassword.setDisable(true);
            lblConfirmPassword.setDisable(true);
            txtConfirmPassword.setDisable(true);

            textArea.setDisable(false);
            lblProgress.setVisible(true);
            progressBar.setVisible(true);
            btnInstall.setDisable(true);

            musicFolder = txtFolder.getText();
            password = txtPassword.getText();

            setupWorker = createSetupWorker();
            progressBar.progressProperty().unbind();
            progressBar.progressProperty().bind(setupWorker.progressProperty());

            setupWorker.messageProperty().addListener(
                    (ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
                        String[] values = newValue.split("\\|");
                        lblProgress.setText(values[0] + "%");
                        textArea.appendText(values[1] + "\n");

                        if (values[1].equals(Globals.SETUP_MSG_DONE)) {
                            btnInstall.setVisible(false);
                            btnDone.setVisible(true);
                        }

                    });

            new Thread(setupWorker).start();

        }
    });

    btnDone.setOnAction((ActionEvent event) -> {
        primaryStage.hide();
        new ServerScene(installFolder, musicFolder).showWindow(new Stage());
    });

    try {
        String imgUrl = new File(Globals.IC_LOGO).toURI().toURL().toString();
        javafx.scene.image.Image i = new javafx.scene.image.Image(imgUrl);
        primaryStage.getIcons().add(i);
    } catch (MalformedURLException ex) {
        Logger.getLogger(ServerScene.class.getName()).log(Level.SEVERE, null, ex);
    }

    scene = new Scene(grid, 600, 400);
    primaryStage.setScene(scene);

    scene.getStylesheets().add(SetupScene.class.getResource(Globals.CSS_FILE).toExternalForm());
    //  grid.setGridLinesVisible(true);
    primaryStage.show();
}

From source file:Main.java

private static Node createConfirmationPanel() {
    final Label acceptanceLabel = new Label("Not Available");

    final Button acceptButton = new Button("Accept");
    acceptButton.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(final ActionEvent event) {
            acceptanceLabel.setText("Accepted");
        }//from  w ww  .  j  a v  a2  s . co m
    });

    final Button declineButton = new Button("Decline");
    declineButton.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(final ActionEvent event) {
            acceptanceLabel.setText("Declined");
        }
    });

    final HBox panel = createHBox(6, acceptButton, declineButton, acceptanceLabel);
    panel.setAlignment(Pos.CENTER_LEFT);
    configureBorder(panel);

    return panel;
}

From source file:gov.va.isaac.sync.view.SyncView.java

private void initGui() {
    root_ = new BorderPane();
    root_.setPrefWidth(550);/*w  w w. j  a  v  a 2s  .co m*/

    VBox titleBox = new VBox();

    Label title = new Label("Datastore Synchronization");
    title.getStyleClass().add("titleLabel");
    title.setAlignment(Pos.CENTER);
    title.setMaxWidth(Double.MAX_VALUE);
    title.setPadding(new Insets(10));
    titleBox.getChildren().add(title);
    titleBox.getStyleClass().add("headerBackground");

    url_ = AppContext.getAppConfiguration().getCurrentChangeSetUrl();
    String urlType = AppContext.getAppConfiguration().getChangeSetUrlTypeName();

    String syncUsername = ExtendedAppContext.getCurrentlyLoggedInUserProfile().getSyncUsername();
    if (StringUtils.isBlank(syncUsername)) {
        syncUsername = ExtendedAppContext.getCurrentlyLoggedInUser();
    }

    url_ = syncService_.substituteURL(url_, syncUsername);

    Label info = new CopyableLabel("Sync using " + urlType + ": " + url_);
    info.setTooltip(new Tooltip(url_));

    titleBox.getChildren().add(info);

    titleBox.setPadding(new Insets(5, 5, 5, 5));
    root_.setTop(titleBox);

    VBox centerContent = new VBox();
    centerContent.setFillWidth(true);
    centerContent.setPrefWidth(Double.MAX_VALUE);
    centerContent.setPadding(new Insets(10));
    centerContent.getStyleClass().add("itemBorder");
    centerContent.setSpacing(10.0);

    centerContent.getChildren().add(new Label("Status:"));

    summary_ = new TextArea();
    summary_.setWrapText(true);
    summary_.setEditable(false);
    summary_.setMaxWidth(Double.MAX_VALUE);
    summary_.setMaxHeight(Double.MAX_VALUE);
    summary_.setPrefHeight(150.0);

    centerContent.getChildren().add(summary_);
    VBox.setVgrow(summary_, Priority.ALWAYS);

    pb_ = new ProgressBar(0.0);
    pb_.setPrefHeight(20);
    pb_.setMaxWidth(Double.MAX_VALUE);

    centerContent.getChildren().add(pb_);

    root_.setCenter(centerContent);

    //Bottom buttons
    HBox buttons = new HBox();
    buttons.setMaxWidth(Double.MAX_VALUE);
    buttons.setAlignment(Pos.CENTER);
    buttons.setPadding(new Insets(5));
    buttons.setSpacing(30);

    Button cancel = new Button("Close");
    cancel.setOnAction((action) -> {
        if (running_.get()) {
            addLine("Cancelling...");
            cancel.setDisable(true);
            cancelRequested_ = true;
        } else {
            cancel.getScene().getWindow().hide();
            root_ = null;
        }
    });
    buttons.getChildren().add(cancel);

    Button action = new Button("Synchronize");
    action.disableProperty().bind(running_);
    action.setOnAction((theAction) -> {
        summary_.setText("");
        pb_.setProgress(-1.0);
        running_.set(true);
        Utility.execute(() -> sync());
    });
    buttons.getChildren().add(action);

    cancel.minWidthProperty().bind(action.widthProperty());

    running_.addListener(change -> {
        if (running_.get()) {
            cancel.setText("Cancel");
        } else {
            cancel.setText("Close");
        }
        cancel.setDisable(false);
    });

    root_.setBottom(buttons);
}

From source file:pah9qdmoviereviews.MovieReviewsFXMLController.java

public void ready(Stage stage, Scene scene) {
    this.stage = stage;
    this.scene = scene;

    movieReviewManager = new NYTMoviewReviewManager();
    movieReviewManager.addPropertyChangeSupport(((evt) -> {
        switch (evt.getPropertyName()) {
        case "Exception":
            Platform.runLater(() -> displayExceptionAlert((Exception) evt.getNewValue()));
            break;
        case "Add Movie Review":
            Platform.runLater(() -> {
                movieReviews.add((NYTMovieReview) evt.getNewValue());
                this.foundText.setText(("Found " + movieReviews.size() + " results for " + searchString + "."));
            });/*from   w w  w. j  av a 2s . c  o m*/
            break;
        case "Clear Movie Reviews":
            Platform.runLater(() -> movieReviews.clear());
            break;
        case "Completed":
            if (movieReviews.isEmpty())
                this.foundText.setText("No reviews found for " + searchString);
            break;
        default:
            Platform.runLater(
                    () -> displayExceptionAlert(new Exception("Invalid Property Change Support Property")));
            break;
        }

    }));

    movieReviews = FXCollections.observableArrayList();
    listView.setItems(movieReviews);
    listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<NYTMovieReview>() {
        @Override
        public void changed(ObservableValue<? extends NYTMovieReview> observable, NYTMovieReview oldValue,
                NYTMovieReview newValue) {
            detailsBox.getChildren().clear();
            movieImage.setImage(null);
            if (newValue != null) {
                DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
                String pictureLink = newValue.getPictureLink();
                if (pictureLink != null && !pictureLink.isEmpty()) {
                    reviewBox.getChildren().remove(0);
                    reviewBox.getChildren().add(0, movieImage);
                    movieImage.setImage(new Image(pictureLink));
                } else {
                    reviewBox.getChildren().remove(0);
                    reviewBox.getChildren().add(0, missingImageText);
                    movieImage.setImage(null);
                }

                ArrayList<Label> labelArray = new ArrayList<>();
                if (!newValue.getDisplayTitle().isEmpty()) {
                    Label titleLabel = new Label(newValue.getDisplayTitle());
                    titleLabel.fontProperty().set(Font.font(20));
                    labelArray.add(titleLabel);
                }
                if (!newValue.getSummary().isEmpty()) {
                    labelArray.add(new Label("Summary: " + newValue.getSummary()));
                }
                if (!newValue.getMpaaRating().isEmpty()) {
                    labelArray.add(new Label("MPAA Rating: " + newValue.getMpaaRating()));
                }
                if (newValue.getPublicationDate() != null) {
                    labelArray.add(
                            new Label("Publication Date: " + dateFormat.format(newValue.getPublicationDate())));
                }
                if (newValue.getOpeningDate() != null) {
                    labelArray.add(new Label("Opening Date: " + dateFormat.format(newValue.getOpeningDate())));
                }

                labelArray.forEach((label) -> {
                    label.wrapTextProperty().set(true);
                });

                detailsBox.getChildren().addAll(labelArray);

                Button openButton = new Button("Open Review");
                openButton.setOnAction((event) -> {
                    try {
                        Desktop.getDesktop().browse(new URI(newValue.getArticleLink()));
                    } catch (Exception ex) {
                        displayExceptionAlert(ex);
                    }
                });

                detailsBox.getChildren().add(openButton);
            }
        }
    });

    HBox.setMargin(missingImageText, new Insets(15, 15, 15, 15));
    searchTextField.setOnKeyPressed((event) -> {
        if (event.getCode() == KeyCode.ENTER) {
            loadReviews(searchTextField.getText());
        }
    });
    //        searchTextField.textProperty().addListener((observable, oldValue, newValue) -> {
    //            if(newValue != null && !newValue.isEmpty())
    //                loadReviews(newValue);
    //        });
}

From source file:de.rkl.tools.tzconv.TimezoneConverter.java

private Node createZoneIdSelectionButtonBox() {
    final Button zoneIdSelection = new Button("Select zone IDs to be included in text");
    zoneIdSelection.setOnAction(this::openZoneIdSelectionDialog);
    final HBox buttonBox = new HBox(DEFAULT_BOX_SPACING, zoneIdSelection);
    buttonBox.alignmentProperty().setValue(Pos.CENTER);
    return buttonBox;
}

From source file:de.rkl.tools.tzconv.TimezoneConverter.java

private Node createCopyToClipboard(final TextInputControl mainArea) {
    final Button copyToClipboard = new Button("Copy to Clipboard");
    copyToClipboard.setOnAction(event -> {
        final StringSelection stringSelection = new StringSelection(mainArea.textProperty().getValue());
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, stringSelection);
    });/* w w w  .  j  a v a2  s. c  o  m*/
    final HBox copyToClipboardBox = new HBox(copyToClipboard);
    copyToClipboardBox.alignmentProperty().setValue(Pos.CENTER);
    return copyToClipboardBox;
}