-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0, 1.2.2
-
beta3
-
x86, sparc
-
solaris_2.5, windows_nt
Name: krT82822 Date: 10/27/99
When you create a DragGestureRecognizer to make it so if the control key is down, it is a move and the default is a copy (no modifiers), you get a loss of information because it is hardcoded in the native implementation. An example is included that shows that if fires with the action of DnDConstants.ACTION_COPY when the control key is NOT pressed, and you will notice that in the gestureRecognized event on the listener, it will be correct saying it a COPY action, but when the listener gets the events for a DragListener or DropListener, the event action is changed from a copy back to a move. I looked at the win32 native implementation in the file "awt_DnDDS.cpp" and "awt_DnDDT.cpp" and you will notice that when it maps from an "effect" back to a java "action", it is hardcoded and does not give you the same result that was fired when it was recognized. It should ask something in java like the gesture recognizer for a mapping so it can be consistent with custom recognizers.
public class CustomizableDragGestureRecognizer extends MouseDragGestureRecognizer {
protected static final int motionThreshold = getMotionThreshold();
protected static final int ButtonMask = InputEvent.BUTTON1_MASK | InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK;
protected static final int ModMask = InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK;
protected CustomizableDragGestureRecognizer(DragSource source, Component component,
int actions, DragGestureListener listener) {
super(source, component, actions, listener);
}
private static int getMotionThreshold() {
try {
return ((Integer)Toolkit.getDefaultToolkit().getDesktopProperty("DnD.gestureMotionThreshold")).intValue();
} catch (Exception e) {
//return a default
return 5;
}
}
protected int mapDragOperationFromModifiers(MouseEvent event) {
int mods = event.getModifiers();
int btns = mods & ButtonMask;
if ((mods & ~(ButtonMask | ModMask)) != 0 ||
!(btns == InputEvent.BUTTON1_MASK ||
btns == InputEvent.BUTTON2_MASK ||
btns == InputEvent.BUTTON3_MASK
)
) {
return DnDConstants.ACTION_NONE;
}
if ((mods &= ModMask) == 0)
//return DnDConstants.ACTION_MOVE;
return DnDConstants.ACTION_COPY;
else if (mods == ModMask)
return DnDConstants.ACTION_LINK;
else if (mods == InputEvent.CTRL_MASK)
return DnDConstants.ACTION_COPY;
//return DnDConstants.ACTION_MOVE;
else {
return DnDConstants.ACTION_NONE;
}
}
public void mousePressed(MouseEvent event) {
resetRecognizer();
if (mapDragOperationFromModifiers(event) != DnDConstants.ACTION_NONE) {
appendEvent(event);
}
}
public void mouseReleased(MouseEvent event) {
resetRecognizer();
}
public void mouseEntered(MouseEvent event) {
resetRecognizer();
}
public void mouseExited(MouseEvent event) {
if (!events.isEmpty()) {
// a gesture is pending
int dragAction = mapDragOperationFromModifiers(event);
if (dragAction != DnDConstants.ACTION_NONE) {
appendEvent(event);
fireDragGestureRecognized(dragAction, ((MouseEvent)getTriggerEvent()).getPoint());
} else {
resetRecognizer();
}
}
}
public void mouseDragged(MouseEvent event) {
if (!events.isEmpty()) {
// a gesture is pending
int op = mapDragOperationFromModifiers(event);
if (op == DnDConstants.ACTION_NONE) {
return;
}
MouseEvent trigger = (MouseEvent)events.get(0);
Point origin = trigger.getPoint();
Point current = event.getPoint();
int dx = Math.abs(origin.x - current.x);
int dy = Math.abs(origin.y - current.y);
if (dx > motionThreshold || dy > motionThreshold) {
System.out.println("op is "+ op);
System.out.println("copy is " + DnDConstants.ACTION_COPY);
fireDragGestureRecognized(op, ((MouseEvent)getTriggerEvent()).getPoint());
} else {
appendEvent(event);
}
}
}
//do nothing for these events
public void mouseMoved(MouseEvent event) { }
public void mouseClicked(MouseEvent event) { }
}
(Review ID: 96932)
======================================================================
- duplicates
-
JDK-4143344 unclear spec for java.awt.dnd.DropTargetDragEvent
-
- Closed
-