Class FileTransferHandler

java.lang.Object
javax.swing.TransferHandler
is.codion.swing.common.ui.FileTransferHandler
All Implemented Interfaces:
Serializable

public abstract class FileTransferHandler extends TransferHandler
Handles the importing of files during drag'n drop operations.
See Also:
  • Constructor Details

    • FileTransferHandler

      public FileTransferHandler()
  • Method Details

    • canImport

      public boolean canImport(TransferHandler.TransferSupport transferSupport)
      Overrides:
      canImport in class TransferHandler
    • importData

      public boolean importData(TransferHandler.TransferSupport transferSupport)
      Overrides:
      importData in class TransferHandler
    • addSingleFileDragAndDropSupport

      public static void addSingleFileDragAndDropSupport(JTextComponent textComponent)
      Makes the text component accept files during drag and drop operations and insert the absolute path of the dropped file (the first file in a list if more than one file is dropped)
      Parameters:
      textComponent - the text component
    • fileDataFlavor

      public static boolean fileDataFlavor(TransferHandler.TransferSupport transferSupport)
      Parameters:
      transferSupport - a drag'n drop transfer support instance
      Returns:
      true if the given transfer support instance represents a file or a list of files
    • transferFiles

      public static List<File> transferFiles(TransferHandler.TransferSupport transferSupport)
      Returns the files described by the given transfer support object. An empty list is returned if no files are found.
      Parameters:
      transferSupport - the drag'n drop transfer support
      Returns:
      the files described by the given transfer support object
      Throws:
      RuntimeException - in case of an exception
    • importFiles

      protected abstract boolean importFiles(Component component, List<File> files)
      Called after a successful import
      Parameters:
      component - the component
      files - the imported files, non-null and containing at least one item
      Returns:
      true if the files were inserted into the component, false otherwise