Search in sources :

Example 31 with ComboBox

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

the class ImageConfigDialog method createContent.

private Node createContent() {
    final GridPane layout = new GridPane();
    layout.setHgap(5);
    layout.setVgap(5);
    // Debug layout
    // layout.setGridLinesVisible(true);
    // Row to use for the next elements
    int row = 0;
    Label label = new Label("Value Range");
    final Font font = label.getFont();
    final Font section_font = Font.font(font.getFamily(), FontWeight.BOLD, font.getSize());
    label.setFont(section_font);
    layout.add(label, 0, ++row);
    // Only show the color mapping selector when it's currently a named mapping.
    // Suppress when widget has a custom color map.
    final ColorMappingFunction selected_mapping = plot.internalGetImagePlot().getColorMapping();
    if (selected_mapping instanceof NamedColorMapping) {
        label = new Label("Mapping");
        layout.add(label, 1, row);
        final ComboBox<String> mappings = new ComboBox<>();
        mappings.setEditable(false);
        mappings.setMaxWidth(Double.MAX_VALUE);
        for (NamedColorMapping mapping : NamedColorMappings.getMappings()) mappings.getItems().add(mapping.getName());
        mappings.setValue(((NamedColorMapping) selected_mapping).getName());
        mappings.setOnAction(event -> {
            final NamedColorMapping mapping = NamedColorMappings.getMapping(mappings.getValue());
            plot.setColorMapping(mapping);
        });
        layout.add(mappings, 2, row++);
    }
    label = new Label("Minimum");
    layout.add(label, 1, row);
    final TextField min = new TextField(Double.toString(plot.getValueRange().getLow()));
    layout.add(min, 2, row);
    label = new Label("Maximum");
    layout.add(label, 1, ++row);
    final TextField max = new TextField(Double.toString(plot.getValueRange().getHigh()));
    layout.add(max, 2, row);
    final EventHandler<ActionEvent> update_range = event -> {
        try {
            plot.setValueRange(Double.parseDouble(min.getText().trim()), Double.parseDouble(max.getText().trim()));
            plot.internalGetImagePlot().fireChangedValueRange();
        } catch (NumberFormatException ex) {
            final ValueRange range = plot.getValueRange();
            min.setText(Double.toString(range.getLow()));
            max.setText(Double.toString(range.getHigh()));
        }
    };
    min.setOnAction(update_range);
    max.setOnAction(update_range);
    final CheckBox autoscale = new CheckBox("auto-scale");
    autoscale.setSelected(plot.isAutoscale());
    min.setDisable(autoscale.isSelected());
    max.setDisable(autoscale.isSelected());
    autoscale.setOnAction(event -> {
        plot.setAutoscale(autoscale.isSelected());
        min.setDisable(autoscale.isSelected());
        max.setDisable(autoscale.isSelected());
        plot.internalGetImagePlot().fireChangedAutoScale();
    });
    layout.add(autoscale, 2, ++row);
    final CheckBox show_color_bar = new CheckBox("show color bar");
    show_color_bar.setSelected(plot.isShowingColorMap());
    show_color_bar.setOnAction(event -> plot.showColorMap(show_color_bar.isSelected()));
    layout.add(show_color_bar, 2, ++row);
    final CheckBox logscale = new CheckBox("log scale");
    logscale.setSelected(plot.isLogscale());
    logscale.setOnAction(event -> {
        plot.setLogscale(logscale.isSelected());
        plot.internalGetImagePlot().fireChangedLogarithmic();
    });
    layout.add(logscale, 2, ++row);
    label = new Label("Horizontal Axis");
    label.setFont(section_font);
    layout.add(label, 0, ++row);
    row = addAxisContent(layout, row, plot.getXAxis());
    label = new Label("Vertical Axis");
    label.setFont(section_font);
    layout.add(label, 0, ++row);
    row = addAxisContent(layout, row, plot.getYAxis());
    return layout;
}
Also used : NamedColorMapping(org.csstudio.javafx.rtplot.NamedColorMapping) EventHandler(javafx.event.EventHandler) FontWeight(javafx.scene.text.FontWeight) Activator(org.csstudio.javafx.rtplot.Activator) NamedColorMappings(org.csstudio.javafx.rtplot.NamedColorMappings) TextField(javafx.scene.control.TextField) Modality(javafx.stage.Modality) Dialog(javafx.scene.control.Dialog) Label(javafx.scene.control.Label) ButtonType(javafx.scene.control.ButtonType) Node(javafx.scene.Node) CheckBox(javafx.scene.control.CheckBox) Font(javafx.scene.text.Font) ValueRange(org.csstudio.javafx.rtplot.data.ValueRange) ActionEvent(javafx.event.ActionEvent) ComboBox(javafx.scene.control.ComboBox) RTImagePlot(org.csstudio.javafx.rtplot.RTImagePlot) ImageView(javafx.scene.image.ImageView) ColorMappingFunction(org.csstudio.javafx.rtplot.ColorMappingFunction) Axis(org.csstudio.javafx.rtplot.Axis) GridPane(javafx.scene.layout.GridPane) GridPane(javafx.scene.layout.GridPane) ComboBox(javafx.scene.control.ComboBox) ActionEvent(javafx.event.ActionEvent) ColorMappingFunction(org.csstudio.javafx.rtplot.ColorMappingFunction) Label(javafx.scene.control.Label) Font(javafx.scene.text.Font) ValueRange(org.csstudio.javafx.rtplot.data.ValueRange) CheckBox(javafx.scene.control.CheckBox) NamedColorMapping(org.csstudio.javafx.rtplot.NamedColorMapping) TextField(javafx.scene.control.TextField)

