|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.TransferHandler be.ugent.caagt.swirl.dnd.LocalTransferHandler
public class LocalTransferHandler
Transfer handler for drag and drop of objects within
the same virtual machine. Differs from the standard TransferHandler
in the following ways:
DragHandler
.
LocalTransferHandler handler = new LocalTransferHandler (); handler.setDragHandler (someDragHandler); handler.addDropHandler (handlerForSomeClass); handler.addDropHandler (handlerForSomeOtherClass); ... parent.setDragEnabled (true); parent.setTransferHandler (handler);Clients may choose to register handlers as part of the constructor of an extension of this class.
isTransferAllowed(javax.swing.JComponent, javax.swing.JComponent)
, exportDone(javax.swing.JComponent, javax.swing.JComponent, java.lang.Object[], java.lang.Class>, int)
provide both a source
and target
parameter which can be used by client implementations. Because
Swing support for this kind of information is poor (at least in versions of Java prior
to 6.0), source and target references
are stored as static variables of this class. As a consequence, they are only
reliable when the transfer handler for both source and target are of type
LocalTransferHandler
.
Note Like TransferHandler
, objects of this class can be shared
by different components.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.TransferHandler |
---|
javax.swing.TransferHandler.DropLocation, javax.swing.TransferHandler.TransferSupport |
Field Summary |
---|
Fields inherited from class javax.swing.TransferHandler |
---|
COPY, COPY_OR_MOVE, LINK, MOVE, NONE |
Constructor Summary | |
---|---|
LocalTransferHandler()
Create a handler of this type. |
Method Summary | |
---|---|
void |
addDropHandler(DropHandler handler)
Register a drop handler. |
boolean |
canImport(javax.swing.JComponent comp,
java.awt.datatransfer.DataFlavor[] transferFlavors)
Overrides the standard functionality of TransferHandler by delegating
to the individual drop handlers registered with this object. |
protected java.awt.datatransfer.Transferable |
createTransferable(javax.swing.JComponent comp)
Creates a transferable encapsulating the objects returned by getExportedObjects(javax.swing.JComponent) with a data flavor derived from the value
of getExportedClass(javax.swing.JComponent) . |
protected void |
exportDone(javax.swing.JComponent source,
javax.swing.JComponent target,
java.lang.Object[] objects,
java.lang.Class<?> type,
int action)
Invoked after data have been dragged-and-dropped from a component managed by this handler. |
protected void |
exportDone(javax.swing.JComponent source,
java.awt.datatransfer.Transferable data,
int action)
Delegates to exportDone(javax.swing.JComponent, javax.swing.JComponent, java.lang.Object[], java.lang.Class>, int) . |
DragHandler |
getDragHandler()
Return the drag handler used by this transfer handler, or null
when none is registered. |
protected java.lang.Class |
getExportedClass(javax.swing.JComponent source)
Return the class of objects being exported. |
protected java.lang.Object |
getExportedObjects(javax.swing.JComponent source)
Return the object(s) to be exported by a drag-and-drop or cut-and-paste operation. |
int |
getSourceActions(javax.swing.JComponent source)
Returns the type of transfer actions supported by the given source component. |
boolean |
importData(javax.swing.JComponent comp,
java.awt.datatransfer.Transferable t)
Overrides the standard functionality of TransferHandler by delegating
to the individual drop handlers registered with this object. |
protected boolean |
isTransferAllowed(javax.swing.JComponent source,
javax.swing.JComponent target)
Indicates whether a transfer from a given source to given destination is allowed. |
void |
setDragHandler(DragHandler dragHandler)
Install a drag handler. |
Methods inherited from class javax.swing.TransferHandler |
---|
canImport, exportAsDrag, exportToClipboard, getCopyAction, getCutAction, getPasteAction, getVisualRepresentation, importData |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LocalTransferHandler()
Method Detail |
---|
public void addDropHandler(DropHandler handler)
handler.acceptDrop
.
public void setDragHandler(DragHandler dragHandler)
public DragHandler getDragHandler()
null
when none is registered.
protected boolean isTransferAllowed(javax.swing.JComponent source, javax.swing.JComponent target)
Delegates to the drag handler, or returns true when no drag handler is registered.
source
- The component that is the source of the data.target
- The component that is the target of the data, or null
if the target transfer handler is not of this type.public boolean canImport(javax.swing.JComponent comp, java.awt.datatransfer.DataFlavor[] transferFlavors)
TransferHandler
by delegating
to the individual drop handlers registered with this object.
Note: At this point it is not always possible to recognize a multiple
drag onto a drop target that only accepts single elements. This special case
is handled by a subsequent call to importData(javax.swing.JComponent, java.awt.datatransfer.Transferable)
.
canImport
in class javax.swing.TransferHandler
public boolean importData(javax.swing.JComponent comp, java.awt.datatransfer.Transferable t)
TransferHandler
by delegating
to the individual drop handlers registered with this object.
importData
in class javax.swing.TransferHandler
public int getSourceActions(javax.swing.JComponent source)
TransferHandler.COPY
, TransferHandler.MOVE
,
TransferHandler.COPY_OR_MOVE
, TransferHandler.LINK
or TransferHandler.NONE
. This implementation
delegates to the drag handler if it exists or otherwise returns
NONE
.
getSourceActions
in class javax.swing.TransferHandler
protected void exportDone(javax.swing.JComponent source, javax.swing.JComponent target, java.lang.Object[] objects, java.lang.Class<?> type, int action)
MOVE
and source and target are not the same (or are not views
of the same model),
the objects need to be removed from the source. When the
action is COPY
or LINK
, nothing needs to be done.This implementation delegates to the drag handler if one is registered and otherwise does nothing.
objects
- Array of objects which have been exportedtype
- Element type of this arrayaction
- the actual action that was performed, will never be NONEsource
- The component that is the source of the data.target
- The component that was the target of the data, or null
if the source transfer handler is not of this type.protected final void exportDone(javax.swing.JComponent source, java.awt.datatransfer.Transferable data, int action)
exportDone(javax.swing.JComponent, javax.swing.JComponent, java.lang.Object[], java.lang.Class>, int)
.
exportDone
in class javax.swing.TransferHandler
protected java.lang.Object getExportedObjects(javax.swing.JComponent source)
This implementation delegates to the drag handler if one is registered.
source
- component from which data should be exportedprotected java.lang.Class getExportedClass(javax.swing.JComponent source)
getExportedObjects(javax.swing.JComponent)
is used, or the element type if an array is returned.This implementation delegates to drag handler if one is registered and returns null otherwise. This implementation delegates to the drag handler if one is registered.
source
- component from which data should be exportedprotected final java.awt.datatransfer.Transferable createTransferable(javax.swing.JComponent comp)
getExportedObjects(javax.swing.JComponent)
with a data flavor derived from the value
of getExportedClass(javax.swing.JComponent)
.
createTransferable
in class javax.swing.TransferHandler
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |