Search in sources :

Example 6 with RelativeRectangle

use of com.intellij.ui.awt.RelativeRectangle in project intellij-community by JetBrains.

the class ChangesDnDSupport method update.

@Override
public boolean update(DnDEvent aEvent) {
    aEvent.hideHighlighter();
    aEvent.setDropPossible(false, "");
    Object attached = aEvent.getAttachedObject();
    if (!(attached instanceof ChangeListDragBean))
        return false;
    final ChangeListDragBean dragBean = (ChangeListDragBean) attached;
    if (dragBean.getSourceComponent() != myTree)
        return false;
    dragBean.setTargetNode(null);
    RelativePoint dropPoint = aEvent.getRelativePoint();
    Point onTree = dropPoint.getPoint(myTree);
    final TreePath dropPath = myTree.getPathForLocation(onTree.x, onTree.y);
    if (dropPath == null)
        return false;
    ChangesBrowserNode dropNode = (ChangesBrowserNode) dropPath.getLastPathComponent();
    while (!((ChangesBrowserNode) dropNode.getParent()).isRoot()) {
        dropNode = (ChangesBrowserNode) dropNode.getParent();
    }
    if (!dropNode.canAcceptDrop(dragBean)) {
        return false;
    }
    final Rectangle tableCellRect = myTree.getPathBounds(new TreePath(dropNode.getPath()));
    if (fitsInBounds(tableCellRect)) {
        aEvent.setHighlighting(new RelativeRectangle(myTree, tableCellRect), DnDEvent.DropTargetHighlightingType.RECTANGLE);
    }
    aEvent.setDropPossible(true);
    dragBean.setTargetNode(dropNode);
    return false;
}
Also used : TreePath(javax.swing.tree.TreePath) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 7 with RelativeRectangle

use of com.intellij.ui.awt.RelativeRectangle in project intellij-community by JetBrains.

the class DnDManagerImpl method showHighlighter.

void showHighlighter(final RelativeRectangle rectangle, final int aType, final DnDEvent aEvent) {
    final JLayeredPane layeredPane = getLayeredPane(rectangle.getPoint().getComponent());
    final Rectangle bounds = rectangle.getRectangleOn(layeredPane);
    showHighlighter(layeredPane, aEvent, bounds, aType);
}
Also used : RelativeRectangle(com.intellij.ui.awt.RelativeRectangle)

Example 8 with RelativeRectangle

use of com.intellij.ui.awt.RelativeRectangle in project intellij-community by JetBrains.

the class RowsDnDSupport method installImpl.