Example 32 with ComboBox

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

the class PropertyPanelSection method bindSimplePropertyField.

/**
 * Some 'simple' properties are handled
 *  in static method to allow use in the
 *  RulesDialog
 *  @param undo
 *  @param bindings
 *  @param property
 *  @param other
 *  @return
 */
public static Node bindSimplePropertyField(final UndoableActionManager undo, final List<WidgetPropertyBinding<?, ?>> bindings, final WidgetProperty<?> property, final List<Widget> other) {
    final Widget widget = property.getWidget();
    Node field = null;
    if (property.isReadonly()) {
        // If "Type", use a label with an icon.
        if (property.getName().equals(CommonWidgetProperties.propType.getName())) {
            final String type = widget.getType();
            try {
                final Image image = new Image(WidgetFactory.getInstance().getWidgetDescriptor(type).getIconStream());
                final ImageView icon = new ImageView(image);
                final String name = WidgetFactory.getInstance().getWidgetDescriptor(type).getName();
                field = new Label(name, icon);
            } catch (Exception ex) {
                // Some widgets have no icon (e.g. DisplayModel).
                field = new Label(String.valueOf(property.getValue()));
            }
        } else {
            final TextField text = new TextField();
            text.setText(String.valueOf(property.getValue()));
            text.setDisable(true);
            field = text;
        }
    } else if (property instanceof ColorWidgetProperty) {
        final ColorWidgetProperty color_prop = (ColorWidgetProperty) property;
        final WidgetColorPropertyField color_field = new WidgetColorPropertyField();
        final WidgetColorPropertyBinding binding = new WidgetColorPropertyBinding(undo, color_field, color_prop, other);
        bindings.add(binding);
        binding.bind();
        field = color_field;
    } else if (property instanceof FontWidgetProperty) {
        final FontWidgetProperty font_prop = (FontWidgetProperty) property;
        final Button font_field = new Button();
        font_field.setMaxWidth(Double.MAX_VALUE);
        final WidgetFontPropertyBinding binding = new WidgetFontPropertyBinding(undo, font_field, font_prop, other);
        bindings.add(binding);
        binding.bind();
        field = font_field;
    } else if (property instanceof EnumWidgetProperty<?>) {
        final EnumWidgetProperty<?> enum_prop = (EnumWidgetProperty<?>) property;
        final ComboBox<String> combo = new ComboBox<>();
        combo.setPromptText(property.getDefaultValue().toString());
        combo.getItems().addAll(enum_prop.getLabels());
        combo.setMaxWidth(Double.MAX_VALUE);
        combo.setMaxHeight(Double.MAX_VALUE);
        final ToggleButton macroButton = new ToggleButton("$");
        try {
            macroButton.setGraphic(new ImageView(new Image(ResourceUtil.openPlatformResource("platform:/plugin/org.csstudio.display.builder.editor/icons/macro-edit.png"))));
        } catch (Exception ex) {
            logger.log(Level.WARNING, "Cannot load macro edit image.", ex);
        }
        macroButton.getStyleClass().add("macro_button");
        macroButton.setTooltip(new Tooltip(Messages.MacroEditButton));
        BorderPane.setMargin(macroButton, new Insets(0, 0, 0, 3));
        BorderPane.setAlignment(macroButton, Pos.CENTER);
        final EnumWidgetPropertyBinding binding = new EnumWidgetPropertyBinding(undo, combo, enum_prop, other);
        bindings.add(binding);
        binding.bind();
        final EventHandler<ActionEvent> macro_handler = event -> {
            final boolean use_macro = macroButton.isSelected() || MacroHandler.containsMacros(enum_prop.getSpecification());
            combo.setEditable(use_macro);
            // now that the combo has become editable.
            if (use_macro && combo.getEditor().getText().isEmpty())
                binding.restore();
        };
        macroButton.setOnAction(macro_handler);
        macroButton.setSelected(MacroHandler.containsMacros(enum_prop.getSpecification()));
        macro_handler.handle(null);
        field = new BorderPane(combo, null, macroButton, null, null);
        // When used in RulesDialog, field can get focus.
        // In that case, forward focus to combo
        field.focusedProperty().addListener((ob, o, focused) -> {
            if (focused) {
                combo.requestFocus();
                if (combo.isEditable())
                    combo.getEditor().selectAll();
            }
        });
    } else if (property instanceof BooleanWidgetProperty) {
        final BooleanWidgetProperty bool_prop = (BooleanWidgetProperty) property;
        final ComboBox<String> combo = new ComboBox<>();
        combo.setPromptText(property.getDefaultValue().toString());
        combo.getItems().addAll("true", "false");
        combo.setMaxWidth(Double.MAX_VALUE);
        combo.setMaxHeight(Double.MAX_VALUE);
        combo.setEditable(true);
        // BooleanWidgetPropertyBinding makes either check or combo visible
        // for plain boolean vs. macro-based value
        final CheckBox check = new CheckBox();
        StackPane.setAlignment(check, Pos.CENTER_LEFT);
        final ToggleButton macroButton = new ToggleButton("$");
        try {
            macroButton.setGraphic(new ImageView(new Image(ResourceUtil.openPlatformResource("platform:/plugin/org.csstudio.display.builder.editor/icons/macro-edit.png"))));
        } catch (Exception ex) {
            logger.log(Level.WARNING, "Cannot load macro edit image.", ex);
        }
        macroButton.getStyleClass().add("macro_button");
        macroButton.setTooltip(new Tooltip(Messages.MacroEditButton));
        BorderPane.setMargin(macroButton, new Insets(0, 0, 0, 3));
        BorderPane.setAlignment(macroButton, Pos.CENTER);
        final BooleanWidgetPropertyBinding binding = new BooleanWidgetPropertyBinding(undo, check, combo, macroButton, bool_prop, other);
        bindings.add(binding);
        binding.bind();
        field = new BorderPane(new StackPane(combo, check), null, macroButton, null, null);
        // For RulesDialog, see above
        field.focusedProperty().addListener((ob, o, focused) -> {
            if (focused) {
                if (combo.isVisible()) {
                    combo.requestFocus();
                    combo.getEditor().selectAll();
                } else if (check.isVisible())
                    check.requestFocus();
            }
        });
    } else if (property instanceof ColorMapWidgetProperty) {
        final ColorMapWidgetProperty colormap_prop = (ColorMapWidgetProperty) property;
        final Button map_button = new Button();
        map_button.setMaxWidth(Double.MAX_VALUE);
        final ColorMapPropertyBinding binding = new ColorMapPropertyBinding(undo, map_button, colormap_prop, other);
        bindings.add(binding);
        binding.bind();
        field = map_button;
    } else if (property instanceof WidgetClassProperty) {
        final WidgetClassProperty widget_class_prop = (WidgetClassProperty) property;
        final ComboBox<String> combo = new ComboBox<>();
        combo.setPromptText(property.getDefaultValue().toString());
        combo.setEditable(true);
        // List classes of this widget
        final String type = widget.getType();
        final Collection<String> classes = WidgetClassesService.getWidgetClasses().getWidgetClasses(type);
        combo.getItems().addAll(classes);
        combo.setMaxWidth(Double.MAX_VALUE);
        final WidgetClassBinding binding = new WidgetClassBinding(undo, combo, widget_class_prop, other);
        bindings.add(binding);
        binding.bind();
        field = combo;
    } else if (property instanceof FilenameWidgetProperty) {
        final FilenameWidgetProperty file_prop = (FilenameWidgetProperty) property;
        final TextField text = new TextField();
        text.setPromptText(file_prop.getDefaultValue().toString());
        text.setMaxWidth(Double.MAX_VALUE);
        final Button select_file = new Button("...");
        select_file.setOnAction(event -> {
            try {
                final String filename = FilenameSupport.promptForRelativePath(widget, file_prop.getValue());
                if (filename != null)
                    undo.execute(new SetMacroizedWidgetPropertyAction(file_prop, filename));
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Cannot prompt for " + file_prop, ex);
            }
        });
        final MacroizedWidgetPropertyBinding binding = new MacroizedWidgetPropertyBinding(undo, text, file_prop, other);
        bindings.add(binding);
        binding.bind();
        field = new HBox(text, select_file);
        HBox.setHgrow(text, Priority.ALWAYS);
        // For RulesDialog, see above
        field.focusedProperty().addListener((ob, o, focused) -> {
            if (focused)
                text.requestFocus();
        });
    } else if (property instanceof PVNameWidgetProperty) {
        final PVNameWidgetProperty pv_prop = (PVNameWidgetProperty) property;
        final TextField text = new TextField();
        text.setPromptText(pv_prop.getDefaultValue().toString());
        final MacroizedWidgetPropertyBinding binding = new MacroizedWidgetPropertyBinding(undo, text, pv_prop, other) {

            @Override
            public void bind() {
                super.bind();
                autocomplete_menu.attachField(text);
            }

            @Override
            public void unbind() {
                super.unbind();
                autocomplete_menu.removeField(text);
            }
        };
        bindings.add(binding);
        binding.bind();
        // Allow editing long PV names, including loc://text("Log text with newlines"),
        // in dialog
        final Button open_editor = new Button("...");
        open_editor.setOnAction(event -> {
            final MultiLineInputDialog dialog = new MultiLineInputDialog(pv_prop.getSpecification());
            DialogHelper.positionDialog(dialog, open_editor, -600, 0);
            final Optional<String> result = dialog.showAndWait();
            if (!result.isPresent())
                return;
            undo.execute(new SetMacroizedWidgetPropertyAction(pv_prop, result.get()));
            for (Widget w : other) {
                final MacroizedWidgetProperty<?> other_prop = (MacroizedWidgetProperty<?>) w.getProperty(pv_prop.getName());
                undo.execute(new SetMacroizedWidgetPropertyAction(other_prop, result.get()));
            }
        });
        field = new HBox(text, open_editor);
        HBox.setHgrow(text, Priority.ALWAYS);
        // For RulesDialog, see similar code elsewhere
        field.focusedProperty().addListener((ob, o, focused) -> {
            if (focused)
                text.requestFocus();
        });
    } else if (property instanceof MacroizedWidgetProperty) {
        // MacroizedWidgetProperty needs to be checked _after_ subclasses like PVNameWidgetProperty, FilenameWidgetProperty
        final MacroizedWidgetProperty<?> macro_prop = (MacroizedWidgetProperty<?>) property;
        final TextField text = new TextField();
        text.setPromptText(macro_prop.getDefaultValue().toString());
        final MacroizedWidgetPropertyBinding binding = new MacroizedWidgetPropertyBinding(undo, text, macro_prop, other);
        bindings.add(binding);
        binding.bind();
        if (CommonWidgetProperties.propText.getName().equals(property.getName()) || CommonWidgetProperties.propTooltip.getName().equals(property.getName())) {
            // Allow editing multi-line text in dialog
            final Button open_editor = new Button("...");
            open_editor.setOnAction(event -> {
                final MultiLineInputDialog dialog = new MultiLineInputDialog(macro_prop.getSpecification());
                DialogHelper.positionDialog(dialog, open_editor, -600, 0);
                final Optional<String> result = dialog.showAndWait();
                if (!result.isPresent())
                    return;
                undo.execute(new SetMacroizedWidgetPropertyAction(macro_prop, result.get()));
                for (Widget w : other) {
                    final MacroizedWidgetProperty<?> other_prop = (MacroizedWidgetProperty<?>) w.getProperty(macro_prop.getName());
                    undo.execute(new SetMacroizedWidgetPropertyAction(other_prop, result.get()));
                }
            });
            field = new HBox(text, open_editor);
            HBox.setHgrow(text, Priority.ALWAYS);
            // For RulesDialog, see above
            field.focusedProperty().addListener((ob, o, focused) -> {
                if (focused)
                    text.requestFocus();
            });
        } else
            field = text;
    } else if (property instanceof PointsWidgetProperty) {
        final PointsWidgetProperty points_prop = (PointsWidgetProperty) property;
        final Button points_field = new Button();
        points_field.setMaxWidth(Double.MAX_VALUE);
        final PointsPropertyBinding binding = new PointsPropertyBinding(undo, points_field, points_prop, other);
        bindings.add(binding);
        binding.bind();
        field = points_field;
    }
    return field;
}
Also used : EventHandler(javafx.event.EventHandler) Button(javafx.scene.control.Button) FilenameSupport(org.csstudio.display.builder.representation.javafx.FilenameSupport) HPos(javafx.geometry.HPos) Pos(javafx.geometry.Pos) UndoableActionManager(org.csstudio.display.builder.util.undo.UndoableActionManager) ScriptsWidgetProperty(org.csstudio.display.builder.model.properties.ScriptsWidgetProperty) SetMacroizedWidgetPropertyAction(org.csstudio.display.builder.editor.undo.SetMacroizedWidgetPropertyAction) StackPane(javafx.scene.layout.StackPane) MultiLineInputDialog(org.csstudio.javafx.MultiLineInputDialog) StructuredWidgetProperty(org.csstudio.display.builder.model.StructuredWidgetProperty) MacrosWidgetProperty(org.csstudio.display.builder.model.properties.MacrosWidgetProperty) ComboBox(javafx.scene.control.ComboBox) ResourceUtil(org.csstudio.display.builder.util.ResourceUtil) EnumWidgetProperty(org.csstudio.display.builder.model.properties.EnumWidgetProperty) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) BooleanWidgetProperty(org.csstudio.display.builder.model.properties.BooleanWidgetProperty) HBox(javafx.scene.layout.HBox) TextField(javafx.scene.control.TextField) Collection(java.util.Collection) WidgetClassProperty(org.csstudio.display.builder.model.properties.WidgetClassProperty) WidgetClassesService(org.csstudio.display.builder.model.persist.WidgetClassesService) Spinner(javafx.scene.control.Spinner) Messages(org.csstudio.display.builder.editor.Messages) CommonWidgetProperties(org.csstudio.display.builder.model.properties.CommonWidgetProperties) MacroizedWidgetProperty(org.csstudio.display.builder.model.MacroizedWidgetProperty) Separator(javafx.scene.control.Separator) Priority(javafx.scene.layout.Priority) List(java.util.List) ColorWidgetProperty(org.csstudio.display.builder.model.properties.ColorWidgetProperty) PointsWidgetProperty(org.csstudio.display.builder.model.properties.PointsWidgetProperty) ToggleButton(javafx.scene.control.ToggleButton) WidgetFactory(org.csstudio.display.builder.model.WidgetFactory) Optional(java.util.Optional) AutocompleteMenu(org.csstudio.display.builder.representation.javafx.AutocompleteMenu) BorderPane(javafx.scene.layout.BorderPane) PVNameWidgetProperty(org.csstudio.display.builder.model.properties.PVNameWidgetProperty) ColumnConstraints(javafx.scene.layout.ColumnConstraints) Plugin.logger(org.csstudio.display.builder.editor.Plugin.logger) FilenameWidgetProperty(org.csstudio.display.builder.model.properties.FilenameWidgetProperty) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) RulesWidgetProperty(org.csstudio.display.builder.model.properties.RulesWidgetProperty) Insets(javafx.geometry.Insets) Tooltip(javafx.scene.control.Tooltip) GridPane(javafx.scene.layout.GridPane) ArrayWidgetProperty(org.csstudio.display.builder.model.ArrayWidgetProperty) Label(javafx.scene.control.Label) WidgetPropertyCategory(org.csstudio.display.builder.model.WidgetPropertyCategory) FontWidgetProperty(org.csstudio.display.builder.model.properties.FontWidgetProperty) Node(javafx.scene.Node) CheckBox(javafx.scene.control.CheckBox) ColorMapWidgetProperty(org.csstudio.display.builder.model.properties.ColorMapWidgetProperty) ActionsWidgetProperty(org.csstudio.display.builder.model.properties.ActionsWidgetProperty) ActionEvent(javafx.event.ActionEvent) MacroHandler(org.csstudio.display.builder.model.macros.MacroHandler) ImageView(javafx.scene.image.ImageView) DialogHelper(org.csstudio.javafx.DialogHelper) Widget(org.csstudio.display.builder.model.Widget) Image(javafx.scene.image.Image) BorderPane(javafx.scene.layout.BorderPane) HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) PointsWidgetProperty(org.csstudio.display.builder.model.properties.PointsWidgetProperty) FontWidgetProperty(org.csstudio.display.builder.model.properties.FontWidgetProperty) Node(javafx.scene.Node) ColorMapWidgetProperty(org.csstudio.display.builder.model.properties.ColorMapWidgetProperty) Widget(org.csstudio.display.builder.model.Widget) Label(javafx.scene.control.Label) EventHandler(javafx.event.EventHandler) WidgetClassProperty(org.csstudio.display.builder.model.properties.WidgetClassProperty) Image(javafx.scene.image.Image) Button(javafx.scene.control.Button) ToggleButton(javafx.scene.control.ToggleButton) MultiLineInputDialog(org.csstudio.javafx.MultiLineInputDialog) TextField(javafx.scene.control.TextField) ImageView(javafx.scene.image.ImageView) StackPane(javafx.scene.layout.StackPane) ToggleButton(javafx.scene.control.ToggleButton) BooleanWidgetProperty(org.csstudio.display.builder.model.properties.BooleanWidgetProperty) Optional(java.util.Optional) ComboBox(javafx.scene.control.ComboBox) Tooltip(javafx.scene.control.Tooltip) FilenameWidgetProperty(org.csstudio.display.builder.model.properties.FilenameWidgetProperty) MacroizedWidgetProperty(org.csstudio.display.builder.model.MacroizedWidgetProperty) SetMacroizedWidgetPropertyAction(org.csstudio.display.builder.editor.undo.SetMacroizedWidgetPropertyAction) EnumWidgetProperty(org.csstudio.display.builder.model.properties.EnumWidgetProperty) CheckBox(javafx.scene.control.CheckBox) ColorWidgetProperty(org.csstudio.display.builder.model.properties.ColorWidgetProperty) PVNameWidgetProperty(org.csstudio.display.builder.model.properties.PVNameWidgetProperty)

