Example usage for javafx.scene.control ToggleButton selectedProperty

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

Introduction

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

Prototype

public final BooleanProperty selectedProperty() 

Source Link

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Toggle Button Sample");
    stage.setWidth(250);/*from w  ww.  j  a va 2s  .co  m*/
    stage.setHeight(180);

    final ToggleGroup group = new ToggleGroup();

    group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle) {
            System.out.println((Color) group.getSelectedToggle().getUserData());
        }
    });
    Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("root.png")));
    ToggleButton tb1 = new ToggleButton("A", rootIcon);
    System.out.println(tb1.selectedProperty());

    tb1.setToggleGroup(group);
    tb1.setUserData(Color.LIGHTGREEN);
    tb1.setSelected(true);

    ToggleButton tb2 = new ToggleButton("B");
    tb2.setToggleGroup(group);
    tb2.setUserData(Color.LIGHTBLUE);
    ToggleButton tb3 = new ToggleButton("C");
    tb3.setToggleGroup(group);
    tb3.setUserData(Color.SALMON);

    HBox hbox = new HBox();

    hbox.getChildren().add(tb1);
    hbox.getChildren().add(tb2);
    hbox.getChildren().add(tb3);

    ((Group) scene.getRoot()).getChildren().add(hbox);
    stage.setScene(scene);
    stage.show();
}

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
 *///from w ww  . jav  a  2  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());
}