/** * An event filter to prevent the deselection of all buttons * * @param event The input event to be filtered */ private static void eventFilter(ActionEvent event) { ToggleButton source = (ToggleButton) event.getSource(); if (source.getToggleGroup() == null || !source.isSelected()) { source.fire(); } }
/** * An event filter to prevent the deselection of all buttons * * @param event The input event to be filtered */ private void eventFilter(ActionEvent event) { ToggleButton source = (ToggleButton) event.getSource(); if (source.getToggleGroup() == null || !source.isSelected()) { source.fire(); } } }
/** * {@inheritDoc} */ @Override public void initialise() { // set the behavior for the icons list toggle button getSkin().getIconsListButton().addEventFilter(ActionEvent.ANY, this::eventFilter); getSkin().getIconsListButton().setOnAction(event -> getControl().setSelected(ListWidgetType.ICONS_LIST)); // set the behavior for the compact list toggle button getSkin().getCompactListButton().addEventFilter(ActionEvent.ANY, this::eventFilter); getSkin().getCompactListButton().setOnAction(event -> getControl().setSelected(ListWidgetType.COMPACT_LIST)); // set the behavior for the details list toggle button getSkin().getDetailsListButton().addEventFilter(ActionEvent.ANY, this::eventFilter); getSkin().getDetailsListButton().setOnAction(event -> getControl().setSelected(ListWidgetType.DETAILS_LIST)); /* * perform the initial list widget selection based on the given input property, * which normally represents the user settings */ Optional.ofNullable(getControl().getSelected()) .ifPresent(selected -> getSkin().getListButton(selected).fire()); // change the selection based on a change in the selected property getControl().selectedProperty() .addListener(invalidatedEvent -> getSkin().getListButton(getControl().getSelected()).fire()); }
((ToggleButton) firstToggle).fire();