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