Search in sources :

Example 46 with RadComponent

use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.

the class InplaceEditingLayer method startInplaceEditing.

/**
   * Starts editing of "inplace" property for the component at the
   * specified point <code>(x, y)</code>.
   *
   * @param x x coordinate in the editor coordinate system
   * @param y y coordinate in the editor coordinate system
   */
public void startInplaceEditing(final int x, final int y) {
    final RadComponent inplaceComponent = FormEditingUtil.getRadComponentAt(myEditor.getRootContainer(), x, y);
    if (inplaceComponent == null) {
        // nothing to edit
        return;
    }
    // Try to find property with inplace editor
    final Point p = SwingUtilities.convertPoint(this, x, y, inplaceComponent.getDelegee());
    final Property inplaceProperty = inplaceComponent.getInplaceProperty(p.x, p.y);
    if (inplaceProperty != null) {
        final Rectangle bounds = inplaceComponent.getInplaceEditorBounds(inplaceProperty, p.x, p.y);
        startInplaceEditing(inplaceComponent, inplaceProperty, bounds, new InplaceContext(true));
    }
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) Property(com.intellij.uiDesigner.propertyInspector.Property) InplaceContext(com.intellij.uiDesigner.propertyInspector.InplaceContext)

Example 47 with RadComponent

use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.

the class MainProcessor method processMousePressed.

private void processMousePressed(final MouseEvent e) {
    if (myCurrentProcessor != null) {
        if (myCurrentProcessor.needMousePressed()) {
            myCurrentProcessor.processMouseEvent(e);
            return;
        }
        // Sun sometimes skips mouse released events...
        myCurrentProcessor.cancelOperation();
        myCurrentProcessor = null;
    }
    RadComponent component = null;
    final RadComponent draggerHost = FormEditingUtil.getDraggerHost(myEditor);
    // Try to understand whether we pressed inside dragger area
    if (draggerHost != null) {
        final JComponent delegee = draggerHost.getDelegee();
        final Point p = SwingUtilities.convertPoint(delegee, 0, 0, e.getComponent());
        if (p.x - MainProcessor.DRAGGER_SIZE <= e.getX() && e.getX() <= p.x && p.y - MainProcessor.DRAGGER_SIZE <= e.getY() && e.getY() <= p.y) {
            component = draggerHost;
        }
    }
    // If user clicked not inside dragger then we have find RadComponent at the click point
    if (component == null) {
        component = FormEditingUtil.getRadComponentAt(myEditor.getRootContainer(), e.getX(), e.getY());
    }
    if (component == null) {
        return;
    }
    final ComponentItem selectedItem = PaletteToolWindowManager.getInstance(myEditor).getActiveItem(ComponentItem.class);
    if (selectedItem != null) {
        myInsertComponentProcessor.setSticky(UIUtil.isControlKeyDown(e));
        myCurrentProcessor = myInsertComponentProcessor;
        return;
    }
    if (!UIUtil.isControlKeyDown(e) && !e.isShiftDown()) {
        if (!component.isSelected() || FormEditingUtil.getSelectedComponents(myEditor).size() != 1) {
            FormEditingUtil.selectSingleComponent(myEditor, component);
        }
    }
    final Point point = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), component.getDelegee());
    final int resizeMask = Painter.getResizeMask(component, point.x, point.y);
    LOG.debug("MainProcessor.processMousePressed: resizeMask at (" + point.x + "," + point.y + ") is " + resizeMask);
    if (resizeMask != 0) {
        if (component.getParent() != null) {
            component = component.getParent().getActionTargetComponent(component);
        }
        myCurrentProcessor = new ResizeProcessor(myEditor, component, resizeMask);
    } else if (component instanceof RadRootContainer || e.isShiftDown()) {
        myCurrentProcessor = new GroupSelectionProcessor(myEditor, component);
    } else if (!e.isShiftDown()) {
        myCurrentProcessor = new DragSelectionProcessor(myEditor);
    }
    updateDragger(e);
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer)

Example 48 with RadComponent

use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.

the class NoLabelForInspection method checkComponentProperties.