private static void installImpl(@NotNull final JComponent component, @NotNull final EditableModel model) {
    component.setTransferHandler(new TransferHandler(null));
    DnDSupport.createBuilder(component).setBeanProvider(info -> {
        final Point p = info.getPoint();
        return new DnDDragStartBean(new RowDragInfo(component, Integer.valueOf(getRow(component, p))));
    }).setTargetChecker(new DnDTargetChecker() {

        @Override
        public boolean update(DnDEvent event) {
            final Object o = event.getAttachedObject();
            if (!(o instanceof RowDragInfo) || ((RowDragInfo) o).component != component) {
                event.setDropPossible(false, "");
                return true;
            }
            event.setDropPossible(true);
            int oldIndex = ((RowDragInfo) o).row;
            int newIndex = getRow(component, event.getPoint());
            if (newIndex == -1) {
                event.setDropPossible(false, "");
                return true;
            }
            Rectangle cellBounds = getCellBounds(component, newIndex);
            if (model instanceof RefinedDropSupport) {
                RefinedDropSupport.Position position = ((RefinedDropSupport) model).isDropInto(component, oldIndex, newIndex) ? INTO : (event.getPoint().y < cellBounds.y + cellBounds.height / 2) ? ABOVE : BELOW;
                boolean canDrop = ((RefinedDropSupport) model).canDrop(oldIndex, newIndex, position);
                event.setDropPossible(canDrop);
                if (canDrop && oldIndex != newIndex) {
                    if (position == BELOW) {
                        cellBounds.y += cellBounds.height - 2;
                    }
                    RelativeRectangle rectangle = new RelativeRectangle(component, cellBounds);
                    switch(position) {
                        case INTO:
                            event.setHighlighting(rectangle, DnDEvent.DropTargetHighlightingType.RECTANGLE);
                            break;
                        case ABOVE:
                        case BELOW:
                            rectangle.getDimension().height = 2;
                            event.setHighlighting(rectangle, DnDEvent.DropTargetHighlightingType.FILLED_RECTANGLE);
                            break;
                    }
                    return true;
                } else {
                    event.hideHighlighter();
                    return true;
                }
            } else {
                if (oldIndex == newIndex) {
                    // Drag&Drop always starts with new==old and we shouldn't display 'rejecting' cursor in this case
                    return true;
                }
                boolean canExchange = model.canExchangeRows(oldIndex, newIndex);
                if (canExchange) {
                    if (oldIndex < newIndex) {
                        cellBounds.y += cellBounds.height - 2;
                    }
                    RelativeRectangle rectangle = new RelativeRectangle(component, cellBounds);
                    rectangle.getDimension().height = 2;
                    event.setDropPossible(true);
                    event.setHighlighting(rectangle, DnDEvent.DropTargetHighlightingType.FILLED_RECTANGLE);
                } else {
                    event.setDropPossible(false);
                }
                return true;
            }
        }
    }).setDropHandler(new DnDDropHandler() {

        @Override
        public void drop(DnDEvent event) {
            final Object o = event.getAttachedObject();
            final Point p = event.getPoint();
            if (o instanceof RowDragInfo && ((RowDragInfo) o).component == component) {
                int oldIndex = ((RowDragInfo) o).row;
                if (oldIndex == -1)
                    return;
                int newIndex = getRow(component, p);
                if (newIndex == -1) {
                    newIndex = getRowCount(component) - 1;
                }
                if (oldIndex != newIndex) {
                    if (model instanceof RefinedDropSupport) {
                        Rectangle cellBounds = getCellBounds(component, newIndex);
                        RefinedDropSupport.Position position = ((RefinedDropSupport) model).isDropInto(component, oldIndex, newIndex) ? INTO : (event.getPoint().y < cellBounds.y + cellBounds.height / 2) ? ABOVE : BELOW;
                        if (((RefinedDropSupport) model).canDrop(oldIndex, newIndex, position)) {
                            ((RefinedDropSupport) model).drop(oldIndex, newIndex, position);
                        }
                    } else {
                        if (model.canExchangeRows(oldIndex, newIndex)) {
                            model.exchangeRows(oldIndex, newIndex);
                            setSelectedRow(component, newIndex);
                        }
                    }
                }
            }
            event.hideHighlighter();
        }
    }).install();
}
Also used : java.awt(java.awt) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) Function(com.intellij.util.Function) EditableModel(com.intellij.util.ui.EditableModel) com.intellij.ide.dnd(com.intellij.ide.dnd) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) Position(com.intellij.ui.RowsDnDSupport.RefinedDropSupport.Position) Position(com.intellij.ui.RowsDnDSupport.RefinedDropSupport.Position) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) Position(com.intellij.ui.RowsDnDSupport.RefinedDropSupport.Position) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle)

Example 9 with RelativeRectangle

use of com.intellij.ui.awt.RelativeRectangle in project intellij-community by JetBrains.

the class CalloutComponent method show.

