Search in sources :

Example 26 with GridLayoutManager

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;
}
Also used : GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) ContentFolder(com.intellij.openapi.roots.ContentFolder) GridConstraints(com.intellij.uiDesigner.core.GridConstraints)

Example 27 with GridLayoutManager

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

the class GridInsertLocationTest method testGrowComponent.

public void testGrowComponent() {
    myContainer.setLayout(new GridLayoutManager(2, 2));
    //  *|.       *** .
    //
    //  ***   ->  *****
    insertComponent(0, 0, 1, 1);
    RadComponent c = insertComponent(1, 0, 1, 2);
    GridInsertLocation location = new GridInsertLocation(myContainer, 0, 0, GridInsertMode.ColumnAfter);
    DraggedComponentList dcl = DraggedComponentList.withComponents(myDropComponent);
    assertTrue(location.canDrop(dcl));
    doDrop(location);
    assertEquals(3, myManager.getGridColumnCount(myContainer));
    assertEquals(3, c.getConstraints().getColSpan());
}
Also used : GridInsertLocation(com.intellij.uiDesigner.designSurface.GridInsertLocation) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) DraggedComponentList(com.intellij.uiDesigner.designSurface.DraggedComponentList)

Example 28 with GridLayoutManager

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

the class GridChangeUtilTest method test_margins_and_gaps.

public void test_margins_and_gaps() {
    final Insets margin = new Insets(11, 12, 13, 14);
    final int hGap = 15;
    final int vGap = 16;
    final RadContainer grid = createGrid(2, 3, margin, hGap, vGap);
    {
        final LayoutManager oldLayout = grid.getLayout();
        GridChangeUtil.insertRowOrColumn(grid, 1, false, false);
        final GridLayoutManager newLayout = (GridLayoutManager) grid.getLayout();
        assertGridDimensions(grid, 2, 4);
        assertTrue(oldLayout != newLayout);
        assertTrue(margin != newLayout.getMargin());
        assertEquals(margin, newLayout.getMargin());
        assertEquals(hGap, newLayout.getHGap());
        assertEquals(vGap, newLayout.getVGap());
    }
    {
        final LayoutManager oldLayout = grid.getLayout();
        GridChangeUtil.splitRow(grid, 1);
        final GridLayoutManager newLayout = (GridLayoutManager) grid.getLayout();
        assertGridDimensions(grid, 3, 4);
        assertTrue(oldLayout != newLayout);
        assertTrue(margin != newLayout.getMargin());
        assertEquals(margin, newLayout.getMargin());
        assertEquals(hGap, newLayout.getHGap());
        assertEquals(vGap, newLayout.getVGap());
    }
}
Also used : Insets(java.awt.Insets) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) LayoutManager(java.awt.LayoutManager) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 29 with GridLayoutManager

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

the class GridLayoutSourceGenerator method generateContainerLayout.

@Override
public void generateContainerLayout(final LwContainer container, final FormSourceCodeGenerator generator, final String variable) {
    if (container.isXY()) {
        if (container.getComponentCount() != 0) {
            throw new IllegalStateException("only empty xys are accepted");
        }
    // no layout needed
    } else {
        if (container.isGrid()) {
            final GridLayoutManager layout = (GridLayoutManager) container.getLayout();
            generator.startMethodCall(variable, "setLayout");
            generator.startConstructor(GridLayoutManager.class.getName());
            generator.push(layout.getRowCount());
            generator.push(layout.getColumnCount());
            generator.newInsets(layout.getMargin());
            generator.push(layout.getHGap());
            generator.push(layout.getVGap());
            if (layout.isSameSizeHorizontally() || layout.isSameSizeVertically()) {
                // values differ from the defaults - use appropriate constructor
                generator.push(layout.isSameSizeHorizontally());
                generator.push(layout.isSameSizeVertically());
            }
            // GridLayoutManager
            generator.endConstructor();
            generator.endMethod();
        } else if (container.isXY()) {
            throw new IllegalArgumentException("XY is not supported");
        } else {
            throw new IllegalArgumentException("unknown layout: " + container.getLayout());
        }
    }
}
Also used : GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager)

Example 30 with GridLayoutManager

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());
}
Also used : GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints)

Aggregations

GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)40 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)17 Spacer (com.intellij.uiDesigner.core.Spacer)5 Module (com.intellij.openapi.module.Module)2 JBTextField (com.intellij.ui.components.JBTextField)2 DraggedComponentList (com.intellij.uiDesigner.designSurface.DraggedComponentList)2 GridInsertLocation (com.intellij.uiDesigner.designSurface.GridInsertLocation)2 ComponentItem (com.intellij.uiDesigner.palette.ComponentItem)2 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)2 XYLayoutManager (com.intellij.uiDesigner.shared.XYLayoutManager)2 Insets (java.awt.Insets)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 AndroidTargetHash.getAddonHashString (com.android.sdklib.AndroidTargetHash.getAddonHashString)1 BuildFileKey (com.android.tools.idea.gradle.parser.BuildFileKey)1 TemplateManager (com.android.tools.idea.templates.TemplateManager)1 TemplateMetadata (com.android.tools.idea.templates.TemplateMetadata)1 ImageComponent (com.android.tools.idea.ui.ImageComponent)1 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)1 LineMarginBorder (com.intellij.designer.designSurface.feedbacks.LineMarginBorder)1