Search in sources :

Example 36 with RadContainer

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

the class GuiEditor method refreshProperties.

private void refreshProperties() {
    final Ref<Boolean> anythingModified = new Ref<>();
    FormEditingUtil.iterate(myRootContainer, new FormEditingUtil.ComponentVisitor() {

        public boolean visit(final IComponent component) {
            final RadComponent radComponent = (RadComponent) component;
            boolean componentModified = false;
            for (IProperty prop : component.getModifiedProperties()) {
                if (prop instanceof IntroStringProperty) {
                    IntroStringProperty strProp = (IntroStringProperty) prop;
                    componentModified = strProp.refreshValue(radComponent) || componentModified;
                }
            }
            if (component instanceof RadContainer) {
                componentModified = ((RadContainer) component).updateBorder() || componentModified;
            }
            if (component.getParentContainer() instanceof RadTabbedPane) {
                componentModified = ((RadTabbedPane) component.getParentContainer()).refreshChildTitle(radComponent) || componentModified;
            }
            if (componentModified) {
                anythingModified.set(Boolean.TRUE);
            }
            return true;
        }
    });
    if (!anythingModified.isNull()) {
        refresh();
        DesignerToolWindow designerToolWindow = DesignerToolWindowManager.getInstance(this);
        ComponentTree tree = designerToolWindow.getComponentTree();
        if (tree != null)
            tree.repaint();
        PropertyInspector inspector = designerToolWindow.getPropertyInspector();
        if (inspector != null)
            inspector.synchWithTree(true);
    }
}
Also used : IComponent(com.intellij.uiDesigner.lw.IComponent) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) DesignerToolWindow(com.intellij.uiDesigner.propertyInspector.DesignerToolWindow) PropertyInspector(com.intellij.uiDesigner.propertyInspector.PropertyInspector) ComponentTree(com.intellij.uiDesigner.componentTree.ComponentTree) Ref(com.intellij.openapi.util.Ref) RadTabbedPane(com.intellij.uiDesigner.radComponents.RadTabbedPane) IProperty(com.intellij.uiDesigner.lw.IProperty) IntroStringProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 37 with RadContainer

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

the class AbstractMoveSelectionAction method moveSelectionByGrid.

private boolean moveSelectionByGrid(final RadComponent selectedComponent) {
    final RadContainer parent = selectedComponent.getParent();
    if (parent == null || !parent.getLayoutManager().isGrid()) {
        return false;
    }
    int row = selectedComponent.getConstraints().getRow();
    int column = selectedComponent.getConstraints().getColumn();
    RadComponent lastComponent = null;
    do {
        row += getRowMoveDelta();
        column += getColumnMoveDelta();
        if (row < 0 || row >= parent.getGridRowCount() || column < 0 || column >= parent.getGridColumnCount()) {
            if (myMoveToLast) {
                break;
            }
            return false;
        }
        final RadComponent component = parent.getComponentAtGrid(row, column);
        if (component != null && component != selectedComponent) {
            if (myMoveToLast) {
                if (myExtend) {
                    FormEditingUtil.selectComponent(myEditor, component);
                }
                lastComponent = component;
            } else {
                selectOrExtend(component);
                return true;
            }
        }
    } while (true);
    if (lastComponent != null) {
        selectOrExtend(lastComponent);
        return true;
    }
    return false;
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 38 with RadContainer

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

the class CreateComponentAction method getCreateLocation.

private static ComponentDropLocation getCreateLocation(final GuiEditor editor, final List<RadComponent> selection) {
    ComponentDropLocation dropLocation = null;
    if (selection.size() > 0) {
        RadComponent component = selection.get(0);
        final RadContainer container = component.getParent();
        if (container.getLayoutManager().isGrid()) {
            GridConstraints c = component.getConstraints();
            // try to insert in empty cell to the right or below the component; if not found -
            // insert row below selected component
            int nextCol = FormEditingUtil.adjustForGap(component.getParent(), c.getColumn() + c.getColSpan(), false, 1);
            int nextRow = FormEditingUtil.adjustForGap(component.getParent(), c.getRow() + c.getRowSpan(), true, 1);
            if (nextCol < container.getGridColumnCount() && container.getComponentAtGrid(c.getRow(), nextCol) == null) {
                dropLocation = new GridDropLocation(container, c.getRow(), nextCol);
            } else if (nextRow < container.getGridRowCount() && container.getComponentAtGrid(nextRow, c.getColumn()) == null) {
                dropLocation = new GridDropLocation(container, nextRow, c.getColumn());
            } else {
                dropLocation = new GridInsertLocation(container, c.getRow() + c.getRowSpan() - 1, c.getColumn(), GridInsertMode.RowAfter);
            }
        }
    }
    if (dropLocation == null) {
        final Point mousePosition = editor.getMainProcessor().getLastMousePosition();
        if (mousePosition != null) {
            RadContainer container = GridInsertProcessor.getDropTargetContainer(editor.getRootContainer(), mousePosition);
            if (container == null) {
                container = editor.getRootContainer();
            }
            if (container instanceof RadRootContainer && container.getComponentCount() == 1 && container.getComponent(0) instanceof RadContainer) {
                RadContainer childContainer = (RadContainer) container.getComponent(0);
                dropLocation = childContainer.getDropLocation(null);
            } else {
                dropLocation = GridInsertProcessor.getDropLocation(editor.getRootContainer(), mousePosition);
            }
        } else {
            final RadRootContainer container = editor.getRootContainer();
            if (container.getComponentCount() == 1 && container.getComponent(0) instanceof RadContainer) {
                RadContainer childContainer = (RadContainer) container.getComponent(0);
                dropLocation = childContainer.getDropLocation(null);
            } else {
                dropLocation = container.getDropLocation(null);
            }
        }
    }
    return dropLocation;
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 39 with RadContainer

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

the class DuplicateComponentsAction method update.

protected void update(@NotNull GuiEditor editor, final ArrayList<RadComponent> selection, final AnActionEvent e) {
    FormEditingUtil.remapToActionTargets(selection);
    final RadContainer parent = FormEditingUtil.getSelectionParent(selection);
    e.getPresentation().setEnabled(parent != null && (parent.getLayoutManager().isGrid() || parent.getLayoutManager().isIndexed()));
    // 3) all selected components have the same row and rowspan
    if (selection.size() > 1 && parent != null && parent.getLayoutManager().isGrid()) {
        e.getPresentation().setEnabled(canDuplicate(selection, true) || canDuplicate(selection, false));
    }
}
Also used : RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 40 with RadContainer

use of com.intellij.uiDesigner.radComponents.RadContainer 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)

Aggregations

RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)51 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)20 RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)6 ArrayList (java.util.ArrayList)6 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)5 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)3 IComponent (com.intellij.uiDesigner.lw.IComponent)3 ComponentTreeBuilder (com.intellij.uiDesigner.componentTree.ComponentTreeBuilder)2 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)2 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)2 IProperty (com.intellij.uiDesigner.lw.IProperty)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 LayoutManager (java.awt.LayoutManager)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Ref (com.intellij.openapi.util.Ref)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 SelectionState (com.intellij.uiDesigner.SelectionState)1 ComponentPtr (com.intellij.uiDesigner.componentTree.ComponentPtr)1 ComponentTree (com.intellij.uiDesigner.componentTree.ComponentTree)1