Example 33 with ComboBox

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

the class DisplayEditor method createToolbar.

private ToolBar createToolbar() {
    final Button undo_button = createButton(ActionDescription.UNDO);
    final Button redo_button = createButton(ActionDescription.REDO);
    undo_button.setDisable(true);
    redo_button.setDisable(true);
    undo.addListener((to_undo, to_redo) -> {
        undo_button.setDisable(to_undo == null);
        redo_button.setDisable(to_redo == null);
    });
    final ComboBox<String> zoom_levels = new ComboBox<>();
    zoom_levels.getItems().addAll(JFXRepresentation.ZOOM_LEVELS);
    zoom_levels.setEditable(true);
    zoom_levels.setValue(JFXRepresentation.DEFAULT_ZOOM_LEVEL);
    zoom_levels.setTooltip(new Tooltip("Select Zoom Level"));
    zoom_levels.setPrefWidth(100.0);
    // For Ctrl-Wheel zoom gesture
    zoomListener zl = new zoomListener(zoom_levels);
    toolkit.setZoomListener(zl);
    zoom_levels.setOnAction(event -> {
        final String actual = requestZoom(zoom_levels.getValue());
        // Java 9 results in IndexOutOfBoundException
        // when combo is updated within the action handler,
        // so defer to another UI tick
        Platform.runLater(() -> zoom_levels.setValue(actual));
    });
    final MenuButton order = new MenuButton(null, null, createMenuItem(ActionDescription.TO_BACK), createMenuItem(ActionDescription.MOVE_UP), createMenuItem(ActionDescription.MOVE_DOWN), createMenuItem(ActionDescription.TO_FRONT));
    order.setTooltip(new Tooltip("Order"));
    final MenuButton align = new MenuButton(null, null, createMenuItem(ActionDescription.ALIGN_LEFT), createMenuItem(ActionDescription.ALIGN_CENTER), createMenuItem(ActionDescription.ALIGN_RIGHT), createMenuItem(ActionDescription.ALIGN_TOP), createMenuItem(ActionDescription.ALIGN_MIDDLE), createMenuItem(ActionDescription.ALIGN_BOTTOM));
    align.setTooltip(new Tooltip("Align"));
    final MenuButton size = new MenuButton(null, null, createMenuItem(ActionDescription.MATCH_WIDTH), createMenuItem(ActionDescription.MATCH_HEIGHT));
    align.setTooltip(new Tooltip("Size"));
    final MenuButton dist = new MenuButton(null, null, createMenuItem(ActionDescription.DIST_HORIZ), createMenuItem(ActionDescription.DIST_VERT));
    align.setTooltip(new Tooltip("Distribute"));
    // Use the first item as the icon for the drop-down...
    try {
        order.setGraphic(new ImageView(new Image(ResourceUtil.openPlatformResource(ActionDescription.TO_BACK.getIconResourcePath()))));
        align.setGraphic(new ImageView(new Image(ResourceUtil.openPlatformResource(ActionDescription.ALIGN_LEFT.getIconResourcePath()))));
        size.setGraphic(new ImageView(new Image(ResourceUtil.openPlatformResource(ActionDescription.MATCH_WIDTH.getIconResourcePath()))));
        dist.setGraphic(new ImageView(new Image(ResourceUtil.openPlatformResource(ActionDescription.DIST_HORIZ.getIconResourcePath()))));
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Cannot load icon", ex);
    }
    return new ToolBar(createToggleButton(ActionDescription.ENABLE_GRID), createToggleButton(ActionDescription.ENABLE_SNAP), createToggleButton(ActionDescription.ENABLE_COORDS), new Separator(), order, align, size, dist, new Separator(), undo_button, redo_button, new Separator(), zoom_levels);
}
Also used : Button(javafx.scene.control.Button) ToggleButton(javafx.scene.control.ToggleButton) MenuButton(javafx.scene.control.MenuButton) ComboBox(javafx.scene.control.ComboBox) Tooltip(javafx.scene.control.Tooltip) ToolBar(javafx.scene.control.ToolBar) MenuButton(javafx.scene.control.MenuButton) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image) Separator(javafx.scene.control.Separator)

