Example usage for javafx.scene.control ToggleButton getStyleClass

List of usage examples for javafx.scene.control ToggleButton getStyleClass

Introduction

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

Prototype

@Override
    public final ObservableList<String> getStyleClass() 

Source Link

Usage

From source file:net.rptools.tokentool.controller.ManageOverlays_Controller.java

private void loadImages(File dir) {
    // Clear Details panel
    clearDetails();//from w w w. ja  va  2 s. c o  m

    currentDirectory = dir;
    File[] files = dir.listFiles(ImageUtil.SUPPORTED_FILENAME_FILTER);

    Task<Void> task = new Task<Void>() {
        @Override
        public Void call() {
            for (File file : files) {
                Path filePath = file.toPath();

                if (loadOverlaysThread.isInterrupted()) {
                    Platform.runLater(() -> overlayViewFlowPane.getChildren().clear());
                    break;
                }

                try {
                    ToggleButton overlayButton = new ToggleButton();
                    ImageView imageViewNode = ImageUtil.getOverlayThumb(new ImageView(), filePath);

                    overlayButton.getStyleClass().add("overlay-toggle-button");
                    overlayButton.setGraphic(imageViewNode);
                    overlayButton.setUserData(file);
                    overlayButton.setToggleGroup(overlayToggleGroup);

                    overlayButton.addEventHandler(ActionEvent.ACTION, event -> {
                        // No modifier keys used so add toggle group back to all buttons
                        resetToggleGroup();

                        // Also set button to selected due to resetting toggle groups & no unselecting needed, makes for better interface IMO
                        overlayButton.setSelected(true);

                        // Update the Details panel with the last selected overlay
                        File overlayFile = (File) overlayButton.getUserData();
                        updateDetails(overlayFile, (ImageView) overlayButton.getGraphic(),
                                overlayButton.isSelected());

                        // Consume the event, no more logic needed
                        event.consume();
                    });

                    overlayButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
                        @Override
                        public void handle(MouseEvent event) {
                            // Allow multiple selections if shortcutKey+left_mouse is pressed
                            if (event.getButton().equals(MouseButton.PRIMARY) && event.isShortcutDown()) {
                                // Update the Details panel with the last selected overlay
                                File overlayFile = (File) overlayButton.getUserData();
                                updateDetails(overlayFile, (ImageView) overlayButton.getGraphic(), true);

                                // Remove the toggle group to allow multiple toggle button selection
                                overlayButton.setToggleGroup(null);

                                // Select the button
                                overlayButton.setSelected(true);

                                // Consume the event, no more logic needed
                                event.consume();
                            }
                        }
                    });

                    Platform.runLater(() -> overlayViewFlowPane.getChildren().add(overlayButton));
                } catch (IOException e) {
                    log.error("Loading image: " + filePath.getFileName(), e);
                }

            }

            return null;
        }
    };

    loadOverlaysThread.interrupt();
    executorService.execute(task);
}

From source file:org.sleuthkit.autopsy.imagegallery.gui.drawableviews.GroupPane.java

/**
 * called automatically during constructor by FXMLConstructor.
 *
 * checks that FXML loading went ok and performs additional setup
 */// w  w w. j  a v a2  s  .  c  o  m
@FXML
@NbBundle.Messages({ "GroupPane.gridViewContextMenuItem.extractFiles=Extract File(s)",
        "GroupPane.bottomLabel.displayText=Group Viewing History: ",
        "GroupPane.hederLabel.displayText=Tag Selected Files:",
        "GroupPane.catContainerLabel.displayText=Categorize Selected File:",
        "GroupPane.catHeadingLabel.displayText=Category:" })
