Package ca.cgjennings.ui.dnd
Class FileDrop
- java.lang.Object
-
- ca.cgjennings.ui.dnd.FileDrop
-
public class FileDrop extends java.lang.ObjectA support class that allows interface components to easily accept files being dropped on them from other components or from the platform.- Since:
- 1.61
- Author:
- Adapted from public domain code by Robert Harder and Nathan Blomquist
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileDrop.DropEventEvent that is provided to listeners when files are dropped on a target.static interfaceFileDrop.DropListenerListener that may be registered to receiveFileDrop.DropEvents when files are dropped on a target component.static interfaceFileDrop.ListenerA simpler listener that may be used as an alternative toFileDrop.DropListener.
-
Constructor Summary
Constructors Constructor Description FileDrop(java.awt.Component component, FileDrop.Listener listener)Creates a newFileDropon the component.FileDrop(java.awt.Component component, javax.swing.JComponent borderOwner, boolean attachToDescendants)Creates a newFileDropon the component.FileDrop(java.awt.Component component, javax.swing.JComponent borderOwner, boolean attachToDescendants, FileDrop.Listener listener)Creates a newFileDropon the component.FileDrop(java.awt.Component component, javax.swing.JComponent borderOwner, FileDrop.Listener listener)Creates a newFileDropon the component.FileDrop(javax.swing.JComponent borderOwner, java.awt.Component[] components)Creates a newFileDropon the specified components.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.FileFiltergetFileFilter()Returns the file filter for this drop handler.static FileDropof(javax.swing.JComponent borderOwner, java.awt.Component... components)Creates and returns a newFileDropon the specified components.static voidremove(java.awt.Component component, boolean recursive)Removes all drag-and-drop support from a component and optionally from its descendants.voidsetFileFilter(java.io.FileFilter fileFilter)Sets the file filter for this drop handler.voidsetListener(FileDrop.DropListener complexListener)Sets the drop listener to receive detailed information about dropped files.voidsetListener(FileDrop.Listener simpleListener)Sets the drop listener to a simple listener that receives a non-null, non-empty array of files.
-
-
-
Constructor Detail
-
FileDrop
public FileDrop(java.awt.Component component, javax.swing.JComponent borderOwner, boolean attachToDescendants)Creates a newFileDropon the component. If the component is aJComponent, aDropBorderwill appear when dragging files over it.- Parameters:
component- the component that will accept filesborderOwner- if non-null, a component whose border will change to indicate that files are being dragged over the componentattachToDescendants- iftrue, then all of the descendants of the component will also listen for file drops
-
FileDrop
public FileDrop(java.awt.Component component, FileDrop.Listener listener)Creates a newFileDropon the component. If the component is aJComponent, aDropBorderwill appear when dragging files over it.- Parameters:
component- the component that will accept fileslistener- the optional simple listener that will be notified when files are dropped
-
FileDrop
public FileDrop(java.awt.Component component, javax.swing.JComponent borderOwner, FileDrop.Listener listener)Creates a newFileDropon the component. IfborderOwneris notnull, aDropBorderwill appear when dragging files over the component.- Parameters:
component- the component that will accept filesborderOwner- if non-null, a component whose border will change to indicate that files are being dragged over the componentlistener- the optional simple listener that will be notified when files are dropped
-
FileDrop
public FileDrop(java.awt.Component component, javax.swing.JComponent borderOwner, boolean attachToDescendants, FileDrop.Listener listener)Creates a newFileDropon the component. If the component is aJComponent, aDropBorderwill appear when dragging files over it.- Parameters:
component- the component that will accept filesborderOwner- if non-null, a component whose border will change to indicate that files are being dragged over the componentattachToDescendants- iftrue, then all of the descendants of the component will also listen for file dropslistener- the optional simple listener that will be notified when files are dropped
-
FileDrop
public FileDrop(javax.swing.JComponent borderOwner, java.awt.Component[] components)Creates a newFileDropon the specified components. The drop will initially have no listener attached.- Parameters:
borderOwner- if non-null, a component whose border will change to indicate that files are being dragged over the componentcomponents- the components that will accept files- See Also:
setListener(ca.cgjennings.ui.dnd.FileDrop.Listener)
-
-
Method Detail
-
of
public static FileDrop of(javax.swing.JComponent borderOwner, java.awt.Component... components)
Creates and returns a newFileDropon the specified components. The returnedFileDropwill have no listener attached, but is can be set using builder-style method chaining.The method was added to deal with two issues: First, when this form was provided as a constrctor, it broke scripts as the script engine could not distinguish which overload to choose. Second, it avoids some compiler warnings as a common patern is to create a
FileDropin a constructor without storing a reference to it.- Parameters:
borderOwner- if non-null, a component whose border will change to indicate that files are being dragged over the componentcomponents- the components that will accept files- See Also:
setListener(ca.cgjennings.ui.dnd.FileDrop.Listener)
-
setListener
public final void setListener(FileDrop.Listener simpleListener)
Sets the drop listener to a simple listener that receives a non-null, non-empty array of files. Only one listener may be attached to theFileDrop.- Parameters:
simpleListener- the listener, or null to stop receiving events
-
setListener
public void setListener(FileDrop.DropListener complexListener)
Sets the drop listener to receive detailed information about dropped files. Only one listener may be attached to theFileDrop.- Parameters:
complexListener- the listener, or null to stop receiving events
-
setFileFilter
public void setFileFilter(java.io.FileFilter fileFilter)
Sets the file filter for this drop handler. When set, dropped files will be filtered before calling the drop listener.- Parameters:
fileFilter- the filter to apply, ornullto accept all files
-
getFileFilter
public java.io.FileFilter getFileFilter()
Returns the file filter for this drop handler.- Returns:
- the file filter for this drop handler, or
null
-
remove
public static void remove(java.awt.Component component, boolean recursive)Removes all drag-and-drop support from a component and optionally from its descendants.- Parameters:
component- the top-level component to modifyrecursive- iftrue, apply recursively to all descendants
-
-