Search in sources :

Example 1 with ButtonBase

use of javafx.scene.control.ButtonBase in project org.csstudio.display.builder by kasemir.

the class ActionButtonRepresentation method makeBaseButton.

// private int calls = 0;
/**
 * Create <code>base</code>, either single-action button
 *  or menu for selecting one out of N actions
 */
private ButtonBase makeBaseButton() {
    final ActionInfos actions = model_widget.propActions().getValue();
    final ButtonBase result;
    if (actions.isExecutedAsOne() || actions.getActions().size() < 2) {
        final Button button = new Button();
        button.setOnAction(event -> handleActions(actions.getActions()));
        result = button;
    } else {
        final MenuButton button = new MenuButton();
        // Experimenting with ways to force update of popup location,
        // #226
        button.showingProperty().addListener((prop, old, showing) -> {
            if (showing) {
            // System.out.println("Showing " + model_widget + " menu: " + showing);
            // if (++calls > 2)
            // {
            // System.out.println("Hack!");
            // if (button.getPopupSide() == Side.BOTTOM)
            // button.setPopupSide(Side.LEFT);
            // else
            // button.setPopupSide(Side.BOTTOM);
            // // button.layout();
            // }
            }
        });
        for (final ActionInfo action : actions.getActions()) {
            final MenuItem item = new MenuItem(makeActionText(action), new ImageView(new Image(action.getType().getIconStream())));
            item.getStyleClass().add("action_button_item");
            item.setOnAction(event -> handleAction(action));
            button.getItems().add(item);
        }
        result = button;
    }
    result.setStyle(background);
    result.getStyleClass().add("action_button");
    result.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.
    result.setMinSize(ButtonBase.USE_PREF_SIZE, ButtonBase.USE_PREF_SIZE);
    // Monitor keys that modify the OpenDisplayActionInfo.Target.
    // Use filter to capture event that's otherwise already handled.
    result.addEventFilter(MouseEvent.MOUSE_PRESSED, this::checkModifiers);
    // Need to attach TT to the specific button, not the common jfx_node Pane
    TooltipSupport.attach(result, model_widget.propTooltip());
    result.setCursor(Cursor.HAND);
    return result;
}
Also used : Button(javafx.scene.control.Button) MenuButton(javafx.scene.control.MenuButton) ActionInfos(org.csstudio.display.builder.model.properties.ActionInfos) MenuButton(javafx.scene.control.MenuButton) ActionInfo(org.csstudio.display.builder.model.properties.ActionInfo) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo) MenuItem(javafx.scene.control.MenuItem) ButtonBase(javafx.scene.control.ButtonBase) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image)

Example 2 with ButtonBase

use of javafx.scene.control.ButtonBase in project org.csstudio.display.builder by kasemir.

the class ImageToolbarHandler method newItem.

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;
}
Also used : ToggleButton(javafx.scene.control.ToggleButton) Button(javafx.scene.control.Button) ToggleButton(javafx.scene.control.ToggleButton) Tooltip(javafx.scene.control.Tooltip) ButtonBase(javafx.scene.control.ButtonBase) ImageView(javafx.scene.image.ImageView)

Example 3 with ButtonBase

use of javafx.scene.control.ButtonBase in project org.csstudio.display.builder by kasemir.

the class ToolbarHandler method newItem.

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;
}
Also used : ToggleButton(javafx.scene.control.ToggleButton) Button(javafx.scene.control.Button) ToggleButton(javafx.scene.control.ToggleButton) Tooltip(javafx.scene.control.Tooltip) ButtonBase(javafx.scene.control.ButtonBase) ImageView(javafx.scene.image.ImageView)

Aggregations

Button (javafx.scene.control.Button)3 ButtonBase (javafx.scene.control.ButtonBase)3 ImageView (javafx.scene.image.ImageView)3 ToggleButton (javafx.scene.control.ToggleButton)2 Tooltip (javafx.scene.control.Tooltip)2 MenuButton (javafx.scene.control.MenuButton)1 MenuItem (javafx.scene.control.MenuItem)1 Image (javafx.scene.image.Image)1 ActionInfo (org.csstudio.display.builder.model.properties.ActionInfo)1 ActionInfos (org.csstudio.display.builder.model.properties.ActionInfos)1 OpenDisplayActionInfo (org.csstudio.display.builder.model.properties.OpenDisplayActionInfo)1