Search in sources :

Example 36 with GridConstraints

use of com.intellij.uiDesigner.core.GridConstraints in project android by JetBrains.

the class TemplateParameterStep2 method addComponent.

private static int addComponent(JComponent parent, JComponent component, int row, int column, boolean isLast) {
    GridConstraints gridConstraints = new GridConstraints();
    gridConstraints.setRow(row);
    gridConstraints.setColumn(column);
    boolean isGreedyComponent = component instanceof JTextField || component instanceof Spacer || component instanceof LabelWithEditLink || component instanceof TextAccessor || component instanceof EditorComboBox;
    int columnSpan = (isLast && isGreedyComponent) ? COLUMN_COUNT - column : 1;
    gridConstraints.setColSpan(columnSpan);
    gridConstraints.setAnchor(GridConstraints.ALIGN_LEFT);
    gridConstraints.setHSizePolicy(isGreedyComponent ? GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW : GridConstraints.SIZEPOLICY_CAN_SHRINK);
    gridConstraints.setVSizePolicy(component instanceof Spacer ? GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW : GridConstraints.SIZEPOLICY_FIXED);
    gridConstraints.setFill(GridConstraints.FILL_HORIZONTAL);
    parent.add(component, gridConstraints);
    if (isLast && !isGreedyComponent && column < COLUMN_COUNT - 1) {
        addComponent(parent, new Spacer(), row, column + 1, true);
    }
    return columnSpan;
}
Also used : LabelWithEditLink(com.android.tools.adtui.LabelWithEditLink) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) Spacer(com.intellij.uiDesigner.core.Spacer)

Example 37 with GridConstraints

use of com.intellij.uiDesigner.core.GridConstraints 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;
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HideableDecorator(com.intellij.ui.HideableDecorator) NotNull(org.jetbrains.annotations.NotNull) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) Spacer(com.intellij.uiDesigner.core.Spacer) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 38 with GridConstraints

use of com.intellij.uiDesigner.core.GridConstraints in project intellij-community by JetBrains.

the class GridBagConverter method getWeight.

private double getWeight(final GridConstraints constraints, final boolean horizontal) {
    int policy = horizontal ? constraints.getHSizePolicy() : constraints.getVSizePolicy();
    if ((policy & GridConstraints.SIZEPOLICY_WANT_GROW) != 0) {
        return 1.0;
    }
    boolean canGrow = ((policy & GridConstraints.SIZEPOLICY_CAN_GROW) != 0);
    for (Iterator iterator = myConstraints.iterator(); iterator.hasNext(); ) {
        GridConstraints otherConstraints = (GridConstraints) iterator.next();
        if (!constraintsIntersect(horizontal, constraints, otherConstraints)) {
            int otherPolicy = horizontal ? otherConstraints.getHSizePolicy() : otherConstraints.getVSizePolicy();
            if ((otherPolicy & GridConstraints.SIZEPOLICY_WANT_GROW) != 0) {
                return 0.0;
            }
            if (!canGrow && ((otherPolicy & GridConstraints.SIZEPOLICY_CAN_GROW) != 0)) {
                return 0.0;
            }
        }
    }
    return 1.0;
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) Iterator(java.util.Iterator)

Example 39 with GridConstraints

use of com.intellij.uiDesigner.core.GridConstraints in project intellij-community by JetBrains.

the class GridBagConverter method convert.

public Result[] convert() {
    ArrayList results = new ArrayList();
    for (int i = 0; i < myComponents.size(); i++) {
        results.add(convert((JComponent) myComponents.get(i), (GridConstraints) myConstraints.get(i)));
    }
    //addFillerPanels(results);
    final Result[] resultArray = (Result[]) results.toArray(new Result[results.size()]);
    if (myHGap > 0 || myVGap > 0) {
        applyGaps(resultArray);
    }
    if (mySameSizeHorz) {
        makeSameSizes(resultArray, true);
    }
    if (mySameSizeVert) {
        makeSameSizes(resultArray, false);
    }
    return resultArray;
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) ArrayList(java.util.ArrayList)

