This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


javax.swing
class TransferHandler.TransferSupport

java.lang.Object extended by javax.swing.TransferHandler.TransferSupport
Enclosing class:
TransferHandler

public static final class TransferHandler.TransferSupport
extends Object

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.

The main purpose of this class is to provide the information needed by a developer to determine the suitability of a transfer or to import the data contained within. But it also doubles as a controller for customizing properties during drag and drop, such as whether or not to show the drop location, and which drop action to use.

Developers typically need not create instances of this class. Instead, they are something provided by the DnD implementation to certain methods in TransferHandler.


Constructor Summary

          Create a TransferSupport with isDrop() false for the given component and Transferable.
 
Method Summary
 Component

          Returns the target component of this transfer.
 DataFlavor[]

          Returns the data flavors for this transfer.
 int

          Returns the action chosen for the drop, when this represents a drop.
 TransferHandler.DropLocation

          Returns the current (non-) drop location for the component, when this represents a drop.
 int

          Returns the drag source's supported drop actions, when this represents a drop.
 Transferable

          Returns the Transferable associated with this transfer.
 int

          Returns the user drop action for the drop, when this represents a drop.
 boolean

          Returns whether or not the given data flavor is supported.
 boolean

          Returns whether or not this TransferSupport represents a drop operation.
 void
setDropAction(int dropAction)

          Sets the drop action for the transfer - which must represent a drop - to the given action, instead of the default user drop action.
 void
setShowDropLocation(boolean showDropLocation)

          Sets whether or not the drop location should be visually indicated for the transfer - which must represent a drop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransferHandler.TransferSupport

public TransferHandler.TransferSupport(Component component,
                                       Transferable transferable)
Create a TransferSupport with isDrop() false for the given component and Transferable.

Parameters:
component - the target component
transferable - the transferable
Method Detail

getComponent

public Component getComponent()
Returns the target component of this transfer.

Returns:
the target component

getDataFlavors

public DataFlavor[] getDataFlavors()
Returns the data flavors for this transfer.

Returns:
the data flavors for this transfer

getDropAction

public int getDropAction()
Returns the action chosen for the drop, when this {@code TransferSupport} represents a drop.

Unless explicitly chosen by way of {@code setDropAction}, this returns the user drop action provided by {@code getUserDropAction}.

You may wish to query this in {@code TransferHandler}'s {@code importData} method to customize processing based on the action.

This method is only for use with drag and drop transfers. Calling it when {@code isDrop()} is {@code false} results in an {@code IllegalStateException}.

Returns:
the action chosen for the drop

getDropLocation

public TransferHandler.DropLocation getDropLocation()
Returns the current (non-{@code null}) drop location for the component, when this {@code TransferSupport} represents a drop.

Note: For components with built-in drop support, this location will be a subclass of {@code DropLocation} of the same type returned by that component's {@code getDropLocation} method.

This method is only for use with drag and drop transfers. Calling it when {@code isDrop()} is {@code false} results in an {@code IllegalStateException}.

Returns:
the drop location

getSourceDropActions

public int getSourceDropActions()
Returns the drag source's supported drop actions, when this {@code TransferSupport} represents a drop.

The source actions represent the set of actions supported by the source of this transfer, and are represented as some bitwise-OR combination of {@code COPY}, {@code MOVE} and {@code LINK}. You may wish to query this in {@code TransferHandler}'s {@code canImport} method when determining the suitability of a drop or when deciding on a drop action to explicitly choose. To determine if a particular action is supported by the source, bitwise-AND the action with the source drop actions, and then compare the result against the original action. For example:

 boolean copySupported = (COPY & getSourceDropActions()) == COPY;
 

This method is only for use with drag and drop transfers. Calling it when {@code isDrop()} is {@code false} results in an {@code IllegalStateException}.

Returns:
the drag source's supported drop actions

getTransferable

public Transferable getTransferable()
Returns the Transferable associated with this transfer.

Note: Unless it is necessary to fetch the Transferable directly, use one of the other methods on this class to inquire about the transfer. This may perform better than fetching the Transferable and asking it directly.

Returns:
the Transferable associated with this transfer

getUserDropAction

public int getUserDropAction()
Returns the user drop action for the drop, when this {@code TransferSupport} represents a drop.

The user drop action is chosen for a drop as described in the documentation for {@link java.awt.dnd.DropTargetDragEvent} and {@link java.awt.dnd.DropTargetDropEvent}. A different action may be chosen as the drop action by way of the {@code setDropAction} method.

You may wish to query this in {@code TransferHandler}'s {@code canImport} method when determining the suitability of a drop or when deciding on a drop action to explicitly choose.

This method is only for use with drag and drop transfers. Calling it when {@code isDrop()} is {@code false} results in an {@code IllegalStateException}.

Returns:
the user drop action

isDataFlavorSupported

public boolean isDataFlavorSupported(DataFlavor df)
Returns whether or not the given data flavor is supported.

Parameters:
df - the DataFlavor to test
Returns:
whether or not the given flavor is supported.

isDrop

public boolean isDrop()
Returns whether or not this TransferSupport represents a drop operation.

Returns:
true if this is a drop operation, false otherwise.

setDropAction

public void setDropAction(int dropAction)
Sets the drop action for the transfer - which must represent a drop - to the given action, instead of the default user drop action. The action must be supported by the source's drop actions, and must be one of {@code COPY}, {@code MOVE} or {@code LINK}.

This method is only for use with drag and drop transfers. Calling it when {@code isDrop()} is {@code false} results in an {@code IllegalStateException}.

Parameters:
dropAction - the drop action

setShowDropLocation

public void setShowDropLocation(boolean showDropLocation)
Sets whether or not the drop location should be visually indicated for the transfer - which must represent a drop. This is applicable to those components that automatically show the drop location when appropriate during a drag and drop operation). By default, the drop location is shown only when the {@code TransferHandler} has said it can accept the import represented by this {@code TransferSupport}. With this method you can force the drop location to always be shown, or always not be shown.

This method is only for use with drag and drop transfers. Calling it when {@code isDrop()} is {@code false} results in an {@code IllegalStateException}.

Parameters:
showDropLocation - whether or not to indicate the drop location


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.