Search in sources :

Example 56 with RadComponent

use of com.intellij.uiDesigner.radComponents.RadComponent 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 57 with RadComponent

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

the class CreateComponentAction method actionPerformed.

protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
    Processor<ComponentItem> processor = selectedValue -> {
        if (selectedValue != null) {
            myLastCreatedComponent = selectedValue;
            editor.getMainProcessor().startInsertProcessor(selectedValue, getCreateLocation(editor, selection));
        }
        return true;
    };
    PaletteListPopupStep step = new PaletteListPopupStep(editor, myLastCreatedComponent, processor, UIDesignerBundle.message("create.component.title"));
    final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(step);
    if (selection.size() > 0) {
        FormEditingUtil.showPopupUnderComponent(listPopup, selection.get(0));
    } else {
        listPopup.showInCenterOf(editor.getRootContainer().getDelegee());
    }
}
Also used : UIDesignerBundle(com.intellij.uiDesigner.UIDesignerBundle) com.intellij.uiDesigner.designSurface(com.intellij.uiDesigner.designSurface) ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) java.awt(java.awt) ListPopup(com.intellij.openapi.ui.popup.ListPopup) List(java.util.List) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) Processor(com.intellij.util.Processor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer) ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) ListPopup(com.intellij.openapi.ui.popup.ListPopup)

Example 58 with RadComponent

use of com.intellij.uiDesigner.radComponents.RadComponent 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 59 with RadComponent

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

the class DuplicateComponentsAction method canDuplicate.

private static boolean canDuplicate(final List<RadComponent> selection, final boolean incrementRow) {
    int aRow = selection.get(0).getConstraints().getCell(incrementRow);
    int aRowSpan = selection.get(0).getConstraints().getSpan(incrementRow);
    for (int i = 1; i < selection.size(); i++) {
        final RadComponent c = selection.get(i);
        if (c.getConstraints().getSpan(incrementRow) > 1 || aRowSpan > 1) {
            if (c.getConstraints().getCell(incrementRow) != aRow || c.getConstraints().getSpan(incrementRow) != aRowSpan) {
                return false;
            }
        }
    }
    return true;
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent)

Example 60 with RadComponent

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

the class DuplicateComponentsAction method adjustDuplicates.

private static void adjustDuplicates(final Map<RadComponent, RadComponent> duplicates) {
    for (RadComponent c : duplicates.keySet()) {
        RadComponent copy = duplicates.get(c);
        if (c.getBinding() != null) {
            String binding = BindingProperty.getDefaultBinding(copy);
            new BindingProperty(c.getProject()).setValueEx(copy, binding);
            copy.setDefaultBinding(true);
        }
        for (IProperty prop : copy.getModifiedProperties()) {
            if (prop instanceof IntroComponentProperty) {
                final IntroComponentProperty componentProperty = (IntroComponentProperty) prop;
                String copyValue = componentProperty.getValue(copy);
                for (RadComponent original : duplicates.keySet()) {
                    if (original.getId().equals(copyValue)) {
                        componentProperty.setValueEx(copy, duplicates.get(original).getId());
                    }
                }
            }
        }
    }
}
Also used : IntroComponentProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty) IProperty(com.intellij.uiDesigner.lw.IProperty) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) BindingProperty(com.intellij.uiDesigner.propertyInspector.properties.BindingProperty)

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