Search in sources :

Example 6 with ChildrenProperty

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

the class SelectedWidgetUITracker method updateWidgetsFromTracker.

/**
 * Updates widgets to current tracker location and size
 */
private void updateWidgetsFromTracker(final Rectangle2D original, final Rectangle2D current) {
    if (updating)
        return;
    updating = true;
    try {
        group_handler.hide();
        final List<Rectangle2D> orig_position = widgets.stream().map(GeometryTools::getBounds).collect(Collectors.toList());
        // If there was only one widget, the tracker bounds represent
        // the desired widget location and size.
        // But tracker bounds can apply to one or more widgets, so need to
        // determine the change in tracker bounds, apply those to each widget.
        final double dx = current.getMinX() - original.getMinX();
        final double dy = current.getMinY() - original.getMinY();
        final double dw = current.getWidth() - original.getWidth();
        final double dh = current.getHeight() - original.getHeight();
        final int N = orig_position.size();
        // Use compound action if there's more than one widget
        final CompoundUndoableAction compound = N > 1 ? new CompoundUndoableAction(Messages.UpdateWidgetLocation) : null;
        for (int i = 0; i < N; ++i) {
            final Widget widget = widgets.get(i);
            final Rectangle2D orig = orig_position.get(i);
            final ChildrenProperty orig_parent_children = ChildrenProperty.getParentsChildren(widget);
            ChildrenProperty parent_children = group_handler.getActiveParentChildren();
            if (parent_children == null)
                parent_children = widget.getDisplayModel().runtimeChildren();
            if (orig_parent_children == parent_children) {
                // Slightly faster since parent stays the same
                if (!widget.propX().isUsingWidgetClass())
                    widget.propX().setValue((int) (orig.getMinX() + dx));
                if (!widget.propY().isUsingWidgetClass())
                    widget.propY().setValue((int) (orig.getMinY() + dy));
            } else {
                // Update to new parent
                if (widget.getDisplayModel().isClassModel()) {
                    logger.log(Level.WARNING, "Widget hierarchy is not permitted for class model");
                    return;
                }
                final Point2D old_offset = GeometryTools.getDisplayOffset(widget);
                orig_parent_children.removeChild(widget);
                parent_children.addChild(widget);
                final Point2D new_offset = GeometryTools.getDisplayOffset(widget);
                logger.log(Level.FINE, "{0} moves from {1} ({2}) to {3} ({4})", new Object[] { widget, orig_parent_children.getWidget(), old_offset, parent_children.getWidget(), new_offset });
                // Account for old and new display offset
                if (!widget.propX().isUsingWidgetClass())
                    widget.propX().setValue((int) (orig.getMinX() + dx + old_offset.getX() - new_offset.getX()));
                if (!widget.propY().isUsingWidgetClass())
                    widget.propY().setValue((int) (orig.getMinY() + dy + old_offset.getY() - new_offset.getY()));
            }
            if (!widget.propWidth().isUsingWidgetClass())
                widget.propWidth().setValue((int) Math.max(1, orig.getWidth() + dw));
            if (!widget.propHeight().isUsingWidgetClass())
                widget.propHeight().setValue((int) Math.max(1, orig.getHeight() + dh));
            final UndoableAction step = new UpdateWidgetLocationAction(widget, orig_parent_children, parent_children, (int) orig.getMinX(), (int) orig.getMinY(), (int) orig.getWidth(), (int) orig.getHeight());
            if (compound == null)
                undo.add(step);
            else
                compound.add(step);
        }
        if (compound != null)
            undo.add(compound);
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Failed to move/resize widgets", ex);
    } finally {
        updating = false;
        updateTrackerFromWidgets();
    }
}
Also used : ChildrenProperty(org.csstudio.display.builder.model.ChildrenProperty) Point2D(javafx.geometry.Point2D) CompoundUndoableAction(org.csstudio.display.builder.util.undo.CompoundUndoableAction) Rectangle2D(javafx.geometry.Rectangle2D) ActionButtonWidget(org.csstudio.display.builder.model.widgets.ActionButtonWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) Widget(org.csstudio.display.builder.model.Widget) UndoableAction(org.csstudio.display.builder.util.undo.UndoableAction) CompoundUndoableAction(org.csstudio.display.builder.util.undo.CompoundUndoableAction) UpdateWidgetLocationAction(org.csstudio.display.builder.editor.undo.UpdateWidgetLocationAction)

