Search in sources :

Example 6 with GridConstraints

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

the class NoButtonGroupInspection method checkComponentProperties.

@Override
protected void checkComponentProperties(Module module, IComponent component, FormErrorCollector collector) {
    if (FormInspectionUtil.isComponentClass(module, component, JRadioButton.class)) {
        final IRootContainer root = FormEditingUtil.getRoot(component);
        if (root == null)
            return;
        if (root.getButtonGroupName(component) == null) {
            EditorQuickFixProvider quickFixProvider = null;
            IContainer parent = component.getParentContainer();
            for (int i = 0; i < parent.getComponentCount(); i++) {
                IComponent child = parent.getComponent(i);
                if (child != component && FormInspectionUtil.isComponentClass(module, child, JRadioButton.class)) {
                    final GridConstraints c1 = component.getConstraints();
                    final GridConstraints c2 = child.getConstraints();
                    if (areCellsAdjacent(parent, c1, c2)) {
                        final String groupName = root.getButtonGroupName(child);
                        if (groupName == null) {
                            quickFixProvider = new EditorQuickFixProvider() {

                                @Override
                                public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                                    return new CreateGroupQuickFix(editor, component, c1.getColumn() == c2.getColumn());
                                }
                            };
                            break;
                        } else {
                            quickFixProvider = new EditorQuickFixProvider() {

                                @Override
                                public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                                    return new AddToGroupQuickFix(editor, component, groupName);
                                }
                            };
                        }
                    }
                }
            }
            collector.addError(getID(), component, null, UIDesignerBundle.message("inspection.no.button.group.error"), quickFixProvider);
        }
    }
}
Also used : QuickFix(com.intellij.uiDesigner.quickFixes.QuickFix) IComponent(com.intellij.uiDesigner.lw.IComponent) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) IRootContainer(com.intellij.uiDesigner.lw.IRootContainer) IContainer(com.intellij.uiDesigner.lw.IContainer)

Example 7 with GridConstraints

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

the class ResizeProcessor method processMouseEvent.

