Search in sources :

Example 61 with RadComponent

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

the class ExpandSelectionAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    final GuiEditor editor = FormEditingUtil.getEditorFromContext(e.getDataContext());
    assert editor != null;
    final SelectionState selectionState = editor.getSelectionState();
    selectionState.setInsideChange(true);
    ComponentTreeBuilder builder = DesignerToolWindowManager.getInstance(editor).getComponentTreeBuilder();
    if (builder != null) {
        builder.beginUpdateSelection();
    }
    final Stack<ComponentPtr[]> history = selectionState.getSelectionHistory();
    try {
        final ComponentPtr[] ptrs = history.peek();
        for (int i = ptrs.length - 1; i >= 0; i--) {
            // Skip invalid components
            final ComponentPtr ptr = ptrs[i];
            ptr.validate();
            if (!ptr.isValid()) {
                continue;
            }
            // Extend selection
            final RadComponent component = ptr.getComponent();
            final RadContainer parent = component.getParent();
            if (parent == null) {
                // skip components without parents
                continue;
            }
            boolean shouldSelectParent = true;
            for (int j = parent.getComponentCount() - 1; j >= 0; j--) {
                final RadComponent sibling = parent.getComponent(j);
                if (!sibling.isSelected()) {
                    shouldSelectParent = false;
                    sibling.setSelected(true);
                }
            }
            if (shouldSelectParent) {
                parent.setSelected(true);
            }
        }
        // Store new selection
        history.push(SelectionState.getSelection(editor));
    } finally {
        if (builder != null) {
            builder.endUpdateSelection();
        }
        selectionState.setInsideChange(false);
    }
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor) ComponentPtr(com.intellij.uiDesigner.componentTree.ComponentPtr) SelectionState(com.intellij.uiDesigner.SelectionState) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer) ComponentTreeBuilder(com.intellij.uiDesigner.componentTree.ComponentTreeBuilder)

Example 62 with RadComponent

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

the class CutCopyPasteSupport method deserializeComponents.

@Nullable
private static ArrayList<RadComponent> deserializeComponents(final GuiEditor editor, final String serializedComponents) {
    ArrayList<RadComponent> components = new ArrayList<>();
    TIntArrayList xs = new TIntArrayList();
    TIntArrayList ys = new TIntArrayList();
    if (!loadComponentsToPaste(editor, serializedComponents, xs, ys, components)) {
        return null;
    }
    return components;
}
Also used : ArrayList(java.util.ArrayList) TIntArrayList(gnu.trove.TIntArrayList) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) TIntArrayList(gnu.trove.TIntArrayList) Nullable(org.jetbrains.annotations.Nullable)

Example 63 with RadComponent

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

the class CutCopyPasteSupport method performPaste.

public void performPaste(@NotNull final DataContext dataContext) {
    final String serializedComponents = getSerializedComponents();
    if (serializedComponents == null) {
        return;
    }
    final ArrayList<RadComponent> componentsToPaste = new ArrayList<>();
    final TIntArrayList xs = new TIntArrayList();
    final TIntArrayList ys = new TIntArrayList();
    loadComponentsToPaste(myEditor, serializedComponents, xs, ys, componentsToPaste);
    myEditor.getMainProcessor().startPasteProcessor(componentsToPaste, xs, ys);
}
Also used : ArrayList(java.util.ArrayList) TIntArrayList(gnu.trove.TIntArrayList) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) TIntArrayList(gnu.trove.TIntArrayList)

Example 64 with RadComponent

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

the class FormEditingUtil method getSelectionBounds.

public static Rectangle getSelectionBounds(List<RadComponent> selection) {
    int minRow = Integer.MAX_VALUE;
    int minCol = Integer.MAX_VALUE;
    int maxRow = 0;
    int maxCol = 0;
    for (RadComponent c : selection) {
        minRow = Math.min(minRow, c.getConstraints().getRow());
        minCol = Math.min(minCol, c.getConstraints().getColumn());
        maxRow = Math.max(maxRow, c.getConstraints().getRow() + c.getConstraints().getRowSpan());
        maxCol = Math.max(maxCol, c.getConstraints().getColumn() + c.getConstraints().getColSpan());
    }
    return new Rectangle(minCol, minRow, maxCol - minCol, maxRow - minRow);
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 65 with RadComponent

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

the class FormEditingUtil method selectComponents.

public static void selectComponents(final GuiEditor editor, List<RadComponent> components) {
    if (components.size() > 0) {
        RadComponent component = components.get(0);
        ComponentTreeBuilder builder = DesignerToolWindowManager.getInstance(editor).getComponentTreeBuilder();
        if (builder == null) {
            // race condition when handling event?
            return;
        }
        builder.beginUpdateSelection();
        try {
            clearSelection((RadContainer) getRoot(component));
            for (RadComponent aComponent : components) {
                selectComponent(editor, aComponent);
            }
        } finally {
            builder.endUpdateSelection();
        }
    }
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) ComponentTreeBuilder(com.intellij.uiDesigner.componentTree.ComponentTreeBuilder)

Aggregations

RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)86 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)22 RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)18 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)15 ArrayList (java.util.ArrayList)12 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)8 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)8 IComponent (com.intellij.uiDesigner.lw.IComponent)7 IProperty (com.intellij.uiDesigner.lw.IProperty)6 ComponentItem (com.intellij.uiDesigner.palette.ComponentItem)5 RadButtonGroup (com.intellij.uiDesigner.radComponents.RadButtonGroup)5 ListPopup (com.intellij.openapi.ui.popup.ListPopup)4 ComponentTree (com.intellij.uiDesigner.componentTree.ComponentTree)4 IntrospectedProperty (com.intellij.uiDesigner.propertyInspector.IntrospectedProperty)4 IntroComponentProperty (com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty)4 QuickFix (com.intellij.uiDesigner.quickFixes.QuickFix)4 Nullable (org.jetbrains.annotations.Nullable)4 RelativePoint (com.intellij.ui.awt.RelativePoint)3 Palette (com.intellij.uiDesigner.palette.Palette)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3