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());
}
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;
}
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);
}
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);
}
}
}
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);
}
}
Aggregations