use of com.intellij.uiDesigner.core.GridLayoutManager in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoLibrariesConfigurableProvider method createConfigurable.
@Nullable
private Configurable createConfigurable(boolean dialogMode) {
return new CompositeConfigurable<UnnamedConfigurable>() {
@Nullable
@Override
public JComponent createComponent() {
List<UnnamedConfigurable> configurables = getConfigurables();
Collection<HideableDecorator> hideableDecorators = ContainerUtil.newHashSet();
GridLayoutManager layoutManager = new GridLayoutManager(configurables.size() + 1, 1, new Insets(0, 0, 0, 0), -1, -1);
JPanel rootPanel = new JPanel(layoutManager);
Spacer spacer = new Spacer();
rootPanel.add(spacer, new GridConstraints(configurables.size(), 0, 1, 1, GridConstraints.ANCHOR_SOUTH, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null));
for (int i = 0; i < configurables.size(); i++) {
UnnamedConfigurable configurable = configurables.get(i);
JComponent configurableComponent = configurable.createComponent();
assert configurableComponent != null;
JPanel hideablePanel = new JPanel(new BorderLayout());
rootPanel.add(hideablePanel, configurableConstrains(i));
if (configurable instanceof Configurable) {
String displayName = ((Configurable) configurable).getDisplayName();
ListenableHideableDecorator decorator = new ListenableHideableDecorator(hideablePanel, displayName, configurableComponent);
decorator.addListener(new MyHideableDecoratorListener(layoutManager, hideablePanel, spacer, hideableDecorators, configurableExpandedPropertyKey((Configurable) configurable)));
hideableDecorators.add(decorator);
decorator.setOn(isConfigurableExpanded(i, (Configurable) configurable));
}
}
if (dialogMode) {
rootPanel.setPreferredSize(new Dimension(400, 600));
}
rootPanel.revalidate();
return rootPanel;
}
@NotNull
@Override
protected List<UnnamedConfigurable> createConfigurables() {
List<UnnamedConfigurable> result = ContainerUtil.newArrayList();
String[] urlsFromEnv = ContainerUtil.map2Array(GoSdkUtil.getGoPathsRootsFromEnvironment(), String.class, VirtualFile::getUrl);
result.add(new GoLibrariesConfigurable("Global libraries", GoApplicationLibrariesService.getInstance(), urlsFromEnv));
if (!myProject.isDefault()) {
result.add(new GoLibrariesConfigurable("Project libraries", GoProjectLibrariesService.getInstance(myProject)));
result.add(new GoModuleAwareConfigurable(myProject, "Module libraries", null) {
@NotNull
@Override
protected UnnamedConfigurable createModuleConfigurable(@NotNull Module module) {
return new GoLibrariesConfigurable("Module libraries", GoModuleLibrariesService.getInstance(module));
}
});
}
return result;
}
@NotNull
@Nls
@Override
public String getDisplayName() {
return "Go Libraries";
}
@Nullable
@Override
public String getHelpTopic() {
return null;
}
@NotNull
private GridConstraints configurableConstrains(int i) {
return new GridConstraints(i, 0, 1, 1, GridConstraints.ANCHOR_NORTHEAST, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null);
}
private boolean isConfigurableExpanded(int index, @NotNull Configurable configurable) {
return PropertiesComponent.getInstance(myProject).getBoolean(configurableExpandedPropertyKey(configurable), index < 2);
}
private void storeConfigurableExpandedProperty(@NotNull String storeKey, @NotNull Boolean value) {
PropertiesComponent.getInstance(myProject).setValue(storeKey, value.toString());
}
private String configurableExpandedPropertyKey(@NotNull Configurable configurable) {
String keyName = "configurable " + configurable.getDisplayName() + " is expanded".toLowerCase(Locale.US);
return StringUtil.replaceChar(keyName, ' ', '.');
}
class MyHideableDecoratorListener extends ListenableHideableDecorator.MyListener {
private final GridLayoutManager myLayoutManager;
private final JPanel myHideablePanel;
@NotNull
private final String myStoreKey;
private final Spacer mySpacer;
private final Collection<HideableDecorator> myHideableDecorators;
public MyHideableDecoratorListener(@NotNull GridLayoutManager layoutManager, @NotNull JPanel hideablePanel, @NotNull Spacer spacer, @NotNull Collection<HideableDecorator> hideableDecorators, @NotNull String storeKey) {
myLayoutManager = layoutManager;
myHideablePanel = hideablePanel;
myStoreKey = storeKey;
mySpacer = spacer;
myHideableDecorators = hideableDecorators;
}
@Override
public void on() {
GridConstraints c = myLayoutManager.getConstraintsForComponent(myHideablePanel);
c.setVSizePolicy(c.getVSizePolicy() | GridConstraints.SIZEPOLICY_WANT_GROW);
GridConstraints spacerConstraints = myLayoutManager.getConstraintsForComponent(mySpacer);
spacerConstraints.setVSizePolicy(spacerConstraints.getVSizePolicy() & ~GridConstraints.SIZEPOLICY_WANT_GROW);
storeConfigurableExpandedProperty(myStoreKey, Boolean.TRUE);
}
@Override
public void beforeOff() {
GridConstraints c = myLayoutManager.getConstraintsForComponent(myHideablePanel);
c.setVSizePolicy(c.getVSizePolicy() & ~GridConstraints.SIZEPOLICY_WANT_GROW);
}
@Override
public void afterOff() {
if (isAllDecoratorsCollapsed()) {
GridConstraints c = myLayoutManager.getConstraintsForComponent(mySpacer);
c.setVSizePolicy(c.getVSizePolicy() | GridConstraints.SIZEPOLICY_WANT_GROW);
}
storeConfigurableExpandedProperty(myStoreKey, Boolean.FALSE);
}
private boolean isAllDecoratorsCollapsed() {
for (HideableDecorator hideableDecorator : myHideableDecorators) {
if (hideableDecorator.isExpanded()) {
return false;
}
}
return true;
}
}
};
}
use of com.intellij.uiDesigner.core.GridLayoutManager in project intellij-community by JetBrains.
the class ContentRootPanel method createFolderGroupComponent.
protected JComponent createFolderGroupComponent(String title, ContentFolder[] folders, Color foregroundColor, @Nullable ModuleSourceRootEditHandler<?> editor) {
final JPanel panel = new JPanel(new GridLayoutManager(folders.length, 3, JBUI.insets(1, 17, 0, 5), 0, 1));
panel.setOpaque(false);
for (int idx = 0; idx < folders.length; idx++) {
final ContentFolder folder = folders[idx];
final int verticalPolicy = idx == folders.length - 1 ? GridConstraints.SIZEPOLICY_CAN_GROW : GridConstraints.SIZEPOLICY_FIXED;
panel.add(createFolderComponent(folder, foregroundColor, editor), new GridConstraints(idx, 0, 1, 1, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, verticalPolicy, null, null, null));
int column = 1;
int colspan = 2;
if (editor != null) {
JComponent additionalComponent = createRootPropertiesEditor(editor, (SourceFolder) folder);
if (additionalComponent != null) {
panel.add(additionalComponent, new GridConstraints(idx, column++, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, verticalPolicy, null, null, null));
colspan = 1;
}
}
panel.add(createFolderDeleteComponent(folder, editor), new GridConstraints(idx, column, 1, colspan, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, verticalPolicy, null, null, null));
}
final JLabel titleLabel = new JLabel(title);
final Font labelFont = UIUtil.getLabelFont();
titleLabel.setFont(labelFont.deriveFont(Font.BOLD));
titleLabel.setOpaque(false);
titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
registerTextComponent(titleLabel, foregroundColor);
final JPanel groupPanel = new JPanel(new BorderLayout());
groupPanel.setOpaque(false);
groupPanel.add(titleLabel, BorderLayout.NORTH);
groupPanel.add(panel, BorderLayout.CENTER);
return groupPanel;
}
use of com.intellij.uiDesigner.core.GridLayoutManager 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.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);
}
Aggregations