Search in sources :

Example 26 with GridConstraints

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

the class RadGridLayoutManager method updateConstraints.

@Override
protected void updateConstraints(RadComponent component) {
    GridLayoutManager layout = (GridLayoutManager) component.getParent().getLayout();
    final GridConstraints radConstraints = component.getConstraints();
    final GridConstraints delegeeConstraints = layout.getConstraintsForComponent(component.getDelegee());
    if (radConstraints != delegeeConstraints) {
        delegeeConstraints.restore(radConstraints);
    }
    super.updateConstraints(component);
}
Also used : GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints)

Example 27 with GridConstraints

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

the class EmmetCompositeConfigurable method createComponent.

@Nullable
@Override
public JComponent createComponent() {
    final JPanel rootPanel = new JPanel(new GridLayoutManager(myInnerConfigurables.length + 1, 1, new Insets(0, 0, 0, 0), -1, -1, false, false));
    rootPanel.add(myTemplateExpandShortcutPanel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_NORTH, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
    for (int i = 0; i < myInnerConfigurables.length; i++) {
        UnnamedConfigurable configurable = myInnerConfigurables[i];
        final JComponent component = configurable.createComponent();
        assert component != null;
        int vSizePolicy = GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK;
        if (i + 1 == myInnerConfigurables.length) {
            vSizePolicy |= GridConstraints.SIZEPOLICY_WANT_GROW;
        }
        rootPanel.add(component, new GridConstraints(i + 1, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, vSizePolicy, null, null, null));
    }
    rootPanel.revalidate();
    return rootPanel;
}
Also used : GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) UnnamedConfigurable(com.intellij.openapi.options.UnnamedConfigurable) Nullable(org.jetbrains.annotations.Nullable)

Example 28 with GridConstraints

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

the class FormEditingUtil method deleteComponents.

public static void deleteComponents(final Collection<? extends RadComponent> selection, boolean deleteEmptyCells) {
    if (selection.size() == 0) {
        return;
    }
    final RadRootContainer rootContainer = (RadRootContainer) getRoot(selection.iterator().next());
    final Set<String> deletedComponentIds = new HashSet<>();
    for (final RadComponent component : selection) {
        boolean wasSelected = component.isSelected();
        final RadContainer parent = component.getParent();
        boolean wasPackedHorz = false;
        boolean wasPackedVert = false;
        if (parent.getParent() != null && parent.getParent().isXY()) {
            final Dimension minSize = parent.getMinimumSize();
            wasPackedHorz = parent.getWidth() == minSize.width;
            wasPackedVert = parent.getHeight() == minSize.height;
        }
        iterate(component, new ComponentVisitor() {

            public boolean visit(final IComponent c) {
                RadComponent rc = (RadComponent) c;
                BindingProperty.checkRemoveUnusedField(rootContainer, rc.getBinding(), null);
                deletedComponentIds.add(rc.getId());
                return true;
            }
        });
        GridConstraints delConstraints = parent.getLayoutManager().isGrid() ? component.getConstraints() : null;
        int index = parent.indexOfComponent(component);
        parent.removeComponent(component);
        if (wasSelected) {
            if (parent.getComponentCount() > index) {
                parent.getComponent(index).setSelected(true);
            } else if (index > 0 && parent.getComponentCount() == index) {
                parent.getComponent(index - 1).setSelected(true);
            } else {
                parent.setSelected(true);
            }
        }
        if (delConstraints != null && deleteEmptyCells) {
            deleteEmptyGridCells(parent, delConstraints);
        }
        if (wasPackedHorz || wasPackedVert) {
            final Dimension minSize = parent.getMinimumSize();
            Dimension newSize = new Dimension(parent.getWidth(), parent.getHeight());
            if (wasPackedHorz) {
                newSize.width = minSize.width;
            }
            if (wasPackedVert) {
                newSize.height = minSize.height;
            }
            parent.setSize(newSize);
        }
    }
    iterate(rootContainer, new ComponentVisitor() {

        public boolean visit(final IComponent component) {
            RadComponent rc = (RadComponent) component;
            for (IProperty p : component.getModifiedProperties()) {
                if (p instanceof IntroComponentProperty) {
                    IntroComponentProperty icp = (IntroComponentProperty) p;
                    final String value = icp.getValue(rc);
                    if (deletedComponentIds.contains(value)) {
                        try {
                            icp.resetValue(rc);
                        } catch (Exception e) {
                        // ignore
                        }
                    }
                }
            }
            return true;
        }
    });
}
Also used : RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RelativePoint(com.intellij.ui.awt.RelativePoint) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) IncorrectOperationException(com.intellij.util.IncorrectOperationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IntroComponentProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer) HashSet(com.intellij.util.containers.HashSet)

