Search in sources :

Example 16 with RadRootContainer

use of com.intellij.uiDesigner.radComponents.RadRootContainer in project intellij-community by JetBrains.

the class FormEditingUtil method deleteComponents.

public static void deleteComponents(final Collection<? extends RadComponent> selection, boolean deleteEmptyCells) {
    if (selection.size() == 0) {
        return;
    }
    final RadRootContainer rootContainer = (RadRootContainer) getRoot(selection.iterator().next());
    final Set<String> deletedComponentIds = new HashSet<>();
    for (final RadComponent component : selection) {
        boolean wasSelected = component.isSelected();
        final RadContainer parent = component.getParent();
        boolean wasPackedHorz = false;
        boolean wasPackedVert = false;
        if (parent.getParent() != null && parent.getParent().isXY()) {
            final Dimension minSize = parent.getMinimumSize();
            wasPackedHorz = parent.getWidth() == minSize.width;
            wasPackedVert = parent.getHeight() == minSize.height;
        }
        iterate(component, new ComponentVisitor() {

            public boolean visit(final IComponent c) {
                RadComponent rc = (RadComponent) c;
                BindingProperty.checkRemoveUnusedField(rootContainer, rc.getBinding(), null);
                deletedComponentIds.add(rc.getId());
                return true;
            }
        });
        GridConstraints delConstraints = parent.getLayoutManager().isGrid() ? component.getConstraints() : null;
        int index = parent.indexOfComponent(component);
        parent.removeComponent(component);
        if (wasSelected) {
            if (parent.getComponentCount() > index) {
                parent.getComponent(index).setSelected(true);
            } else if (index > 0 && parent.getComponentCount() == index) {
                parent.getComponent(index - 1).setSelected(true);
            } else {
                parent.setSelected(true);
            }
        }
        if (delConstraints != null && deleteEmptyCells) {
            deleteEmptyGridCells(parent, delConstraints);
        }
        if (wasPackedHorz || wasPackedVert) {
            final Dimension minSize = parent.getMinimumSize();
            Dimension newSize = new Dimension(parent.getWidth(), parent.getHeight());
            if (wasPackedHorz) {
                newSize.width = minSize.width;
            }
            if (wasPackedVert) {
                newSize.height = minSize.height;
            }
            parent.setSize(newSize);
        }
    }
    iterate(rootContainer, new ComponentVisitor() {

        public boolean visit(final IComponent component) {
            RadComponent rc = (RadComponent) component;
            for (IProperty p : component.getModifiedProperties()) {
                if (p instanceof IntroComponentProperty) {
                    IntroComponentProperty icp = (IntroComponentProperty) p;
                    final String value = icp.getValue(rc);
                    if (deletedComponentIds.contains(value)) {
                        try {
                            icp.resetValue(rc);
                        } catch (Exception e) {
                        // ignore
                        }
                    }
                }
            }
            return true;
        }
    });
}
Also used : RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RelativePoint(com.intellij.ui.awt.RelativePoint) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) IncorrectOperationException(com.intellij.util.IncorrectOperationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IntroComponentProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer) HashSet(com.intellij.util.containers.HashSet)

Example 17 with RadRootContainer

use of com.intellij.uiDesigner.radComponents.RadRootContainer in project intellij-community by JetBrains.

the class FormEditingUtil method canDeleteSelection.

public static boolean canDeleteSelection(final GuiEditor editor) {
    final ArrayList<RadComponent> selection = getSelectedComponents(editor);
    if (selection.isEmpty())
        return false;
    final RadRootContainer rootContainer = editor.getRootContainer();
    if (rootContainer.getComponentCount() > 0 && selection.contains(rootContainer.getComponent(0))) {
        return false;
    }
    return true;
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer)

Example 18 with RadRootContainer

use of com.intellij.uiDesigner.radComponents.RadRootContainer in project intellij-community by JetBrains.

the class StringDescriptorManager method resolve.

