Class DropFileTransferHandler

java.lang.Object
javax.swing.TransferHandler
org.monte.media.swing.datatransfer.DropFileTransferHandler
All Implemented Interfaces:
Serializable

public class DropFileTransferHandler extends TransferHandler
The DropFileTransferHandler can be used to add drag and drop support. When a file is dropped, the supplied ActionListner is invoked. The filename is passed in the action command.
Author:
Werner Randelshofer
See Also:
  • Constructor Details

    • DropFileTransferHandler

      public DropFileTransferHandler()
      Creates a new instance.
    • DropFileTransferHandler

      public DropFileTransferHandler(int fileSelectionMode)
      Creates a new instance.
      Parameters:
      fileSelectionMode - JFileChooser file selection mode.
    • DropFileTransferHandler

      public DropFileTransferHandler(int fileSelectionMode, FileFilter filter)
      Creates a new instance.
      Parameters:
      fileSelectionMode - JFileChooser file selection mode.
    • DropFileTransferHandler

      public DropFileTransferHandler(int fileSelectionMode, FileFilter filter, ActionListener l)
      Creates a new instance.
      Parameters:
      fileSelectionMode - JFileChooser file selection mode.
  • Method Details

    • setActionListener

      public void setActionListener(ActionListener l)
    • importData

      public boolean importData(JComponent c, Transferable t)
      Overrides:
      importData in class TransferHandler
    • createTransferable

      protected Transferable createTransferable(JComponent comp)
      Overrides:
      createTransferable in class TransferHandler
    • canImport

      public boolean canImport(JComponent comp, DataFlavor[] transferFlavors)
      Overrides:
      canImport in class TransferHandler
    • getImportFlavor

      protected DataFlavor getImportFlavor(DataFlavor[] flavors, JComponent c)
      Try to find a flavor that can be used to import a Transferable. The set of usable flavors are tried in the following order:
      1. First, an attempt to find a text/plain flavor is made.
      2. Second, an attempt to find a flavor representing a String reference in the same VM is made.
      3. Lastly, DataFlavor.stringFlavor is searched for.
    • getSourceActions

      public int getSourceActions(JComponent comp)
      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.
      Overrides:
      getSourceActions in class TransferHandler
      Parameters:
      comp - The component holding the data to be transfered. This argument is provided to enable sharing of TransferHandlers by multiple components.
      Returns:
      This is implemented to return NONE if the component is a JPasswordField since exporting data via user gestures is not allowed. If the text component is editable, COPY_OR_MOVE is returned, otherwise just COPY is allowed.
    • exportDone

      protected void exportDone(JComponent comp, Transferable data, int action)
      This method is called after data has been exported. This method should remove the data that was transfered if the action was MOVE.
      Overrides:
      exportDone in class TransferHandler
      Parameters:
      comp - The component that was the source of the data.
      data - The data that was transferred or possibly null if the action is NONE.
      action - The actual action that was performed.
    • getFileFilter

      public FileFilter getFileFilter()
      Returns:
      the fileFilter
    • setFileFilter

      public void setFileFilter(FileFilter fileFilter)
      Parameters:
      fileFilter - the fileFilter to set