@Override
protected void checkComponentProperties(final Module module, final IComponent component, FormErrorCollector collector) {
    ComponentItem item = Palette.getInstance(module.getProject()).getItem(component.getComponentClassName());
    if (item != null && item.isCanAttachLabel()) {
        IComponent root = component;
        while (root.getParentContainer() != null) {
            root = root.getParentContainer();
        }
        final Ref<Boolean> found = new Ref<>(Boolean.FALSE);
        final Ref<RadComponent> candidateLabel = new Ref<>();
        final List<RadComponent> allLabels = new ArrayList<>();
        FormEditingUtil.iterate(root, new FormEditingUtil.ComponentVisitor() {

            @Override
            public boolean visit(final IComponent c2) {
                if (FormInspectionUtil.isComponentClass(module, c2, JLabel.class)) {
                    IProperty prop = FormInspectionUtil.findProperty(c2, SwingProperties.LABEL_FOR);
                    if (prop != null && component.getId().equals(prop.getPropertyValue(c2))) {
                        found.set(Boolean.TRUE);
                        return false;
                    } else if (component instanceof RadComponent && (prop == null || StringUtil.isEmpty((String) prop.getPropertyValue(c2)))) {
                        RadComponent radComponent = (RadComponent) component;
                        final RadComponent radComponent2 = (RadComponent) c2;
                        allLabels.add(radComponent2);
                        if (radComponent.getParent() == radComponent2.getParent() && radComponent.getParent().getLayoutManager().isGrid()) {
                            GridConstraints gc1 = radComponent.getConstraints();
                            GridConstraints gc2 = radComponent2.getConstraints();
                            int nextColumn = FormEditingUtil.nextCol(radComponent.getParent(), gc2.getColumn());
                            int nextRow = FormEditingUtil.nextRow(radComponent.getParent(), gc2.getRow());
                            if (gc1.getRow() == gc2.getRow() && nextColumn == gc1.getColumn() || gc1.getColumn() == gc2.getColumn() && nextRow == gc1.getRow()) {
                                candidateLabel.set(radComponent2);
                            }
                        }
                    }
                }
                return true;
            }
        });
        if (!found.get().booleanValue()) {
            if (!candidateLabel.isNull()) {
                allLabels.clear();
                allLabels.add(candidateLabel.get());
            }
            EditorQuickFixProvider[] quickFixProviders = new EditorQuickFixProvider[allLabels.size()];
            for (int i = 0; i < quickFixProviders.length; i++) {
                final RadComponent label = allLabels.get(i);
                quickFixProviders[i] = new EditorQuickFixProvider() {

                    @Override
                    public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                        return new MyQuickFix(editor, component, label);
                    }
                };
            }
            collector.addError(getID(), component, null, UIDesignerBundle.message("inspection.no.label.for.error"), quickFixProviders);
        }
    }
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) QuickFix(com.intellij.uiDesigner.quickFixes.QuickFix) IComponent(com.intellij.uiDesigner.lw.IComponent) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) ArrayList(java.util.ArrayList) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor) Ref(com.intellij.openapi.util.Ref) IProperty(com.intellij.uiDesigner.lw.IProperty) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil)

Example 49 with RadComponent

use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.

the class GridReplaceDropLocation method processDrop.

@Override
public void processDrop(final GuiEditor editor, final RadComponent[] components, final GridConstraints[] constraintsToAdjust, final ComponentDragObject dragObject) {
    RadComponent c = myContainer.getComponentAtGrid(myRow, myColumn);
    if (c != null) {
        FormEditingUtil.deleteComponents(Collections.singletonList(c), false);
    }
    super.processDrop(editor, components, constraintsToAdjust, dragObject);
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent)

Example 50 with RadComponent

use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.

the class GroupSelectionProcessor method processMouseEvent.

protected void processMouseEvent(final MouseEvent e) {
    if (e.getID() == MouseEvent.MOUSE_PRESSED) {
        myStartPoint = e.getPoint();
        myEditor.getDragLayer().add(myRectangePainter);
    } else if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
        final Rectangle rectangle = getRectangle(e);
        myRectangePainter.setBounds(rectangle);
        myEditor.getDragLayer().repaint();
    } else if (e.getID() == MouseEvent.MOUSE_RELEASED) {
        final Rectangle rectangle = getRectangle(e);
        if (e.isShiftDown() && rectangle.width <= 3 && rectangle.height <= 3) {
            RadComponent component = FormEditingUtil.getRadComponentAt(myEditor.getRootContainer(), e.getX(), e.getY());
            if (component != null) {
                RadComponent anchor = myEditor.getSelectionAnchor();
                if (anchor == null || anchor.getParent() != component.getParent() || anchor.getParent() == null || !anchor.getParent().getLayoutManager().isGrid()) {
                    component.setSelected(!component.isSelected());
                } else {
                    selectComponentsInRange(component, anchor);
                    myEditor.setSelectionLead(component);
                }
            }
        }
        markRectangle(myEditor.getRootContainer(), rectangle, e.getComponent());
        final JComponent dragLayer = myEditor.getDragLayer();
        dragLayer.remove(myRectangePainter);
        dragLayer.repaint();
        myStartPoint = null;
    }
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent)

Aggregations

RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)86 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)22 RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)18 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)15 ArrayList (java.util.ArrayList)12 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)8 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)8 IComponent (com.intellij.uiDesigner.lw.IComponent)7 IProperty (com.intellij.uiDesigner.lw.IProperty)6 ComponentItem (com.intellij.uiDesigner.palette.ComponentItem)5 RadButtonGroup (com.intellij.uiDesigner.radComponents.RadButtonGroup)5 ListPopup (com.intellij.openapi.ui.popup.ListPopup)4 ComponentTree (com.intellij.uiDesigner.componentTree.ComponentTree)4 IntrospectedProperty (com.intellij.uiDesigner.propertyInspector.IntrospectedProperty)4 IntroComponentProperty (com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty)4 QuickFix (com.intellij.uiDesigner.quickFixes.QuickFix)4 Nullable (org.jetbrains.annotations.Nullable)4 RelativePoint (com.intellij.ui.awt.RelativePoint)3 Palette (com.intellij.uiDesigner.palette.Palette)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3