Search in sources :

Example 1 with GridLayoutManager

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

the class InplaceEditingLayer method startEditing.

public void startEditing(@Nullable InplaceContext inplaceContext) {
    try {
        List<RadComponent> selection = myDesigner.getSurfaceArea().getSelection();
        if (selection.size() != 1) {
            return;
        }
        myRadComponent = selection.get(0);
        myProperties = myRadComponent.getInplaceProperties();
        if (myProperties.isEmpty()) {
            myRadComponent = null;
            myProperties = null;
            return;
        }
        myInplaceComponent = new JPanel(new GridLayoutManager(myProperties.size(), 2));
        myInplaceComponent.setBorder(new LineMarginBorder(5, 5, 5, 5));
        new AnAction() {

            @Override
            public void actionPerformed(AnActionEvent e) {
                finishEditing(false);
            }
        }.registerCustomShortcutSet(CommonShortcuts.ESCAPE, myInplaceComponent);
        myEditors = new ArrayList<>();
        JComponent componentToFocus = null;
        Font font = null;
        if (inplaceContext == null) {
            inplaceContext = new InplaceContext();
        }
        int row = 0;
        for (Property property : myProperties) {
            JLabel label = new JLabel(property.getName() + ":");
            if (font == null) {
                font = label.getFont().deriveFont(Font.BOLD);
            }
            label.setFont(font);
            myInplaceComponent.add(label, new GridConstraints(row, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, 0, 0, null, null, null));
            PropertyEditor editor = property.getEditor();
            myEditors.add(editor);
            JComponent component = editor.getComponent(myRadComponent, myDesigner, property.getValue(myRadComponent), inplaceContext);
            myInplaceComponent.add(component, new GridConstraints(row++, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, 0, null, null, null));
            if (componentToFocus == null) {
                componentToFocus = editor.getPreferredFocusedComponent();
            }
        }
        for (PropertyEditor editor : myEditors) {
            editor.addPropertyEditorListener(myEditorListener);
        }
        Rectangle bounds = myRadComponent.getBounds(this);
        Dimension size = myInplaceComponent.getPreferredSize();
        myPreferredWidth = Math.max(size.width, bounds.width);
        myInplaceComponent.setBounds(bounds.x, bounds.y, myPreferredWidth, size.height);
        add(myInplaceComponent);
        myDesigner.getSurfaceArea().addSelectionListener(mySelectionListener);
        if (componentToFocus == null) {
            componentToFocus = IdeFocusTraversalPolicy.getPreferredFocusedComponent(myInplaceComponent);
        }
        if (componentToFocus == null) {
            componentToFocus = myInplaceComponent;
        }
        if (componentToFocus.requestFocusInWindow()) {
            myFocusWatcher.install(myInplaceComponent);
        } else {
            grabFocus();
            final JComponent finalComponentToFocus = componentToFocus;
            ApplicationManager.getApplication().invokeLater(() -> {
                finalComponentToFocus.requestFocusInWindow();
                myFocusWatcher.install(myInplaceComponent);
            });
        }
        enableEvents(AWTEvent.MOUSE_EVENT_MASK);
        repaint();
    } catch (Throwable e) {
        LOG.error(e);
    }
}
Also used : RadComponent(com.intellij.designer.model.RadComponent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) LineMarginBorder(com.intellij.designer.designSurface.feedbacks.LineMarginBorder) PropertyEditor(com.intellij.designer.propertyTable.PropertyEditor) InplaceContext(com.intellij.designer.propertyTable.InplaceContext) Property(com.intellij.designer.model.Property)

Example 2 with GridLayoutManager

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

the class PyUniversalTestForm method addCustomOptions.