void initialize() {
    assert cat0Toggle != null : "fx:id=\"cat0Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert cat1Toggle != null : "fx:id=\"cat1Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert cat2Toggle != null : "fx:id=\"cat2Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert cat3Toggle != null : "fx:id=\"cat3Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert cat4Toggle != null : "fx:id=\"cat4Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert cat5Toggle != null : "fx:id=\"cat5Toggle\" was not injected: check your FXML file 'SlideShowView.fxml'.";
    assert gridView != null : "fx:id=\"tilePane\" was not injected: check your FXML file 'GroupPane.fxml'.";
    assert catSelectedSplitMenu != null : "fx:id=\"grpCatSplitMenu\" was not injected: check your FXML file 'GroupHeader.fxml'.";
    assert tagSelectedSplitMenu != null : "fx:id=\"grpTagSplitMenu\" was not injected: check your FXML file 'GroupHeader.fxml'.";
    assert headerToolBar != null : "fx:id=\"headerToolBar\" was not injected: check your FXML file 'GroupHeader.fxml'.";
    assert segButton != null : "fx:id=\"previewList\" was not injected: check your FXML file 'GroupHeader.fxml'.";
    assert slideShowToggle != null : "fx:id=\"segButton\" was not injected: check your FXML file 'GroupHeader.fxml'.";
    assert tileToggle != null : "fx:id=\"tileToggle\" was not injected: check your FXML file 'GroupHeader.fxml'.";

    for (Category cat : Category.values()) {
        ToggleButton toggleForCategory = getToggleForCategory(cat);
        toggleForCategory.setBorder(new Border(
                new BorderStroke(cat.getColor(), BorderStrokeStyle.SOLID, CORNER_RADII_2, BORDER_WIDTHS_2)));
        toggleForCategory.getStyleClass().remove("radio-button");
        toggleForCategory.getStyleClass().add("toggle-button");
        toggleForCategory.selectedProperty().addListener((ov, wasSelected, toggleSelected) -> {
            if (toggleSelected && slideShowPane != null) {
                slideShowPane.getFileID().ifPresent(fileID -> {
                    selectionModel.clearAndSelect(fileID);
                    new CategorizeAction(controller, cat, ImmutableSet.of(fileID)).handle(null);
                });
            }
        });
    }

    //configure flashing glow animation on next unseen group button
    flashAnimation.setCycleCount(Timeline.INDEFINITE);
    flashAnimation.setAutoReverse(true);

    //configure gridView cell properties
    DoubleBinding cellSize = controller.thumbnailSizeProperty().add(75);
    gridView.cellHeightProperty().bind(cellSize);
    gridView.cellWidthProperty().bind(cellSize);
    gridView.setCellFactory((GridView<Long> param) -> new DrawableCell());

    BooleanBinding isSelectionEmpty = Bindings.isEmpty(selectionModel.getSelected());
    catSelectedSplitMenu.disableProperty().bind(isSelectionEmpty);
    tagSelectedSplitMenu.disableProperty().bind(isSelectionEmpty);

    Platform.runLater(() -> {
        try {
            TagSelectedFilesAction followUpSelectedACtion = new TagSelectedFilesAction(
                    controller.getTagsManager().getFollowUpTagName(), controller);
            tagSelectedSplitMenu.setText(followUpSelectedACtion.getText());
            tagSelectedSplitMenu.setGraphic(followUpSelectedACtion.getGraphic());
            tagSelectedSplitMenu.setOnAction(followUpSelectedACtion);
        } catch (TskCoreException tskCoreException) {
            LOGGER.log(Level.WARNING, "failed to load FollowUpTagName", tskCoreException); //NON-NLS
        }
        tagSelectedSplitMenu.showingProperty().addListener(showing -> {
            if (tagSelectedSplitMenu.isShowing()) {
                List<MenuItem> selTagMenues = Lists.transform(
                        controller.getTagsManager().getNonCategoryTagNames(),
                        tagName -> GuiUtils.createAutoAssigningMenuItem(tagSelectedSplitMenu,
                                new TagSelectedFilesAction(tagName, controller)));
                tagSelectedSplitMenu.getItems().setAll(selTagMenues);
            }
        });

    });

    CategorizeSelectedFilesAction cat5SelectedAction = new CategorizeSelectedFilesAction(Category.FIVE,
            controller);
    catSelectedSplitMenu.setOnAction(cat5SelectedAction);
    catSelectedSplitMenu.setText(cat5SelectedAction.getText());
    catSelectedSplitMenu.setGraphic(cat5SelectedAction.getGraphic());
    catSelectedSplitMenu.showingProperty().addListener(showing -> {
        if (catSelectedSplitMenu.isShowing()) {
            List<MenuItem> categoryMenues = Lists.transform(Arrays.asList(Category.values()),
                    cat -> GuiUtils.createAutoAssigningMenuItem(catSelectedSplitMenu,
                            new CategorizeSelectedFilesAction(cat, controller)));
            catSelectedSplitMenu.getItems().setAll(categoryMenues);
        }
    });

    slideShowToggle.getStyleClass().remove("radio-button");
    slideShowToggle.getStyleClass().add("toggle-button");
    tileToggle.getStyleClass().remove("radio-button");
    tileToggle.getStyleClass().add("toggle-button");

    bottomLabel.setText(Bundle.GroupPane_bottomLabel_displayText());
    headerLabel.setText(Bundle.GroupPane_hederLabel_displayText());
    catContainerLabel.setText(Bundle.GroupPane_catContainerLabel_displayText());
    catHeadingLabel.setText(Bundle.GroupPane_catHeadingLabel_displayText());
    //show categorization controls depending on group view mode
    headerToolBar.getItems().remove(catSegmentedContainer);
    groupViewMode.addListener((ObservableValue<? extends GroupViewMode> observable, GroupViewMode oldValue,
            GroupViewMode newValue) -> {
        if (newValue == GroupViewMode.SLIDE_SHOW) {
            headerToolBar.getItems().remove(catSplitMenuContainer);
            headerToolBar.getItems().add(catSegmentedContainer);
        } else {
            headerToolBar.getItems().remove(catSegmentedContainer);
            headerToolBar.getItems().add(catSplitMenuContainer);
        }
    });

    //listen to toggles and update view state
    slideShowToggle
            .setOnAction(onAction -> activateSlideShowViewer(selectionModel.lastSelectedProperty().get()));
    tileToggle.setOnAction(onAction -> activateTileViewer());

    controller.viewState().addListener((observable, oldViewState, newViewState) -> setViewState(newViewState));

    addEventFilter(KeyEvent.KEY_PRESSED, tileKeyboardNavigationHandler);
    gridView.addEventHandler(MouseEvent.MOUSE_CLICKED, new MouseHandler());

    ActionUtils.configureButton(undoAction, undoButton);
    ActionUtils.configureButton(redoAction, redoButton);
    ActionUtils.configureButton(forwardAction, forwardButton);
    ActionUtils.configureButton(backAction, backButton);
    ActionUtils.configureButton(nextGroupAction, nextButton);
    /*
     * the next button does stuff in the GroupPane that next action does'nt
     * know about, so do that stuff and then delegate to nextGroupAction
     */
    final EventHandler<ActionEvent> onAction = nextButton.getOnAction();
    nextButton.setOnAction(actionEvent -> {
        flashAnimation.stop();
        nextButton.setEffect(null);
        onAction.handle(actionEvent);
    });

    nextGroupAction.disabledProperty().addListener((Observable observable) -> {
        boolean newValue = nextGroupAction.isDisabled();
        nextButton.setEffect(newValue ? null : DROP_SHADOW);
        if (newValue) {//stop on disabled
            flashAnimation.stop();
        } else { //play when enabled
            flashAnimation.play();
        }
    });

    //listen to tile selection and make sure it is visible in scroll area
    selectionModel.lastSelectedProperty().addListener((observable, oldFileID, newFileId) -> {
        if (groupViewMode.get() == GroupViewMode.SLIDE_SHOW && slideShowPane != null) {
            slideShowPane.setFile(newFileId);
        } else {
            scrollToFileID(newFileId);
        }
    });

    setViewState(controller.viewState().get());
}