Example 34 with ComboBox

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

the class RulesDialog method createContent.

private SplitPane createContent() {
    final Node rules = createRulesTable();
    final HBox pvs = createPVsTable();
    final HBox exprs = createExpressionsTable();
    // Display PVs of currently selected rule
    rules_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
        selected_rule_item = selected;
        if (selected == null) {
            pvs.setDisable(true);
            exprs.setDisable(true);
            btn_remove_rule.setDisable(true);
            btn_dup_rule.setDisable(true);
            btn_move_rule_up.setDisable(true);
            btn_move_rule_down.setDisable(true);
            btn_show_script.setDisable(true);
            propComboBox.setDisable(true);
            propComboBox.getSelectionModel().select(null);
            valExpBox.setDisable(true);
            pv_items.clear();
            expression_items.clear();
        } else {
            pvs.setDisable(false);
            exprs.setDisable(false);
            final TableViewSelectionModel<RuleItem> model = rules_table.getSelectionModel();
            btn_remove_rule.setDisable(false);
            btn_dup_rule.setDisable(false);
            btn_move_rule_up.setDisable(model.getSelectedIndex() == 0);
            btn_move_rule_down.setDisable(model.getSelectedIndex() == rule_items.size() - 1);
            btn_show_script.setDisable(false);
            propComboBox.setDisable(false);
            propComboBox.getSelectionModel().select(getPropLongString(selected));
            valExpBox.setDisable(false);
            valExpBox.selectedProperty().set(selected.prop_as_expr.get());
            pv_items.setAll(selected.pvs);
            expression_items.setAll(selected.expressions);
            fixupPVs(0);
        }
    });
    // Update PVs of selected rule from PVs table
    final ListChangeListener<PVTableItem> pll = change -> {
        final RuleItem selected = rules_table.getSelectionModel().getSelectedItem();
        if (selected != null)
            selected.pvs = new ArrayList<>(change.getList());
    };
    pv_items.addListener(pll);
    // Update buttons for currently selected PV
    pvs_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
        if (selected == null) {
            btn_rm_pv.setDisable(true);
            btn_move_pv_up.setDisable(true);
            btn_move_pv_down.setDisable(true);
        } else {
            final TableViewSelectionModel<PVTableItem> model = pvs_table.getSelectionModel();
            btn_rm_pv.setDisable(false);
            btn_move_pv_up.setDisable(model.getSelectedIndex() == 0);
            btn_move_pv_down.setDisable(model.getSelectedIndex() == pv_items.size() - 1);
        }
    });
    // Update Expressions of selected rule from Expressions table
    final ListChangeListener<ExprItem<?>> ell = change -> {
        final RuleItem selected = rules_table.getSelectionModel().getSelectedItem();
        if (selected != null)
            selected.expressions = new ArrayList<>(change.getList());
    };
    expression_items.addListener(ell);
    // Update buttons for currently selected expression
    expressions_table.getSelectionModel().selectedItemProperty().addListener((prop, old, selected) -> {
        if (selected == null) {
            btn_rm_exp.setDisable(true);
            btn_move_exp_up.setDisable(true);
            btn_move_exp_down.setDisable(true);
        } else {
            final TableViewSelectionModel<ExprItem<?>> model = expressions_table.getSelectionModel();
            btn_rm_exp.setDisable(false);
            btn_move_exp_up.setDisable(model.getSelectedIndex() == 0);
            btn_move_exp_down.setDisable(model.getSelectedIndex() == expression_items.size() - 1);
        }
    });
    // What is the property id option we are using?
    final Label propLabel = new Label("Property ID:");
    // Show each property with current value
    final ObservableList<String> prop_id_opts = FXCollections.observableArrayList();
    for (PropInfo pi : propinfo_ls) {
        // Property _value_ can be long, ex. points of a polyline
        // Truncate the value that's shown in the combo box
        // to prevent combo from using all screen width.
        String prop_opt = pi.toString();
        if (prop_opt.length() > MAX_PROP_LENGTH)
            prop_opt = prop_opt.substring(0, MAX_PROP_LENGTH) + "...";
        prop_id_opts.add(prop_opt);
    }
    propComboBox = new ComboBox<String>(prop_id_opts);
    propComboBox.setDisable(true);
    propComboBox.getSelectionModel().selectedIndexProperty().addListener((p, o, index) -> {
        // Select property info based on index within combo.
        final int idx = index.intValue();
        if (idx >= 0) {
            final PropInfo prop = propinfo_ls.get(idx);
            if (selected_rule_item.tryUpdatePropID(undo, prop.getPropID()))
                expression_items.setAll(selected_rule_item.expressions);
        }
    });
    propComboBox.setMinHeight(27);
    propComboBox.setMaxWidth(Double.MAX_VALUE);
    HBox.setHgrow(propComboBox, Priority.ALWAYS);
    // TODO: change this to actually manipulate expression objects in the rule
    valExpBox = new CheckBox("Value as Expression");
    valExpBox.setDisable(true);
    valExpBox.selectedProperty().addListener((ov, old_val, new_val) -> {
        if (!selected_rule_item.tryTogglePropAsExpr(undo, new_val))
            logger.log(Level.FINE, "Did not update rule property as expression flag to " + new_val);
        else
            expression_items.setAll(selected_rule_item.expressions);
    });
    final Region spring = new Region();
    HBox.setHgrow(spring, Priority.ALWAYS);
    final HBox props = new HBox(10, propLabel, propComboBox, spring, valExpBox);
    props.setAlignment(Pos.CENTER);
    pvs.setPadding(new Insets(0, 10, 0, 0));
    exprs.setPadding(new Insets(0, 0, 0, 10));
    HBox.setHgrow(pvs, Priority.ALWAYS);
    HBox.setHgrow(exprs, Priority.ALWAYS);
    final Preferences pref = Preferences.userNodeForPackage(RulesDialog.class);
    final double prefRSPDividerPosition = pref.getDouble("rule.content.divider.position", 0.5);
    ruleSplitPane = new SplitPane(pvs, exprs);
    ruleSplitPane.setOrientation(Orientation.HORIZONTAL);
    ruleSplitPane.setDividerPositions(prefRSPDividerPosition);
    ruleSplitPane.setStyle("-fx-background-insets: 0, 0;");
    VBox.setVgrow(ruleSplitPane, Priority.ALWAYS);
    final VBox subitems = new VBox(10, props, ruleSplitPane);
    final VBox rulebox = new VBox(10, rules);
    rulebox.setPadding(new Insets(0, 10, 0, 0));
    subitems.setPadding(new Insets(0, 0, 0, 10));
    VBox.setVgrow(rules, Priority.ALWAYS);
    HBox.setHgrow(subitems, Priority.ALWAYS);
    final double prefWidth = pref.getDouble("content.width", -1);
    final double prefHeight = pref.getDouble("content.height", -1);
    final double prefDividerPosition = pref.getDouble("content.divider.position", 0.3);
    final SplitPane splitPane = new SplitPane(rulebox, subitems);
    splitPane.setOrientation(Orientation.HORIZONTAL);
    splitPane.setDividerPositions(prefDividerPosition);
    if (prefWidth > 0 && prefHeight > 0)
        splitPane.setPrefSize(prefWidth, prefHeight);
    // Select the first rule
    if (!rules_table.getItems().isEmpty()) {
        Platform.runLater(() -> {
            rules_table.getSelectionModel().select(0);
            rules_table.requestFocus();
        });
    } else
        Platform.runLater(() -> btn_add_rule.requestFocus());
    return splitPane;
}
Also used : Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) UndoableActionManager(org.csstudio.display.builder.util.undo.UndoableActionManager) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) LineNumberTableCellFactory(org.csstudio.javafx.LineNumberTableCellFactory) VBox(javafx.scene.layout.VBox) AutoCompletedTableCell(org.csstudio.display.builder.representation.javafx.PVTableItem.AutoCompletedTableCell) RuleInfo(org.csstudio.display.builder.model.rules.RuleInfo) TableHelper(org.csstudio.javafx.TableHelper) ListChangeListener(javafx.collections.ListChangeListener) ComboBox(javafx.scene.control.ComboBox) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) TableView(javafx.scene.control.TableView) ModelThreadPool(org.csstudio.display.builder.model.util.ModelThreadPool) Pane(javafx.scene.layout.Pane) Orientation(javafx.geometry.Orientation) HBox(javafx.scene.layout.HBox) PVTableItem(org.csstudio.display.builder.representation.javafx.PVTableItem) SplitPane(javafx.scene.control.SplitPane) TextField(javafx.scene.control.TextField) Language(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog.Language) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) Collectors(java.util.stream.Collectors) CommonWidgetProperties(org.csstudio.display.builder.model.properties.CommonWidgetProperties) Platform(javafx.application.Platform) Priority(javafx.scene.layout.Priority) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) Region(javafx.scene.layout.Region) CheckBoxTableCell(javafx.scene.control.cell.CheckBoxTableCell) AutocompleteMenu(org.csstudio.display.builder.representation.javafx.AutocompleteMenu) JFXUtil(org.csstudio.display.builder.representation.javafx.JFXUtil) ObservableList(javafx.collections.ObservableList) DefaultStringConverter(javafx.util.converter.DefaultStringConverter) ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) StringProperty(javafx.beans.property.StringProperty) ExpressionInfo(org.csstudio.display.builder.model.rules.RuleInfo.ExpressionInfo) TableViewSelectionModel(javafx.scene.control.TableView.TableViewSelectionModel) SyntaxHighlightedMultiLineInputDialog(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog) ExprInfoValue(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoValue) Plugin.logger(org.csstudio.display.builder.editor.Plugin.logger) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ButtonType(javafx.scene.control.ButtonType) JFXBaseRepresentation(org.csstudio.display.builder.representation.javafx.widgets.JFXBaseRepresentation) FXCollections(javafx.collections.FXCollections) BackingStoreException(java.util.prefs.BackingStoreException) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) RulesWidgetProperty(org.csstudio.display.builder.model.properties.RulesWidgetProperty) Messages(org.csstudio.display.builder.representation.javafx.Messages) TableCell(javafx.scene.control.TableCell) Insets(javafx.geometry.Insets) Tooltip(javafx.scene.control.Tooltip) Dialog(javafx.scene.control.Dialog) Label(javafx.scene.control.Label) Node(javafx.scene.Node) CheckBox(javafx.scene.control.CheckBox) Preferences(java.util.prefs.Preferences) TimeUnit(java.util.concurrent.TimeUnit) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ScriptsDialog(org.csstudio.display.builder.representation.javafx.ScriptsDialog) DialogHelper(org.csstudio.javafx.DialogHelper) Widget(org.csstudio.display.builder.model.Widget) ChangeListener(javafx.beans.value.ChangeListener) PropInfo(org.csstudio.display.builder.model.rules.RuleInfo.PropInfo) HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) Node(javafx.scene.Node) Label(javafx.scene.control.Label) PropInfo(org.csstudio.display.builder.model.rules.RuleInfo.PropInfo) ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) SplitPane(javafx.scene.control.SplitPane) PVTableItem(org.csstudio.display.builder.representation.javafx.PVTableItem) Preferences(java.util.prefs.Preferences) CheckBox(javafx.scene.control.CheckBox) Region(javafx.scene.layout.Region) VBox(javafx.scene.layout.VBox)