protected void processMouseEvent(final MouseEvent e) {
    if (e.getID() == MouseEvent.MOUSE_PRESSED) {
        myLastPoint = e.getPoint();
        myBounds = myOriginalParent.getLayoutManager().isGrid() ? myResizedCopy.getBounds() : myComponent.getBounds();
        myOriginalBounds = new Rectangle(myBounds);
    } else if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
        final int dx = e.getX() - myLastPoint.x;
        final int dy = e.getY() - myLastPoint.y;
        if (myOriginalParent.getLayoutManager().isGrid()) {
            final Point point = SwingUtilities.convertPoint(myEditor.getDragLayer(), e.getX(), e.getY(), myOriginalParent.getDelegee());
            putGridSpanFeedback(point);
        } else if (myOriginalParent.isXY()) {
            myEditor.getActiveDecorationLayer().removeFeedback();
            setCursor(getResizeCursor());
        } else {
            return;
        }
        final GridConstraints constraints = myComponent.getConstraints();
        if ((myResizeMask & Painter.WEST_MASK) != 0) {
            myBounds.x += dx;
            myBounds.width -= dx;
        }
        if ((myResizeMask & Painter.EAST_MASK) != 0) {
            myBounds.width += dx;
        }
        if ((myResizeMask & Painter.NORTH_MASK) != 0) {
            myBounds.y += dy;
            myBounds.height -= dy;
        }
        if ((myResizeMask & Painter.SOUTH_MASK) != 0) {
            myBounds.height += dy;
        }
        final Dimension minSize = myComponent.getMinimumSize();
        final Rectangle newBounds = myOriginalParent.getLayoutManager().isGrid() ? myResizedCopy.getBounds() : myComponent.getBounds();
        // Component's bounds cannot be less the some minimum size
        if (myBounds.width >= minSize.width) {
            newBounds.x = myBounds.x;
            newBounds.width = myBounds.width;
        } else {
            if ((myResizeMask & Painter.WEST_MASK) != 0) {
                newBounds.x = newBounds.x + newBounds.width - minSize.width;
                newBounds.width = minSize.width;
            } else if ((myResizeMask & Painter.EAST_MASK) != 0) {
                newBounds.width = minSize.width;
            }
        }
        if (myBounds.height >= minSize.height) {
            newBounds.y = myBounds.y;
            newBounds.height = myBounds.height;
        } else {
            if ((myResizeMask & Painter.NORTH_MASK) != 0) {
                newBounds.y = newBounds.y + newBounds.height - minSize.height;
                newBounds.height = minSize.height;
            } else if ((myResizeMask & Painter.SOUTH_MASK) != 0) {
                newBounds.height = minSize.height;
            }
        }
        final Dimension size = newBounds.getSize();
        Util.adjustSize(myComponent.getDelegee(), constraints, size);
        newBounds.width = size.width;
        newBounds.height = size.height;
        if (myOriginalParent.getLayoutManager().isGrid()) {
            myResizedCopy.setBounds(newBounds);
        } else {
            if (myEditor.ensureEditable()) {
                myComponent.setBounds(newBounds);
            }
        }
        myEditor.refresh();
        myLastPoint = e.getPoint();
    } else if (e.getID() == MouseEvent.MOUSE_RELEASED) {
        boolean modified = false;
        myComponent.getDelegee().setVisible(true);
        myComponent.setResizing(false);
        myComponent.setSelected(true);
        if (myResizedCopy != null) {
            myEditor.getDragLayer().remove(myResizedCopy.getDelegee());
        }
        if (myOriginalParent.getLayoutManager().isGrid() && myEditor.ensureEditable()) {
            final Point point = SwingUtilities.convertPoint(myEditor.getDragLayer(), e.getX(), e.getY(), myOriginalParent.getDelegee());
            Rectangle rcGrid = getGridSpanGridRect(myOriginalParent, myOriginalConstraints, point, myResizeMask);
            if (rcGrid != null && isGridSpanDropAllowed(rcGrid)) {
                GridConstraints oldConstraints = (GridConstraints) myOriginalConstraints.clone();
                myOriginalConstraints.setColumn(rcGrid.x);
                myOriginalConstraints.setRow(rcGrid.y);
                myOriginalConstraints.setColSpan(rcGrid.width);
                myOriginalConstraints.setRowSpan(rcGrid.height);
                myComponent.fireConstraintsChanged(oldConstraints);
                modified = true;
            }
        } else {
            modified = true;
        }
        myEditor.getActiveDecorationLayer().removeFeedback();
        myComponent.setDragging(false);
        if (modified) {
            if (myEditor.ensureEditable()) {
                myEditor.refreshAndSave(true);
            }
        }
    }
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Dimension(java.awt.Dimension)

Example 8 with GridConstraints

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

the class GridSpanInsertProcessor method doBefore.

public void doBefore(int newCell) {
    if (myMode == GridInsertMode.RowBefore) {
        int oldRow = myInsertCellComponent.getConstraints().getRow();
        int columns = myLayoutManager.getGridColumnCount(myContainer);
        for (int i = 0; i < columns; i++) {
            if (i != myColumn) {
                RadComponent component = RadAbstractGridLayoutManager.getComponentAtGrid(myContainer, oldRow, i);
                if (component != null) {
                    GridConstraints constraints = component.getConstraints();
                    if (constraints.getRow() == oldRow) {
                        GridConstraints oldConstraints = (GridConstraints) constraints.clone();
                        constraints.setRow(newCell);
                        constraints.setRowSpan(constraints.getRowSpan() + oldRow - newCell);
                        component.fireConstraintsChanged(oldConstraints);
                    }
                    i = constraints.getColumn() + constraints.getColSpan() - 1;
                }
            }
        }
    } else if (myMode == GridInsertMode.ColumnBefore) {
        int oldColumn = myInsertCellComponent.getConstraints().getColumn();
        int rows = myLayoutManager.getGridRowCount(myContainer);
        for (int i = 0; i < rows; i++) {
            if (i != myRow) {
                RadComponent component = RadAbstractGridLayoutManager.getComponentAtGrid(myContainer, i, oldColumn);
                if (component != null) {
                    GridConstraints constraints = component.getConstraints();
                    if (constraints.getColumn() == oldColumn) {
                        GridConstraints oldConstraints = (GridConstraints) constraints.clone();
                        constraints.setColumn(newCell);
                        constraints.setColSpan(constraints.getColSpan() + oldColumn - newCell);
                        component.fireConstraintsChanged(oldConstraints);
                    }
                    i = constraints.getRow() + constraints.getRowSpan() - 1;
                }
            }
        }
    }
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent)

