Search in sources :

Example 51 with GridConstraints

use of com.intellij.uiDesigner.core.GridConstraints in project intellij-community by JetBrains.

the class AddComponentAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null)
        return;
    GroupItem groupItem = e.getData(GroupItem.DATA_KEY);
    PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
    PsiElement elementToAdd = (psiFile != null) ? findElementToAdd(psiFile) : null;
    String className = "";
    if (elementToAdd instanceof PsiClass) {
        className = ((PsiClass) elementToAdd).getQualifiedName();
        assert className != null;
    } else if (elementToAdd instanceof PsiFile) {
        try {
            className = Utils.getBoundClassName(elementToAdd.getText());
        } catch (Exception e1) {
            className = "";
        }
    }
    // Show dialog
    final ComponentItem itemToBeAdded = new ComponentItem(project, className, null, null, new GridConstraints(), new HashMap<>(), true, /*all user defined components are removable*/
    false, false);
    Window parentWindow = WindowManager.getInstance().suggestParentWindow(project);
    final ComponentItemDialog dialog = new ComponentItemDialog(project, parentWindow, itemToBeAdded, false);
    dialog.setTitle(UIDesignerBundle.message("title.add.component"));
    dialog.showGroupChooser(groupItem);
    if (!dialog.showAndGet()) {
        return;
    }
    groupItem = dialog.getSelectedGroup();
    // If the itemToBeAdded is already in palette do nothing
    if (groupItem.containsItemClass(itemToBeAdded.getClassName())) {
        return;
    }
    assignDefaultIcon(project, itemToBeAdded);
    // add to the group
    final Palette palette = Palette.getInstance(project);
    palette.addItem(groupItem, itemToBeAdded);
    palette.fireGroupsChanged();
}
Also used : PsiClass(com.intellij.psi.PsiClass) Project(com.intellij.openapi.project.Project) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 52 with GridConstraints

use of com.intellij.uiDesigner.core.GridConstraints in project intellij-community by JetBrains.

the class ComponentItem method createAnyComponentItem.

public static ComponentItem createAnyComponentItem(final Project project) {
    ComponentItem result = new ComponentItem(project, "", null, null, new GridConstraints(), new HashMap<>(), false, false, false);
    result.myAnyComponent = true;
    return result;
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints)

Example 53 with GridConstraints

use of com.intellij.uiDesigner.core.GridConstraints in project intellij-community by JetBrains.

the class NoLabelForInspection method checkComponentProperties.

@Override
protected void checkComponentProperties(final Module module, final IComponent component, FormErrorCollector collector) {
    ComponentItem item = Palette.getInstance(module.getProject()).getItem(component.getComponentClassName());
    if (item != null && item.isCanAttachLabel()) {
        IComponent root = component;
        while (root.getParentContainer() != null) {
            root = root.getParentContainer();
        }
        final Ref<Boolean> found = new Ref<>(Boolean.FALSE);
        final Ref<RadComponent> candidateLabel = new Ref<>();
        final List<RadComponent> allLabels = new ArrayList<>();
        FormEditingUtil.iterate(root, new FormEditingUtil.ComponentVisitor() {

            @Override
            public boolean visit(final IComponent c2) {
                if (FormInspectionUtil.isComponentClass(module, c2, JLabel.class)) {
                    IProperty prop = FormInspectionUtil.findProperty(c2, SwingProperties.LABEL_FOR);
                    if (prop != null && component.getId().equals(prop.getPropertyValue(c2))) {
                        found.set(Boolean.TRUE);
                        return false;
                    } else if (component instanceof RadComponent && (prop == null || StringUtil.isEmpty((String) prop.getPropertyValue(c2)))) {
                        RadComponent radComponent = (RadComponent) component;
                        final RadComponent radComponent2 = (RadComponent) c2;
                        allLabels.add(radComponent2);
                        if (radComponent.getParent() == radComponent2.getParent() && radComponent.getParent().getLayoutManager().isGrid()) {
                            GridConstraints gc1 = radComponent.getConstraints();
                            GridConstraints gc2 = radComponent2.getConstraints();
                            int nextColumn = FormEditingUtil.nextCol(radComponent.getParent(), gc2.getColumn());
                            int nextRow = FormEditingUtil.nextRow(radComponent.getParent(), gc2.getRow());
                            if (gc1.getRow() == gc2.getRow() && nextColumn == gc1.getColumn() || gc1.getColumn() == gc2.getColumn() && nextRow == gc1.getRow()) {
                                candidateLabel.set(radComponent2);
                            }
                        }
                    }
                }
                return true;
            }
        });
        if (!found.get().booleanValue()) {
            if (!candidateLabel.isNull()) {
                allLabels.clear();
                allLabels.add(candidateLabel.get());
            }
            EditorQuickFixProvider[] quickFixProviders = new EditorQuickFixProvider[allLabels.size()];
            for (int i = 0; i < quickFixProviders.length; i++) {
                final RadComponent label = allLabels.get(i);
                quickFixProviders[i] = new EditorQuickFixProvider() {

                    @Override
                    public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                        return new MyQuickFix(editor, component, label);
                    }
                };
            }
            collector.addError(getID(), component, null, UIDesignerBundle.message("inspection.no.label.for.error"), quickFixProviders);
        }
    }
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) QuickFix(com.intellij.uiDesigner.quickFixes.QuickFix) IComponent(com.intellij.uiDesigner.lw.IComponent) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) ArrayList(java.util.ArrayList) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor) Ref(com.intellij.openapi.util.Ref) IProperty(com.intellij.uiDesigner.lw.IProperty) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil)

