Search in sources :

Example 16 with GridConstraints

use of com.intellij.uiDesigner.core.GridConstraints 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)

Example 17 with GridConstraints

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

the class DesignDropTargetListener method processDrop.

private boolean processDrop(final DraggedComponentList dcl, final Point dropPoint, final int dropAction) {
    myEditor.getActiveDecorationLayer().removeFeedback();
    final ArrayList<RadComponent> dclComponents = dcl.getComponents();
    final int componentCount = dclComponents.size();
    ComponentDropLocation location = GridInsertProcessor.getDropLocation(myEditor.getRootContainer(), dropPoint);
    if (FormEditingUtil.isDropOnChild(dcl, location)) {
        setDraggingState(dcl, false);
        return false;
    }
    if (!location.canDrop(dcl)) {
        setDraggingState(dcl, false);
        return false;
    }
    if (!myEditor.ensureEditable()) {
        setDraggingState(dcl, false);
        return false;
    }
    List<RadComponent> droppedComponents;
    RadContainer[] originalParents = dcl.getOriginalParents();
    cancelDrag();
    if (dropAction == DnDConstants.ACTION_COPY) {
        setDraggingState(dcl, false);
        droppedComponents = myDraggedComponentsCopy;
        if (droppedComponents == null) {
            return false;
        }
    } else {
        for (int i = 0; i < dclComponents.size(); i++) {
            LOG.info("Removing component " + dclComponents.get(i).getId() + " with constraints " + dcl.getOriginalConstraints()[i]);
            originalParents[i].removeComponent(dclComponents.get(i));
        }
        droppedComponents = dclComponents;
    }
    final RadComponent[] components = droppedComponents.toArray(new RadComponent[componentCount]);
    final GridConstraints[] originalConstraints = dcl.getOriginalConstraints();
    location.processDrop(myEditor, components, originalConstraints, dcl);
    if (dropAction == DnDConstants.ACTION_COPY) {
        for (RadComponent component : droppedComponents) {
            InsertComponentProcessor.createBindingWhenDrop(myEditor, component, false);
        }
        FormEditingUtil.selectComponents(myEditor, droppedComponents);
    } else {
        setDraggingState(dcl, false);
    }
    for (int i = 0; i < originalConstraints.length; i++) {
        if (originalParents[i].getLayoutManager().isGrid()) {
            FormEditingUtil.deleteEmptyGridCells(originalParents[i], originalConstraints[i]);
        }
    }
    return true;
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 18 with GridConstraints

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

the class InputExpressionDialog method setEditor.

private void setEditor(JComponent editor, int vSizePolicy) {
    if (myEditorComponent != null) {
        myForm.getEditorPanel().remove(myEditorComponent);
    }
    final GridConstraints gridConstraints = new GridConstraints();
    gridConstraints.setFill(vSizePolicy == GridConstraints.SIZEPOLICY_WANT_GROW ? GridConstraints.FILL_BOTH : GridConstraints.FILL_HORIZONTAL);
    gridConstraints.setVSizePolicy(vSizePolicy);
    myForm.getEditorPanel().add(myEditorComponent = editor, gridConstraints);
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints)

Example 19 with GridConstraints

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

the class PyUniversalTestForm method create.

/**
   * @param configuration configuration to configure form on creation
   * @param customOptions additional option names this form shall support. Make sure your configuration has appropriate properties.
   */
@NotNull
public static PyUniversalTestForm create(@NotNull final PyUniversalTestConfiguration configuration, @NotNull final CustomOption... customOptions) {
    // TODO: DOC
    final PyUniversalTestForm form = new PyUniversalTestForm();
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileOrFolderDescriptor(PythonFileType.INSTANCE);
    form.myTargetText.addBrowseFolderListener("Choose File or Folder", null, configuration.getProject(), descriptor);
    for (final TestTargetType testTargetType : TestTargetType.values()) {
        final JBRadioButton button = new JBRadioButton(StringUtil.capitalize(testTargetType.name().toLowerCase(Locale.getDefault())));
        button.setActionCommand(testTargetType.name());
        button.addActionListener(o -> form.configureElementsVisibility());
        form.myButtonGroup.add(button);
        form.myTargets.add(button);
    }
    form.myButtonGroup.getElements().nextElement().setSelected(true);
    form.myOptionsForm = PyCommonOptionsFormFactory.getInstance().createForm(configuration.getCommonOptionsFormData());
    final GridConstraints constraints = new GridConstraints();
    constraints.setFill(GridConstraints.FILL_BOTH);
    form.myOptionsPanel.add(form.myOptionsForm.getMainPanel(), constraints);
    form.myLabel.setText(configuration.getTestFrameworkName());
    form.addCustomOptions(ObjectArrays.concat(customOptions, new CustomOption(PyUniversalTestsKt.getAdditionalArgumentsPropertyName(), TestTargetType.values())));
    configuration.copyTo(ReflectionUtilsKt.getProperties(form, null, true));
    return form;
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) JBRadioButton(com.intellij.ui.components.JBRadioButton) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with GridConstraints

use of com.intellij.uiDesigner.core.GridConstraints 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)

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