Search in sources :

Example 1 with WidgetProperty

use of org.csstudio.display.builder.model.WidgetProperty in project org.csstudio.display.builder by kasemir.

the class SymbolRepresentation method updateSymbols.

private synchronized void updateSymbols() {
    try {
        ArrayWidgetProperty<WidgetProperty<String>> propSymbols = model_widget.propSymbols();
        List<WidgetProperty<String>> fileNames = propSymbols.getValue();
        if (model_widget.getImportedFrom() != null) {
            updateImportedSymbols();
        }
        if (fileNames == null) {
            logger.log(Level.WARNING, "Empty list of file names.");
        } else {
            imagesList.clear();
            fileNames.stream().forEach(f -> {
                String fileName = f.getValue();
                Image image = imagesMap.get(fileName);
                if (image == null) {
                    image = loadSymbol(fileName);
                    if (image != null) {
                        imagesMap.put(fileName, image);
                    }
                }
                if (image != null) {
                    imagesList.add(image);
                }
            });
            Set<String> toBeRemoved = imagesMap.keySet().stream().filter(f -> !imagesList.contains(imagesMap.get(f))).collect(Collectors.toSet());
            toBeRemoved.stream().forEach(f -> imagesMap.remove(f));
            setImageIndex(Math.min(Math.max(getImageIndex(), 0), imagesList.size() - 1));
            maxSize = computeMaximumSize(model_widget);
        }
    } finally {
        valueChanged(null, null, null);
    }
}
Also used : WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) ArrayWidgetProperty(org.csstudio.display.builder.model.ArrayWidgetProperty) Pos(javafx.geometry.Pos) ListNumber(org.diirt.util.array.ListNumber) VString(org.diirt.vtype.VString) VEnumArray(org.diirt.vtype.VEnumArray) Map(java.util.Map) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) DirtyFlag(org.csstudio.display.builder.model.DirtyFlag) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) Circle(javafx.scene.shape.Circle) VNumberArray(org.diirt.vtype.VNumberArray) ListInt(org.diirt.util.array.ListInt) VEnum(org.diirt.vtype.VEnum) VBoolean(org.diirt.vtype.VBoolean) Font(javafx.scene.text.Font) Set(java.util.Set) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) Platform(javafx.application.Platform) List(java.util.List) AnchorPane(javafx.scene.layout.AnchorPane) JFXUtil(org.csstudio.display.builder.representation.javafx.JFXUtil) BorderPane(javafx.scene.layout.BorderPane) CornerRadii(javafx.scene.layout.CornerRadii) FontWeight(javafx.scene.text.FontWeight) DisplayModel(org.csstudio.display.builder.model.DisplayModel) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Bindings(javafx.beans.binding.Bindings) IntegerProperty(javafx.beans.property.IntegerProperty) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Insets(javafx.geometry.Insets) BackgroundFill(javafx.scene.layout.BackgroundFill) Color(javafx.scene.paint.Color) ModelResourceUtil(org.csstudio.display.builder.model.util.ModelResourceUtil) ArrayWidgetProperty(org.csstudio.display.builder.model.ArrayWidgetProperty) Label(javafx.scene.control.Label) Dimension2D(javafx.geometry.Dimension2D) Executor(java.util.concurrent.Executor) VType(org.diirt.vtype.VType) SymbolWidget(org.csstudio.display.builder.model.widgets.SymbolWidget) VNumber(org.diirt.vtype.VNumber) Background(javafx.scene.layout.Background) Styles(org.csstudio.javafx.Styles) ToolkitRepresentation.logger(org.csstudio.display.builder.representation.ToolkitRepresentation.logger) TreeMap(java.util.TreeMap) MacroHandler(org.csstudio.display.builder.model.macros.MacroHandler) ImageView(javafx.scene.image.ImageView) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) Collections(java.util.Collections) Image(javafx.scene.image.Image) VString(org.diirt.vtype.VString) Image(javafx.scene.image.Image)

Example 2 with WidgetProperty

use of org.csstudio.display.builder.model.WidgetProperty in project org.csstudio.display.builder by kasemir.

the class ImageRepresentation method coloringChanged.

/**
 * Changes that affect the coloring of the image but not the zoom, size
 */
