Example usage for javafx.scene.control Button setGraphic

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

Introduction

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

Prototype

public final void setGraphic(Node value) 

Source Link

Usage

From source file:de.pixida.logtest.designer.commons.SelectFileButton.java

public static Button createButtonWithFileSelection(final TextField inputFieldShowingPath, final String icon,
        final String title, final String fileMask, final String fileMaskDescription) {
    final Button selectLogFileButton = new Button("Select");
    selectLogFileButton.setGraphic(Icons.getIconGraphics(icon));
    selectLogFileButton.setOnAction(event -> {
        final FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(title);//from www  . j  a va2  s.  co  m
        if (StringUtils.isNotBlank(fileMask) && StringUtils.isNotBlank(fileMaskDescription)) {
            fileChooser.getExtensionFilters()
                    .add(new FileChooser.ExtensionFilter(fileMaskDescription, fileMask));
        }
        File initialDirectory = new File(inputFieldShowingPath.getText().trim());
        if (!initialDirectory.isDirectory()) {
            initialDirectory = initialDirectory.getParentFile();
        }
        if (initialDirectory == null || !initialDirectory.isDirectory()) {
            if (lastFolder != null) {
                initialDirectory = lastFolder;
            } else {
                initialDirectory = new File(".");
            }
        }
        fileChooser.setInitialDirectory(initialDirectory);
        final File selectedFile = fileChooser.showOpenDialog(((Node) event.getTarget()).getScene().getWindow());
        if (selectedFile != null) {
            inputFieldShowingPath.setText(selectedFile.getAbsolutePath());
            final File parent = selectedFile.getParentFile();
            if (parent != null && parent.isDirectory()) {
                lastFolder = parent;
            }
        }
    });
    return selectLogFileButton;
}

From source file:de.pixida.logtest.designer.logreader.LogReaderEditor.java

public VBox createRunForm() {
    // CHECKSTYLE:OFF Yes, we are using lots of constants here. It does not make sense to name them using final variables.
    final VBox lines = new VBox();
    lines.setSpacing(10d);/*from www .ja  va 2s.  co  m*/
    final HBox inputTypeLine = new HBox();
    inputTypeLine.setSpacing(30d);
    final ToggleGroup group = new ToggleGroup();
    final RadioButton inputTypeText = new RadioButton("Paste/Enter text");
    inputTypeText.setToggleGroup(group);
    final RadioButton inputTypeFile = new RadioButton("Read log file");
    inputTypeFile.setToggleGroup(group);
    inputTypeLine.getChildren().add(inputTypeText);
    inputTypeLine.getChildren().add(inputTypeFile);
    inputTypeText.setSelected(true);
    final TextField pathInput = new TextField();
    HBox.setHgrow(pathInput, Priority.ALWAYS);
    final Button selectLogFileButton = SelectFileButton.createButtonWithFileSelection(pathInput,
            LOG_FILE_ICON_NAME, "Select log file", null, null);
    final Text pathInputLabel = new Text("Log file path: ");
    final HBox fileInputConfig = new HBox();
    fileInputConfig.setAlignment(Pos.CENTER_LEFT);
    fileInputConfig.visibleProperty().bind(inputTypeFile.selectedProperty());
    fileInputConfig.managedProperty().bind(fileInputConfig.visibleProperty());
    fileInputConfig.getChildren().addAll(pathInputLabel, pathInput, selectLogFileButton);
    final TextArea logInputText = new TextArea();
    HBox.setHgrow(logInputText, Priority.ALWAYS);
    logInputText.setPrefRowCount(10);
    logInputText.setStyle("-fx-font-family: monospace");
    final HBox enterTextConfig = new HBox();
    enterTextConfig.getChildren().add(logInputText);
    enterTextConfig.visibleProperty().bind(inputTypeText.selectedProperty());
    enterTextConfig.managedProperty().bind(enterTextConfig.visibleProperty());
    final Button startBtn = new Button("Read Log");
    startBtn.setPadding(new Insets(8d));
    // CHECKSTYLE:ON
    startBtn.setGraphic(Icons.getIconGraphics("control_play_blue"));
    HBox.setHgrow(startBtn, Priority.ALWAYS);
    startBtn.setMaxWidth(Double.MAX_VALUE);
    startBtn.setOnAction(event -> this.runLogFileReader(inputTypeFile, pathInput, logInputText));
    final HBox startLine = new HBox();
    startLine.getChildren().add(startBtn);
    lines.getChildren().addAll(inputTypeLine, fileInputConfig, enterTextConfig, startLine, new Text("Results:"),
            this.parsedLogEntries);
    return lines;
}

From source file:de.pixida.logtest.designer.testrun.TestRunEditor.java