Example 7 with ChildrenProperty

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

the class DisplayEditor method createWidget.

/**
 * @param region Requested location and size of the new widget
 *  @param desc Description for widget to create
 */
private void createWidget(final Rectangle2D region, final WidgetDescriptor desc) {
    // Create widget of that type
    final Widget widget = desc.createWidget();
    // Size to rubberbanded region, optionally constrained by grid
    final Point2D location = selection_tracker.gridConstrain(region.getMinX(), region.getMinY());
    widget.propX().setValue((int) location.getX());
    widget.propY().setValue((int) location.getY());
    final Point2D size = selection_tracker.gridConstrain(region.getWidth(), region.getHeight());
    widget.propWidth().setValue((int) size.getX());
    widget.propHeight().setValue((int) size.getY());
    // Add to model
    final ChildrenProperty target = model.runtimeChildren();
    widget_naming.setDefaultName(model, widget);
    undo.execute(new AddWidgetAction(selection, target, widget));
    // De-activate the palette, so rubberband will from now on select widgets
    palette.clearSelectedWidgetType();
    // Select the new widget
    selection.setSelection(Arrays.asList(widget));
}
Also used : ChildrenProperty(org.csstudio.display.builder.model.ChildrenProperty) AddWidgetAction(org.csstudio.display.builder.editor.undo.AddWidgetAction) Point2D(javafx.geometry.Point2D) ArrayWidget(org.csstudio.display.builder.model.widgets.ArrayWidget) Widget(org.csstudio.display.builder.model.Widget)

Example 8 with ChildrenProperty

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

the class DisplayEditor method addWidgets.

/**
 * @param widgets Widgets to be added to existing model
 */
private void addWidgets(final List<Widget> widgets) {
    // Dropped into a sub-group or the main display?
    ChildrenProperty target = group_handler.getActiveParentChildren();
    if (target == null)
        target = model.runtimeChildren();
    Widget container = target.getWidget();
    // Correct all dropped widget locations relative to container
    Point2D offset = GeometryTools.getContainerOffset(container);
    // Also account for scroll pane
    Point2D origin = JFXGeometryTools.getContentOrigin(model_root);
    int dx = (int) (offset.getX() - origin.getX());
    int dy = (int) (offset.getY() - origin.getY());
    // Add dropped widgets
    try {
        final ListIterator<Widget> it = widgets.listIterator();
        if (container instanceof ArrayWidget) {
            if (target.getValue().isEmpty()) {
                // Drop first widget into ArrayWidget
                Widget widget = it.next();
                widget.propX().setValue(widget.propX().getValue() - dx);
                widget.propY().setValue(widget.propY().getValue() - dy);
                widget_naming.setDefaultName(container.getDisplayModel(), widget);
                undo.execute(new AddWidgetAction(selection, target, widget));
            }
            // Hide highlight, since not adding to ArrayWidget container
            if (it.hasNext())
                group_handler.hide();
            // Re-assign target, container, etc. to use ArrayWidget's parent
            target = ChildrenProperty.getParentsChildren(container);
            container = target.getWidget();
            offset = GeometryTools.getContainerOffset(container);
            origin = JFXGeometryTools.getContentOrigin(model_root);
            dx = (int) (offset.getX() - origin.getX());
            dy = (int) (offset.getY() - origin.getY());
        }
        while (it.hasNext()) {
            Widget widget = it.next();
            widget.propX().setValue(widget.propX().getValue() - dx);
            widget.propY().setValue(widget.propY().getValue() - dy);
            widget_naming.setDefaultName(container.getDisplayModel(), widget);
            undo.execute(new AddWidgetAction(selection, target, widget));
        }
        selection.setSelection(widgets);
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Cannot add widgets", ex);
    }
}
Also used : ChildrenProperty(org.csstudio.display.builder.model.ChildrenProperty) AddWidgetAction(org.csstudio.display.builder.editor.undo.AddWidgetAction) ArrayWidget(org.csstudio.display.builder.model.widgets.ArrayWidget) Point2D(javafx.geometry.Point2D) ArrayWidget(org.csstudio.display.builder.model.widgets.ArrayWidget) Widget(org.csstudio.display.builder.model.Widget)

Example 9 with ChildrenProperty

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

the class GroupWidget method defineProperties.

