Search in sources :

Example 61 with GridConstraints

use of com.intellij.uiDesigner.core.GridConstraints 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 62 with GridConstraints

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

the class IndentProperty method setValueImpl.

protected void setValueImpl(RadComponent component, Integer value) throws Exception {
    final int indent = value.intValue();
    final GridConstraints constraints = component.getConstraints();
    if (constraints.getIndent() != indent) {
        GridConstraints oldConstraints = (GridConstraints) constraints.clone();
        constraints.setIndent(indent);
        component.fireConstraintsChanged(oldConstraints);
    }
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints)

Example 63 with GridConstraints

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

the class UseParentLayoutProperty method setValueImpl.

protected void setValueImpl(RadComponent component, Boolean value) throws Exception {
    final boolean useParentLayout = value.booleanValue();
    final GridConstraints constraints = component.getConstraints();
    if (constraints.isUseParentLayout() != useParentLayout) {
        GridConstraints oldConstraints = (GridConstraints) constraints.clone();
        constraints.setUseParentLayout(useParentLayout);
        component.fireConstraintsChanged(oldConstraints);
    }
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints)

Example 64 with GridConstraints

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

the class RadAbstractGridLayoutManager method changeContainerLayout.

@Override
public void changeContainerLayout(RadContainer container) throws IncorrectOperationException {
    if (container.getLayoutManager().isGrid()) {
        RadAbstractGridLayoutManager grid = container.getGridLayoutManager();
        List<Boolean> canRowsGrow = collectCanCellsGrow(grid, container, true);
        List<Boolean> canColumnsGrow = collectCanCellsGrow(grid, container, false);
        List<RadComponent> contents = collectComponents(container);
        changeLayoutFromGrid(container, contents, canRowsGrow, canColumnsGrow);
        int oldGapMultiplier = grid.getGapCellCount() + 1;
        int gapMultiplier = getGapCellCount() + 1;
        for (RadComponent c : contents) {
            GridConstraints gc = c.getConstraints();
            gc.setRow(gc.getRow() * gapMultiplier / oldGapMultiplier);
            gc.setColumn(gc.getColumn() * gapMultiplier / oldGapMultiplier);
            container.addComponent(c);
        }
    } else if (container.getLayoutManager().isIndexed()) {
        List<RadComponent> components = collectComponents(container);
        changeLayoutFromIndexed(container, components);
        int gapMultiplier = getGapCellCount() + 1;
        for (int i = 0; i < components.size(); i++) {
            GridConstraints gc = components.get(i).getConstraints();
            gc.setRow(0);
            gc.setColumn(i * gapMultiplier);
            gc.setRowSpan(1);
            gc.setColSpan(1);
            container.addComponent(components.get(i));
        }
    } else if (container.getComponentCount() == 0) {
        container.setLayoutManager(this);
    } else {
        throw new IncorrectOperationException("Cannot change from " + container.getLayout() + " to grid layout");
    }
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) ArrayList(java.util.ArrayList) List(java.util.List) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 65 with GridConstraints

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

the class RadFormLayoutManager method adjustDeletedCellOrigins.

private void adjustDeletedCellOrigins(final RadContainer grid, final int cellIndex, final boolean isRow) {
    int gapCellDelta = isGapCell(grid, isRow, cellIndex + 1) ? 2 : 1;
    for (RadComponent component : grid.getComponents()) {
        // ensure that we don't have component origins in the deleted cells
        final GridConstraints gc = component.getConstraints();
        if (gc.getCell(isRow) == cellIndex) {
            final int span = gc.getSpan(isRow);
            if (span > gapCellDelta) {
                gc.setCell(isRow, cellIndex + gapCellDelta);
                gc.setSpan(isRow, span - gapCellDelta);
                updateConstraints(component);
            } else {
                throw new IllegalArgumentException("Attempt to delete grid row/column which contains origins of 1-span components");
            }
        }
    }
}
Also used : 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