JDK-4290983 : Drag and Drop Support for Swing Components
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0,1.2.1,1.2.2,1.3.0,1.4.0,1.4.2
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    generic,solaris_2.6,windows_nt,windows_2000,windows_xp generic,solaris_2.6,windows_nt,windows_2000,windows_xp
  • CPU: generic,x86
  • Submitted: 1999-11-12
  • Updated: 2000-10-24
  • Resolved: 2000-10-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 betaFixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description

Name: rb24441			Date: 03/16/00

While support for Drag and Drop has been available since JDK 1.2, usage 
in Java Foundation Classes required unique developer implementations on a per
component basis. In JDK1.3 default Drag and Drop implementations will be made
available on JText, JList, JTree, JLabel, and JTable components. Additional APIs
will be added to activate alternative Drag and Drop implementation or to disable DnD on a component.  

======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin merlin-beta FIXED IN: merlin merlin-beta INTEGRATED IN: merlin-beta
14-06-2004

EVALUATION Name: db100478 Date: 09/08/2000 Committing to merlin release ====================================================================== A full description of the proposal is available at http://javaweb.eng/swing/merlin/specs/dnd/ A summary of the api is as follows: The following public class added to the javax.swing package /** * This class is used to handle the transfer of a 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. * <p> * This class is implemented to provide a default behavior of transfering * 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 consructed 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. * * * @author Timothy Prinzing * @version %I% %G% */ public class TransferHandler { /** * An <code>int</code> representing no tansfer action. */ public static final int NONE = DnDConstants.ACTION_NONE; /** * An <code>int</code> representing a &quot;copy&quot; transfer action. * This value is used when data is copied to a clipboard * or copied elsewhere in a drag and drop operation. */ public static final int COPY = DnDConstants.ACTION_COPY; /** * An <code>int</code> representing a &quot;move&quot; transfer action. * This value is used when data is moved to a clipboard (i.e. a cut) * or moved elsewhere in a drag and drop operation. */ public static final int MOVE = DnDConstants.ACTION_MOVE; /** * An <code>int</code> representing a source action capability of either * &quot;copy&quot; or &quot;move&quot;. */ public static final int COPY_OR_MOVE = DnDConstants.ACTION_COPY_OR_MOVE; /** * Construct a transfer handler that can transfer a Java Bean property * from one component to another via the clipboard or a drag and drop * operation. * * @param property The name of the property to transfer. This can * be null if there is no property associated with the transfer * handler (e.g. A subclass that performs some other kind of transfer). */ public TransferHandler(String property) { } /** * Convenience constructor for subclasses. */ protected TransferHandler() { } /** * This method causes the Swing drag support to be initiated. This is called by * the various UI implementations in the javax.Swing.plaf.basic package if the * dragEnabled property is set on the component. This can be called by custom UI * implementations to use the Swing drag support. This method can also be called * by a Swing extension written as a subclass of JComponent to take advantage of * the Swing drag support. * <p> * The transfer <em>will not</em> have been completed at the * return of this call (i.e. the call does not block waiting for the drop). * The transfer will take place through the Swing implementation of the * java.awt.dnd mechanism, requiring no further effort from the developer. * The exportDone method will be called when the transfer has completed. * * @param comp The component holding the data to be transfered. This * argument is provided to enable sharing of TransferHandlers by * multiple components. * @param e The event that triggered the transfer. * @param action The transfer action initially requested. This should * be a value of either COPY or MOVE. * The value may be changed during the course of the drag operation. */ public void exportAsDrag(JComponent comp, InputEvent e, int action) { } /** * This method causes a transfer from the given component to the * given clipboard. This method is called by the default cut and * copy actions registered in a components action map. * <p> * The transfer <em>will</em> have been completed at the * return of this call. The transfer will take place using the * java.awt.datatransfer mechanism, requiring no further effort from the developer. * The exportDone method will be called when the transfer has completed. If the * requested action isn't supported, exportDone will be called with an action of * NONE. * * @param comp The component holding the data to be transfered. This * argument is provided to enable sharing of TransferHandlers by * multiple components. * @param clip The clipboard to transfer the data into. * @param action The transfer action requested. This should * be a value of either 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 * supported. */ public void exportToClipboard(JComponent comp, Clipboard clip, int action) { } /** * This method causes a transfer to a component from a clipboard or a * DND drop operation. The Transferable represents the data to be * imported into the component. * * @param comp The component to receive the transfer. This * argument is provided to enable sharing of TransferHandlers by * multiple components. * @param t The data to import * @return true if the data was inserted into the component, false otherwise. */ public boolean importData(JComponent comp, Transferable t) { } /** * This method indicates if a component would accept an import of the given * set of data flavors prior to actually attempting to import it. * * @param comp The component to receive the transfer. This * argument is provided to enable sharing of TransferHandlers by * multiple components. * @param tranferFlavors The data formats available * @return true if the data can be inserted into the component, false otherwise. */ public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) { } /** * This is the type of transfer actions supported by the source. Some models are * not mutable, so a transfer operation of COPY only should * be advertised in that case. * * @param c The component holding the data to be transfered. This * argument is provided to enable sharing of TransferHandlers by * multiple components. * @return This is implemented to return COPY * if the transfer property can be found, otherwise NONE * is returned. A return value of NONE disables any transfers out of the component. */ public int getSourceActions(JComponent c) { } /** * The object returned by this method establishes the look of a transfer. This is * useful for both providing feedback while performing a drag operation and for * representing the transfer in a clipboard implementation that has a visual * appearance. The implementation of the Icon interface should not alter the * graphics clip or alpha level. The icon implementation need not be rectangular * or paint all of the bounding rectangle and logic that calls the icons paint * method should not assume the all bits are painted. Null is a valid return value * for this method and indicates there is no visual representation provided. The * calling logic is free to represent the transferable however it wants in this case. * <p> * The default Swing logic will not do an alpha blended drag animation if * the return is null. * * @param t The data to be transfered. This value is expected to have been * created by the createTransferable method. * @return This is implemented to return null, indicating * there is no default visual representation. */ public Icon getVisualRepresentation(Transferable t) { } /** * Create a Transferable to use as the source for a data transfer. * * @param c The component holding the data to be transfered. This * argument is provided to enable sharing of TransferHandlers by * multiple components. * @return The representation of the data to be transfered. * */ protected Transferable createTransferable(JComponent c) { } /** * This method is called after data has been exported. This method should remove * the data that was transfered if the action was MOVE. * <p> * This method is implemented to do nothing since MOVE is not a supported * action of this implementation (i.e. getSourceActions does not include MOVE). * * @param source The component that was the source of the data. * @param data The data that was transferred. * @param action The actual action that was performed. */ protected void exportDone(JComponent source, Transferable data, int action) { } } The following methods added to javax.swing.JComponent /** * The transferHandler property is the primary part of the API * for the developer wanting to enable data transfer support in Swing. The * TransferHandler installed defines how data is imported and exported from * the component. It is used by drag and drop support as well as clipboard * transfer support. The value can be null if the component does not support * data transfer operations. * * @see TransferHandler * @see getTransferHandler * @since 1.4 * @beaninfo * bound: true * hidden: true * description: Mechanism for transfer of data to and from the component */ public void setTransferHandler(TransferHandler newHandler) { } /** * The transferHandler property is the primary part of the API * for the developer wanting to enable data transfer support in Swing. The * TransferHandler installed defines how data is imported and exported from * the component. The is used by drag and drop support as well as clipboard * transfer support. The value can be null if the component does not support * data transfer operations. * * @return the currently installed TransferHandler implementation, or null if * data transfers are not supported by the component. * @see TransferHandler * @see setTransferHandler * @since 1.4 */ public TransferHandler getTransferHandler() { } The following methods added to javax.swing.text.JTextComponent, javax.swing.JList, javax.swing.JTree, javax.swing.JTable, javax.swing.JFileChooser, and javax.swing.JColorChooser /** * The dragEnabled property determines whether or not the automatic Swing drag handling is * enabled. The transferHandler property needs to be set to a non-null value for the drag to do * anything. The default value for this property is false. * <p> * If the value is true, a mouse press on a selection will cause a drag and drop operation * to be initiated. Setting this value to true will therefore have a subtle effect on * how selections behave. * * @param b the value to set the dragEnabled property to. * @see #getDragEnabled * @see #setTransferHandler * @see TransferHandler * @since 1.4 */ public void setDragEnabled(boolean b) { dragEnabled = b; } /** * The dragEnabled property determines whether or not the automatic Swing drag handling is * enabled. The transferHandler property needs to be set to a non-null value for the drag to do * anything. The default value for this property is false. * <p> * If the value is true, a mouse press on a selection will cause a drag and drop operation * to be initiated. Setting this value to true will therefore have a subtle effect on * how selections behave. * * @return the value of the dragEnabled property * @see #setDragEnabled * @see #setTransferHandler * @see TransferHandler * @since 1.4 */ public boolean getDragEnabled() { return dragEnabled; } To minimize the effects of enabling drag operations on JTree, the nested class MouseHandler in javax.swing.plaf.basic.BasicTreeUI needs to implement java.awt.MouseMotionListener timothy.prinzing@eng 2000-10-16
16-10-2000