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