@Nullable
public String resolve(@NotNull RadComponent component, @Nullable StringDescriptor descriptor) {
    RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(component);
    Locale locale = (root != null) ? root.getStringDescriptorLocale() : null;
    return resolve(descriptor, locale);
}
Also used : Locale(java.util.Locale) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with RadRootContainer

use of com.intellij.uiDesigner.radComponents.RadRootContainer in project intellij-community by JetBrains.

the class PassiveDecorationLayer method paint.

public void paint(final Graphics g) {
    // Passive decoration
    final RadRootContainer root = myEditor.getRootContainer();
    for (int i = root.getComponentCount() - 1; i >= 0; i--) {
        final RadComponent component = root.getComponent(i);
        paintPassiveDecoration(component, g);
    }
    // Paint active decorators
    paintChildren(g);
}
Also used : RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent)

Example 20 with RadRootContainer

use of com.intellij.uiDesigner.radComponents.RadRootContainer in project intellij-community by JetBrains.

the class PassiveDecorationLayer method paintPassiveDecoration.

/**
   * Paints all necessary decoration for the specified <code>component</code>
   */
protected final void paintPassiveDecoration(final RadComponent component, final Graphics g) {
    // Paint component bounds and grid markers
    Painter.paintComponentDecoration(myEditor, component, g);
    final Set<RadButtonGroup> paintedGroups = new HashSet<>();
    final RadRootContainer rootContainer = myEditor.getRootContainer();
    final ComponentTree componentTree = DesignerToolWindowManager.getInstance(myEditor).getComponentTree();
    final Collection<RadButtonGroup> selectedGroups = componentTree != null ? componentTree.getSelectedElements(RadButtonGroup.class) : Collections.<RadButtonGroup>emptyList();
    // Paint selection and dragger
    FormEditingUtil.iterate(component, new FormEditingUtil.ComponentVisitor<RadComponent>() {

        public boolean visit(final RadComponent component) {
            final Point point = SwingUtilities.convertPoint(component.getDelegee(), 0, 0, rootContainer.getDelegee());
            RadButtonGroup group = (RadButtonGroup) FormEditingUtil.findGroupForComponent(rootContainer, component);
            if (group != null && !paintedGroups.contains(group) && (component.isSelected() || selectedGroups.contains(group))) {
                paintedGroups.add(group);
                Painter.paintButtonGroupLines(rootContainer, group, g);
            }
            g.translate(point.x, point.y);
            try {
                if (myEditor.isShowComponentTags() && FormEditingUtil.isComponentSwitchedInView(component)) {
                    Painter.paintComponentTag(component, g);
                }
                Painter.paintSelectionDecoration(component, g, myEditor.getGlassLayer().isFocusOwner());
                // Over selection we have to paint dragger
                if (component.hasDragger()) {
                    final Icon icon = getDragIcon();
                    icon.paintIcon(PassiveDecorationLayer.this, g, -icon.getIconWidth(), -icon.getIconHeight());
                }
            } finally {
                g.translate(-point.x, -point.y);
            }
            return true;
        }
    });
}
Also used : RadButtonGroup(com.intellij.uiDesigner.radComponents.RadButtonGroup) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) ComponentTree(com.intellij.uiDesigner.componentTree.ComponentTree) HashSet(com.intellij.util.containers.HashSet)

Aggregations

RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)29 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)17 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)6 RadButtonGroup (com.intellij.uiDesigner.radComponents.RadButtonGroup)4 Locale (java.util.Locale)4 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 HashSet (com.intellij.util.containers.HashSet)3 ArrayList (java.util.ArrayList)3 Nullable (org.jetbrains.annotations.Nullable)3 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)2 IButtonGroup (com.intellij.uiDesigner.lw.IButtonGroup)2 LwInspectionSuppression (com.intellij.uiDesigner.lw.LwInspectionSuppression)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 Project (com.intellij.openapi.project.Project)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)1 ComponentPtr (com.intellij.uiDesigner.componentTree.ComponentPtr)1 ComponentTree (com.intellij.uiDesigner.componentTree.ComponentTree)1