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;
}
};
}
Aggregations