public class TransferHandler extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
static int |
COPY |
static int |
COPY_OR_MOVE |
static int |
MOVE |
static int |
NONE |
Modifier | Constructor and Description |
---|---|
protected |
TransferHandler() |
|
TransferHandler(String property) |
Modifier and Type | Method and Description |
---|---|
boolean |
canImport(JComponent c,
DataFlavor[] flavors)
Returns
true if the data in this TransferHandler can be
imported into the specified component. |
protected Transferable |
createTransferable(JComponent c)
Creates a
Transferable that can be used to export data
from the specified component. |
void |
exportAsDrag(JComponent c,
InputEvent e,
int action) |
protected void |
exportDone(JComponent c,
Transferable data,
int action)
This method is invoked after data has been exported.
|
void |
exportToClipboard(JComponent c,
Clipboard clip,
int action)
Exports the property of the component
c that was
specified for this TransferHandler to the clipboard, performing
the specified action. |
static Action |
getCopyAction() |
static Action |
getCutAction() |
static Action |
getPasteAction() |
int |
getSourceActions(JComponent c) |
Icon |
getVisualRepresentation(Transferable t) |
boolean |
importData(JComponent c,
Transferable t)
Imports the transfer data represented by
t into the specified
component c by setting the property of this TransferHandler
on that component. |
public static final int NONE
public static final int COPY
public static final int MOVE
public static final int COPY_OR_MOVE
protected TransferHandler()
public TransferHandler(String property)
public static Action getCopyAction()
public static Action getCutAction()
public static Action getPasteAction()
public boolean canImport(JComponent c, DataFlavor[] flavors)
true
if the data in this TransferHandler can be
imported into the specified component. This will be the case when:
application/x-java-jvm-local-object-ref
.c
- the component to checkflavors
- the possible data flavorstrue
if the data in this TransferHandler can be
imported into the specified component, false
otherwiseprotected Transferable createTransferable(JComponent c)
Transferable
that can be used to export data
from the specified component.
This method returns null
when the specified component
doesn't have a readable property that matches the property name
specified in the TransferHandler
constructor.c
- the component to create a transferable forTransferable
that can be used to export data
from the specified component, or null if the component doesn't
have a readable property like the transfer handlerpublic void exportAsDrag(JComponent c, InputEvent e, int action)
protected void exportDone(JComponent c, Transferable data, int action)
MOVE
.
The default implementation does nothing because MOVE is not supported.c
- the source componentdata
- the data that has been transferred or null
when the action is NONEaction
- the action that has been performedpublic void exportToClipboard(JComponent c, Clipboard clip, int action) throws IllegalStateException
c
that was
specified for this TransferHandler to the clipboard, performing
the specified action.
This will check if the action is allowed by calling
getSourceActions(JComponent)
. If the action is not allowed,
then no export is performed.
In either case the method exportDone(javax.swing.JComponent, java.awt.datatransfer.Transferable, int)
will be called with
the action that has been performed, or NONE
if the action
was not allowed or could otherwise not be completed.
Any IllegalStateException that is thrown by the Clipboard due to
beeing unavailable will be propagated through this method.c
- the component from which to exportclip
- the clipboard to which the data will be exportedaction
- the action to performIllegalStateException
- when the clipboard is not availablepublic int getSourceActions(JComponent c)
public Icon getVisualRepresentation(Transferable t)
public boolean importData(JComponent c, Transferable t)
t
into the specified
component c
by setting the property of this TransferHandler
on that component. If this succeeds, this method returns
true
, otherwise false
.c
- the component to import intot
- the transfer data to importtrue
if the transfer succeeds, false
otherwise