DragGestureRecognizer.java [plain text]
package java.awt.dnd;
import java.awt.Component;
import java.awt.Point;
import java.awt.event.InputEvent;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.TooManyListenersException;
public abstract class DragGestureRecognizer implements Serializable
{
private static final long serialVersionUID = 8996673345831063337L;
protected DragSource dragSource;
protected Component component;
protected transient DragGestureListener dragGestureListener;
protected int sourceActions;
protected ArrayList events = new ArrayList();
protected DragGestureRecognizer(DragSource ds, Component c, int sa,
DragGestureListener dgl)
{
if (ds == null)
throw new IllegalArgumentException();
dragSource = ds;
component = c;
sourceActions = sa;
dragGestureListener = dgl;
}
protected DragGestureRecognizer(DragSource ds, Component c, int sa)
{
this(ds, c, sa, null);
}
protected DragGestureRecognizer(DragSource ds, Component c)
{
this(ds, c, 0, null);
}
protected DragGestureRecognizer(DragSource ds)
{
this(ds, null, 0, null);
}
protected abstract void registerListeners();
protected abstract void unregisterListeners();
public DragSource getDragSource()
{
return dragSource;
}
public Component getComponent()
{
return component;
}
public void setComponent(Component c)
{
component = c;
}
public int getSourceActions()
{
return sourceActions;
}
public void setSourceActions(int sa)
{
sourceActions = sa;
}
public InputEvent getTriggerEvent()
{
return events.size() > 0 ? (InputEvent) events.get(0) : null;
}
public void resetRecognizer()
{
throw new Error("not implemented");
}
public void addDragGestureListener(DragGestureListener dgl)
throws TooManyListenersException
{
if (dragGestureListener != null)
throw new TooManyListenersException();
dragGestureListener = dgl;
}
public void removeDragGestureListener(DragGestureListener dgl)
{
if (dragGestureListener != dgl)
throw new IllegalArgumentException();
dragGestureListener = null;
}
protected void fireDragGestureRecognized(int dragAction, Point p)
{
throw new Error("not implemented");
}
protected void appendEvent(InputEvent e)
{
if (e == null)
return;
events.add(e);
}
private void readObject(ObjectInputStream s)
throws ClassNotFoundException, IOException
{
s.defaultReadObject();
dragGestureListener = (DragGestureListener) s.readObject();
}
private void writeObject(ObjectOutputStream s) throws IOException
{
s.defaultWriteObject();
s.writeObject(dragGestureListener instanceof Serializable
? dragGestureListener : null);
}
}