Example 29 with GridConstraints

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

the class GridChangeUtil method canDeleteCell.

/**
   * @param cellIndex column or row index, depending on isRow parameter; must be in the range 0..grid.get{Row|Column}Count()-1
   * @param isRow if true, row is deleted, otherwise column
   * @return whether the specified column can be deleted
   */
public static CellStatus canDeleteCell(@NotNull final RadContainer grid, final int cellIndex, final boolean isRow) {
    check(grid, isRow, cellIndex);
    // Do not allow to delete the single row/column
    if (isRow && grid.getGridRowCount() <= grid.getGridLayoutManager().getMinCellCount()) {
        return CellStatus.Required;
    } else if (!isRow && grid.getGridColumnCount() <= grid.getGridLayoutManager().getMinCellCount()) {
        return CellStatus.Required;
    }
    boolean haveComponents = false;
    boolean haveOrigins = false;
    boolean haveSingleSpan = false;
    for (int i = 0; i < grid.getComponentCount(); i++) {
        final GridConstraints constraints = grid.getComponent(i).getConstraints();
        final int cell = constraints.getCell(isRow);
        final int span = constraints.getSpan(isRow);
        if (cellIndex >= cell && cellIndex < cell + span) {
            haveComponents = true;
            if (cellIndex == cell) {
                haveOrigins = true;
                if (span == 1) {
                    haveSingleSpan = true;
                }
            }
        }
    }
    if (haveSingleSpan)
        return CellStatus.Required;
    if (haveOrigins)
        return CellStatus.CanShift;
    if (haveComponents)
        return CellStatus.Redundant;
    return CellStatus.Empty;
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints)

Example 30 with GridConstraints

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

the class GridChangeUtil method deleteCell.

/**
   * @param cellIndex column or row index, depending on isRow parameter; must be in the range 0..grid.get{Row|Column}Count()-1
   * @param isRow if true, row is deleted, otherwise column
   */
public static void deleteCell(final RadContainer grid, final int cellIndex, final boolean isRow) {
    check(grid, isRow, cellIndex);
    if (canDeleteCell(grid, cellIndex, isRow) == CellStatus.Required) {
        throw new IllegalArgumentException("cell cannot be deleted");
    }
    final RadAbstractGridLayoutManager oldLayout = grid.getGridLayoutManager();
    final LayoutManager newLayout = oldLayout.copyLayout(grid.getLayout(), isRow ? -1 : 0, isRow ? 0 : -1);
    GridConstraints[] oldConstraints = copyConstraints(grid);
    for (int i = grid.getComponentCount() - 1; i >= 0; i--) {
        final GridConstraints constraints = grid.getComponent(i).getConstraints();
        if (constraints.getCell(isRow) > cellIndex) {
            // component starts after the cell being deleted - move it
            addToCell(constraints, isRow, -1);
        } else if (isCellInsideComponent(constraints, isRow, cellIndex)) {
            // component belongs to the cell being deleted - decrement component's span
            addToSpan(constraints, isRow, -1);
        }
    }
    grid.setLayout(newLayout);
    fireAllConstraintsChanged(grid, oldConstraints);
}
Also used : RadAbstractGridLayoutManager(com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager) RadAbstractGridLayoutManager(com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager) 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