public TitledPane createPanelForLaunchingTests() {
    final Button startBtn = new Button("Run Test");
    startBtn.disableProperty().bind(this.testRunService.runningProperty());
    final double startButtonPadding = 8d;
    startBtn.setPadding(new Insets(startButtonPadding));
    startBtn.setGraphic(Icons.getIconGraphics("control_play_blue"));
    HBox.setHgrow(startBtn, Priority.ALWAYS);
    startBtn.setMaxWidth(Double.MAX_VALUE);
    startBtn.setOnAction(event -> {/*from   ww  w . ja v a2s .  co m*/
        final Job job = this.createJobFromConfig();
        this.testRunService.setJob(job);
        this.testRunService.start();
    });
    final HBox startLine = new HBox();
    startLine.getChildren().add(startBtn);
    final VBox runLines = new VBox();
    final double linesSpacing = 10d;
    runLines.setSpacing(linesSpacing);
    final TextFlow resultBar = new TextFlow();
    resultBar.backgroundProperty().bind(this.resultBarBackgroundProperty);
    this.resultBarBackgroundProperty.set(RESULT_BAR_BACKGROUND_IDLE);
    resultBar.setStyle("-fx-border-color: black; -fx-border-width:1");
    final Text resultBarText = new Text();
    resultBarText.textProperty().bind(this.resultBarTextProperty);
    this.resultBarTextProperty.set("Idle");
    resultBar.getChildren().add(resultBarText);
    resultBar.setTextAlignment(TextAlignment.CENTER);
    final double resultBarPadding = 2d;
    resultBar.setPadding(new Insets(resultBarPadding));
    final int logOutputLinesSize = 25;
    this.resultLogOutputText.setPrefRowCount(logOutputLinesSize);
    this.resultLogOutputText.setEditable(false);
    this.resultLogOutputText.setStyle("-fx-font-family: monospace");
    HBox.setHgrow(this.resultLogOutputText, Priority.ALWAYS);
    runLines.getChildren().addAll(startLine, new Text("Recent results:"), resultBar, this.resultLogOutputText);
    final TitledPane runPane = new TitledPane("Run", runLines);
    runPane.setGraphic(Icons.getIconGraphics("lightning_go"));
    runPane.setCollapsible(false);
    return runPane;
}

From source file:com.panemu.tiwulfx.table.TableControl.java

private Button buildButton(Node graphic) {
    Button btn = new Button();
    btn.setGraphic(graphic);
    btn.getStyleClass().add("flat-button");
    btn.setOnAction(buttonHandler);/*from w w w.jav a2s . c o m*/
    return btn;
}

From source file:photobooth.views.EmailPane.java

private void addXButton() {
    Button button = new Button();
    try {/*from   w w w.  j  a  va  2s . c  om*/
        button.setGraphic(
                new ImageView(new Image(getClass().getResource("/photobooth/images/exit.png").openStream())));
    } catch (IOException ex) {
        Logger.getLogger(EmailPane.class.getName()).log(Level.SEVERE, null, ex);
    }
    button.setStyle("-fx-background-color: transparent;");
    button.setLayoutX(730);
    button.setLayoutY(10);
    button.setMaxSize(50, 50);
    button.setMinSize(50, 50);
    button.getStyleClass().add("blueButton");
    this.getChildren().add(button);
    button.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            t.cancel();
            t.purge();
            Global.getInstance().setSceneRoot(HomePane.getInstance());
        }
    });
}

From source file:photobooth.views.ExplorerPane.java

private void addXButton() throws IOException {
    Button button = new Button();
    button.setGraphic(
            new ImageView(new Image(getClass().getResource("/photobooth/images/exit.png").openStream())));
    button.setStyle("-fx-background-color: transparent;");
    button.setLayoutX(730);/*from  ww  w. j a  v  a  2  s.c  o m*/
    button.setLayoutY(10);
    button.setMaxSize(50, 50);
    button.setMinSize(50, 50);
    button.getStyleClass().add("blueButton");
    this.getChildren().add(button);
    button.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            Global.getInstance().setSceneRoot(HomePane.getInstance());
        }
    });
}

From source file:photobooth.views.ExplorerPane.java

private void addUpButton() throws IOException {
    Button button = new Button();
    button.setGraphic(
            new ImageView(new Image(getClass().getResource("/photobooth/images/up.png").openStream())));
    button.setStyle("-fx-background-color: transparent;");
    button.setMaxSize(50, 50);//from w  w  w .  j  a v a 2s  .  c o m
    button.setMinSize(50, 50);
    button.setLayoutX(120);
    button.setLayoutY(10);
    this.getChildren().add(button);
    button.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            Global.getInstance().setSceneRoot(LoadingPane.getInstance());

            Platform.runLater(() -> {
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        ExplorerPane.getInstance().setDir(new File(dir).getParentFile().getAbsolutePath(), 0,
                                limit, directoryLevel - 1);
                        Global.getInstance().setSceneRoot(ExplorerPane.getInstance());
                    }
                }).start();
            });

        }
    });

}

