Search in sources :

Example 1 with ComponentItem

use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.

the class AlignProperty method isModified.

@Override
public boolean isModified(final RadComponent component) {
    AlignPropertyProvider provider = getAlignPropertyProvider(component);
    if (provider != null) {
        return provider.isAlignmentModified(component, myHorizontal);
    }
    final ComponentItem item = component.getPalette().getItem(component.getComponentClassName());
    if (item == null)
        return false;
    return Utils.alignFromConstraints(component.getConstraints(), myHorizontal) != Utils.alignFromConstraints(item.getDefaultConstraints(), myHorizontal);
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem)

Example 2 with ComponentItem

use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.

the class MorphAction method actionPerformed.

protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
    Processor<ComponentItem> processor = selectedValue -> {
        Runnable runnable = () -> {
            for (RadComponent c : selection) {
                if (!morphComponent(editor, c, selectedValue))
                    break;
            }
            editor.refreshAndSave(true);
        };
        CommandProcessor.getInstance().executeCommand(editor.getProject(), runnable, UIDesignerBundle.message("morph.component.command"), null);
        IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
            IdeFocusManager.getGlobalInstance().requestFocus(editor.getGlassLayer(), true);
        });
        return true;
    };
    PaletteListPopupStep step = new PaletteListPopupStep(editor, myLastMorphComponent, processor, UIDesignerBundle.message("morph.component.title"));
    step.hideNonAtomic();
    if (selection.size() == 1) {
        step.hideComponentClass(selection.get(0).getComponentClassName());
    }
    final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(step);
    FormEditingUtil.showPopupUnderComponent(listPopup, selection.get(0));
}
Also used : PsiType(com.intellij.psi.PsiType) UIDesignerBundle(com.intellij.uiDesigner.UIDesignerBundle) RadAtomicComponent(com.intellij.uiDesigner.radComponents.RadAtomicComponent) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) ChangeFieldTypeFix(com.intellij.uiDesigner.quickFixes.ChangeFieldTypeFix) ArrayList(java.util.ArrayList) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor) Palette(com.intellij.uiDesigner.palette.Palette) PsiElementFactory(com.intellij.psi.PsiElementFactory) IProperty(com.intellij.uiDesigner.lw.IProperty) Logger(com.intellij.openapi.diagnostic.Logger) IntroComponentProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) BindingProperty(com.intellij.uiDesigner.propertyInspector.properties.BindingProperty) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) CommandProcessor(com.intellij.openapi.command.CommandProcessor) ListPopup(com.intellij.openapi.ui.popup.ListPopup) List(java.util.List) IComponent(com.intellij.uiDesigner.lw.IComponent) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) Processor(com.intellij.util.Processor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) PsiField(com.intellij.psi.PsiField) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer) NotNull(org.jetbrains.annotations.NotNull) InsertComponentProcessor(com.intellij.uiDesigner.designSurface.InsertComponentProcessor) FormInspectionUtil(com.intellij.uiDesigner.inspections.FormInspectionUtil) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) ListPopup(com.intellij.openapi.ui.popup.ListPopup)

Example 3 with ComponentItem

use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.

the class SurroundAction method actionPerformed.

public void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
    // the action is also reused as quickfix for NoScrollPaneInspection, so this code should be kept here
    FormEditingUtil.remapToActionTargets(selection);
    if (!editor.ensureEditable()) {
        return;
    }
    final RadContainer selectionParent = FormEditingUtil.getSelectionParent(selection);
    assert selectionParent != null;
    final Palette palette = Palette.getInstance(editor.getProject());
    final ComponentItem cItem = palette.getItem(myComponentClass);
    assert cItem != null : myComponentClass;
    CommandProcessor.getInstance().executeCommand(editor.getProject(), () -> {
        RadContainer newContainer = (RadContainer) InsertComponentProcessor.createInsertedComponent(editor, cItem);
        if (newContainer == null) {
            return;
        }
        if (cItem == palette.getPanelItem()) {
            if (selectionParent.getLayoutManager().isGrid()) {
                try {
                    newContainer.setLayoutManager(LayoutManagerRegistry.createLayoutManager(selectionParent.getLayoutManager().getName()));
                } catch (Exception e1) {
                    LOG.error(e1);
                    return;
                }
            } else {
                newContainer.setLayoutManager(LayoutManagerRegistry.createDefaultGridLayoutManager(editor.getProject()));
            }
        }
        Rectangle rc = new Rectangle(0, 0, 1, 1);
        int minIndex = Integer.MAX_VALUE;
        if (selectionParent.getLayoutManager().isGrid()) {
            rc = FormEditingUtil.getSelectionBounds(selection);
        } else if (selectionParent.getLayoutManager().isIndexed()) {
            for (RadComponent c : selection) {
                minIndex = Math.min(minIndex, selectionParent.indexOfComponent(c));
            }
        }
        for (RadComponent c : selection) {
            selectionParent.removeComponent(c);
        }
        if (selectionParent.getLayoutManager().isGrid()) {
            final GridConstraints newConstraints = newContainer.getConstraints();
            newConstraints.setRow(rc.y);
            newConstraints.setColumn(rc.x);
            newConstraints.setRowSpan(rc.height);
            newConstraints.setColSpan(rc.width);
        } else if (selectionParent.getLayout() instanceof XYLayoutManager && selection.size() == 1) {
            newContainer.setBounds(selection.get(0).getBounds());
        }
        if (selection.size() == 1) {
            newContainer.setCustomLayoutConstraints(selection.get(0).getCustomLayoutConstraints());
        }
        if (minIndex != Integer.MAX_VALUE) {
            selectionParent.addComponent(newContainer, minIndex);
        } else {
            selectionParent.addComponent(newContainer);
        }
        if (newContainer instanceof RadTabbedPane) {
            // the first tab is created by RadTabbedPane itself
            assert newContainer.getComponentCount() == 1;
            newContainer = (RadContainer) newContainer.getComponent(0);
        } else if (newContainer instanceof RadSplitPane) {
            if (selection.size() > 2) {
                RadContainer panel = InsertComponentProcessor.createPanelComponent(editor);
                panel.setCustomLayoutConstraints(LwSplitPane.POSITION_LEFT);
                newContainer.addComponent(panel);
                newContainer = panel;
            } else {
                if (selection.size() > 0) {
                    selection.get(0).setCustomLayoutConstraints(LwSplitPane.POSITION_LEFT);
                }
                if (selection.size() > 1) {
                    selection.get(1).setCustomLayoutConstraints(LwSplitPane.POSITION_RIGHT);
                }
            }
        }
        // otherwise, copy column properties and row/col spans
        if (newContainer.getComponentClass().equals(JPanel.class) && selection.size() > 1) {
            if (selectionParent.getLayoutManager().isGrid()) {
                newContainer.getGridLayoutManager().copyGridSection(selectionParent, newContainer, rc);
            } else {
                // TODO[yole]: correctly handle surround from indexed
                newContainer.setLayout(new GridLayoutManager(rc.height, rc.width));
            }
        }
        for (RadComponent c : selection) {
            if (selectionParent.getLayoutManager().isGrid()) {
                if (selection.size() > 1) {
                    c.getConstraints().setRow(c.getConstraints().getRow() - rc.y);
                    c.getConstraints().setColumn(c.getConstraints().getColumn() - rc.x);
                } else {
                    c.getConstraints().setRow(0);
                    c.getConstraints().setColumn(0);
                    c.getConstraints().setRowSpan(1);
                    c.getConstraints().setColSpan(1);
                }
            }
            newContainer.addComponent(c);
        }
        editor.refreshAndSave(true);
    }, null, null);
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) Palette(com.intellij.uiDesigner.palette.Palette) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) XYLayoutManager(com.intellij.uiDesigner.shared.XYLayoutManager)

