Fields Summary |
---|
private static final long | serialVersionUID |
protected static final int | DEFAULTAn int used by updateCurrentCursor()
indicating that the Cursor should change
to the default (no drop) Cursor . |
protected static final int | ENTERAn int used by updateCurrentCursor()
indicating that the Cursor
has entered a DropTarget . |
protected static final int | OVERAn int used by updateCurrentCursor()
indicating that the Cursor is
over a DropTarget . |
protected static final int | CHANGEDAn int used by updateCurrentCursor()
indicating that the user operation has changed. |
private static Transferable | emptyTransferable |
private transient DragSourceContextPeer | peer |
private DragGestureEvent | triggerThe event which triggered the start of the drag. |
private Cursor | cursorThe current drag cursor. |
private transient Transferable | transferable |
private transient DragSourceListener | listener |
private boolean | useCustomCursortrue if the custom drag cursor is used instead of the
default one. |
private final int | sourceActionsA bitwise mask of DnDConstants that represents the set of
drop actions supported by the drag source for the drag operation associated
with this DragSourceContext. |
Methods Summary |
---|
public synchronized void | addDragSourceListener(java.awt.dnd.DragSourceListener dsl)Add a DragSourceListener to this
DragSourceContext if one has not already been added.
If a DragSourceListener already exists,
this method throws a TooManyListenersException .
if (dsl == null) return;
if (equals(dsl)) throw new IllegalArgumentException("DragSourceContext may not be its own listener");
if (listener != null)
throw new TooManyListenersException();
else
listener = dsl;
|
public void | dragDropEnd(java.awt.dnd.DragSourceDropEvent dsde)Calls dragDropEnd on the
DragSourceListener s registered with this
DragSourceContext and with the associated
DragSource , and passes them the specified
DragSourceDropEvent .
DragSourceListener dsl = listener;
if (dsl != null) {
dsl.dragDropEnd(dsde);
}
getDragSource().processDragDropEnd(dsde);
|
public void | dragEnter(java.awt.dnd.DragSourceDragEvent dsde)Calls dragEnter on the
DragSourceListener s registered with this
DragSourceContext and with the associated
DragSource , and passes them the specified
DragSourceDragEvent .
DragSourceListener dsl = listener;
if (dsl != null) {
dsl.dragEnter(dsde);
}
getDragSource().processDragEnter(dsde);
updateCurrentCursor(dsde.getDropAction(), dsde.getTargetActions(), ENTER);
|
public void | dragExit(java.awt.dnd.DragSourceEvent dse)Calls dragExit on the
DragSourceListener s registered with this
DragSourceContext and with the associated
DragSource , and passes them the specified
DragSourceEvent .
DragSourceListener dsl = listener;
if (dsl != null) {
dsl.dragExit(dse);
}
getDragSource().processDragExit(dse);
updateCurrentCursor(DnDConstants.ACTION_NONE, DnDConstants.ACTION_NONE, DEFAULT);
|
public void | dragMouseMoved(java.awt.dnd.DragSourceDragEvent dsde)Calls dragMouseMoved on the
DragSourceMotionListener s registered with the
DragSource associated with this
DragSourceContext , and them passes the specified
DragSourceDragEvent .
getDragSource().processDragMouseMoved(dsde);
|
public void | dragOver(java.awt.dnd.DragSourceDragEvent dsde)Calls dragOver on the
DragSourceListener s registered with this
DragSourceContext and with the associated
DragSource , and passes them the specified
DragSourceDragEvent .
DragSourceListener dsl = listener;
if (dsl != null) {
dsl.dragOver(dsde);
}
getDragSource().processDragOver(dsde);
updateCurrentCursor(dsde.getDropAction(), dsde.getTargetActions(), OVER);
|
public void | dropActionChanged(java.awt.dnd.DragSourceDragEvent dsde)Calls dropActionChanged on the
DragSourceListener s registered with this
DragSourceContext and with the associated
DragSource , and passes them the specified
DragSourceDragEvent .
DragSourceListener dsl = listener;
if (dsl != null) {
dsl.dropActionChanged(dsde);
}
getDragSource().processDropActionChanged(dsde);
updateCurrentCursor(dsde.getDropAction(), dsde.getTargetActions(), CHANGED);
|
public java.awt.Component | getComponent()Returns the Component associated with this
DragSourceContext . return trigger.getComponent();
|
public java.awt.Cursor | getCursor()Returns the current drag Cursor .
return cursor;
|
public java.awt.dnd.DragSource | getDragSource()Returns the DragSource
that instantiated this DragSourceContext . return trigger.getDragSource();
|
public int | getSourceActions()Returns a bitwise mask of DnDConstants that
represent the set of drop actions supported by the drag source for the
drag operation associated with this DragSourceContext .
return sourceActions;
|
public java.awt.datatransfer.Transferable | getTransferable()Returns the Transferable associated with
this DragSourceContext . return transferable;
|
public java.awt.dnd.DragGestureEvent | getTrigger()Returns the DragGestureEvent
that initially triggered the drag. return trigger;
|
private void | readObject(java.io.ObjectInputStream s)Deserializes this DragSourceContext . This method first
performs default deserialization for all non-transient
fields. This object's Transferable and
DragSourceListener are then deserialized as well by using
the next two objects in the stream. If the resulting
Transferable is null , this object's
Transferable is set to a dummy Transferable
which supports no DataFlavor s.
s.defaultReadObject();
transferable = (Transferable)s.readObject();
listener = (DragSourceListener)s.readObject();
// Implementation assumes 'transferable' is never null.
if (transferable == null) {
if (emptyTransferable == null) {
emptyTransferable = new Transferable() {
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[0];
}
public boolean isDataFlavorSupported(DataFlavor flavor)
{
return false;
}
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException
{
throw new UnsupportedFlavorException(flavor);
}
};
}
transferable = emptyTransferable;
}
|
public synchronized void | removeDragSourceListener(java.awt.dnd.DragSourceListener dsl)Removes the specified DragSourceListener
from this DragSourceContext .
if (listener != null && listener.equals(dsl)) {
listener = null;
} else
throw new IllegalArgumentException();
|
public synchronized void | setCursor(java.awt.Cursor c)Sets the cursor for this drag operation to the specified
Cursor . If the specified Cursor
is null , the default drag cursor behavior is
activated for this drag operation, otherwise it is deactivated.
useCustomCursor = (c != null);
setCursorImpl(c);
|
private void | setCursorImpl(java.awt.Cursor c)
if (cursor == null || !cursor.equals(c)) {
cursor = c;
if (peer != null) peer.setCursor(cursor);
}
|
public void | transferablesFlavorsChanged()Notifies the peer that the Transferable 's
DataFlavor s have changed.
if (peer != null) peer.transferablesFlavorsChanged();
|
protected synchronized void | updateCurrentCursor(int dropOp, int targetAct, int status)If the default drag cursor behavior is active, this method
sets the default drag cursor for the specified selected
operation, supported actions and status, otherwise this
method does nothing.
// if the cursor has been previously set then dont do any defaults
// processing.
if (useCustomCursor) {
return;
}
// do defaults processing
Cursor c = null;
switch (status) {
default:
targetAct = DnDConstants.ACTION_NONE;
case ENTER:
case OVER:
case CHANGED:
int ra = dropOp & targetAct;
if (ra == DnDConstants.ACTION_NONE) { // no drop possible
if ((dropOp & DnDConstants.ACTION_LINK) == DnDConstants.ACTION_LINK)
c = DragSource.DefaultLinkNoDrop;
else if ((dropOp & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE)
c = DragSource.DefaultMoveNoDrop;
else
c = DragSource.DefaultCopyNoDrop;
} else { // drop possible
if ((ra & DnDConstants.ACTION_LINK) == DnDConstants.ACTION_LINK)
c = DragSource.DefaultLinkDrop;
else if ((ra & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE)
c = DragSource.DefaultMoveDrop;
else
c = DragSource.DefaultCopyDrop;
}
}
setCursorImpl(c);
|
private void | writeObject(java.io.ObjectOutputStream s)Serializes this DragSourceContext . This method first
performs default serialization. Next, this object's
Transferable is written out if and only if it can be
serialized. If not, null is written instead. In this case,
a DragSourceContext created from the resulting deserialized
stream will contain a dummy Transferable which supports no
DataFlavor s. Finally, this object's
DragSourceListener is written out if and only if it can be
serialized. If not, null is written instead.
s.defaultWriteObject();
s.writeObject(SerializationTester.test(transferable)
? transferable : null);
s.writeObject(SerializationTester.test(listener)
? listener : null);
|