use of org.netbeans.swing.tabcontrol.customtabs.Tabbed in project netbeans-rcp-lite by outersky.
the class TopComponentDragSupport method eventDispatched.
/**
* Simulates drag gesture recongition valid for winsys.
* Implements <code>AWTEventListener</code>.
*/
@Override
public void eventDispatched(AWTEvent evt) {
MouseEvent me = (MouseEvent) evt;
// #118828
if (!(evt.getSource() instanceof Component)) {
return;
}
// #40736: only left mouse button drag should start DnD
if ((me.getID() == MouseEvent.MOUSE_PRESSED) && SwingUtilities.isLeftMouseButton(me)) {
startingPoint = me.getPoint();
startingComponent = me.getComponent();
startingTime = me.getWhen();
} else if (me.getID() == MouseEvent.MOUSE_RELEASED) {
startingPoint = null;
startingComponent = null;
}
if (me.isConsumed())
return;
if (evt.getID() != MouseEvent.MOUSE_DRAGGED) {
return;
}
if (windowDnDManager.isDragging()) {
return;
}
if (startingPoint == null) {
return;
}
if (evt.getSource() instanceof JButton) {
// do not initiate topcomponent drag when the mouse is dragged out of a tabcontrol button
return;
}
if (!WindowDnDManager.isDnDEnabled()) {
return;
}
Component srcComp = startingComponent;
if (srcComp == null) {
return;
}
final Point point = new Point(startingPoint);
Point currentPoint = me.getPoint();
Component currentComponent = me.getComponent();
if (currentComponent == null) {
return;
}
currentPoint = SwingUtilities.convertPoint(currentComponent, currentPoint, srcComp);
if (Math.abs(currentPoint.x - point.x) <= Constants.DRAG_GESTURE_START_DISTANCE && Math.abs(currentPoint.y - point.y) <= Constants.DRAG_GESTURE_START_DISTANCE) {
return;
}
// time check, to prevent wild mouse clicks to be considered DnD start
if (me.getWhen() - startingTime <= Constants.DRAG_GESTURE_START_TIME) {
return;
}
startingPoint = null;
startingComponent = null;
if (DEBUG) {
// NOI18N
debugLog("");
// NOI18N
debugLog("eventDispatched (MOUSE_DRAGGED)");
}
// XXX Do not clash with JTree (e.g. in explorer) drag.
if ((srcComp instanceof JTree) && ((JTree) srcComp).getPathForLocation(me.getX(), me.getY()) != null) {
return;
}
// #22622: AWT listener just passivelly listnens what is happenning around,
// and we need always the deepest component to start from.
srcComp = SwingUtilities.getDeepestComponentAt(srcComp, point.x, point.y);
boolean ctrlDown = me.isControlDown();
TopComponent tc = null;
Tabbed tabbed;
if (srcComp instanceof Tabbed.Accessor) {
tabbed = ((Tabbed.Accessor) srcComp).getTabbed();
} else {
Tabbed.Accessor acc = (Tabbed.Accessor) SwingUtilities.getAncestorOfClass(Tabbed.Accessor.class, srcComp);
tabbed = acc != null ? acc.getTabbed() : null;
}
if (tabbed == null) {
return;
}
// #22132. If in modal dialog no drag allowed.
Dialog dlg = (Dialog) SwingUtilities.getAncestorOfClass(Dialog.class, tabbed.getComponent());
if (dlg != null && dlg.isModal()) {
return;
}
Point ppp = new Point(point);
Point p = SwingUtilities.convertPoint(srcComp, ppp, tabbed.getComponent());
TopComponentDraggable draggable = null;
// #106761: tabForCoordinate may return -1, so check is needed
int tabIndex = tabbed.tabForCoordinate(p);
tc = tabIndex != -1 ? tabbed.getTopComponentAt(tabIndex) : null;
if (tc == null) {
Rectangle tabsArea = tabbed.getTabsArea();
if (tabsArea.contains(p)) {
TopComponent[] tcs = tabbed.getTopComponents();
if (null != tcs && tcs.length > 0) {
ModeImpl mode = (ModeImpl) WindowManagerImpl.getInstance().findMode(tcs[0]);
if (null != mode && ((mode.getKind() == Constants.MODE_KIND_EDITOR && Switches.isEditorModeDragAndDropEnabled()) || (mode.getKind() == Constants.MODE_KIND_VIEW && Switches.isViewModeDragAndDropEnabled()))) {
draggable = new TopComponentDraggable(mode);
}
}
}
} else {
if (Switches.isTopComponentDragAndDropEnabled() && Switches.isDraggingEnabled(tc)) {
ModeImpl mode = (ModeImpl) WindowManagerImpl.getInstance().findMode(tc);
if (null != mode)
draggable = new TopComponentDraggable(tc);
}
}
if (null == draggable)
return;
// #21918. See above.
if (ctrlDown) {
hackUserDropAction = DnDConstants.ACTION_COPY;
} else {
hackUserDropAction = DnDConstants.ACTION_MOVE;
}
List<MouseEvent> list = new ArrayList<MouseEvent>();
list.add(me);
// Get start droppable (if there) and its starting point.
TopComponentDroppable startDroppable = (TopComponentDroppable) SwingUtilities.getAncestorOfClass(TopComponentDroppable.class, null == tc ? tabbed.getComponent() : tc);
Point startPoint;
if (startDroppable == null && tc != null) {
startDroppable = (TopComponentDroppable) SwingUtilities.getAncestorOfClass(TopComponentDroppable.class, tabbed.getComponent());
}
if (startDroppable != null) {
startPoint = point;
Point pp = new Point(point);
startPoint = SwingUtilities.convertPoint(srcComp, pp, (Component) startDroppable);
} else {
startPoint = null;
}
// dragSource.startDrag(event, Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR) ,image , new Point(-offX, -offY),text, this);
doStartDrag(srcComp, draggable, new DragGestureEvent(new FakeDragGestureRecognizer(windowDnDManager, me), hackUserDropAction, point, list), startDroppable, startPoint);
}
Aggregations