Search in sources :

Example 1 with RelativeRectangle

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

the class DnDManagerImpl method showHighlighter.

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

Example 2 with RelativeRectangle

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

the class ActionToolbarImpl method showAutoPopup.

private void showAutoPopup() {
    if (isPopupShowing())
        return;
    final ActionGroup group;
    if (myOrientation == SwingConstants.HORIZONTAL) {
        group = myActionGroup;
    } else {
        final DefaultActionGroup outside = new DefaultActionGroup();
        for (int i = myFirstOutsideIndex; i < myVisibleActions.size(); i++) {
            outside.add(myVisibleActions.get(i));
        }
        group = outside;
    }
    PopupToolbar popupToolbar = new PopupToolbar(myPlace, group, true, myDataManager, myActionManager, myUpdater.getKeymapManager(), this) {

        @Override
        protected void onOtherActionPerformed() {
            hidePopup();
        }

        @Override
        protected DataContext getDataContext() {
            return ActionToolbarImpl.this.getDataContext();
        }
    };
    popupToolbar.setLayoutPolicy(NOWRAP_LAYOUT_POLICY);
    popupToolbar.updateActionsImmediately();
    Point location;
    if (myOrientation == SwingConstants.HORIZONTAL) {
        location = getLocationOnScreen();
    } else {
        location = getLocationOnScreen();
        location.y = location.y + getHeight() - popupToolbar.getPreferredSize().height;
    }
    final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(popupToolbar, null);
    builder.setResizable(false).setMovable(// fit the screen automatically
    true).setRequestFocus(false).setTitle(null).setCancelOnClickOutside(true).setCancelOnOtherWindowOpen(true).setCancelCallback(() -> {
        final boolean toClose = myActionManager.isActionPopupStackEmpty();
        if (toClose) {
            myUpdater.updateActions(false, true);
        }
        return toClose;
    }).setCancelOnMouseOutCallback(new MouseChecker() {

        @Override
        public boolean check(final MouseEvent event) {
            return myAutoPopupRec != null && myActionManager.isActionPopupStackEmpty() && !new RelativeRectangle(ActionToolbarImpl.this, myAutoPopupRec).contains(new RelativePoint(event));
        }
    });
    builder.addListener(new JBPopupAdapter() {

        @Override
        public void onClosed(LightweightWindowEvent event) {
            processClosed();
        }
    });
    myPopup = builder.createPopup();
    final AnActionListener.Adapter listener = new AnActionListener.Adapter() {

        @Override
        public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
            final JBPopup popup = myPopup;
            if (popup != null && !popup.isDisposed() && popup.isVisible()) {
                popup.cancel();
            }
        }
    };
    ActionManager.getInstance().addAnActionListener(listener);
    Disposer.register(myPopup, popupToolbar);
    Disposer.register(popupToolbar, new Disposable() {

        @Override
        public void dispose() {
            ActionManager.getInstance().removeAnActionListener(listener);
        }
    });
    myPopup.showInScreenCoordinates(this, location);
    final Window window = SwingUtilities.getWindowAncestor(this);
    if (window != null) {
        final ComponentAdapter componentAdapter = new ComponentAdapter() {

            @Override
            public void componentResized(final ComponentEvent e) {
                hidePopup();
            }

            @Override
            public void componentMoved(final ComponentEvent e) {
                hidePopup();
            }

            @Override
            public void componentShown(final ComponentEvent e) {
                hidePopup();
            }

            @Override
            public void componentHidden(final ComponentEvent e) {
                hidePopup();
            }
        };
        window.addComponentListener(componentAdapter);
        Disposer.register(popupToolbar, new Disposable() {

            @Override
            public void dispose() {
                window.removeComponentListener(componentAdapter);
            }
        });
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) MouseEvent(java.awt.event.MouseEvent) ComponentAdapter(java.awt.event.ComponentAdapter) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) AnActionListener(com.intellij.openapi.actionSystem.ex.AnActionListener) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 3 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 4 with RelativeRectangle

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

the class LayoutTreeComponent method update.

@Override
public boolean update(DnDEvent aEvent) {
    aEvent.setDropPossible(false);
    aEvent.hideHighlighter();
    final Object object = aEvent.getAttachedObject();
    if (object instanceof PackagingElementDraggingObject) {
        final DefaultMutableTreeNode parent = findParentCompositeElementNode(aEvent.getRelativePoint().getPoint(myTree));
        if (parent != null) {
            final PackagingElementDraggingObject draggingObject = (PackagingElementDraggingObject) object;
            final PackagingElementNode node = getNode(parent);
            if (node != null && draggingObject.canDropInto(node)) {
                final PackagingElement element = node.getFirstElement();
                if (element instanceof CompositePackagingElement) {
                    draggingObject.setTargetNode(node);
                    draggingObject.setTargetElement((CompositePackagingElement<?>) element);
                    final Rectangle bounds = myTree.getPathBounds(TreeUtil.getPathFromRoot(parent));
                    aEvent.setHighlighting(new RelativeRectangle(myTree, bounds), DnDEvent.DropTargetHighlightingType.RECTANGLE);
                    aEvent.setDropPossible(true);
                }
            }
        }
    }
    return false;
}
Also used : PackagingElementNode(com.intellij.openapi.roots.ui.configuration.artifacts.nodes.PackagingElementNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) PackagingElement(com.intellij.packaging.elements.PackagingElement) DirectoryPackagingElement(com.intellij.packaging.impl.elements.DirectoryPackagingElement) CompositePackagingElement(com.intellij.packaging.elements.CompositePackagingElement)

Example 5 with RelativeRectangle

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

the class FavoritesPanel method highlight.

private void highlight(FavoritesListNode node, DnDEvent event) {
    int pathCount = 0;
    Object object = event.getAttachedObject();
    if (object instanceof TreePath) {
        pathCount = ((TreePath) object).getPathCount();
    }
    if (node != null) {
        TreePath pathToList = myTree.getPath(node);
        while (pathToList != null) {
            final Object pathObj = pathToList.getLastPathComponent();
            if (pathObj instanceof DefaultMutableTreeNode) {
                final Object userObject = ((DefaultMutableTreeNode) pathObj).getUserObject();
                if (userObject instanceof FavoritesTreeNodeDescriptor) {
                    if (((FavoritesTreeNodeDescriptor) userObject).getElement() == node) {
                        break;
                    }
                }
            }
            pathToList = pathToList.getParentPath();
        }
        if (pathToList != null) {
            Rectangle bounds = myTree.getPathBounds(pathToList);
            if (bounds != null) {
                if (pathCount == 2) {
                    FavoritesListNode pathToReorder = FavoritesTreeViewPanel.getListNodeFromPath((TreePath) object);
                    FavoritesListNode anchorPath = FavoritesTreeViewPanel.getListNodeFromPath(pathToList);
                    boolean below = event.getPoint().y >= bounds.y + bounds.height / 2;
                    if (pathToReorder == null || anchorPath == null || !FavoritesManager.getInstance(myProject).canReorder(pathToReorder.getValue(), anchorPath.getValue(), !below)) {
                        event.hideHighlighter();
                        return;
                    }
                    if (below) {
                        bounds.y += bounds.height - 2;
                    }
                    bounds.height = 2;
                    event.setHighlighting(new RelativeRectangle(myTree, bounds), DnDEvent.DropTargetHighlightingType.RECTANGLE);
                } else {
                    event.setHighlighting(new RelativeRectangle(myTree, bounds), DnDEvent.DropTargetHighlightingType.RECTANGLE);
                }
            }
        }
    } else {
        event.hideHighlighter();
    }
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle)

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