private void coloringChanged(final WidgetProperty<?> property, final Object old_value, final Object new_value) {
    image_plot.setInterpolation(Interpolation.values()[model_widget.propDataInterpolation().getValue().ordinal()]);
    final ColorMap colormap = model_widget.propDataColormap().getValue();
    final ColorMappingFunction map_function;
    if (colormap instanceof PredefinedColorMaps.Predefined)
        map_function = NamedColorMappings.getMapping(((PredefinedColorMaps.Predefined) colormap).getName());
    else
        map_function = value -> ColorMappingFunction.getRGB(colormap.getColor(value));
    image_plot.setColorMapping(map_function);
}
Also used : Arrays(java.util.Arrays) DisplayModel(org.csstudio.display.builder.model.DisplayModel) PredefinedColorMaps(org.csstudio.display.builder.model.properties.PredefinedColorMaps) Interpolation(org.csstudio.javafx.rtplot.Interpolation) VImageType(org.diirt.vtype.VImageType) Level(java.util.logging.Level) RTImagePlotListener(org.csstudio.javafx.rtplot.RTImagePlotListener) ValueFactory(org.diirt.vtype.ValueFactory) ImageWidget(org.csstudio.display.builder.model.widgets.plots.ImageWidget) RTImagePlot(org.csstudio.javafx.rtplot.RTImagePlot) ArrayInt(org.diirt.util.array.ArrayInt) DirtyFlag(org.csstudio.display.builder.model.DirtyFlag) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) ModelThreadPool(org.csstudio.display.builder.model.util.ModelThreadPool) AxisWidgetProperty(org.csstudio.display.builder.model.widgets.plots.ImageWidget.AxisWidgetProperty) VNumberArray(org.diirt.vtype.VNumberArray) Pane(javafx.scene.layout.Pane) NamedColorMappings(org.csstudio.javafx.rtplot.NamedColorMappings) ModelResourceUtil(org.csstudio.display.builder.model.util.ModelResourceUtil) Rectangle2D(javafx.geometry.Rectangle2D) ROIWidgetProperty(org.csstudio.display.builder.model.widgets.plots.ImageWidget.ROIWidgetProperty) RegionBaseRepresentation(org.csstudio.display.builder.representation.javafx.widgets.RegionBaseRepresentation) RepresentationUpdateThrottle(org.csstudio.display.builder.representation.RepresentationUpdateThrottle) RegionOfInterest(org.csstudio.javafx.rtplot.RegionOfInterest) VType(org.diirt.vtype.VType) ColorMap(org.csstudio.display.builder.model.properties.ColorMap) ToolkitRepresentation.logger(org.csstudio.display.builder.representation.ToolkitRepresentation.logger) TimeUnit(java.util.concurrent.TimeUnit) Platform(javafx.application.Platform) List(java.util.List) MacroHandler(org.csstudio.display.builder.model.macros.MacroHandler) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) ArrayDouble(org.diirt.util.array.ArrayDouble) ColorMappingFunction(org.csstudio.javafx.rtplot.ColorMappingFunction) JFXUtil(org.csstudio.display.builder.representation.javafx.JFXUtil) Axis(org.csstudio.javafx.rtplot.Axis) VImage(org.diirt.vtype.VImage) Image(javafx.scene.image.Image) ColorMap(org.csstudio.display.builder.model.properties.ColorMap) PredefinedColorMaps(org.csstudio.display.builder.model.properties.PredefinedColorMaps) ColorMappingFunction(org.csstudio.javafx.rtplot.ColorMappingFunction)

Example 3 with WidgetProperty

use of org.csstudio.display.builder.model.WidgetProperty in project org.csstudio.display.builder by kasemir.

the class WidgetTransfer method installSymbolWidgetFromImageFiles.

/**
 * @param files The pathnames of the image files used by the symbol widget.
 * @param selection_tracker Used to get the grid steps from its model to be
 *            used in offsetting multiple widgets.
 * @param widgets The container of the created widgets.
 * @param updates Updates to perform on widgets
 */