Example 35 with ComboBox

use of javafx.scene.control.ComboBox in project bisq-desktop by bisq-network.

the class CreateOfferView method addPaymentGroup.

private void addPaymentGroup() {
    TitledGroupBg titledGroupBg = addTitledGroupBg(gridPane, gridRow, 2, Res.get("shared.selectTradingAccount"));
    GridPane.setColumnSpan(titledGroupBg, 3);
    // noinspection unchecked
    paymentAccountsComboBox = addLabelComboBox(gridPane, gridRow, Res.getWithCol("shared.tradingAccount"), Layout.FIRST_ROW_DISTANCE).second;
    paymentAccountsComboBox.setPromptText(Res.get("shared.selectTradingAccount"));
    paymentAccountsComboBox.setMinWidth(300);
    editOfferElements.add(paymentAccountsComboBox);
    // we display either currencyComboBox (multi currency account) or currencyTextField (single)
    Tuple2<Label, ComboBox> currencyComboBoxTuple = addLabelComboBox(gridPane, ++gridRow, Res.getWithCol("shared.currency"));
    currencyComboBoxLabel = currencyComboBoxTuple.first;
    editOfferElements.add(currencyComboBoxLabel);
    // noinspection unchecked
    currencyComboBox = currencyComboBoxTuple.second;
    editOfferElements.add(currencyComboBox);
    currencyComboBox.setPromptText(Res.get("list.currency.select"));
    currencyComboBox.setConverter(new StringConverter<TradeCurrency>() {

        @Override
        public String toString(TradeCurrency tradeCurrency) {
            return tradeCurrency.getNameAndCode();
        }

        @Override
        public TradeCurrency fromString(String s) {
            return null;
        }
    });
    Tuple2<Label, TextField> currencyTextFieldTuple = addLabelTextField(gridPane, gridRow, Res.getWithCol("shared.currency"), "", 5);
    currencyTextFieldLabel = currencyTextFieldTuple.first;
    editOfferElements.add(currencyTextFieldLabel);
    currencyTextField = currencyTextFieldTuple.second;
    editOfferElements.add(currencyTextField);
}
Also used : TradeCurrency(bisq.core.locale.TradeCurrency) ComboBox(javafx.scene.control.ComboBox) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Label(javafx.scene.control.Label) BalanceTextField(bisq.desktop.components.BalanceTextField) InputTextField(bisq.desktop.components.InputTextField) InfoInputTextField(bisq.desktop.components.InfoInputTextField) TextField(javafx.scene.control.TextField) FundsTextField(bisq.desktop.components.FundsTextField) AddressTextField(bisq.desktop.components.AddressTextField) TitledGroupBg(bisq.desktop.components.TitledGroupBg)

Aggregations

ComboBox (javafx.scene.control.ComboBox)48 Label (javafx.scene.control.Label)30 Insets (javafx.geometry.Insets)15 HBox (javafx.scene.layout.HBox)15 Button (javafx.scene.control.Button)14 TextField (javafx.scene.control.TextField)14 GridPane (javafx.scene.layout.GridPane)14 VBox (javafx.scene.layout.VBox)12 AutoTooltipLabel (bisq.desktop.components.AutoTooltipLabel)10 BorderPane (javafx.scene.layout.BorderPane)9 Text (javafx.scene.text.Text)9 TradeCurrency (bisq.core.locale.TradeCurrency)8 List (java.util.List)8 FXCollections (javafx.collections.FXCollections)8 Tooltip (javafx.scene.control.Tooltip)8 Priority (javafx.scene.layout.Priority)8 Popup (bisq.desktop.main.overlays.popups.Popup)7 Node (javafx.scene.Node)7 ImageView (javafx.scene.image.ImageView)7 TextWithStyle (org.phoenicis.javafx.views.common.TextWithStyle)7