javafx.scene.control.ButtonBase Java Examples
The following examples show how to use
javafx.scene.control.ButtonBase.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NavigationAction.java From phoebus with Eclipse Public License 1.0 | 6 votes |
/** @param instance {@link DisplayRuntimeInstance} * @param navigation {@link DisplayNavigation} for that instance * @return Button for navigating 'back' */ public static ButtonBase createBackAction(final DisplayRuntimeInstance instance, final DisplayNavigation navigation) { return new NavigationAction(instance, navigation, Messages.NavigateBack_TT, backward, backward_dis) { @Override protected List<DisplayInfo> getDisplays() { return navigation.getBackwardDisplays(); } @Override protected DisplayInfo getDisplayInfo(final int steps) { return navigation.goBackward(steps); } }; }
Example #2
Source File: NavigationAction.java From phoebus with Eclipse Public License 1.0 | 6 votes |
/** @param instance {@link DisplayRuntimeInstance} * @param navigation {@link DisplayNavigation} for that instance * @return Button for navigating 'forward' */ public static ButtonBase createForewardAction(final DisplayRuntimeInstance instance, final DisplayNavigation navigation) { return new NavigationAction(instance, navigation, Messages.NavigateForward_TT, forward, forward_dis) { @Override protected List<DisplayInfo> getDisplays() { return navigation.getForwardDisplays(); } @Override protected DisplayInfo getDisplayInfo(final int steps) { return navigation.goForward(steps); } }; }
Example #3
Source File: SlideCheckBoxBehavior.java From JFX8CustomControls with Apache License 2.0 | 6 votes |
/** * 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(); } }
Example #4
Source File: FXUIUtils.java From marathonv5 with Apache License 2.0 | 6 votes |
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; }
Example #5
Source File: ChoiceButtonRepresentation.java From phoebus with Eclipse Public License 1.0 | 6 votes |
private void sizeButtons() { final int N = Math.max(1, jfx_node.getChildren().size()); final int width, height; if (model_widget.propHorizontal().getValue()) { jfx_node.setPrefColumns(N); width = (int) ((model_widget.propWidth().getValue() - (N-1)*jfx_node.getHgap()) / N); height = model_widget.propHeight().getValue(); } else { jfx_node.setPrefRows(N); width = model_widget.propWidth().getValue(); height = (int) ((model_widget.propHeight().getValue() - (N-1)*jfx_node.getVgap()) / N); } for (Node node : jfx_node.getChildren()) { final ButtonBase b = (ButtonBase) node; b.setMinSize(width, height); b.setPrefSize(width, height); b.setMaxSize(width, height); } }
Example #6
Source File: ActionUtils.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 6 votes |
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); if (action.action != null) 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; }
Example #7
Source File: StateCell.java From phoebus with Eclipse Public License 1.0 | 6 votes |
private Button createButton(final String icon, final String tooltip, final ScanAction action) { final Button button = new Button(); button.setMinSize(ButtonBase.USE_PREF_SIZE, ButtonBase.USE_PREF_SIZE); button.setPrefHeight(20); button.setGraphic(ImageCache.getImageView(StateCell.class, icon)); button.setTooltip(new Tooltip(tooltip)); button.setOnAction(event -> { try { action.perform(getTableRow().getItem().id.get()); } catch (Exception ex) { logger.log(Level.WARNING, "Failed: " + tooltip, ex); } }); return button; }
Example #8
Source File: ToolbarHandler.java From phoebus with Eclipse Public License 1.0 | 6 votes |
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)); // setMinSize tends to have all icons end up in top-left corner?! item.setPrefSize(BUTTON_WIDTH, BUTTON_HEIGHT); toolbar.getItems().add(item); return item; }
Example #9
Source File: ImageToolbarHandler.java From phoebus with Eclipse Public License 1.0 | 6 votes |
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)); item.setMinSize(ToolbarHandler.BUTTON_WIDTH, ToolbarHandler.BUTTON_HEIGHT); toolbar.getItems().add(item); return item; }
Example #10
Source File: SlideCheckBoxBehavior.java From JFX8CustomControls with Apache License 2.0 | 5 votes |
/*************************************************************************** * * * Focus change handling * * * **************************************************************************/ @Override protected void focusChanged() { // If we did have the key down, but are now not focused, then we must // disarm the button. final ButtonBase button = getControl(); if (keyDown && !button.isFocused()) { keyDown = false; button.disarm(); } }
Example #11
Source File: DiagramTabToolBar.java From JetUML with GNU General Public License v3.0 | 5 votes |
/** * Adds the button to this toolbar and the corresponding context menu. * * @param pButton The button to add. * @param pText The text for the menu */ private void add(ButtonBase pButton, Canvas pIcon, String pText) { assert pButton != null; getItems().add( pButton ); MenuItem item = new MenuItem(pText); item.setGraphic(pIcon); item.setOnAction(pButton.getOnAction()); aPopupMenu.getItems().add(item); }
Example #12
Source File: DiagramTabToolBar.java From JetUML with GNU General Public License v3.0 | 5 votes |
/** * Shows or hides the textual description of the tools and commands. * @param pShow True if the labels should be shown */ private void showButtonLabels(boolean pShow) { for( javafx.scene.Node item : getItems() ) { ButtonBase button = (ButtonBase) item; if( pShow ) { if( item instanceof SelectableToolButton && ((SelectableToolButton)item).getPrototype().isPresent()) { SelectableToolButton toolButton = (SelectableToolButton) item; String text = Prototypes.instance().tooltip(toolButton.getPrototype().get(), false); button.setText(text); } else { button.setText(button.getTooltip().getText()); } button.setMaxWidth(Double.MAX_VALUE); } else { button.setText(""); button.autosize(); } } }
Example #13
Source File: HouseRulesPanel.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void setOptionsBasedOnControls() { final GameMode gameMode = SettingsHandler.getGameAsProperty().get(); for (Map.Entry<RuleCheck, ButtonBase> settingsEntry : settings.entrySet()) { // Save settings if (gameMode.getModeContext().getReferenceContext().containsConstructedCDOMObject( RuleCheck.class, settingsEntry.getKey().getKeyName() )) { ButtonBase buttonBase = settingsEntry.getValue(); final boolean isSelected; // see https://github.com/javafxports/openjdk-jfx/issues/494 if (buttonBase instanceof RadioButton) { isSelected = ((Toggle) buttonBase).selectedProperty().get(); } else if (buttonBase instanceof CheckBox) { isSelected = ((CheckBox) buttonBase).selectedProperty().get(); } else { throw new IllegalStateException("button base that isn't of the right type " + buttonBase); } SettingsHandler.setRuleCheck(settingsEntry.getKey().getKeyName(), isSelected); } } }
Example #14
Source File: ArenaBackgroundsSlide.java From ShootOFF with GNU General Public License v3.0 | 5 votes |
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; }
Example #15
Source File: HouseRulesPanel.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void setOptionsBasedOnControls() { final GameMode gameMode = SettingsHandler.getGameAsProperty().get(); for (Map.Entry<RuleCheck, ButtonBase> settingsEntry : settings.entrySet()) { // Save settings if (gameMode.getModeContext().getReferenceContext().containsConstructedCDOMObject( RuleCheck.class, settingsEntry.getKey().getKeyName() )) { ButtonBase buttonBase = settingsEntry.getValue(); final boolean isSelected; // see https://github.com/javafxports/openjdk-jfx/issues/494 if (buttonBase instanceof RadioButton) { isSelected = ((Toggle) buttonBase).selectedProperty().get(); } else if (buttonBase instanceof CheckBox) { isSelected = ((CheckBox) buttonBase).selectedProperty().get(); } else { throw new IllegalStateException("button base that isn't of the right type " + buttonBase); } SettingsHandler.setRuleCheck(settingsEntry.getKey().getKeyName(), isSelected); } } }
Example #16
Source File: DynamicIconSupport.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * 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); } }
Example #17
Source File: SlideCheckBoxBehavior.java From JFX8CustomControls with Apache License 2.0 | 5 votes |
/** * This function is invoked when an appropriate keystroke occurs which * causes this button to be armed if it is not already armed by a mouse * press. */ private void keyPressed() { final ButtonBase button = getControl(); if (!button.isPressed() && !button.isArmed()) { keyDown = true; button.arm(); } }
Example #18
Source File: SlideCheckBoxBehavior.java From JFX8CustomControls with Apache License 2.0 | 5 votes |
/** * Invoked when a valid keystroke release occurs which causes the button * to fire if it was armed by a keyPress. */ private void keyReleased() { final ButtonBase button = getControl(); if (keyDown) { keyDown = false; if (button.isArmed()) { button.disarm(); button.fire(); } } }
Example #19
Source File: SlideCheckBoxBehavior.java From JFX8CustomControls with Apache License 2.0 | 5 votes |
/** * Invoked when a mouse release has occurred. We determine whether this * was done in a manner that would fire the button's action. This happens * only if the button was armed by a corresponding mouse press. */ @Override public void mouseReleased(MouseEvent e) { // if armed by a mouse press instead of key press, then fire! final ButtonBase button = getControl(); if (! keyDown && button.isArmed()) { button.fire(); button.disarm(); } }
Example #20
Source File: SlideCheckBoxBehavior.java From JFX8CustomControls with Apache License 2.0 | 5 votes |
/** * Invoked when the mouse enters the Button. If the Button had been armed * by a mouse press and the mouse is still pressed, then this will cause * the button to be rearmed. */ @Override public void mouseEntered(MouseEvent e) { // rearm if necessary final ButtonBase button = getControl(); super.mouseEntered(e); if (! keyDown && button.isPressed()) { button.arm(); } }
Example #21
Source File: SlideCheckBoxBehavior.java From JFX8CustomControls with Apache License 2.0 | 5 votes |
/** * Invoked when the mouse exits the Button. If the Button is armed due to * a mouse press, then this function will disarm the button upon the mouse * exiting it. */ @Override public void mouseExited(MouseEvent e) { // Disarm if necessary final ButtonBase button = getControl(); super.mouseExited(e); if (! keyDown && button.isArmed()) { button.disarm(); } }
Example #22
Source File: DiagramTabToolBar.java From JetUML with GNU General Public License v3.0 | 5 votes |
/** * Adds the button to this toolbar and the corresponding context menu. * * @param pButton The button to add. * @param pText The text for the menu */ private void add(ButtonBase pButton, String pText) { assert pButton != null; getItems().add( pButton ); MenuItem item = new MenuItem(pText); item.setGraphic(new ImageView(((ImageView)pButton.getGraphic()).getImage())); item.setOnAction(pButton.getOnAction()); aPopupMenu.getItems().add(item); }
Example #23
Source File: FxAction.java From FxDock with Apache License 2.0 | 5 votes |
public void attach(ButtonBase b) { b.setOnAction(this); b.disableProperty().bind(disabledProperty()); if(b instanceof ToggleButton) { ((ToggleButton)b).selectedProperty().bindBidirectional(selectedProperty()); } }
Example #24
Source File: DynamicIconSupport.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * 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.getEnum(PREF_UI_THEME, PREF_DEFAULT_THEME); 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); } }
Example #25
Source File: ToolbarHelper.java From phoebus with Eclipse Public License 1.0 | 5 votes |
/** Hack ill-sized toolbar buttons * * <p>When toolbar is originally hidden and then later * shown, it tends to be garbled, all icons in pile at left end, * Manual fix is to hide and show again. * Workaround is to force another layout a little later. */ public static void refreshHack(final ToolBar toolbar) { if (toolbar.getParent() == null) return; for (Node node : toolbar.getItems()) { if (! (node instanceof ButtonBase)) continue; final ButtonBase button = (ButtonBase) node; final Node icon = button.getGraphic(); if (icon == null) continue; // Re-set the icon to force new layout of button button.setGraphic(null); button.setGraphic(icon); if (button.getWidth() == 0 || button.getHeight() == 0) { // If button has no size, yet, try again later ForkJoinPool.commonPool().submit(() -> { Thread.sleep(500); Platform.runLater(() -> refreshHack(toolbar)); return null; }); return; } } Platform.runLater(() -> toolbar.layout()); }
Example #26
Source File: WebBrowserDemo.java From phoebus with Eclipse Public License 1.0 | 5 votes |
public BrowserWithToolbar(String url) { super(url); locationChanged(null, null, webEngine.getLocation()); //assemble toolbar controls backButton.setOnAction(this::handleBackButton); foreButton.setOnAction(this::handleForeButton); stop.setOnAction(this::handleStop); refresh.setOnAction(this::handleRefresh); addressBar.setOnAction(this::handleGo); go.setOnAction(this::handleGo); foreButton.setDisable(true); backButton.setDisable(true); addressBar.setEditable(true); //addressBar.setOnShowing(this::handleShowing); webEngine.locationProperty().addListener(this::locationChanged); history.getEntries().addListener(this::entriesChanged); for (int i = 0; i < controls.length; i++) { Control control = controls[i]; if (control instanceof ButtonBase) { HBox.setHgrow(control, Priority.NEVER); ((ButtonBase)control).setGraphic(new ImageView(new Image(ModelPlugin.class.getResource("/icons/browser/" + iconFiles[i]).toExternalForm()))); } else HBox.setHgrow(control, Priority.ALWAYS); } //add toolbar component toolbar = new HBox(controls); toolbar.getStyleClass().add("browser-toolbar"); getChildren().add(toolbar); }
Example #27
Source File: BoolButtonRepresentation.java From phoebus with Eclipse Public License 1.0 | 5 votes |
@Override public ButtonBase createJFXNode() throws Exception { led = new Ellipse(); led.getStyleClass().add("led"); button = new Button("BoolButton", led); button.getStyleClass().add("action_button"); 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); // Fix initial layout toolkit.execute(() -> Platform.runLater(button::requestLayout)); if (! toolkit.isEditMode()) { if (model_widget.propMode().getValue() == Mode.TOGGLE) button.setOnAction(event -> handlePress(true)); else { final boolean inverted = model_widget.propMode().getValue() == Mode.PUSH_INVERTED; button.setOnMousePressed(event -> handlePress(! inverted)); button.setOnMouseReleased(event -> handlePress(inverted)); } } return button; }
Example #28
Source File: CheckBoxRepresentation.java From phoebus with Eclipse Public License 1.0 | 5 votes |
@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; }
Example #29
Source File: ChoiceButtonRepresentation.java From phoebus with Eclipse Public License 1.0 | 5 votes |
private void selectionChanged(final ObservableValue<? extends Toggle> obs, final Toggle oldval, final Toggle newval) { if (!active && newval != null) { active = true; try { // For now reset to old value. // New value will be shown if the PV accepts it and sends a value update. toggle.selectToggle(oldval); if (enabled) { final Object value; final VType pv_value = model_widget.runtimePropValue().getValue(); if (pv_value instanceof VEnum || pv_value instanceof VNumber) // PV uses enumerated or numeric type, so write the index value = toggle.getToggles().indexOf(newval); else // PV uses text value = FormatOptionHandler.parse(pv_value, ((ButtonBase) newval).getText(), FormatOption.DEFAULT); logger.log(Level.FINE, "Writing " + value); Platform.runLater(() -> confirm(value)); } } finally { active = false; } } }
Example #30
Source File: ChoiceButtonRepresentation.java From phoebus with Eclipse Public License 1.0 | 5 votes |
private ButtonBase createButton(final String text) { final ToggleButton b = new ToggleButton(text); b.getStyleClass().add("action_button"); b.setToggleGroup(toggle); b.setMnemonicParsing(false); return b; }