private static void installSymbolWidgetFromImageFiles(final List<String> fileNames, final SelectedWidgetUITracker selection_tracker, final List<Widget> widgets, final List<Runnable> updates) {
    logger.log(Level.FINE, "Creating SymbolWidget for {0,number,#########0} dropped images", fileNames.size());
    final DisplayModel model = selection_tracker.getModel();
    final SymbolWidget widget = (SymbolWidget) SymbolWidget.WIDGET_DESCRIPTOR.createWidget();
    ArrayWidgetProperty<WidgetProperty<String>> propSymbols = widget.propSymbols();
    for (int i = 0; i < fileNames.size(); i++) {
        if (i < propSymbols.size()) {
            propSymbols.getElement(i).setValue(fileNames.get(i));
        } else {
            widget.addSymbol(fileNames.get(i));
        }
    }
    final int index = widgets.size();
    widget.propX().setValue(model.propGridStepX().getValue() * index);
    widget.propY().setValue(model.propGridStepY().getValue() * index);
    widgets.add(widget);
    updates.add(() -> updateSymbolWidgetSize(widget));
}
Also used : WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) ArrayWidgetProperty(org.csstudio.display.builder.model.ArrayWidgetProperty) SymbolWidget(org.csstudio.display.builder.model.widgets.SymbolWidget) DisplayModel(org.csstudio.display.builder.model.DisplayModel)

Example 4 with WidgetProperty

use of org.csstudio.display.builder.model.WidgetProperty in project org.csstudio.display.builder by kasemir.

the class DisplayMacroExpander method expand.

private static void expand(final ChildrenProperty widgets, MacroValueProvider input) throws Exception {
    for (Widget widget : widgets.getValue()) {
        final Optional<WidgetProperty<Macros>> macros = widget.checkProperty(CommonWidgetProperties.propMacros);
        if (macros.isPresent())
            macros.get().getValue().expandValues(input);
        // Recurse
        final ChildrenProperty children = ChildrenProperty.getChildren(widget);
        if (children != null)
            expand(children, widget.getMacrosOrProperties());
    }
}
Also used : WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) ChildrenProperty(org.csstudio.display.builder.model.ChildrenProperty) Widget(org.csstudio.display.builder.model.Widget)

Example 5 with WidgetProperty

use of org.csstudio.display.builder.model.WidgetProperty in project org.csstudio.display.builder by kasemir.

the class PropertyPanelSection method createPropertyUI.

/**
 * Add UI items for displaying or editing property
 *  @param property Property (on primary widget)
 *  @param other Zero or more additional widgets that have same type of property
 *  @param structureIndex Index of the array structure (element) being added. It is meaningful
 *                        only for properties instance of {@link StructuredWidgetProperty}.
 */
