Search in sources :

Example 1 with MouseEventAdapter

use of com.intellij.util.ui.MouseEventAdapter in project intellij-community by JetBrains.

the class WideSelectionTreeUI method createMouseListener.

@Override
protected MouseListener createMouseListener() {
    return new MouseEventAdapter<MouseListener>(super.createMouseListener()) {

        @Override
        public void mouseDragged(MouseEvent event) {
            JTree tree = (JTree) event.getSource();
            // DnDManagerImpl.SOURCE_KEY
            Object property = tree.getClientProperty("DnD Source");
            if (property == null) {
                // use Swing-based DnD only if custom DnD is not set 
                super.mouseDragged(event);
            }
        }

        @NotNull
        @Override
        protected MouseEvent convert(@NotNull MouseEvent event) {
            if (!event.isConsumed() && SwingUtilities.isLeftMouseButton(event)) {
                int x = event.getX();
                int y = event.getY();
                JTree tree = (JTree) event.getSource();
                if (tree.isEnabled()) {
                    TreePath path = getClosestPathForLocation(tree, x, y);
                    if (path != null && !isLocationInExpandControl(path, x, y)) {
                        Rectangle bounds = getPathBounds(tree, path);
                        if (bounds != null && bounds.y <= y && y <= (bounds.y + bounds.height)) {
                            x = Math.max(bounds.x, Math.min(x, bounds.x + bounds.width - 1));
                            if (x != event.getX()) {
                                event = convert(event, tree, x, y);
                            }
                        }
                    }
                }
            }
            return event;
        }
    };
}
Also used : MouseEvent(java.awt.event.MouseEvent) TreePath(javax.swing.tree.TreePath) MouseEventAdapter(com.intellij.util.ui.MouseEventAdapter) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MouseEventAdapter (com.intellij.util.ui.MouseEventAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 TreePath (javax.swing.tree.TreePath)1 NotNull (org.jetbrains.annotations.NotNull)1