Search in sources :

Example 6 with GridLayoutManager

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

the class RadGridLayoutManager method canCellGrow.

@Override
public boolean canCellGrow(RadContainer container, boolean isRow, int cellIndex) {
    final GridLayoutManager gridLayoutManager = ((GridLayoutManager) container.getLayout());
    int maxSizePolicy = 0;
    for (int i = 0; i < gridLayoutManager.getCellCount(isRow); i++) {
        maxSizePolicy = Math.max(maxSizePolicy, gridLayoutManager.getCellSizePolicy(isRow, i));
    }
    return gridLayoutManager.getCellSizePolicy(isRow, cellIndex) == maxSizePolicy;
}
Also used : GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager)

Example 7 with GridLayoutManager

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

the class RadGridLayoutManager method writeLayout.

public void writeLayout(final XmlWriter writer, final RadContainer radContainer) {
    GridLayoutManager layout = (GridLayoutManager) radContainer.getLayout();
    writer.addAttribute("row-count", layout.getRowCount());
    writer.addAttribute("column-count", layout.getColumnCount());
    writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_SAME_SIZE_HORIZONTALLY, layout.isSameSizeHorizontally());
    writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_SAME_SIZE_VERTICALLY, layout.isSameSizeVertically());
    RadXYLayoutManager.INSTANCE.writeLayout(writer, radContainer);
}
Also used : GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager)

Example 8 with GridLayoutManager

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

Example 9 with GridLayoutManager

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

the class RadSwingGridLayoutManager method createSnapshotLayout.

@Override
public void createSnapshotLayout(final SnapshotContext context, final JComponent parent, final RadContainer container, final LayoutManager layout) {
    GridLayout gridLayout = (GridLayout) layout;
    int ncomponents = parent.getComponentCount();
    int nrows = gridLayout.getRows();
    int ncols = gridLayout.getColumns();
    if (nrows > 0) {
        ncols = (ncomponents + nrows - 1) / nrows;
    } else {
        nrows = (ncomponents + ncols - 1) / ncols;
    }
    container.setLayout(new GridLayoutManager(nrows, ncols, new Insets(0, 0, 0, 0), gridLayout.getHgap(), gridLayout.getVgap(), true, true));
}
Also used : GridLayout(java.awt.GridLayout) Insets(java.awt.Insets) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager)

Example 10 with GridLayoutManager

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

the class SurroundAction method actionPerformed.

public void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
    // the action is also reused as quickfix for NoScrollPaneInspection, so this code should be kept here
    FormEditingUtil.remapToActionTargets(selection);
    if (!editor.ensureEditable()) {
        return;
    }
    final RadContainer selectionParent = FormEditingUtil.getSelectionParent(selection);
    assert selectionParent != null;
    final Palette palette = Palette.getInstance(editor.getProject());
    final ComponentItem cItem = palette.getItem(myComponentClass);
    assert cItem != null : myComponentClass;
    CommandProcessor.getInstance().executeCommand(editor.getProject(), () -> {
        RadContainer newContainer = (RadContainer) InsertComponentProcessor.createInsertedComponent(editor, cItem);
        if (newContainer == null) {
            return;
        }
        if (cItem == palette.getPanelItem()) {
            if (selectionParent.getLayoutManager().isGrid()) {
                try {
                    newContainer.setLayoutManager(LayoutManagerRegistry.createLayoutManager(selectionParent.getLayoutManager().getName()));
                } catch (Exception e1) {
                    LOG.error(e1);
                    return;
                }
            } else {
                newContainer.setLayoutManager(LayoutManagerRegistry.createDefaultGridLayoutManager(editor.getProject()));
            }
        }
        Rectangle rc = new Rectangle(0, 0, 1, 1);
        int minIndex = Integer.MAX_VALUE;
        if (selectionParent.getLayoutManager().isGrid()) {
            rc = FormEditingUtil.getSelectionBounds(selection);
        } else if (selectionParent.getLayoutManager().isIndexed()) {
            for (RadComponent c : selection) {
                minIndex = Math.min(minIndex, selectionParent.indexOfComponent(c));
            }
        }
        for (RadComponent c : selection) {
            selectionParent.removeComponent(c);
        }
        if (selectionParent.getLayoutManager().isGrid()) {
            final GridConstraints newConstraints = newContainer.getConstraints();
            newConstraints.setRow(rc.y);
            newConstraints.setColumn(rc.x);
            newConstraints.setRowSpan(rc.height);
            newConstraints.setColSpan(rc.width);
        } else if (selectionParent.getLayout() instanceof XYLayoutManager && selection.size() == 1) {
            newContainer.setBounds(selection.get(0).getBounds());
        }
        if (selection.size() == 1) {
            newContainer.setCustomLayoutConstraints(selection.get(0).getCustomLayoutConstraints());
        }
        if (minIndex != Integer.MAX_VALUE) {
            selectionParent.addComponent(newContainer, minIndex);
        } else {
            selectionParent.addComponent(newContainer);
        }
        if (newContainer instanceof RadTabbedPane) {
            // the first tab is created by RadTabbedPane itself
            assert newContainer.getComponentCount() == 1;
            newContainer = (RadContainer) newContainer.getComponent(0);
        } else if (newContainer instanceof RadSplitPane) {
            if (selection.size() > 2) {
                RadContainer panel = InsertComponentProcessor.createPanelComponent(editor);
                panel.setCustomLayoutConstraints(LwSplitPane.POSITION_LEFT);
                newContainer.addComponent(panel);
                newContainer = panel;
            } else {
                if (selection.size() > 0) {
                    selection.get(0).setCustomLayoutConstraints(LwSplitPane.POSITION_LEFT);
                }
                if (selection.size() > 1) {
                    selection.get(1).setCustomLayoutConstraints(LwSplitPane.POSITION_RIGHT);
                }
            }
        }
        // otherwise, copy column properties and row/col spans
        if (newContainer.getComponentClass().equals(JPanel.class) && selection.size() > 1) {
            if (selectionParent.getLayoutManager().isGrid()) {
                newContainer.getGridLayoutManager().copyGridSection(selectionParent, newContainer, rc);
            } else {
                // TODO[yole]: correctly handle surround from indexed
                newContainer.setLayout(new GridLayoutManager(rc.height, rc.width));
            }
        }
        for (RadComponent c : selection) {
            if (selectionParent.getLayoutManager().isGrid()) {
                if (selection.size() > 1) {
                    c.getConstraints().setRow(c.getConstraints().getRow() - rc.y);
                    c.getConstraints().setColumn(c.getConstraints().getColumn() - rc.x);
                } else {
                    c.getConstraints().setRow(0);
                    c.getConstraints().setColumn(0);
                    c.getConstraints().setRowSpan(1);
                    c.getConstraints().setColSpan(1);
                }
            }
            newContainer.addComponent(c);
        }
        editor.refreshAndSave(true);
    }, null, null);
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) Palette(com.intellij.uiDesigner.palette.Palette) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) XYLayoutManager(com.intellij.uiDesigner.shared.XYLayoutManager)

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