Search in sources :

Example 1 with RadComponent

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

the class MainProcessor method updateDragger.

private void updateDragger(final MouseEvent e) {
    final RadComponent component = FormEditingUtil.getRadComponentAt(myEditor.getRootContainer(), e.getX(), e.getY());
    LOG.assertTrue(component != null);
    // Dragger
    final RadComponent oldDraggerHost = FormEditingUtil.getDraggerHost(myEditor);
    RadComponent newDraggerHost = null;
    for (RadComponent c = component; c != null && !(c instanceof RadRootContainer); c = c.getParent()) {
        if (c.isSelected()) {
            newDraggerHost = c;
            break;
        }
    }
    boolean keepOldHost = false;
    if (oldDraggerHost != null && oldDraggerHost.isSelected()) {
        final Point p = SwingUtilities.convertPoint(oldDraggerHost.getDelegee(), 0, 0, e.getComponent());
        final int deltaX = e.getX() - p.x;
        final int deltaY = e.getY() - p.y;
        if (deltaX > -DRAGGER_SIZE && deltaX < oldDraggerHost.getWidth() && deltaY > -DRAGGER_SIZE && deltaY < oldDraggerHost.getHeight()) {
            keepOldHost = true;
            newDraggerHost = null;
        }
    }
    boolean shouldRepaint = false;
    if (oldDraggerHost != null && !keepOldHost && oldDraggerHost != newDraggerHost) {
        oldDraggerHost.setDragger(false);
        shouldRepaint = true;
    }
    if (newDraggerHost != null) {
        newDraggerHost.setDragger(true);
        shouldRepaint = true;
    }
    if (shouldRepaint) {
        myEditor.repaintLayeredPane();
    }
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer)

Example 2 with RadComponent

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

the class MainProcessor method processMouseEvent.

protected void processMouseEvent(final MouseEvent e) {
    myLastMousePosition = e.getPoint();
    if (myCurrentProcessor != null && myCurrentProcessor.isDragActive()) {
        return;
    }
    // motion events should go further
    if (e.isPopupTrigger()) {
        RadComponent component = FormEditingUtil.getRadComponentAt(myEditor.getRootContainer(), e.getX(), e.getY());
        if (component != null && !component.isSelected()) {
            FormEditingUtil.selectSingleComponent(myEditor, component);
        }
        final ActionManager actionManager = ActionManager.getInstance();
        final ActionPopupMenu popupMenu = actionManager.createActionPopupMenu(ActionPlaces.GUI_DESIGNER_EDITOR_POPUP, (ActionGroup) actionManager.getAction(IdeActions.GROUP_GUI_DESIGNER_EDITOR_POPUP));
        popupMenu.getComponent().show(e.getComponent(), e.getX(), e.getY());
        return;
    }
    final int id = e.getID();
    if ((MouseEvent.BUTTON2 == e.getButton() || MouseEvent.BUTTON3 == e.getButton()) && (MouseEvent.MOUSE_PRESSED == id || MouseEvent.MOUSE_RELEASED == id || MouseEvent.MOUSE_CLICKED == id)) {
        return;
    }
    // Handle all left mouse events and all motion events
    final RadComponent componentAt = FormEditingUtil.getRadComponentAt(myEditor.getRootContainer(), e.getX(), e.getY());
    if (componentAt != null) {
        final Point p1 = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), componentAt.getDelegee());
        final Component deepestComponentAt = SwingUtilities.getDeepestComponentAt(componentAt.getDelegee(), p1.x, p1.y);
        final Point p2 = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), deepestComponentAt);
        EventProcessor processor = componentAt.getEventProcessor(e);
        if (processor != null) {
            myCurrentProcessor = processor;
        } else {
            final Component source = deepestComponentAt != null ? deepestComponentAt : componentAt.getDelegee();
            componentAt.processMouseEvent(new MouseEvent(source, id, e.getWhen(), e.getModifiers(), p2.x, p2.y, e.getClickCount(), e.isPopupTrigger(), e.getButton()));
        }
    }
    Cursor cursor = Cursor.getDefaultCursor();
    if (id == MouseEvent.MOUSE_MOVED) {
        if (PaletteToolWindowManager.getInstance(myEditor).getActiveItem(ComponentItem.class) != null) {
            if (myInsertFeedbackEnabled) {
                cursor = myInsertComponentProcessor.processMouseMoveEvent(e);
            }
        } else if (myCurrentProcessor != null) {
            myCurrentProcessor.processMouseEvent(e);
        } else {
            final RadComponent component = FormEditingUtil.getRadComponentAt(myEditor.getRootContainer(), e.getX(), e.getY());
            if (component != null) {
                final Point point = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), component.getDelegee());
                final int resizeMask = Painter.getResizeMask(component, point.x, point.y);
                if (resizeMask != 0) {
                    cursor = Cursor.getPredefinedCursor(Painter.getResizeCursor(resizeMask));
                }
                updateDragger(e);
            }
        }
    } else if (id == MouseEvent.MOUSE_PRESSED) {
        processMousePressed(e);
    } else if (id == MouseEvent.MOUSE_RELEASED) {
        // not every press sets processor so its not a redundant 'if'
        if (myCurrentProcessor != null) {
            myCurrentProcessor.processMouseEvent(e);
            myCurrentProcessor = null;
        }
    } else if (id == MouseEvent.MOUSE_CLICKED) {
        processMouseClicked(e);
    } else if (id == MouseEvent.MOUSE_EXITED) {
        myEditor.getActiveDecorationLayer().removeFeedback();
    }
    if (!e.isConsumed() && myCurrentProcessor != null) {
        myCurrentProcessor.processMouseEvent(e);
    }
    if (myCurrentProcessor != null && myCurrentProcessor.isDragActive()) {
        myEditor.getLayeredPane().setCursor(null);
    } else {
        if (myCurrentProcessor != null && myCurrentProcessor.getCursor() != null) {
            cursor = myCurrentProcessor.getCursor();
        }
        myEditor.getLayeredPane().setCursor(cursor);
    }
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) MouseEvent(java.awt.event.MouseEvent) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent)