Example 54 with GridConstraints

use of com.intellij.uiDesigner.core.GridConstraints in project intellij-community by JetBrains.

the class GroupSelectionProcessor method selectComponentsInRange.

private static void selectComponentsInRange(final RadComponent component, final RadComponent anchor) {
    final GridConstraints c1 = component.getConstraints();
    final GridConstraints c2 = anchor.getConstraints();
    int startRow = Math.min(c1.getRow(), c2.getRow());
    int startCol = Math.min(c1.getColumn(), c2.getColumn());
    int endRow = Math.max(c1.getRow() + c1.getRowSpan(), c2.getRow() + c2.getRowSpan());
    int endCol = Math.max(c1.getColumn() + c1.getColSpan(), c2.getColumn() + c2.getColSpan());
    for (int row = startRow; row < endRow; row++) {
        for (int col = startCol; col < endCol; col++) {
            RadComponent c = anchor.getParent().getComponentAtGrid(row, col);
            if (c != null) {
                c.setSelected(true);
            }
        }
    }
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent)

Example 55 with GridConstraints

use of com.intellij.uiDesigner.core.GridConstraints in project intellij-community by JetBrains.

the class FormEditingUtil method getDefaultConstraints.

public static GridConstraints getDefaultConstraints(final RadComponent component) {
    final Palette palette = Palette.getInstance(component.getProject());
    final ComponentItem item = palette.getItem(component.getComponentClassName());
    if (item != null) {
        return item.getDefaultConstraints();
    }
    return new GridConstraints();
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) Palette(com.intellij.uiDesigner.palette.Palette) GridConstraints(com.intellij.uiDesigner.core.GridConstraints)

Aggregations

GridConstraints (com.intellij.uiDesigner.core.GridConstraints)73 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)17 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)14 Spacer (com.intellij.uiDesigner.core.Spacer)6 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)5 ComponentItem (com.intellij.uiDesigner.palette.ComponentItem)3 CellConstraints (com.jgoodies.forms.layout.CellConstraints)3 ArrayList (java.util.ArrayList)3 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 JBLabel (com.intellij.ui.components.JBLabel)2 JBTextField (com.intellij.ui.components.JBTextField)2 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)2 IComponent (com.intellij.uiDesigner.lw.IComponent)2 Palette (com.intellij.uiDesigner.palette.Palette)2 QuickFix (com.intellij.uiDesigner.quickFixes.QuickFix)2 RadAbstractGridLayoutManager (com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager)2 RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)2 XYLayoutManager (com.intellij.uiDesigner.shared.XYLayoutManager)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 Element (org.jdom.Element)2