private void createPropertyUI(final UndoableActionManager undo, final WidgetProperty<?> property, final List<Widget> other, final int structureIndex, final int indentationLevel) {
    // Skip runtime properties
    if (property.getCategory() == WidgetPropertyCategory.RUNTIME)
        return;
    final Label label = new Label(property.getDescription());
    label.setMaxWidth(Double.MAX_VALUE);
    final String tooltip = property.getDescription() + " (" + property.getPath() + ")";
    label.setTooltip(new Tooltip(tooltip));
    // setGridLinesVisible(true); // For debugging the layout
    Node field = bindSimplePropertyField(undo, bindings, property, other);
    if (field != null) {
    // do nothing
    } else if (property instanceof MacrosWidgetProperty) {
        final MacrosWidgetProperty macros_prop = (MacrosWidgetProperty) property;
        final Button macros_field = new Button();
        macros_field.setMaxWidth(Double.MAX_VALUE);
        final MacrosPropertyBinding binding = new MacrosPropertyBinding(undo, macros_field, macros_prop, other);
        bindings.add(binding);
        binding.bind();
        field = macros_field;
    } else if (property instanceof ActionsWidgetProperty) {
        final ActionsWidgetProperty actions_prop = (ActionsWidgetProperty) property;
        final Button actions_field = new Button();
        actions_field.setMaxWidth(Double.MAX_VALUE);
        final ActionsPropertyBinding binding = new ActionsPropertyBinding(undo, actions_field, actions_prop, other, autocomplete_menu);
        bindings.add(binding);
        binding.bind();
        field = actions_field;
    } else if (property instanceof ScriptsWidgetProperty) {
        final ScriptsWidgetProperty scripts_prop = (ScriptsWidgetProperty) property;
        final Button scripts_field = new Button();
        scripts_field.setMaxWidth(Double.MAX_VALUE);
        final ScriptsPropertyBinding binding = new ScriptsPropertyBinding(undo, scripts_field, scripts_prop, other, autocomplete_menu);
        bindings.add(binding);
        binding.bind();
        field = scripts_field;
    } else if (property instanceof RulesWidgetProperty) {
        final RulesWidgetProperty rules_prop = (RulesWidgetProperty) property;
        final Button rules_field = new Button();
        rules_field.setMaxWidth(Double.MAX_VALUE);
        final RulesPropertyBinding binding = new RulesPropertyBinding(undo, rules_field, rules_prop, other, autocomplete_menu);
        bindings.add(binding);
        binding.bind();
        field = rules_field;
    } else if (property instanceof StructuredWidgetProperty) {
        // Don't allow editing structures and their elements in class mode
        if (class_mode)
            return;
        final StructuredWidgetProperty struct = (StructuredWidgetProperty) property;
        final Label header = new Label(struct.getDescription() + (structureIndex > 0 ? " " + String.valueOf(1 + structureIndex) : ""));
        header.getStyleClass().add("structure_property_name");
        header.setMaxWidth(Double.MAX_VALUE);
        final int row = getNextGridRow();
        fillIndent(indentationLevel, row);
        add(header, 0 + indentationLevel, row, 7 - 2 * indentationLevel, 1);
        final Separator separator = new Separator();
        separator.getStyleClass().add("property_separator");
        add(separator, 0 + indentationLevel, getNextGridRow(), 7 - 2 * indentationLevel, 1);
        for (WidgetProperty<?> elem : struct.getValue()) this.createPropertyUI(undo, elem, other, -1, indentationLevel);
        return;
    } else if (property instanceof ArrayWidgetProperty) {
        // Don't allow editing arrays and their elements in class mode
        if (class_mode)
            return;
        @SuppressWarnings("unchecked") final ArrayWidgetProperty<WidgetProperty<?>> array = (ArrayWidgetProperty<WidgetProperty<?>>) property;
        // UI for changing array size
        final Spinner<Integer> spinner = new Spinner<>(array.getMinimumSize(), 100, 0);
        final ArraySizePropertyBinding count_binding = new ArraySizePropertyBinding(this, undo, spinner, array, other);
        bindings.add(count_binding);
        count_binding.bind();
        // set size of array
        int row = getNextGridRow();
        label.getStyleClass().add("array_property_name");
        label.setMaxWidth(Double.MAX_VALUE);
        label.setMaxHeight(Double.MAX_VALUE);
        spinner.getStyleClass().add("array_property_value");
        spinner.setMaxWidth(Double.MAX_VALUE);
        fillHeaderIndent(indentationLevel, row);
        add(label, indentationLevel, row, 4 - indentationLevel, 1);
        add(spinner, 4, row, 2 - indentationLevel, 1);
        Separator separator = new Separator();
        separator.getStyleClass().add("property_separator");
        add(separator, 1 + indentationLevel, getNextGridRow(), 5 - 2 * indentationLevel, 1);
        // array elements
        final List<WidgetProperty<?>> wpeList = array.getValue();
        for (int i = 0; i < wpeList.size(); i++) {
            final WidgetProperty<?> elem = wpeList.get(i);
            createPropertyUI(undo, elem, other, i, indentationLevel + 1);
        }
        // mark end of array
        row = getNextGridRow();
        final Label endlabel = new Label();
        endlabel.setMaxWidth(Double.MAX_VALUE);
        GridPane.setHgrow(endlabel, Priority.ALWAYS);
        endlabel.getStyleClass().add("array_property_end");
        fillIndent(indentationLevel, row);
        add(endlabel, 0 + indentationLevel, row, 7 - 2 * indentationLevel, 1);
        separator = new Separator();
        separator.getStyleClass().add("property_separator");
        add(separator, 0 + indentationLevel, getNextGridRow(), 7 - 2 * indentationLevel, 1);
        return;
    } else // As new property types are added, they might need to be handled:
    // else if (property instanceof SomeNewWidgetProperty) { ... }
    {
        // Fallback for unknown property: read-only
        final TextField text = new TextField();
        text.setText(String.valueOf(property.getValue()));
        text.setEditable(false);
        field = text;
    }
    // Display Label, Class indicator/checkbox, field
    final int row = getNextGridRow();
    label.getStyleClass().add("property_name");
    field.getStyleClass().add("property_value");
    // Allow label to shrink (can use tooltip to see),
    // but show the value
    // GridPane.setHgrow(label, Priority.ALWAYS);
    GridPane.setHgrow(field, Priority.ALWAYS);
    fillIndent(indentationLevel, row);
    add(label, indentationLevel, row, 3 - indentationLevel, 1);
    final Widget widget = property.getWidget();
    if (!(property == widget.getProperty("type") || property == widget.getProperty("name"))) {
        if (class_mode) {
            // Class definition mode:
            // Check box for 'use_class'
            final CheckBox check = new CheckBox();
            check.setTooltip(use_class_tooltip);
            final WidgetPropertyBinding<?, ?> binding = new UseWidgetClassBinding(undo, check, field, property, other);
            bindings.add(binding);
            binding.bind();
            add(check, 3, row);
        } else {
            // Display file mode:
            // Show if property is set by the class, not editable.
            final Label indicator = new Label();
            indicator.setTooltip(using_class_tooltip);
            final WidgetPropertyBinding<?, ?> binding = new ShowWidgetClassBinding(field, property, indicator);
            bindings.add(binding);
            binding.bind();
            add(indicator, 3, row);
        }
    }
    add(field, 4, row, 3 - indentationLevel, 1);
    final Separator separator = new Separator();
    separator.getStyleClass().add("property_separator");
    add(separator, 0 + indentationLevel, getNextGridRow(), 7 - 2 * indentationLevel, 1);
}
Also used : RulesWidgetProperty(org.csstudio.display.builder.model.properties.RulesWidgetProperty) ScriptsWidgetProperty(org.csstudio.display.builder.model.properties.ScriptsWidgetProperty) Spinner(javafx.scene.control.Spinner) Node(javafx.scene.Node) Label(javafx.scene.control.Label) Widget(org.csstudio.display.builder.model.Widget) ArrayWidgetProperty(org.csstudio.display.builder.model.ArrayWidgetProperty) Button(javafx.scene.control.Button) ToggleButton(javafx.scene.control.ToggleButton) TextField(javafx.scene.control.TextField) MacrosWidgetProperty(org.csstudio.display.builder.model.properties.MacrosWidgetProperty) Tooltip(javafx.scene.control.Tooltip) ScriptsWidgetProperty(org.csstudio.display.builder.model.properties.ScriptsWidgetProperty) StructuredWidgetProperty(org.csstudio.display.builder.model.StructuredWidgetProperty) MacrosWidgetProperty(org.csstudio.display.builder.model.properties.MacrosWidgetProperty) EnumWidgetProperty(org.csstudio.display.builder.model.properties.EnumWidgetProperty) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) BooleanWidgetProperty(org.csstudio.display.builder.model.properties.BooleanWidgetProperty) MacroizedWidgetProperty(org.csstudio.display.builder.model.MacroizedWidgetProperty) ColorWidgetProperty(org.csstudio.display.builder.model.properties.ColorWidgetProperty) PointsWidgetProperty(org.csstudio.display.builder.model.properties.PointsWidgetProperty) PVNameWidgetProperty(org.csstudio.display.builder.model.properties.PVNameWidgetProperty) FilenameWidgetProperty(org.csstudio.display.builder.model.properties.FilenameWidgetProperty) RulesWidgetProperty(org.csstudio.display.builder.model.properties.RulesWidgetProperty) ArrayWidgetProperty(org.csstudio.display.builder.model.ArrayWidgetProperty) FontWidgetProperty(org.csstudio.display.builder.model.properties.FontWidgetProperty) ColorMapWidgetProperty(org.csstudio.display.builder.model.properties.ColorMapWidgetProperty) ActionsWidgetProperty(org.csstudio.display.builder.model.properties.ActionsWidgetProperty) ActionsWidgetProperty(org.csstudio.display.builder.model.properties.ActionsWidgetProperty) CheckBox(javafx.scene.control.CheckBox) StructuredWidgetProperty(org.csstudio.display.builder.model.StructuredWidgetProperty) Separator(javafx.scene.control.Separator)

Aggregations

WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)20 ArrayList (java.util.ArrayList)7 Map (java.util.Map)6 Widget (org.csstudio.display.builder.model.Widget)6 WidgetPropertyListener (org.csstudio.display.builder.model.WidgetPropertyListener)6 List (java.util.List)5 Level (java.util.logging.Level)5 DisplayModel (org.csstudio.display.builder.model.DisplayModel)5 VType (org.diirt.vtype.VType)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 RuntimePV (org.csstudio.display.builder.runtime.pv.RuntimePV)4 Collection (java.util.Collection)3 Label (javafx.scene.control.Label)3 ArrayWidgetProperty (org.csstudio.display.builder.model.ArrayWidgetProperty)3 RuntimePVListener (org.csstudio.display.builder.runtime.pv.RuntimePVListener)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Platform (javafx.application.Platform)2 Insets (javafx.geometry.Insets)2 Pos (javafx.geometry.Pos)2 TextField (javafx.scene.control.TextField)2