Search in sources :

Example 1 with RadComponent

use of com.intellij.designer.model.RadComponent in project intellij-community by JetBrains.

the class CaptionPanel method update.

public void update() {
    List<RadComponent> selection = myMainArea.getSelection();
    if (selection.size() != 1) {
        if (myCaption != null) {
            myCaption = null;
            myRootComponent.setLayout(null);
            myRootChildren = Collections.emptyList();
            myArea.deselectAll();
            revalidate();
            repaint();
        }
        return;
    }
    boolean update = !myRootChildren.isEmpty();
    IntArrayList oldSelection = null;
    if (myCaption != null) {
        oldSelection = new IntArrayList();
        for (RadComponent component : myArea.getSelection()) {
            oldSelection.add(myRootChildren.indexOf(component));
        }
    }
    myArea.deselectAll();
    myRootComponent.setLayout(null);
    ICaption caption = null;
    RadComponent component = selection.get(0);
    RadComponent parent = component.getParent();
    if (parent != null) {
        caption = parent.getLayout().getCaption(component);
    }
    if (caption == null) {
        caption = component.getCaption();
    }
    if (caption == null) {
        myRootChildren = Collections.emptyList();
    } else {
        myRootComponent.setLayout(caption.getCaptionLayout(myMainArea, myHorizontal));
        myRootChildren = caption.getCaptionChildren(myMainArea, myHorizontal);
        for (RadComponent child : myRootChildren) {
            child.setParent(myRootComponent);
        }
        if (myCaption == caption) {
            List<RadComponent> newSelection = new ArrayList<>();
            int componentSize = myRootChildren.size();
            int selectionSize = oldSelection.size();
            for (int i = 0; i < selectionSize; i++) {
                int index = oldSelection.get(i);
                if (0 <= index && index < componentSize) {
                    newSelection.add(myRootChildren.get(index));
                }
            }
            if (!newSelection.isEmpty()) {
                myArea.setSelection(newSelection);
            }
        }
        update |= !myRootChildren.isEmpty();
    }
    myCaption = caption;
    if (update) {
        revalidate();
        repaint();
    }
}
Also used : RadComponent(com.intellij.designer.model.RadComponent) IntArrayList(com.intellij.util.containers.IntArrayList) ArrayList(java.util.ArrayList) IntArrayList(com.intellij.util.containers.IntArrayList)

Example 2 with RadComponent

use of com.intellij.designer.model.RadComponent in project intellij-community by JetBrains.

the class DecorationLayer method paintStaticDecorators.

private void paintStaticDecorators(Graphics2D g) {
    final List<StaticDecorator> decorators = new ArrayList<>();
    final List<RadComponent> selection = myArea.getSelection();
    myArea.getRootComponent().accept(new RadComponentVisitor() {

        @Override
        public void endVisit(RadComponent component) {
            component.addStaticDecorators(decorators, selection);
        }
    }, true);
    for (StaticDecorator decorator : decorators) {
        decorator.decorate(this, g);
    }
}
Also used : RadComponentVisitor(com.intellij.designer.model.RadComponentVisitor) ArrayList(java.util.ArrayList) RadComponent(com.intellij.designer.model.RadComponent)

Example 3 with RadComponent

use of com.intellij.designer.model.RadComponent in project intellij-community by JetBrains.

the class DecorationLayer method paintSelection.

private void paintSelection(Graphics2D g) {
    List<RadComponent> selection = myArea.getSelection();
    for (RadComponent component : selection) {
        ComponentDecorator decorator = getDecorator(component, selection);
        decorator.decorate(this, g, component);
    }
}
Also used : RadComponent(com.intellij.designer.model.RadComponent)

Example 4 with RadComponent

use of com.intellij.designer.model.RadComponent in project intellij-community by JetBrains.

the class InplaceEditingLayer method startEditing.

