1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52:
53:
57: public abstract class DragGestureRecognizer implements Serializable
58: {
59:
62: private static final long serialVersionUID = 8996673345831063337L;
63:
64: protected DragSource dragSource;
65: protected Component component;
66: protected transient DragGestureListener dragGestureListener;
67: protected int sourceActions;
68: protected ArrayList events = new ArrayList();
69:
70: protected DragGestureRecognizer(DragSource ds, Component c, int sa,
71: DragGestureListener dgl)
72: {
73: if (ds == null)
74: throw new IllegalArgumentException();
75: dragSource = ds;
76: component = c;
77: sourceActions = sa;
78: dragGestureListener = dgl;
79: }
80:
81: protected DragGestureRecognizer(DragSource ds, Component c, int sa)
82: {
83: this(ds, c, sa, null);
84: }
85:
86: protected DragGestureRecognizer(DragSource ds, Component c)
87: {
88: this(ds, c, 0, null);
89: }
90:
91: protected DragGestureRecognizer(DragSource ds)
92: {
93: this(ds, null, 0, null);
94: }
95:
96: protected abstract void registerListeners();
97:
98: protected abstract void unregisterListeners();
99:
100: public DragSource getDragSource()
101: {
102: return dragSource;
103: }
104:
105: public Component getComponent()
106: {
107: return component;
108: }
109:
110: public void setComponent(Component c)
111: {
112: component = c;
113: }
114:
115: public int getSourceActions()
116: {
117: return sourceActions;
118: }
119:
120: public void setSourceActions(int sa)
121: {
122: sourceActions = sa;
123: }
124:
125: public InputEvent getTriggerEvent()
126: {
127: return events.size() > 0 ? (InputEvent) events.get(0) : null;
128: }
129:
130: public void resetRecognizer()
131: throws NotImplementedException
132: {
133: events = new ArrayList();
134: }
135:
136:
142: public void addDragGestureListener(DragGestureListener dgl)
143: throws TooManyListenersException
144: {
145: if (dragGestureListener != null)
146: throw new TooManyListenersException();
147: dragGestureListener = dgl;
148: }
149:
150: public void removeDragGestureListener(DragGestureListener dgl)
151: {
152: if (dragGestureListener != dgl)
153: throw new IllegalArgumentException();
154: dragGestureListener = null;
155: }
156:
157:
161: protected void fireDragGestureRecognized(int dragAction, Point p)
162: {
163: if(dragGestureListener != null)
164: dragGestureListener.dragGestureRecognized
165: (new DragGestureEvent(this, dragAction, p, events));
166: }
167:
168: protected void appendEvent(InputEvent e)
169: {
170: if (e == null)
171: return;
172: events.add(e);
173: }
174:
175: private void readObject(ObjectInputStream s)
176: throws ClassNotFoundException, IOException
177: {
178: s.defaultReadObject();
179: dragGestureListener = (DragGestureListener) s.readObject();
180: }
181:
182: private void writeObject(ObjectOutputStream s) throws IOException
183: {
184: s.defaultWriteObject();
185: s.writeObject(dragGestureListener instanceof Serializable
186: ? dragGestureListener : null);
187: }
188: }