Example 4 with ComponentItem

use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.

the class ComponentTree method getComponentIcon.

public static Icon getComponentIcon(final RadComponent component) {
    if (!(component instanceof RadErrorComponent)) {
        final Palette palette = Palette.getInstance(component.getProject());
        final ComponentItem item = palette.getItem(component.getComponentClassName());
        final Icon icon;
        if (item != null) {
            icon = item.getSmallIcon();
        } else {
            icon = UIDesignerIcons.Unknown_small;
        }
        return icon;
    } else {
        return AllIcons.General.Error;
    }
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) Palette(com.intellij.uiDesigner.palette.Palette)

Example 5 with ComponentItem

use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.

the class FirstComponentInsertLocation method processDrop.

@Override
public void processDrop(final GuiEditor editor, final RadComponent[] components, final GridConstraints[] constraintsToAdjust, final ComponentDragObject dragObject) {
    RadAbstractGridLayoutManager gridLayout = myContainer.getGridLayoutManager();
    if (myContainer.getGridRowCount() == 0 && myContainer.getGridColumnCount() == 0) {
        gridLayout.insertGridCells(myContainer, 0, false, true, true);
        gridLayout.insertGridCells(myContainer, 0, true, true, true);
    }
    super.processDrop(editor, components, constraintsToAdjust, dragObject);
    Palette palette = Palette.getInstance(editor.getProject());
    ComponentItem hSpacerItem = palette.getItem(HSpacer.class.getName());
    ComponentItem vSpacerItem = palette.getItem(VSpacer.class.getName());
    InsertComponentProcessor icp = new InsertComponentProcessor(editor);
    if (myXPart == 0) {
        insertSpacer(icp, hSpacerItem, GridInsertMode.ColumnAfter);
    }
    if (myXPart == 2) {
        insertSpacer(icp, hSpacerItem, GridInsertMode.ColumnBefore);
    }
    if (myYPart == 0) {
        insertSpacer(icp, vSpacerItem, GridInsertMode.RowAfter);
    }
    if (myYPart == 2) {
        insertSpacer(icp, vSpacerItem, GridInsertMode.RowBefore);
    }
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) VSpacer(com.intellij.uiDesigner.VSpacer) Palette(com.intellij.uiDesigner.palette.Palette) RadAbstractGridLayoutManager(com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager) HSpacer(com.intellij.uiDesigner.HSpacer)

Aggregations

ComponentItem (com.intellij.uiDesigner.palette.ComponentItem)16 Palette (com.intellij.uiDesigner.palette.Palette)5 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)4 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)4 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)3 ArrayList (java.util.ArrayList)3 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)2 ListPopup (com.intellij.openapi.ui.popup.ListPopup)2 UIDesignerBundle (com.intellij.uiDesigner.UIDesignerBundle)2 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)2 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)2 IComponent (com.intellij.uiDesigner.lw.IComponent)2 IProperty (com.intellij.uiDesigner.lw.IProperty)2 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)2 RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)2 XYLayoutManager (com.intellij.uiDesigner.shared.XYLayoutManager)2 Processor (com.intellij.util.Processor)2 List (java.util.List)2 CommandProcessor (com.intellij.openapi.command.CommandProcessor)1