@Override
protected void defineProperties(final List<WidgetProperty<?>> properties) {
    super.defineProperties(properties);
    properties.add(macros = propMacros.createProperty(this, new Macros()));
    properties.add(children = new ChildrenProperty(this));
    properties.add(style = propStyle.createProperty(this, Style.GROUP));
    properties.add(font = propFont.createProperty(this, WidgetFontService.get(NamedWidgetFonts.DEFAULT)));
    properties.add(foreground = propForegroundColor.createProperty(this, WidgetColorService.getColor(NamedWidgetColors.TEXT)));
    properties.add(background = propBackgroundColor.createProperty(this, WidgetColorService.getColor(NamedWidgetColors.BACKGROUND)));
    properties.add(transparent = propTransparent.createProperty(this, false));
    properties.add(insets = runtimePropExtendedInsets.createProperty(this, new int[] { 0, 0, 0, 0 }));
}
Also used : ChildrenProperty(org.csstudio.display.builder.model.ChildrenProperty) CommonWidgetProperties.propMacros(org.csstudio.display.builder.model.properties.CommonWidgetProperties.propMacros) Macros(org.csstudio.display.builder.model.macros.Macros)

Example 10 with ChildrenProperty

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

the class ParentHandler method locateParent.

/**
 * Locate parent for region of display.
 *
 *  <p>If there is a group or tab that contains the region, it is highlighted.
 *
 *  <p>The widgets in the current selection themselves are ignored
 *  in the search to prevent having a group that's moved locate itself.
 *
 *  @param x
 *  @param y
 *  @param width
 *  @param height
 *  @see #getActiveParentChildren()
 */
public void locateParent(final double x, final double y, final double width, final double height) {
    final Rectangle2D bounds = new Rectangle2D(x, y, width, height);
    final List<Widget> selected_widgets = selection.getSelection();
    final ParentSearchResult res = new ParentWidgetSearch(bounds, model, selected_widgets).compute();
    final ChildrenProperty parent = res.children;
    if (parent == null)
        parent_highlight.setVisible(false);
    else {
        final Rectangle2D group_bounds = GeometryTools.getDisplayBounds(parent.getWidget());
        parent_highlight.setX(group_bounds.getMinX());
        parent_highlight.setY(group_bounds.getMinY());
        parent_highlight.setWidth(group_bounds.getWidth());
        parent_highlight.setHeight(group_bounds.getHeight());
        parent_highlight.setVisible(true);
    }
    active_parent_children = parent;
}
Also used : ChildrenProperty(org.csstudio.display.builder.model.ChildrenProperty) Rectangle2D(javafx.geometry.Rectangle2D) ArrayWidget(org.csstudio.display.builder.model.widgets.ArrayWidget) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) Widget(org.csstudio.display.builder.model.Widget)

Aggregations

ChildrenProperty (org.csstudio.display.builder.model.ChildrenProperty)17 Widget (org.csstudio.display.builder.model.Widget)12 TabsWidget (org.csstudio.display.builder.model.widgets.TabsWidget)4 Point2D (javafx.geometry.Point2D)3 Rectangle2D (javafx.geometry.Rectangle2D)3 ArrayWidget (org.csstudio.display.builder.model.widgets.ArrayWidget)3 GroupWidget (org.csstudio.display.builder.model.widgets.GroupWidget)3 TabItemProperty (org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty)3 AddWidgetAction (org.csstudio.display.builder.editor.undo.AddWidgetAction)2 Matcher (java.util.regex.Matcher)1 TreeItem (javafx.scene.control.TreeItem)1 GroupWidgetsAction (org.csstudio.display.builder.editor.undo.GroupWidgetsAction)1 UpdateWidgetLocationAction (org.csstudio.display.builder.editor.undo.UpdateWidgetLocationAction)1 DisplayModel (org.csstudio.display.builder.model.DisplayModel)1 ParseAgainException (org.csstudio.display.builder.model.WidgetConfigurator.ParseAgainException)1 WidgetTypeException (org.csstudio.display.builder.model.WidgetFactory.WidgetTypeException)1 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)1 Macros (org.csstudio.display.builder.model.macros.Macros)1 CommonWidgetProperties.propMacros (org.csstudio.display.builder.model.properties.CommonWidgetProperties.propMacros)1 ActionButtonWidget (org.csstudio.display.builder.model.widgets.ActionButtonWidget)1