Class URLListTransferHandler

java.lang.Object
javax.swing.TransferHandler
org.bzdev.swing.URLListTransferHandler
All Implemented Interfaces:
Serializable

public class URLListTransferHandler extends TransferHandler
TransferHandler for list of URLs. Allows URLs and file names to be dragged into a JList, and allows the JList to be reordered.

A typical use of this class is shown in the following example:


  JList jlist = ...;
  File currentDirectory = ...;
  TransferHandler th =
      new URLListTransferHandler(jlist, currentDirectory) {
          public void processURL(url) {
            // add the URL to some tables, but check for
            // an existing entry.  The drag and drop code
            // will add the URL to its JList, so processURL does
            // not have to modify the JList.
            ...
          }
          public void assertModified() {
            ...
          }
      };
  jlist.setTransferHandler(th);
  jlist.setDragEnabled(true);
  jlist.setDropMode(DropMode.INSERT);
 
See Also:
  • Constructor Details

    • URLListTransferHandler

      public URLListTransferHandler(JList jlist, File currentDir)
      Constructor.
      Parameters:
      jlist - the JList for this transfer handler
      currentDir - the current working directory for resolving relative file names.
  • Method Details

    • assertModified

      protected void assertModified()
      Assert that the JList's model has been modified. Called if an element is added or removed from the JList's model. By default, does nothing, but subclasses can override it. Called once per drag and drop operation at the end of the data import operation if an insertion or deletion was detected (including in a reorder that managed to restore the previous list ordering).

      This method is meant to provide an indication that a JList's model has been modified programatically in cases where listeners are overkill or merely inconvenient.

    • processURL

      protected void processURL(URL url)
      Process a newly added URL. The default method does nothing, but can be overridden to respond as an entry is inserted or moved. Note that, if the list is reordered, the same URL could be processed multiple times. The associated JList should not be modified by this method as the drag and drop implementation will add or move the entry to the JList automatically.
      Parameters:
      url - the URL
    • createTransferable

      protected Transferable createTransferable(JComponent c)
      Overrides:
      createTransferable in class TransferHandler
    • getSourceActions

      public int getSourceActions(JComponent c)
      Overrides:
      getSourceActions in class TransferHandler
    • importData

      public boolean importData(JComponent comp, Transferable t)
      Overrides:
      importData in class TransferHandler
    • canImport

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

      public boolean importData(TransferHandler.TransferSupport support)
      Overrides:
      importData in class TransferHandler
    • exportDone

      protected void exportDone(JComponent src, Transferable data, int action)
      Overrides:
      exportDone in class TransferHandler