public void startEditing(@Nullable InplaceContext inplaceContext) {
    try {
        List<RadComponent> selection = myDesigner.getSurfaceArea().getSelection();
        if (selection.size() != 1) {
            return;
        }
        myRadComponent = selection.get(0);
        myProperties = myRadComponent.getInplaceProperties();
        if (myProperties.isEmpty()) {
            myRadComponent = null;
            myProperties = null;
            return;
        }
        myInplaceComponent = new JPanel(new GridLayoutManager(myProperties.size(), 2));
        myInplaceComponent.setBorder(new LineMarginBorder(5, 5, 5, 5));
        new AnAction() {

            @Override
            public void actionPerformed(AnActionEvent e) {
                finishEditing(false);
            }
        }.registerCustomShortcutSet(CommonShortcuts.ESCAPE, myInplaceComponent);
        myEditors = new ArrayList<>();
        JComponent componentToFocus = null;
        Font font = null;
        if (inplaceContext == null) {
            inplaceContext = new InplaceContext();
        }
        int row = 0;
        for (Property property : myProperties) {
            JLabel label = new JLabel(property.getName() + ":");
            if (font == null) {
                font = label.getFont().deriveFont(Font.BOLD);
            }
            label.setFont(font);
            myInplaceComponent.add(label, new GridConstraints(row, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, 0, 0, null, null, null));
            PropertyEditor editor = property.getEditor();
            myEditors.add(editor);
            JComponent component = editor.getComponent(myRadComponent, myDesigner, property.getValue(myRadComponent), inplaceContext);
            myInplaceComponent.add(component, new GridConstraints(row++, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, 0, null, null, null));
            if (componentToFocus == null) {
                componentToFocus = editor.getPreferredFocusedComponent();
            }
        }
        for (PropertyEditor editor : myEditors) {
            editor.addPropertyEditorListener(myEditorListener);
        }
        Rectangle bounds = myRadComponent.getBounds(this);
        Dimension size = myInplaceComponent.getPreferredSize();
        myPreferredWidth = Math.max(size.width, bounds.width);
        myInplaceComponent.setBounds(bounds.x, bounds.y, myPreferredWidth, size.height);
        add(myInplaceComponent);
        myDesigner.getSurfaceArea().addSelectionListener(mySelectionListener);
        if (componentToFocus == null) {
            componentToFocus = IdeFocusTraversalPolicy.getPreferredFocusedComponent(myInplaceComponent);
        }
        if (componentToFocus == null) {
            componentToFocus = myInplaceComponent;
        }
        if (componentToFocus.requestFocusInWindow()) {
            myFocusWatcher.install(myInplaceComponent);
        } else {
            grabFocus();
            final JComponent finalComponentToFocus = componentToFocus;
            ApplicationManager.getApplication().invokeLater(() -> {
                finalComponentToFocus.requestFocusInWindow();
                myFocusWatcher.install(myInplaceComponent);
            });
        }
        enableEvents(AWTEvent.MOUSE_EVENT_MASK);
        repaint();
    } catch (Throwable e) {
        LOG.error(e);
    }
}
Also used : RadComponent(com.intellij.designer.model.RadComponent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) LineMarginBorder(com.intellij.designer.designSurface.feedbacks.LineMarginBorder) PropertyEditor(com.intellij.designer.propertyTable.PropertyEditor) InplaceContext(com.intellij.designer.propertyTable.InplaceContext) Property(com.intellij.designer.model.Property)

Example 5 with RadComponent

use of com.intellij.designer.model.RadComponent in project intellij-community by JetBrains.

the class SelectAllAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    RadComponent rootComponent = myArea.getRootComponent();
    if (rootComponent != null) {
        final List<RadComponent> components = new ArrayList<>();
        rootComponent.accept(new RadComponentVisitor() {

            @Override
            public void endVisit(RadComponent component) {
                if (!component.isBackground()) {
                    components.add(component);
                }
            }
        }, true);
        myArea.setSelection(components);
    }
}
Also used : RadComponentVisitor(com.intellij.designer.model.RadComponentVisitor) RadComponent(com.intellij.designer.model.RadComponent) ArrayList(java.util.ArrayList)

Aggregations

RadComponent (com.intellij.designer.model.RadComponent)28 ArrayList (java.util.ArrayList)8 RadComponentVisitor (com.intellij.designer.model.RadComponentVisitor)6 Nullable (org.jetbrains.annotations.Nullable)3 EditOperation (com.intellij.designer.designSurface.EditOperation)2 IComponentCopyProvider (com.intellij.designer.model.IComponentCopyProvider)2 MetaModel (com.intellij.designer.model.MetaModel)2 RadLayout (com.intellij.designer.model.RadLayout)2 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)2 SimpleTransferable (com.intellij.designer.clipboard.SimpleTransferable)1 ComponentTargetFilter (com.intellij.designer.designSurface.ComponentTargetFilter)1 EditableArea (com.intellij.designer.designSurface.EditableArea)1 FeedbackTreeLayer (com.intellij.designer.designSurface.FeedbackTreeLayer)1 LineMarginBorder (com.intellij.designer.designSurface.feedbacks.LineMarginBorder)1 CreationTool (com.intellij.designer.designSurface.tools.CreationTool)1 InputTool (com.intellij.designer.designSurface.tools.InputTool)1 IComponentDeletionParticipant (com.intellij.designer.model.IComponentDeletionParticipant)1 Property (com.intellij.designer.model.Property)1 WrapInProvider (com.intellij.designer.model.WrapInProvider)1 InplaceContext (com.intellij.designer.propertyTable.InplaceContext)1