private void addCustomOptions(@NotNull final CustomOption... customOptions) {
    if (customOptions.length == 0) {
        return;
    }
    final Map<String, JBTextField> optionValueFields = new HashMap<>();
    for (final CustomOption option : customOptions) {
        final JBTextField textField = new JBTextField();
        optionValueFields.put(option.myName, textField);
    }
    myCustomOptionsPanel.setLayout(new GridLayoutManager(customOptions.length, 2));
    for (int i = 0; i < customOptions.length; i++) {
        final CustomOption option = customOptions[i];
        final JBTextField textField = optionValueFields.get(option.myName);
        final GridConstraints labelConstraints = new GridConstraints();
        labelConstraints.setFill(GridConstraints.FILL_VERTICAL);
        labelConstraints.setRow(i);
        labelConstraints.setColumn(0);
        labelConstraints.setHSizePolicy(GridConstraints.SIZEPOLICY_CAN_SHRINK);
        final JLabel label = new JLabel(StringUtil.capitalize(CAPITAL_LETTER.matcher(option.myName).replaceAll(" ")));
        label.setHorizontalAlignment(SwingConstants.LEFT);
        myCustomOptionsPanel.add(label, labelConstraints);
        final GridConstraints textConstraints = new GridConstraints();
        textConstraints.setFill(GridConstraints.FILL_BOTH);
        textConstraints.setRow(i);
        textConstraints.setColumn(1);
        textConstraints.setHSizePolicy(GridConstraints.SIZEPOLICY_CAN_GROW);
        myCustomOptionsPanel.add(textField, textConstraints);
        myCustomOptions.put(option.myName, new OptionHolder(option, label, textField));
    }
}
Also used : GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) JBTextField(com.intellij.ui.components.JBTextField)

Example 3 with GridLayoutManager

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

the class AbstractGridLayoutProperty method setValueImpl.

protected void setValueImpl(final RadContainer component, final Boolean value) throws Exception {
    final AbstractLayout layoutManager = (AbstractLayout) component.getLayout();
    if (!(layoutManager instanceof GridLayoutManager)) {
        throw new IllegalArgumentException("grid layout expected: " + layoutManager);
    }
    final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
    setGridLayoutPropertyValue(gridLayoutManager, value.booleanValue());
}
Also used : GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) AbstractLayout(com.intellij.uiDesigner.core.AbstractLayout)

Example 4 with GridLayoutManager

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

the class RadBoxLayoutManager method createSnapshotLayout.

@Override
public void createSnapshotLayout(final SnapshotContext context, final JComponent parent, final RadContainer container, final LayoutManager layout) {
    int rowCount = 1;
    int colCount = 1;
    boolean hasFiller = false;
    // workaround for lack of BoxLayout.getAxis()
    if (parent.getComponentCount() > 1) {
        for (Component component : parent.getComponents()) {
            if (component instanceof Box.Filler) {
                hasFiller = true;
            }
        }
        Rectangle bounds1 = parent.getComponent(0).getBounds();
        Rectangle bounds2 = parent.getComponent(1).getBounds();
        if (bounds2.x >= bounds1.x + bounds1.width) {
            colCount = parent.getComponentCount();
            if (!hasFiller)
                colCount++;
            myHorizontal = true;
        } else {
            rowCount = parent.getComponentCount();
            if (!hasFiller)
                rowCount++;
        }
    }
    container.setLayout(new GridLayoutManager(rowCount, colCount));
    if (!hasFiller) {
        if (myHorizontal) {
            container.addComponent(new RadHSpacer(context.newId(), colCount - 1));
        } else {
            container.addComponent(new RadVSpacer(context.newId(), rowCount - 1));
        }
    }
}
Also used : GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) Rectangle(java.awt.Rectangle) Component(java.awt.Component)

Example 5 with GridLayoutManager

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

the class RadGridLayoutManager method copyLayout.

@Override
public LayoutManager copyLayout(LayoutManager layout, int rowDelta, int columnDelta) {
    GridLayoutManager oldLayout = (GridLayoutManager) layout;
    final GridLayoutManager newLayout = new GridLayoutManager(oldLayout.getRowCount() + rowDelta, oldLayout.getColumnCount() + columnDelta);
    newLayout.setMargin(oldLayout.getMargin());
    newLayout.setHGap(oldLayout.getHGap());
    newLayout.setVGap(oldLayout.getVGap());
    return newLayout;
}
Also used : GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager)

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