From source file:photobooth.views.ExplorerPane.java

private void addNextButton() throws IOException {
    Button button = new Button();
    button.setGraphic(
            new ImageView(new Image(getClass().getResource("/photobooth/images/next.png").openStream())));
    button.setStyle("-fx-background-radius: 50%; ");
    button.setStyle("-fx-background-color: transparent;");
    button.setLayoutX(740);//w  w  w  .  ja  va 2  s .c o m
    button.setLayoutY(220);
    button.setMaxSize(50, 50);
    button.setMinSize(50, 50);
    this.getChildren().add(button);
    button.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            Global.getInstance().setSceneRoot(LoadingPane.getInstance());
            Platform.runLater(() -> {
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        ExplorerPane.getInstance().setDir(dir, offset + limit, limit, directoryLevel);
                        Global.getInstance().setSceneRoot(ExplorerPane.getInstance());
                    }
                }).start();
            });
        }
    });
}

From source file:photobooth.views.ExplorerPane.java

private void addPrevButton() throws IOException {
    Button button = new Button();
    button.setGraphic(
            new ImageView(new Image(getClass().getResource("/photobooth/images/prev.png").openStream())));
    button.setStyle("-fx-background-radius: 50%; ");
    button.setStyle("-fx-background-color: transparent;");
    button.setLayoutX(10);//from   w ww .j a  v a2s .c  o  m
    button.setLayoutY(220);
    button.setMaxSize(50, 50);
    button.setMinSize(50, 50);
    this.getChildren().add(button);
    button.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            Global.getInstance().setSceneRoot(LoadingPane.getInstance());
            Platform.runLater(() -> {
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        ExplorerPane.getInstance().setDir(dir, offset - limit, limit, directoryLevel);
                        Global.getInstance().setSceneRoot(ExplorerPane.getInstance());
                    }
                }).start();
            });
        }
    });
}

From source file:ubicrypt.ui.ctrl.providers.ProvidersController.java

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
    String fxml = substringBefore(substringAfterLast(url.getFile(), "/"), ".fxml");
    navigator = new StackNavigator(root, fxml, controllerFactory);
    providers.setCellFactory(listView -> new ListCell<ProviderItem>() {
        @Override/*  www .j  a  v a 2 s. com*/
        protected void updateItem(ProviderItem pi, boolean empty) {
            super.updateItem(pi, empty);
            if (empty) {
                setText(null);
                setGraphic(null);
                return;
            }
            setContextMenu(pi.getContextMenu());
            Platform.runLater(() -> setGraphic(pi.getGraphics()));
        }
    });
    providerDescriptors.stream().forEach(pd -> {
        Button button = new Button();
        Image img = pd.getLogo().getImage();
        ImageView view = new ImageView(img);
        view.setFitWidth(30.0);
        view.setPickOnBounds(true);
        view.setPreserveRatio(true);
        button.setGraphic(view);
        button.setOnMouseClicked(mouseEvent -> {
            log.debug("adding provider :{}", pd.getCode());
            navigator.browse(format("provider/%s", pd.getCode()));
        });
        button.setTooltip(new Tooltip("Add " + pd.getDescription()));
        availableProviders.getItems().add(button);
    });

    //provider status events
    providerEvent.subscribe(pevent -> {
        UbiProvider provider = pevent.getHook().getProvider();
        if (!providers.getItems().stream().filter(pi -> pi.getProvider().equals(provider)).findFirst()
                .isPresent()) {
            log.info("add new provider:{}", pevent.getHook().getProvider());
            String code = providerDescriptors.stream().filter(pd -> pd.getType() == provider.getClass())
                    .map(ProviderDescriptor::getCode).findFirst().get();
            final ProviderItem providerItem = new ProviderItem(provider, providerDescriptors.stream()
                    .filter(pd -> pd.getType() == provider.getClass()).findFirst().get(), providerRemover,
                    navigator);
            providers.getItems().add(providerItem);
            pevent.getHook().getStatusEvents().subscribe(providerItem::changeStatus);
        }
        switch (pevent.getEvent()) {
        case removed:
            //TODO: remove provider
            break;
        default:
            log.warn("unmanaged event:{}", pevent.getEvent());
        }
        providers.getItems().stream().filter(pi -> pi.getProvider().equals(provider)).findFirst()
                .ifPresent(pi -> pi.changeStatus(pevent.getEvent()));
    });
}