Example 3 with RadComponent

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

the class GlassLayer method getBestPopupPosition.

@Nullable
public Point getBestPopupPosition() {
    final ArrayList<RadComponent> selection = FormEditingUtil.getSelectedComponents(myEditor);
    if (selection.size() > 0) {
        final RadComponent component = selection.get(0);
        final Rectangle bounds = component.getBounds();
        int bottom = bounds.height > 4 ? bounds.y + bounds.height - 4 : bounds.y;
        int left = bounds.width > 4 ? bounds.x + 4 : bounds.x;
        // the location needs to be within the component
        Point pnt = new Point(left, bottom);
        return SwingUtilities.convertPoint(component.getParent().getDelegee(), pnt, this);
    }
    return null;
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with RadComponent

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

the class GridDropLocation method canDrop.

public boolean canDrop(final ComponentDragObject dragObject) {
    // If target point doesn't belong to any cell and column then do not allow drop.
    if (myRow == -1 || myColumn == -1) {
        LOG.debug("RadContainer.canDrop=false because no cell at mouse position");
        return false;
    }
    // allow drop any (NxM) component to cell (1x1)
    int colSpan = 1;
    int rowSpan = 1;
    for (int i = 0; i < dragObject.getComponentCount(); i++) {
        int relativeCol = dragObject.getRelativeCol(i);
        int relativeRow = dragObject.getRelativeRow(i);
        LOG.debug("checking component: relativeRow" + relativeRow + ", relativeCol" + relativeCol + ", colSpan=" + colSpan + ", rowSpan=" + rowSpan);
        if (myRow + relativeRow < 0 || myColumn + relativeCol < 0 || myRow + relativeRow + rowSpan > myContainer.getGridRowCount() || myColumn + relativeCol + colSpan > myContainer.getGridColumnCount()) {
            LOG.debug("RadContainer.canDrop=false because range is outside grid: row=" + (myRow + relativeRow) + ", col=" + (myColumn + relativeCol) + ", colSpan=" + colSpan + ", rowSpan=" + rowSpan);
            return false;
        }
        final RadComponent componentInRect = findOverlappingComponent(myRow + relativeRow, myColumn + relativeCol, rowSpan, colSpan);
        if (componentInRect != null) {
            LOG.debug("GridDropLocation.canDrop=false because found component " + componentInRect.getId() + " in rect (row=" + (myRow + relativeRow) + ", col=" + (myColumn + relativeCol) + ", rowSpan=" + rowSpan + ", colSpan=" + colSpan + ")");
            return false;
        }
    }
    LOG.debug("canDrop=true");
    return true;
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent)

Example 5 with RadComponent

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

the class GridDropLocation method dropIntoGrid.

protected static void dropIntoGrid(final RadContainer container, final RadComponent[] components, int row, int column, final ComponentDragObject dragObject) {
    assert components.length > 0;
    for (int i = 0; i < components.length; i++) {
        RadComponent c = components[i];
        if (c instanceof RadContainer) {
            final LayoutManager layout = ((RadContainer) c).getLayout();
            if (layout instanceof XYLayoutManager) {
                ((XYLayoutManager) layout).setPreferredSize(c.getSize());
            }
        }
        int relativeCol = dragObject.getRelativeCol(i);
        int relativeRow = dragObject.getRelativeRow(i);
        LOG.debug("dropIntoGrid: relativeRow=" + relativeRow + ", relativeCol=" + relativeCol);
        int colSpan = dragObject.getColSpan(i);
        int rowSpan = dragObject.getRowSpan(i);
        assert row + relativeRow >= 0;
        assert column + relativeCol >= 0;
        if (rowSpan > 1 || colSpan > 1) {
            if ((row + relativeRow + rowSpan > container.getGridRowCount() && rowSpan > 1) || (column + relativeCol + colSpan > container.getGridColumnCount() && colSpan > 1) || container.findComponentInRect(row + relativeRow, column + relativeCol, rowSpan, colSpan) != null) {
                rowSpan = 1;
                colSpan = 1;
            }
        }
        if (!container.getGridLayoutManager().isGridDefinedByComponents()) {
            assert relativeRow + rowSpan <= container.getGridRowCount();
            assert relativeCol + colSpan <= container.getGridColumnCount();
        }
        RadComponent old = container.findComponentInRect(row + relativeRow, column + relativeCol, rowSpan, colSpan);
        if (old != null) {
            LOG.error("Drop rectangle not empty: (" + (row + relativeRow) + ", " + (column + relativeCol) + ", " + rowSpan + ", " + colSpan + "), component ID=" + old.getId());
        }
        final GridConstraints constraints = c.getConstraints();
        constraints.setRow(row + relativeRow);
        constraints.setColumn(column + relativeCol);
        constraints.setRowSpan(rowSpan);
        constraints.setColSpan(colSpan);
        LOG.info("GridDropLocation.dropIntoGrid() constraints=" + constraints);
        container.addComponent(c);
        // Fill DropInfo
        c.revalidate();
    }
    container.revalidate();
    LOG.info("GridDropLocation.dropIntoGrid() done");
}
Also used : LayoutManager(java.awt.LayoutManager) XYLayoutManager(com.intellij.uiDesigner.shared.XYLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) XYLayoutManager(com.intellij.uiDesigner.shared.XYLayoutManager) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

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