Transferable
to and from Swing components. The Transferable
is used to
represent data that is exchanged via a cut, copy, or paste
to/from a clipboard. It is also used in drag-and-drop operations
to represent a drag from a component, and a drop to a component.
Swing provides functionality that automatically supports cut, copy,
and paste keyboard bindings that use the functionality provided by
an implementation of this class. Swing also provides functionality
that automatically supports drag and drop that uses the functionality
provided by an implementation of this class. The Swing developer can
concentrate on specifying the semantics of a transfer primarily by setting
the transferHandler
property on a Swing component.
This class is implemented to provide a default behavior of transferring
a component property simply by specifying the name of the property in
the constructor. For example, to transfer the foreground color from
one component to another either via the clipboard or a drag and drop operation
a TransferHandler
can be constructed with the string "foreground". The
built in support will use the color returned by getForeground
as the source
of the transfer, and setForeground
for the target of a transfer.
Please see How to Use Drag and Drop and Data Transfer, a section in The Java Tutorial, for more information.
Modifier and Type | Class and Description |
---|---|
private static class | TransferHandler.
This is the default drag handler for drag and drop operations that
use the |
private static class | |
public static class | TransferHandler.
Represents a location where dropped data should be inserted. |
pack-priv static interface | TransferHandler.
An interface to tag things with a |
pack-priv static class | |
private static class | |
pack-priv static class | TransferHandler.
This is the default drop target for drag and drop operations if one isn't provided by the developer. |
pack-priv static class | |
public static class | TransferHandler.
This class encapsulates all relevant details of a clipboard or drag and drop transfer, and also allows for customizing aspects of the drag and drop experience. |
Modifier and Type | Field and Description |
---|---|
public static final int | COPY
An |
public static final int | COPY_OR_MOVE
An |
pack-priv static final Action | |
pack-priv static final Action | |
private Image | dragImage
image for the |
private Point | dragImageOffset
anchor offset for the |
public static final int | LINK
An |
public static final int | MOVE
An |
public static final int | NONE
An |
pack-priv static final Action | |
private String | |
private static TransferHandler. |
Access | Constructor and Description |
---|---|
public | TransferHandler(String
the name of the property to transfer; this can
be property)null if there is no property associated with the transfer
handler (a subclass that performs some other kind of transfer, for example)Constructs a transfer handler that can transfer a Java Bean property from one component to another via the clipboard or a drag and drop operation. |
protected |
Modifier and Type | Method and Description |
---|---|
public boolean | Returns: true if the import can happen,
false otherwisethe object containing the details of
the transfer, not supportnull .This method is called repeatedly during a drag and drop operation
to allow the developer to configure properties of, and to return
the acceptability of transfers; with a return value of |
public boolean | Returns: true if the data can be inserted into the component, false otherwisethe component to receive the transfer;
provided to enable sharing of comp, DataFlavor[] TransferHandler sthe data formats available transferFlavors)Indicates whether a component will accept an import of the given set of data flavors prior to actually attempting to import it. |
protected Transferable | Returns: the representation of the data to be transferred, ornull if the property associated with c
is null the component holding the data to be transferred;
provided to enable sharing of c)TransferHandler sCreates a |
public void | exportAsDrag(JComponent
the component holding the data to be transferred;
provided to enable sharing of comp, InputEvent TransferHandler sthe event that triggered the transfer e, int the transfer action initially requested;
either action)COPY , MOVE or LINK ;
the DnD system may change the action used during the
course of the drag operationCauses the Swing drag support to be initiated. |
protected void | exportDone(JComponent
the component that was the source of the data source, Transferable The data that was transferred or possibly null
if the action is data, int NONE .the actual action that was performed action)Invoked after data has been exported. |
public void | exportToClipboard(JComponent
the component holding the data to be transferred;
provided to enable sharing of comp, Clipboard TransferHandler sthe clipboard to transfer the data into clip, int the transfer action requested; this should
be a value of either action)COPY or MOVE ;
the operation performed is the intersection of the transfer
capabilities given by getSourceActions and the requested action;
the intersection may result in an action of NONE
if the requested action isn't supportedCauses a transfer from the given component to the given clipboard. |
public static Action | Returns: anAction for performing copies to the clipboardReturns an |
public static Action | Returns: anAction for performing cuts to the clipboardReturns an |
public Image | |
public Point | Returns: aPoint object that corresponds
to coordinates of an anchor offset of the image
relative to the upper left corner of the image.
The point (0,0) returns by default.Returns an anchor offset for the image to drag. |
private static DropTargetListener | |
public static Action | Returns: anAction for performing pastes from the clipboardReturns an |
private DataFlavor | getPropertyDataFlavor(Class<?> k, DataFlavor[] flavors)
Fetches the data flavor from the array of possible flavors that has data of the type represented by property type. |
private PropertyDescriptor | getPropertyDescriptor(JComponent comp)
Fetches the property descriptor for the property assigned to this transfer handler on the given component (transfer handler may be shared). |
public int | Returns: COPY if the transfer property can be found,
otherwise returns NONE the component holding the data to be transferred;
provided to enable sharing of c)TransferHandler sReturns the type of transfer actions supported by the source;
any bitwise-OR combination of |
public Icon | Returns: null , indicating
there is no default visual representationthe data to be transferred; this value is expected to have been
created by the t)createTransferable methodReturns an object that establishes the look of a transfer. |
public boolean | Returns: true if the data was inserted into the component, false otherwisethe object containing the details of
the transfer, not supportnull .Causes a transfer to occur from a clipboard or a drag and drop operation. |
public boolean | Returns: true if the data was inserted into the component, false otherwisethe component to receive the transfer;
provided to enable sharing of comp, Transferable TransferHandler sthe data to import t)Causes a transfer to a component from a clipboard or a DND drop operation. |
public void | |
public void | setDragImageOffset(Point
a p)Point object that corresponds
to coordinates of an anchor offset of the image
relative to the upper left corner of the imageSets an anchor offset for the image to drag. |