java.lang.Object
javax.swing.TransferHandler
org.bzdev.swing.URLListTransferHandler
- All Implemented Interfaces:
Serializable
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.TransferHandler
TransferHandler.DropLocation, TransferHandler.TransferSupport
-
Field Summary
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, LINK, MOVE, NONE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Assert that the JList's model has been modified.boolean
canImport
(TransferHandler.TransferSupport support) protected Transferable
protected void
exportDone
(JComponent src, Transferable data, int action) int
boolean
importData
(JComponent comp, Transferable t) boolean
protected void
processURL
(URL url) Process a newly added URL.Methods inherited from class javax.swing.TransferHandler
canImport, exportAsDrag, exportToClipboard, getCopyAction, getCutAction, getDragImage, getDragImageOffset, getPasteAction, getVisualRepresentation, setDragImage, setDragImageOffset
-
Constructor Details
-
URLListTransferHandler
Constructor.- Parameters:
jlist
- the JList for this transfer handlercurrentDir
- 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
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
- Overrides:
createTransferable
in classTransferHandler
-
getSourceActions
- Overrides:
getSourceActions
in classTransferHandler
-
importData
- Overrides:
importData
in classTransferHandler
-
canImport
- Overrides:
canImport
in classTransferHandler
-
importData
- Overrides:
importData
in classTransferHandler
-
exportDone
- Overrides:
exportDone
in classTransferHandler
-