public void show(int location, final RelativePoint target) {
    myFrame.pack();
    Dimension frameSize = myFrame.getPreferredSize();
    final Point targetScreenPoint = target.getScreenPoint();
    Point framePoint = new Point();
    switch(location) {
        case Callout.NORTH_WEST:
            framePoint.x = targetScreenPoint.x - frameSize.width - getPointerShift();
            framePoint.y = targetScreenPoint.y - frameSize.height - getPointerShift();
            break;
        case Callout.NORTH_EAST:
            framePoint.x = targetScreenPoint.x + getPointerShift();
            framePoint.y = targetScreenPoint.y - frameSize.height - getPointerShift();
            break;
        case Callout.SOUTH_EAST:
            framePoint.x = targetScreenPoint.x + getPointerShift();
            framePoint.y = targetScreenPoint.y + getPointerShift();
            break;
        case Callout.SOUTH_WEST:
            framePoint.x = targetScreenPoint.x - frameSize.width - getPointerShift();
            framePoint.y = targetScreenPoint.y + getPointerShift();
            break;
    }
    myPointerComponent = new Pointer(location);
    final Rectangle frameBounds = new Rectangle(framePoint, frameSize);
    ScreenUtil.moveRectangleToFitTheScreen(frameBounds);
    myTargetComponent = (JComponent) target.getComponent();
    myTargetWindow = SwingUtilities.getWindowAncestor(myTargetComponent);
    final JLayeredPane layered = getLayeredPane(myTargetWindow);
    final Rectangle layeredBounds = new RelativeRectangle(layered).getScreenRectangle();
    final boolean[] outside = getOutsideAxisCodes(layeredBounds, frameBounds);
    if (outside != null) {
        boolean x = outside[0];
        boolean y = outside[1];
        switch(location) {
            case Callout.NORTH_WEST:
                if (x) {
                    frameBounds.x = layeredBounds.x - frameBounds.width;
                }
                if (y) {
                    frameBounds.y = layeredBounds.y - frameBounds.height;
                }
                break;
            case Callout.NORTH_EAST:
                if (x) {
                    frameBounds.x = (int) layeredBounds.getMaxX();
                }
                if (y) {
                    frameBounds.y = layeredBounds.y - frameBounds.height;
                }
                break;
            case Callout.SOUTH_EAST:
                if (x) {
                    frameBounds.x = (int) layeredBounds.getMaxX();
                }
                if (y) {
                    frameBounds.y = (int) layeredBounds.getMaxY();
                }
                break;
            case Callout.SOUTH_WEST:
                if (x) {
                    frameBounds.x = layeredBounds.x - frameBounds.width;
                }
                if (y) {
                    frameBounds.y = (int) layeredBounds.getMaxY();
                }
                break;
        }
    }
    Point targetLayeredPoint = target.getPoint(layered);
    Rectangle frameLayeredBounds = RelativeRectangle.fromScreen(layered, frameBounds).getRectangleOn(layered);
    Rectangle pointerBounds = new Rectangle();
    final int extraPoint = 1;
    switch(location) {
        case Callout.NORTH_WEST:
            pointerBounds.x = (int) frameLayeredBounds.getMaxX() - extraPoint;
            pointerBounds.y = (int) frameLayeredBounds.getMaxY() - extraPoint;
            pointerBounds.width = targetLayeredPoint.x - pointerBounds.x;
            pointerBounds.height = targetLayeredPoint.y - pointerBounds.y;
            break;
        case Callout.NORTH_EAST:
            pointerBounds.x = targetLayeredPoint.x;
            pointerBounds.y = (int) frameLayeredBounds.getMaxY() - extraPoint;
            pointerBounds.width = frameLayeredBounds.x + extraPoint - targetLayeredPoint.x;
            pointerBounds.height = targetLayeredPoint.y - pointerBounds.y;
            break;
        case Callout.SOUTH_EAST:
            pointerBounds.x = targetLayeredPoint.x;
            pointerBounds.y = targetLayeredPoint.y;
            pointerBounds.width = frameLayeredBounds.x + extraPoint - targetLayeredPoint.x;
            pointerBounds.height = (int) frameLayeredBounds.getMaxY() + extraPoint - targetLayeredPoint.y - frameLayeredBounds.height;
            break;
        case Callout.SOUTH_WEST:
            pointerBounds.x = (int) frameLayeredBounds.getMaxX() - extraPoint;
            pointerBounds.y = targetLayeredPoint.y;
            pointerBounds.width = targetLayeredPoint.x - pointerBounds.x;
            pointerBounds.height = frameLayeredBounds.y + extraPoint - targetLayeredPoint.y;
            break;
    }
    layered.add(myPointerComponent, JLayeredPane.POPUP_LAYER);
    myPointerComponent.setBounds(pointerBounds);
    myFrame.setBounds(frameBounds);
    myFrame.setVisible(true);
    SwingUtilities.invokeLater(() -> {
        installDisposeListeners();
        myFrame.setVisible(true);
    });
}
Also used : RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Aggregations

RelativeRectangle (com.intellij.ui.awt.RelativeRectangle)9 RelativePoint (com.intellij.ui.awt.RelativePoint)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 TreePath (javax.swing.tree.TreePath)2 com.intellij.ide.dnd (com.intellij.ide.dnd)1 Disposable (com.intellij.openapi.Disposable)1 AnActionListener (com.intellij.openapi.actionSystem.ex.AnActionListener)1 PackagingElementNode (com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingElementNode)1 CompositePackagingElement (com.intellij.packaging.elements.CompositePackagingElement)1 PackagingElement (com.intellij.packaging.elements.PackagingElement)1 DirectoryPackagingElement (com.intellij.packaging.impl.elements.DirectoryPackagingElement)1 Position (com.intellij.ui.RowsDnDSupport.RefinedDropSupport.Position)1 Function (com.intellij.util.Function)1 EditableModel (com.intellij.util.ui.EditableModel)1 java.awt (java.awt)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 MouseEvent (java.awt.event.MouseEvent)1 javax.swing (javax.swing)1 TreeNode (javax.swing.tree.TreeNode)1