public static void alwaysInTop(Alert alert) { try{ DialogPane root = alert.getDialogPane(); Stage dialogStage = new Stage(StageStyle.UTILITY); for (ButtonType buttonType : root.getButtonTypes()) { ButtonBase button = (ButtonBase) root.lookupButton(buttonType); button.setOnAction(evt -> { root.setUserData(buttonType); dialogStage.close(); }); } root.getScene().setRoot(new Group()); Scene scene = new Scene(root); dialogStage.setScene(scene); dialogStage.initModality(Modality.APPLICATION_MODAL); dialogStage.setAlwaysOnTop(true); dialogStage.setResizable(false); dialogStage.showAndWait(); }catch(Exception e){ } // Optional<ButtonType> result = Optional.ofNullable((ButtonType) root.getUserData()); }
public static ButtonBase _initButtonBase(String name, String toolTip, boolean enabled, String buttonText, ButtonBase button) { button.setId(name + "Button"); button.setTooltip(new Tooltip(toolTip)); Node enabledIcon = getImageFrom(name, "icons/", FromOptions.NULL_IF_NOT_EXISTS); if (enabledIcon != null) { button.setText(null); button.setGraphic(enabledIcon); } if (buttonText != null) { button.setText(buttonText); } else if (enabledIcon == null) { button.setText(name); } button.setDisable(!enabled); button.setMinWidth(Region.USE_PREF_SIZE); return button; }
public ButtonBaseBinder(ButtonBase button) { super(button); actionHandler = new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { onOccur(); } }; button.setOnAction(actionHandler); changeListener = new ChangeListener<String>() { @Override public synchronized void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { doOnchange(oldValue,newValue); } }; button.textProperty().addListener(changeListener); }
/** * Setup the round button. * * @param button Button to setup * @param params Customization parameters * @param graphic Graphics contents * @param tooltip Tooltip text */ public static void setupMenuButton(ButtonBase button, RadialMenuParams params, Node graphic, String tooltip, boolean addStyle) { button.minWidthProperty().bind(params.buttonSizeProperty()); button.minHeightProperty().bind(params.buttonSizeProperty()); button.prefWidthProperty().bind(params.buttonSizeProperty()); button.prefHeightProperty().bind(params.buttonSizeProperty()); button.maxWidthProperty().bind(params.buttonSizeProperty()); button.maxHeightProperty().bind(params.buttonSizeProperty()); if (addStyle) { button.getStylesheets().addAll(params.getStyleSheets()); } button.setId(params.getStyleId()); button.getStyleClass().addAll(params.getStyleClasses()); button.setGraphic(graphic); button.setTooltip(new Tooltip(tooltip)); }
public ToggleButtonToolBar(boolean isVeritcal, List<T> list) { buttons = list.stream() .map(l -> { ToggleButton tb = l.icon().isPresent() ? new ToggleButton(l.displayName(), new SmallIcon(l)) : new ToggleButton(l.displayName()); tb.setUserData(l); return tb; }) .collect(Collectors.toList()); for (ButtonBase node : buttons) { node.setMaxWidth(Double.MAX_VALUE); } this.getChildren().addAll(buttons); }
public static ButtonBase createToolBarButton(Action action) { ButtonBase button = (action.selected != null) ? new ToggleButton() : new Button(); button.setGraphic(FontAwesomeIconFactory.get().createIcon(action.icon, "1.2em")); String tooltip = action.text; if (tooltip.endsWith("...")) tooltip = tooltip.substring(0, tooltip.length() - 3); if (action.accelerator != null) tooltip += " (" + action.accelerator.getDisplayText() + ')'; button.setTooltip(new Tooltip(tooltip)); button.setFocusTraversable(false); button.setOnAction(action.action); if (action.disable != null) button.disableProperty().bind(action.disable); if (action.selected != null) ((ToggleButton)button).selectedProperty().bindBidirectional(action.selected); return button; }
private ButtonBase newItem(final boolean toggle, final ToolIcons icon, final String tool_tip) { final ButtonBase item = toggle ? new ToggleButton() : new Button(); try { item.setGraphic(new ImageView(Activator.getIcon(icon.name().toLowerCase()))); } catch (Exception ex) { logger.log(Level.WARNING, "Cannot get icon" + icon, ex); item.setText(icon.toString()); } item.setTooltip(new Tooltip(tool_tip)); toolbar.getItems().add(item); return item; }
@Override protected final void configFooter() { final ActionManager am = application.getActionManager(); final HBox footerLeft = new HBox(); footerLeft.getStyleClass().addAll(StyleClass.TOOLBAR, StyleClass.ALIGN_CENTER_LEFT); HBox.setHgrow(footerLeft, Priority.ALWAYS); footer.getChildren().add(footerLeft); configFooterLeftToolBar(footerLeft); final HBox footerRight = new HBox(); footerRight.getStyleClass().addAll(StyleClass.TOOLBAR, StyleClass.ALIGN_CENTER_RIGHT); HBox.setHgrow(footerRight, Priority.NEVER); footer.getChildren().add(footerRight); final ButtonBase hideNavigatorButton = am.createButton(HideNavigatorAction.ID); footerRight.getChildren().add(hideNavigatorButton); }
/** * Invoked when a mouse press has occurred over the button. In addition to * potentially arming the Button, this will transfer focus to the button */ @Override public void mousePressed(MouseEvent e) { final ButtonBase button = getControl(); super.mousePressed(e); // if the button is not already focused, then request the focus if (! button.isFocused() && button.isFocusTraversable()) { button.requestFocus(); } // arm the button if it is a valid mouse event // Note there appears to be a bug where if I press and hold and release // then there is a clickCount of 0 on the release, whereas a quick click // has a release clickCount of 1. So here I'll check clickCount <= 1, // though it should really be == 1 I think. boolean valid = (e.getButton() == MouseButton.PRIMARY && ! (e.isMiddleButtonDown() || e.isSecondaryButtonDown() || e.isShiftDown() || e.isControlDown() || e.isAltDown() || e.isMetaDown())); if (! button.isArmed() && valid) { button.arm(); } }
MultiKeyPopup() { buttonPane = new TilePane(); buttonPane.getStyleClass().add(DEFAULT_STYLE_CLASS); buttonPane.setFocusTraversable(false); buttonPane.getChildren().addListener((ListChangeListener<Node>) c -> { while (c.next()) { if (c.wasPermutated() || !c.wasAdded()) { continue; } c.getAddedSubList().forEach(node -> { node.setFocusTraversable(false); if (node instanceof ButtonBase) { ((ButtonBase) node).setOnAction(event -> hide()); } }); } }); getContent().add(buttonPane); setAutoFix(true); setAutoHide(true); }
/** * Private constructor. * * @param buttonBase The button. */ private ClickRepeater(final ButtonBase buttonBase, final Duration interval) { initialPause.setOnFinished(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { // Fire the button the first time after the initial pause. buttonBase.fire(); } }); pauseTransition.setDuration(interval); pauseTransition.setCycleCount(Animation.INDEFINITE); pauseTransition.currentTimeProperty().addListener(new ChangeListener<Duration>() { @Override public void changed(ObservableValue<? extends Duration> observableValue, Duration duration, Duration duration2) { // Every time a new cycle starts, fire the button. if (duration.greaterThan(duration2)) { buttonBase.fire(); } } }); changeListener = new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observableValue, Boolean aBoolean, Boolean aBoolean2) { if (aBoolean2) { // If the button gets armed, start the animation. sequentialTransition.playFromStart(); } else { // Stop the animation, if the button is no longer armed. sequentialTransition.stop(); } } }; buttonBase.armedProperty().addListener(changeListener); }
/** * Installs the click repeating behavior for a {@link ButtonBase} and also allows to set a click interval. * * @param buttonBase The button. * @param interval The click interval. */ public static void install(ButtonBase buttonBase, Duration interval) { // Uninstall any previous behavior. uninstall(buttonBase); // Initializes a new ClickRepeater if (!buttonBase.getProperties().containsKey(ClickRepeater.class)) { // Store the ClickRepeater in the button's properties. // If the button will get GCed, so will its ClickRepeater. buttonBase.getProperties().put(ClickRepeater.class, new ClickRepeater(buttonBase, interval)); } }
/** * Uninstalls the click repeater behavior from a button. * * @param buttonBase The button. */ public static void uninstall(ButtonBase buttonBase) { if (buttonBase.getProperties().containsKey(ClickRepeater.class) && buttonBase.getProperties().get(ClickRepeater.class) instanceof ClickRepeater) { ClickRepeater clickRepeater = (ClickRepeater) buttonBase.getProperties().remove(ClickRepeater.class); buttonBase.armedProperty().removeListener(clickRepeater.changeListener); } }
/** * Adds support changing icons by pressed. * * @param buttons the buttons. */ @FXThread public static void addSupport(@NotNull final ButtonBase... buttons) { for (final ButtonBase button : buttons) { addSupport(button); } }
/** * Adds support changing icons by pressed. * * @param button the button. */ @FXThread public static void addSupport(@NotNull final ButtonBase button) { final EditorConfig editorConfig = EditorConfig.getInstance(); final CssColorTheme theme = editorConfig.getTheme(); if (!theme.needRepaintIcons()) { return; } final ImageView graphic = (ImageView) button.getGraphic(); final Image image = graphic.getImage(); final Image original = FILE_ICON_MANAGER.getOriginal(image); final ObservableMap<Object, Object> properties = button.getProperties(); properties.put(NOT_PRESSED_IMAGE, image); properties.put(PRESSED_IMAGE, original); button.pressedProperty().addListener((observable, oldValue, newValue) -> { if (newValue) { graphic.setImage((Image) properties.get(PRESSED_IMAGE)); } else { graphic.setImage((Image) properties.get(NOT_PRESSED_IMAGE)); } }); if (button.isPressed()) { graphic.setImage(original); } else { graphic.setImage(image); } }
public void attach(ButtonBase b) { b.setOnAction(this); b.disableProperty().bind(disabledProperty()); if(b instanceof ToggleButton) { ((ToggleButton)b).selectedProperty().bindBidirectional(selectedProperty()); } }
public void install(ApplicationContext context, ButtonBase control, Function<Node, Runnable> showNode) { control.managedProperty().bind(visibleProperty()); control.setText(getName(getPath())); control.setOnAction(e -> handle(context, control, showNode)); control.visibleProperty().bind(visibleProperty()); control.disableProperty().bind(disableProperty()); }
public ButtonGroupSkin(ButtonGroup buttonGroup) { super(buttonGroup); this.buttonGroup = buttonGroup; currentPane = this.loadContainer(buttonGroup.getOrientation()); // for adding class to first and last button this.first = new SimpleObjectProperty<>(); this.first.addListener(new StyleClassTogglerOnValue(FIRST_STYLE_CLASS)); this.setSidesButton(); ObservableListUtils.bind(currentPane.getChildren(),buttonGroup.getButtons()); buttonGroup.getButtons().addListener(new ListChangeListener<ButtonBase>() { @Override public void onChanged(Change<? extends ButtonBase> c) { setSidesButton(); currentPane.requestLayout(); } }); buttonGroup.orientationProperty().addListener((observable, oldValue, newValue) -> { changeLayout(newValue); }); currentPane.getChildren().addAll(buttonGroup.getButtons()); super.getChildren().add(currentPane); }
public void addButton(ButtonBase button) { if(null == buttons.get()) { buttons.setValue(FXCollections.observableArrayList()); } button.setMaxSize(Double.MAX_VALUE,Double.MAX_VALUE); buttons.get().add(button); }
/** * Method to configure the {@link ButtonBase} size and graphic to use the {@link Image} * in a consistent style for toolbox buttons. * @param button the {@link ButtonBase} to configure. * @param image the {@link Image} to apply. */ public void styleButtonSize( ButtonBase button, Image image ) { ImageView view = new ImageView( image ); view.setFitHeight( BUTTON_WIDTH ); view.setFitWidth( BUTTON_HEIGHT ); button.setGraphic( view ); button.setPrefSize( BUTTON_WIDTH, BUTTON_HEIGHT ); button.setMaxWidth( BUTTON_WIDTH ); button.setMaxHeight( BUTTON_HEIGHT ); button.setAlignment( Pos.CENTER ); }
/** * Method to apply a style change where there is no background but instead a {@link Color} placed * when pressed and removed when released. * @param button the {@link ButtonBase} to apply the style to. * @param backgroundWhenPressed the {@link Color} to use for the background. */ public void removeBackgroundAndColourOnClick( ButtonBase button, Color backgroundWhenPressed ) { button.setBackground( null ); button.setOnMousePressed( event -> button.setBackground( new Background( new BackgroundFill( backgroundWhenPressed, null, null ) ) ) ); button.setOnMouseReleased( event -> button.setBackground( null ) ); }
/** * Setup the round button. * * @param button Button to setup * @param params Customization parameters * @param graphic Graphics contents * @param tooltip Tooltip text */ public static void setupMenuButton(ButtonBase button, RadialMenuParams params, Node graphic, String tooltip) { button.minWidthProperty().bind(params.buttonSizeProperty()); button.minHeightProperty().bind(params.buttonSizeProperty()); button.prefWidthProperty().bind(params.buttonSizeProperty()); button.prefHeightProperty().bind(params.buttonSizeProperty()); button.maxWidthProperty().bind(params.buttonSizeProperty()); button.maxHeightProperty().bind(params.buttonSizeProperty()); button.setId(CSS_ID); button.getStylesheets().add(CSS_NAME); button.setGraphic(graphic); button.setTooltip(new Tooltip(tooltip)); }
private ButtonBase addNoneButton() { final LocatedImage none = new LocatedImage("/images/blank_page.png"); final InputStream isThumbnail = ArenaBackgroundsSlide.class.getResourceAsStream("/images/blank_page.png"); final ImageView thumbnailView = new ImageView(new Image(isThumbnail, 60, 60, true, true)); final ToggleButton noneButton = (ToggleButton) itemPane.addButton(none, "None", Optional.of(thumbnailView), Optional.empty()); noneButton.setSelected(true); itemPane.setDefault(none); return noneButton; }
private void prepareButtons() { int[] space = new int[] { 3, 7, 10, 13 }; int indexSpace = 0; String[] buttonName = new String[] { "Play", "Stop", "Reverse", "Previous", "Slower", "Faster", "Next", "Step_backward", "Refresh", "Step_forward", "Loop_A_B", "PlayList", "Loop_or_Repeat_mode", "RecordOff" }; buttons = new ButtonBase[buttonName.length]; for (int i = 0; i < buttonName.length; i++) { ButtonBase button = (i == 11 || i == 12) ? new ToggleButton(null, icons[i]) : new Button(null, icons[i]); int size = i == 0 ? 34 : 26; button.setMaxSize(size, size); button.setMinSize(size, size); if(indexSpace < space.length && i == space[indexSpace]){ HBox.setMargin(button, new Insets(0, 0, 0, 10)); indexSpace++; } button.setTooltip(new Tooltip(buttonName[i].replace("_or_", "/").replace("_", " "))); buttons[i] = button; if (i == PLAYLIST) ((ToggleButton) button).setSelected(true); else if (i == LOOPOREPEATMODE) ((ToggleButton) button).setSelected(true); } }
@Override protected final CheckBox createJFXNode() throws Exception { final CheckBox checkbox = new CheckBox(label); checkbox.setMinSize(ButtonBase.USE_PREF_SIZE, ButtonBase.USE_PREF_SIZE); checkbox.setMnemonicParsing(false); if (! toolkit.isEditMode()) checkbox.setOnAction(event -> handlePress()); return checkbox; }
@Override public ButtonBase createJFXNode() throws Exception { led = new Ellipse(); button = new Button("BoolButton", led); button.getStyleClass().add("action_button"); button.setOnAction(event -> handlePress()); button.setMnemonicParsing(false); // Model has width/height, but JFX widget has min, pref, max size. // updateChanges() will set the 'pref' size, so make min use that as well. button.setMinSize(ButtonBase.USE_PREF_SIZE, ButtonBase.USE_PREF_SIZE); return button; }
@Test public void testGetButtonBaseAdjuster() { Adjuster adjuster = Adjuster.getAdjuster(ButtonBase.class); assertThat(adjuster, is(instanceOf(ControlAdjuster.class))); assertThat(adjuster.getNodeClass(), is(sameInstance(Control.class))); }
private void configButton(ButtonBase button) { if (buttonId != null) { button.setId(buttonId); } if ((options & ActionOption.HIDE_BUTTON_TEXT) == 0) { button.textProperty().bindBidirectional(text); } if (description.get() != null) { final Tooltip tooltip = new Tooltip(); tooltip.textProperty().bindBidirectional(description); button.setTooltip(tooltip); } if (style.get() != null) { button.styleProperty().bindBidirectional(style); } if ((graphic.get() != null) && ((options & ActionOption.HIDE_BUTTON_GRAPHIC) == 0)) { button.graphicProperty().bindBidirectional(graphic); } if (alignment.get() != null) { button.alignmentProperty().bindBidirectional(alignment); } if (contentDisplay.get() != null) { button.contentDisplayProperty().bindBidirectional(contentDisplay); } if (graphicTextGap.get() >= 0) { button.graphicTextGapProperty().bindBidirectional(graphicTextGap); } button.visibleProperty().bindBidirectional(visible); button.managedProperty().bindBidirectional(managed); button.mnemonicParsingProperty().bindBidirectional(mnemonicParsing); button.getStyleClass().addAll(styleClass); if (bindStyleClass) { styleClass.setAll(button.getStyleClass()); Bindings.bindContentBidirectional(styleClass, button.getStyleClass()); } button.setOnAction(this); }
/** * Creates a button from the specified action. * * @param id * the id of the specified action, which cannot be the id of the * {@link SeparatorAction}. * @return the button created from the specified action, or null if no such * action */ public final ButtonBase createButton(String id) { if (SeparatorAction.ID.equals(id)) { logger.error("Cannot create button from a SeparatorAction."); return null; } final IAction action = map.get(id); if (action == null) { logger.error("Unknown action id: {}", id); return null; } else { return (ButtonBase) action.createButton(); } }
private void updateSortOrder() { final ApplicationState state = application.getState(); final ActionManager am = application.getActionManager(); final SortOrder order = state.getSortOrder(); logger.debug("Updating the sorting order {}.", order); final IAction sortOrderAsc = am.get(SortOrderAscAction.ID); final IAction sortOrderDesc = am.get(SortOrderDescAction.ID); sortOrderAsc.setSelected(false); sortOrderDesc.setSelected(false); final String newStyleClass; switch (order) { case ASC: sortOrderAsc.setSelected(true); newStyleClass = SortOrderAscAction.BUTTON_CLASS; break; case DESC: sortOrderDesc.setSelected(true); newStyleClass = SortOrderDescAction.BUTTON_CLASS; break; default: logger.error("Unknown sorting order: {}", order); return; } final MainContent mainContent = application.findNodeById(MainContent.ID); final ContentPanel content = mainContent.getCurrentContent(); final ButtonBase sortButton = content.findNodeByClass(SortAction.BUTTON_CLASS); if (sortButton != null) { // change the icon of the sort order button final ObservableList<String> styleClass = sortButton.getStyleClass(); styleClass.remove(SortOrderAscAction.BUTTON_CLASS); styleClass.remove(SortOrderDescAction.BUTTON_CLASS); styleClass.add(newStyleClass); } }
@Override protected void configFooterLeftToolBar(HBox toolBar) { final ActionManager am = application.getActionManager(); final ButtonBase createNote = am.createButton(AnnotateNoteAction.ID); final ButtonBase highlight = am.createButton(AnnotateHighlightAction.ID); final ButtonBase underline = am.createButton(AnnotateUnderlineAction.ID); final ButtonBase strikethrough = am.createButton(AnnotateStrikethroughAction.ID); toolBar.getChildren().addAll(createNote, highlight, underline, strikethrough); }
@Override protected void configFooterRightToolBar(HBox toolBar) { final ActionManager am = application.getActionManager(); final ButtonBase print = am.createButton(PrintAction.ID); final ButtonBase share = am.createButton(ShareAction.ID); final ButtonBase showInspector = am.createButton(ShowInspectorAction.ID); toolBar.getChildren().addAll(print, share, showInspector); }
@Override protected void configFooterRightToolBar(HBox toolBar) { final ActionManager am = application.getActionManager(); final ButtonBase share = am.createButton(ShareAction.ID); final ButtonBase showInspector = am.createButton(ShowInspectorAction.ID); toolBar.getChildren().addAll(share, showInspector); }
@Override protected void configHeader() { final ActionManager am = application.getActionManager(); final ButtonBase overview = am.createButton(InspectorTab.OVERVIEW.actionId()); header.getChildren().add(overview); final ButtonBase activity = am.createButton(InspectorTab.ACTIVITY.actionId()); header.getChildren().add(activity); }
/** * Configures the footer. */ @Override protected final void configFooter() { final ActionManager am = application.getActionManager(); final ButtonBase hideInspectorButton = am.createButton(HideInspectorAction.ID); footer.getChildren().add(hideInspectorButton); }
@Override protected void configFooterLeftToolBar(HBox toolBar) { final ActionManager am = application.getActionManager(); final ButtonBase newSource = am.createButton(NewSourceAction.ID); final ButtonBase manageSource = am.createButton(ManageSourceAction.ID); toolBar.getChildren().addAll(newSource, manageSource); }
@Override protected void configFooterLeftToolBar(HBox toolBar) { final ActionManager am = application.getActionManager(); final ButtonBase newAuthor = am.createButton(NewAuthorAction.ID); final ButtonBase manageAuthor = am.createButton(ManageAuthorAction.ID); toolBar.getChildren().addAll(newAuthor, manageAuthor); }