Search in sources :

Example 56 with GridConstraints

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

the class GridBuildUtil method createTwoDimensionGrid.

private static GridLayoutManager createTwoDimensionGrid(final RadComponent[] selection) {
    final int[] x = new int[selection.length];
    final int[] y = new int[selection.length];
    final int[] colSpans = new int[selection.length];
    final int[] rowSpans = new int[selection.length];
    for (int i = selection.length - 1; i >= 0; i--) {
        x[i] = selection[i].getX();
        y[i] = selection[i].getY();
        rowSpans[i] = selection[i].getHeight();
        colSpans[i] = selection[i].getWidth();
    }
    final Couple<Integer> pair = layoutInGrid(x, y, rowSpans, colSpans);
    for (int i = 0; i < selection.length; i++) {
        final RadComponent component = selection[i];
        final GridConstraints constraints = component.getConstraints();
        constraints.setRow(y[i]);
        constraints.setRowSpan(rowSpans[i]);
        constraints.setColumn(x[i]);
        constraints.setColSpan(colSpans[i]);
    }
    return new GridLayoutManager(pair.first.intValue(), pair.second.intValue());
}
Also used : GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints)

Example 57 with GridConstraints

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

the class GridBuildUtil method createOneDimensionGrid.

private static GridLayoutManager createOneDimensionGrid(final RadComponent[] selection, final boolean isVertical) {
    Arrays.sort(selection, (o1, o2) -> {
        final Rectangle bounds1 = o1.getBounds();
        final Rectangle bounds2 = o2.getBounds();
        if (isVertical) {
            return (bounds1.y + bounds1.height / 2) - (bounds2.y + bounds2.height / 2);
        } else {
            return (bounds1.x + bounds1.width / 2) - (bounds2.x + bounds2.width / 2);
        }
    });
    for (int i = 0; i < selection.length; i++) {
        final RadComponent component = selection[i];
        final GridConstraints constraints = component.getConstraints();
        if (isVertical) {
            constraints.setRow(i);
            constraints.setColumn(0);
        } else {
            constraints.setRow(0);
            constraints.setColumn(i);
        }
        constraints.setRowSpan(1);
        constraints.setColSpan(1);
    }
    final GridLayoutManager gridLayoutManager;
    if (isVertical) {
        gridLayoutManager = new GridLayoutManager(selection.length, 1);
    } else {
        gridLayoutManager = new GridLayoutManager(1, selection.length);
    }
    return gridLayoutManager;
}
Also used : GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints)

Example 58 with GridConstraints

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

the class GridChangeUtil method insertRowOrColumn.

/**
   * @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 inserted, otherwise column
   * @param isBefore if true, row/column will be inserted before row/column with given index, otherwise after
   */
public static void insertRowOrColumn(final RadContainer grid, final int cellIndex, final boolean isRow, final boolean isBefore) {
    check(grid, isRow, cellIndex);
    final RadAbstractGridLayoutManager oldLayout = grid.getGridLayoutManager();
    int beforeIndex = cellIndex;
    if (!isBefore) {
        // beforeIndex can actually be equal to get{Row|Column}Count an case we add row after the last row/column
        beforeIndex++;
    }
    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();
        adjustConstraintsOnInsert(constraints, isRow, beforeIndex, 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)

Example 59 with GridConstraints

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

the class GridChangeUtil method splitCell.

/**
   * @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 splitted, otherwise column
   */
public static void splitCell(final RadContainer grid, final int cellIndex, final boolean isRow) {
    check(grid, isRow, cellIndex);
    int insertedCells = grid.getGridLayoutManager().insertGridCells(grid, cellIndex, isRow, false, false);
    for (int i = grid.getComponentCount() - 1; i >= 0; i--) {
        final RadComponent component = grid.getComponent(i);
        final GridConstraints constraints = component.getConstraints();
        if (constraints.getCell(isRow) + constraints.getSpan(isRow) - 1 == cellIndex) {
            // component belongs to the cell being resized - increment component's span
            GridConstraints oldConstraints = (GridConstraints) constraints.clone();
            constraints.setSpan(isRow, constraints.getSpan(isRow) + insertedCells);
            component.fireConstraintsChanged(oldConstraints);
        }
    }
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent)

Example 60 with GridConstraints

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

the class GridChangeUtil method moveCell.

public static void moveCell(final RadContainer container, final boolean isRow, final int sourceCell, int targetCell) {
    if (targetCell == sourceCell || targetCell == sourceCell + 1)
        return;
    // if column moved to left - components inbetween move to right, and vice versa
    int delta = (sourceCell > targetCell) ? 1 : -1;
    int startCell = Math.min(sourceCell, targetCell);
    int endCell = Math.max(sourceCell, targetCell);
    if (sourceCell < targetCell)
        targetCell--;
    for (RadComponent c : container.getComponents()) {
        GridConstraints constraints = c.getConstraints();
        GridConstraints oldConstraints = (GridConstraints) constraints.clone();
        final int aCell = constraints.getCell(isRow);
        if (aCell == sourceCell) {
            constraints.setCell(isRow, targetCell);
        } else if (aCell >= startCell && aCell < endCell) {
            constraints.setCell(isRow, aCell + delta);
        }
        c.fireConstraintsChanged(oldConstraints);
    }
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent)

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