Search in sources :

Example 1 with GridConstraints

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

Example 5 with GridConstraints

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

the class AlignProperty method setValueImpl.

protected void setValueImpl(final RadComponent component, final Integer value) throws Exception {
    int anchorMask = myHorizontal ? 0x0C : 3;
    int fillMask = myHorizontal ? 1 : 2;
    int anchor = 0;
    int fill = 0;
    switch(value.intValue()) {
        case GridConstraints.ALIGN_FILL:
            fill = myHorizontal ? GridConstraints.FILL_HORIZONTAL : GridConstraints.FILL_VERTICAL;
            break;
        case GridConstraints.ALIGN_LEFT:
            anchor = myHorizontal ? GridConstraints.ANCHOR_WEST : GridConstraints.ANCHOR_NORTH;
            break;
        case GridConstraints.ALIGN_RIGHT:
            anchor = myHorizontal ? GridConstraints.ANCHOR_EAST : GridConstraints.ANCHOR_SOUTH;
            break;
    }
    GridConstraints gc = component.getConstraints();
    GridConstraints oldGC = (GridConstraints) gc.clone();
    gc.setAnchor((gc.getAnchor() & ~anchorMask) | anchor);
    gc.setFill((gc.getFill() & ~fillMask) | fill);
    AlignPropertyProvider provider = getAlignPropertyProvider(component);
    if (provider != null) {
        provider.setAlignment(component, myHorizontal, value.intValue());
    }
    component.fireConstraintsChanged(oldGC);
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints)

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