use of com.intellij.uiDesigner.core.GridLayoutManager 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.GridLayoutManager in project intellij-community by JetBrains.
the class GridBuildUtil method convertToGridImpl.
private static void convertToGridImpl(final GuiEditor editor, final int gridType) {
final boolean createNewContainer;
final RadContainer parent;
final RadComponent[] componentsToConvert;
{
final ArrayList<RadComponent> selection = FormEditingUtil.getSelectedComponents(editor);
if (selection.size() == 0) {
// root container selected
final RadRootContainer rootContainer = editor.getRootContainer();
if (rootContainer.getComponentCount() < 2) {
// nothing to convert
return;
}
componentsToConvert = new RadComponent[rootContainer.getComponentCount()];
for (int i = 0; i < componentsToConvert.length; i++) {
componentsToConvert[i] = rootContainer.getComponent(i);
}
parent = rootContainer;
createNewContainer = true;
} else if (selection.size() == 1 && selection.get(0) instanceof RadContainer) {
parent = (RadContainer) selection.get(0);
componentsToConvert = new RadComponent[parent.getComponentCount()];
for (int i = 0; i < componentsToConvert.length; i++) {
componentsToConvert[i] = parent.getComponent(i);
}
createNewContainer = false;
} else {
componentsToConvert = selection.toArray(new RadComponent[selection.size()]);
parent = selection.get(0).getParent();
createNewContainer = true;
}
}
if (!parent.isXY()) {
// only components in XY can be layed out in grid
return;
}
for (int i = 1; i < componentsToConvert.length; i++) {
final RadComponent component = componentsToConvert[i];
if (component.getParent() != parent) {
return;
}
}
final GridLayoutManager gridLayoutManager;
if (componentsToConvert.length == 0) {
// we convert empty XY panel to grid
gridLayoutManager = new GridLayoutManager(1, 1);
} else {
if (gridType == VERTICAL_GRID) {
gridLayoutManager = createOneDimensionGrid(componentsToConvert, true);
} else if (gridType == HORIZONTAL_GRID) {
gridLayoutManager = createOneDimensionGrid(componentsToConvert, false);
} else if (gridType == GRID) {
gridLayoutManager = createTwoDimensionGrid(componentsToConvert);
} else {
throw new IllegalArgumentException("invalid grid type: " + gridType);
}
}
for (final RadComponent component : componentsToConvert) {
if (component instanceof RadContainer) {
final LayoutManager layout = ((RadContainer) component).getLayout();
if (layout instanceof XYLayoutManager) {
((XYLayoutManager) layout).setPreferredSize(component.getSize());
}
}
}
if (createNewContainer) {
// we should create a new panel
final Module module = editor.getModule();
final ComponentItem panelItem = Palette.getInstance(editor.getProject()).getPanelItem();
final RadContainer newContainer = new RadContainer(editor, FormEditingUtil.generateId(editor.getRootContainer()));
newContainer.setLayout(gridLayoutManager);
newContainer.init(editor, panelItem);
for (RadComponent componentToConvert : componentsToConvert) {
newContainer.addComponent(componentToConvert);
}
final Point topLeftPoint = getTopLeftPoint(componentsToConvert);
newContainer.setLocation(topLeftPoint);
final Point bottomRightPoint = getBottomRightPoint(componentsToConvert);
final Dimension size = new Dimension(bottomRightPoint.x - topLeftPoint.x, bottomRightPoint.y - topLeftPoint.y);
Util.adjustSize(newContainer.getDelegee(), newContainer.getConstraints(), size);
newContainer.getDelegee().setSize(size);
parent.addComponent(newContainer);
FormEditingUtil.clearSelection(editor.getRootContainer());
newContainer.setSelected(true);
// restore binding of main component
{
final String mainComponentBinding = editor.getRootContainer().getMainComponentBinding();
if (mainComponentBinding != null && parent instanceof RadRootContainer) {
newContainer.setBinding(mainComponentBinding);
editor.getRootContainer().setMainComponentBinding(null);
}
}
} else {
// convert entire 'parent' to grid
parent.setLayout(gridLayoutManager);
FormEditingUtil.clearSelection(editor.getRootContainer());
parent.setSelected(true);
}
editor.refreshAndSave(true);
}
use of com.intellij.uiDesigner.core.GridLayoutManager in project intellij-community by JetBrains.
the class AbstractGridLayoutProperty method getValue.
public Boolean getValue(final RadContainer component) {
final LayoutManager layoutManager = component.getLayout();
if (!(layoutManager instanceof GridLayoutManager))
return null;
final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
return getGridLayoutPropertyValue(gridLayoutManager);
}
use of com.intellij.uiDesigner.core.GridLayoutManager in project intellij-community by JetBrains.
the class GridLayoutColumnProperties method showProperties.
public void showProperties(RadContainer container, boolean isRow, int[] selectedIndices) {
myContainer = container;
myRow = isRow;
if (selectedIndices.length != 1) {
myTitleLabel.setText(selectedIndices.length + (isRow ? " rows selected" : " columns selected"));
myWantGrowCheckBox.setEnabled(false);
} else {
mySelectedIndex = selectedIndices[0];
myTitleLabel.setText((isRow ? "Row " : "Column ") + selectedIndices[0]);
myWantGrowCheckBox.setEnabled(true);
GridLayoutManager layout = (GridLayoutManager) container.getLayout();
int sizePolicy = layout.getCellSizePolicy(isRow, selectedIndices[0]);
myWantGrowCheckBox.setSelected((sizePolicy & GridConstraints.SIZEPOLICY_WANT_GROW) != 0);
}
}
use of com.intellij.uiDesigner.core.GridLayoutManager in project intellij-community by JetBrains.
the class RadGridLayoutManager method changeLayoutFromGrid.
@Override
protected void changeLayoutFromGrid(final RadContainer container, final List<RadComponent> contents, final List<Boolean> canRowsGrow, final List<Boolean> canColumnsGrow) {
int rowCount = Math.max(1, canRowsGrow.size());
int columnCount = Math.max(1, canColumnsGrow.size());
container.setLayoutManager(this, new GridLayoutManager(rowCount, columnCount));
}
Aggregations