1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48:
49: public class GtkMouseDragGestureRecognizer
50: extends MouseDragGestureRecognizer
51: {
52:
53: public GtkMouseDragGestureRecognizer (DragSource ds)
54: {
55: this(ds, null, 0, null);
56: }
57:
58: public GtkMouseDragGestureRecognizer (DragSource ds, Component c)
59: {
60: this (ds, c, 0, null);
61: }
62:
63: public GtkMouseDragGestureRecognizer (DragSource ds, Component c, int act)
64: {
65: this(ds, c, act, null);
66: }
67:
68: public GtkMouseDragGestureRecognizer (DragSource ds, Component c, int act,
69: DragGestureListener dgl)
70: {
71: super(ds, c, act, dgl);
72: }
73:
74: public void registerListeners ()
75: {
76: super.registerListeners();
77: }
78:
79: public void unregisterListeners ()
80: {
81: super.unregisterListeners();
82: }
83:
84: public void mouseClicked (MouseEvent e)
85: {
86:
87: }
88:
89: public void mousePressed (MouseEvent e)
90: {
91: events.clear();
92: if (getDropActionFromEvent(e) != DnDConstants.ACTION_NONE)
93: appendEvent(e);
94: }
95:
96: public void mouseReleased (MouseEvent e)
97: {
98: events.clear();
99: }
100:
101: public void mouseEntered (MouseEvent e)
102: {
103: events.clear();
104: }
105:
106: public void mouseExited(MouseEvent e)
107: {
108: if (!events.isEmpty())
109: if (getDropActionFromEvent(e) == DnDConstants.ACTION_NONE)
110: events.clear();
111: }
112:
113: public void mouseDragged(MouseEvent e)
114: {
115: if (!events.isEmpty())
116: {
117: int act = getDropActionFromEvent(e);
118:
119: if (act == DnDConstants.ACTION_NONE)
120: return;
121:
122: Point origin = ((MouseEvent) events.get(0)).getPoint();
123: Point current = e.getPoint();
124: int dx = Math.abs(origin.x - current.x);
125: int dy = Math.abs(origin.y - current.y);
126: int threshold = DragSource.getDragThreshold();
127:
128: if (dx > threshold || dy > threshold)
129: fireDragGestureRecognized(act, origin);
130: else
131: appendEvent(e);
132: }
133: }
134:
135: public void mouseMoved (MouseEvent e)
136: {
137:
138: }
139:
140: private int getDropActionFromEvent(MouseEvent e)
141: {
142: int modEx = e.getModifiersEx();
143: int buttons = modEx & (MouseEvent.BUTTON1_DOWN_MASK
144: | MouseEvent.BUTTON2_DOWN_MASK | MouseEvent.BUTTON3_DOWN_MASK);
145: if (!(buttons == MouseEvent.BUTTON1_DOWN_MASK ||
146: buttons == MouseEvent.BUTTON2_DOWN_MASK))
147: return DnDConstants.ACTION_NONE;
148:
149:
150: int sourceActions = getSourceActions();
151: int mod = modEx
152: & (MouseEvent.SHIFT_DOWN_MASK | MouseEvent.CTRL_DOWN_MASK);
153: switch (mod)
154: {
155: case MouseEvent.SHIFT_DOWN_MASK | MouseEvent.CTRL_DOWN_MASK:
156: return DnDConstants.ACTION_LINK & sourceActions;
157: case MouseEvent.CTRL_DOWN_MASK:
158: return DnDConstants.ACTION_COPY & sourceActions;
159: case MouseEvent.SHIFT_DOWN_MASK:
160: return DnDConstants.ACTION_MOVE & sourceActions;
161: default:
162: if ((sourceActions & DnDConstants.ACTION_MOVE) != 0)
163: return DnDConstants.ACTION_MOVE & sourceActions;
164: else if ((sourceActions & DnDConstants.ACTION_COPY) != 0)
165: return DnDConstants.ACTION_COPY & sourceActions;
166: else if ((sourceActions & DnDConstants.ACTION_LINK) != 0)
167: return DnDConstants.ACTION_LINK & sourceActions;
168: }
169:
170: return DnDConstants.ACTION_NONE & sourceActions;
171: }
172: }