Example 40 with GridConstraints

use of com.intellij.uiDesigner.core.GridConstraints in project intellij-community by JetBrains.

the class GridLayoutSerializer method readChildConstraints.

void readChildConstraints(final Element constraintsElement, final LwComponent component) {
    // Read Grid constraints
    final Element gridElement = LwXmlReader.getChild(constraintsElement, "grid");
    if (gridElement != null) {
        final GridConstraints constraints = new GridConstraints();
        constraints.setRow(LwXmlReader.getRequiredInt(gridElement, "row"));
        constraints.setColumn(LwXmlReader.getRequiredInt(gridElement, "column"));
        constraints.setRowSpan(LwXmlReader.getRequiredInt(gridElement, "row-span"));
        constraints.setColSpan(LwXmlReader.getRequiredInt(gridElement, "col-span"));
        constraints.setVSizePolicy(LwXmlReader.getRequiredInt(gridElement, "vsize-policy"));
        constraints.setHSizePolicy(LwXmlReader.getRequiredInt(gridElement, "hsize-policy"));
        constraints.setAnchor(LwXmlReader.getRequiredInt(gridElement, "anchor"));
        constraints.setFill(LwXmlReader.getRequiredInt(gridElement, "fill"));
        constraints.setIndent(LwXmlReader.getOptionalInt(gridElement, UIFormXmlConstants.ATTRIBUTE_INDENT, 0));
        constraints.setUseParentLayout(LwXmlReader.getOptionalBoolean(gridElement, UIFormXmlConstants.ATTRIBUTE_USE_PARENT_LAYOUT, false));
        // minimum size
        final Element minSizeElement = LwXmlReader.getChild(gridElement, "minimum-size");
        if (minSizeElement != null) {
            constraints.myMinimumSize.width = LwXmlReader.getRequiredInt(minSizeElement, "width");
            constraints.myMinimumSize.height = LwXmlReader.getRequiredInt(minSizeElement, "height");
        }
        // preferred size
        final Element prefSizeElement = LwXmlReader.getChild(gridElement, "preferred-size");
        if (prefSizeElement != null) {
            constraints.myPreferredSize.width = LwXmlReader.getRequiredInt(prefSizeElement, "width");
            constraints.myPreferredSize.height = LwXmlReader.getRequiredInt(prefSizeElement, "height");
        }
        // maximum size
        final Element maxSizeElement = LwXmlReader.getChild(gridElement, "maximum-size");
        if (maxSizeElement != null) {
            constraints.myMaximumSize.width = LwXmlReader.getRequiredInt(maxSizeElement, "width");
            constraints.myMaximumSize.height = LwXmlReader.getRequiredInt(maxSizeElement, "height");
        }
        component.getConstraints().restore(constraints);
    }
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) Element(org.jdom.Element)

Aggregations

GridConstraints (com.intellij.uiDesigner.core.GridConstraints)73 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)17 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)14 Spacer (com.intellij.uiDesigner.core.Spacer)6 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)5 ComponentItem (com.intellij.uiDesigner.palette.ComponentItem)3 CellConstraints (com.jgoodies.forms.layout.CellConstraints)3 ArrayList (java.util.ArrayList)3 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 JBLabel (com.intellij.ui.components.JBLabel)2 JBTextField (com.intellij.ui.components.JBTextField)2 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)2 IComponent (com.intellij.uiDesigner.lw.IComponent)2 Palette (com.intellij.uiDesigner.palette.Palette)2 QuickFix (com.intellij.uiDesigner.quickFixes.QuickFix)2 RadAbstractGridLayoutManager (com.intellij.uiDesigner.radComponents.RadAbstractGridLayoutManager)2 RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)2 XYLayoutManager (com.intellij.uiDesigner.shared.XYLayoutManager)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 Element (org.jdom.Element)2