Example 9 with GridConstraints

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

the class GridSpanInsertProcessor method doAfter.

public void doAfter(int newCell) {
    if (myMode == GridInsertMode.RowAfter) {
        int columns = myLayoutManager.getGridColumnCount(myContainer);
        for (int i = 0; i < columns; i++) {
            if (i != myColumn) {
                RadComponent component = RadAbstractGridLayoutManager.getComponentAtGrid(myContainer, myRow, i);
                if (component != null) {
                    GridConstraints constraints = component.getConstraints();
                    int endRow = constraints.getRow() + constraints.getRowSpan() - 1;
                    if (endRow == myRow) {
                        GridConstraints oldConstraints = (GridConstraints) constraints.clone();
                        constraints.setRowSpan(constraints.getRowSpan() + newCell - myRow);
                        component.fireConstraintsChanged(oldConstraints);
                    }
                    i = constraints.getColumn() + constraints.getColSpan() - 1;
                }
            }
        }
    } else if (myMode == GridInsertMode.ColumnAfter) {
        int rows = myLayoutManager.getGridRowCount(myContainer);
        for (int i = 0; i < rows; i++) {
            if (i != myRow) {
                RadComponent component = RadAbstractGridLayoutManager.getComponentAtGrid(myContainer, i, myColumn);
                if (component != null) {
                    GridConstraints constraints = component.getConstraints();
                    int endColumn = constraints.getColumn() + constraints.getColSpan() - 1;
                    if (endColumn == myColumn) {
                        GridConstraints oldConstraints = (GridConstraints) constraints.clone();
                        constraints.setColSpan(constraints.getColSpan() + newCell - myColumn);
                        component.fireConstraintsChanged(oldConstraints);
                    }
                    i = constraints.getRow() + constraints.getRowSpan() - 1;
                }
            }
        }
    }
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent)

Example 10 with GridConstraints

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

the class Palette method processItemElement.

private void processItemElement(@NotNull final Element itemElement, @NotNull final GroupItem group, final boolean skipExisting) {
    // Class name. It's OK if class does not exist.
    final String className = LwXmlReader.getRequiredString(itemElement, ATTRIBUTE_CLASS);
    if (skipExisting && getItem(className) != null) {
        return;
    }
    // Icon (optional)
    final String iconPath = LwXmlReader.getString(itemElement, ATTRIBUTE_ICON);
    // Tooltip text (optional)
    // can be null
    final String toolTipText = LwXmlReader.getString(itemElement, ATTRIBUTE_TOOLTIP_TEXT);
    boolean autoCreateBinding = LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_AUTO_CREATE_BINDING, false);
    boolean canAttachLabel = LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_CAN_ATTACH_LABEL, false);
    boolean isContainer = LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_IS_CONTAINER, false);
    // Default constraint
    final GridConstraints constraints;
    final Element defaultConstraints = itemElement.getChild(ELEMENT_DEFAULT_CONSTRAINTS);
    if (defaultConstraints != null) {
        constraints = processDefaultConstraintsElement(defaultConstraints);
    } else {
        constraints = new GridConstraints();
    }
    final HashMap<String, StringDescriptor> propertyName2initialValue = new HashMap<>();
    {
        final Element initialValues = itemElement.getChild(ELEMENT_INITIAL_VALUES);
        if (initialValues != null) {
            for (final Object o : initialValues.getChildren(ELEMENT_PROPERTY)) {
                final Element e = (Element) o;
                final String name = LwXmlReader.getRequiredString(e, ATTRIBUTE_NAME);
                // TODO[all] currently all initial values are strings
                final StringDescriptor value = StringDescriptor.create(LwXmlReader.getRequiredString(e, ATTRIBUTE_VALUE));
                propertyName2initialValue.put(name, value);
            }
        }
    }
    final boolean removable = LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_REMOVABLE, true);
    final ComponentItem item = new ComponentItem(myProject, className, iconPath, toolTipText, constraints, propertyName2initialValue, removable, autoCreateBinding, canAttachLabel);
    item.setIsContainer(isContainer);
    addItem(group, item);
}
Also used : GridConstraints(com.intellij.uiDesigner.core.GridConstraints) HashMap(java.util.HashMap) Element(org.jdom.Element) StringDescriptor(com.intellij.uiDesigner.lw.StringDescriptor)

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