corpus-services  1.0
de.uni_hamburg.corpora.swing.FileDrop Class Reference
+ Collaboration diagram for de.uni_hamburg.corpora.swing.FileDrop:

Classes

class  Event
 
interface  Listener
 
class  TransferableObject
 

Public Member Functions

 FileDrop (final java.awt.Component c, final Listener listener)
 
 FileDrop (final java.awt.Component c, final boolean recursive, final Listener listener)
 
 FileDrop (final java.io.PrintStream out, final java.awt.Component c, final Listener listener)
 
 FileDrop (final java.io.PrintStream out, final java.awt.Component c, final boolean recursive, final Listener listener)
 
 FileDrop (final java.awt.Component c, final javax.swing.border.Border dragBorder, final Listener listener)
 
 FileDrop (final java.awt.Component c, final javax.swing.border.Border dragBorder, final boolean recursive, final Listener listener)
 
 FileDrop (final java.io.PrintStream out, final java.awt.Component c, final javax.swing.border.Border dragBorder, final Listener listener)
 
 FileDrop (final java.io.PrintStream out, final java.awt.Component c, final javax.swing.border.Border dragBorder, final boolean recursive, final Listener listener)
 

Static Public Member Functions

static boolean remove (java.awt.Component c)
 
static boolean remove (java.io.PrintStream out, java.awt.Component c, boolean recursive)
 

Detailed Description

This class makes it easy to drag and drop files from the operating system to a Java program. Any java.awt.Component can be dropped onto, but only javax.swing.JComponents will indicate the drop event with a changed border.

To use this class, construct a new FileDrop by passing it the target component and a Listener to receive notification when file(s) have been dropped. Here is an example:

     JPanel myPanel = new JPanel();
     new FileDrop( myPanel, new FileDrop.Listener()
     {   public void filesDropped( java.io.File[] files )
         {   
             // handle file drop
             ...
         }   // end filesDropped
     }); // end FileDrop.Listener

You can specify the border that will appear when files are being dragged by calling the constructor with a javax.swing.border.Border. Only JComponents will show any indication with a border.

You can turn on some debugging features by passing a PrintStream object (such as System.out) into the full constructor. A null value will result in no extra debugging information being output.

I'm releasing this code into the Public Domain. Enjoy.

Original author: Robert Harder, rhard.nosp@m.er@u.nosp@m.sa.ne.nosp@m.t

2007-09-12 Nathan Blomquist – Linux (KDE/Gnome) support added.

Author
Robert Harder
rhard.nosp@m.er@u.nosp@m.sers..nosp@m.sf.n.nosp@m.et
Version
1.0.1

Definition at line 50 of file FileDrop.java.

Constructor & Destructor Documentation

de.uni_hamburg.corpora.swing.FileDrop.FileDrop ( final java.awt.Component  c,
final Listener  listener 
)

Constructs a FileDrop with a default light-blue border and, if c is a java.awt.Container, recursively sets all elements contained within as drop targets, though only the top level container will change borders.

Parameters
cComponent on which files will be dropped.
listenerListens for filesDropped.
Since
1.0

Definition at line 72 of file FileDrop.java.

de.uni_hamburg.corpora.swing.FileDrop.FileDrop ( final java.awt.Component  c,
final boolean  recursive,
final Listener  listener 
)

Constructor with a default border and the option to recursively set drop targets. If your component is a java.awt.Container, then each of its children components will also listen for drops, though only the parent will change borders.

Parameters
cComponent on which files will be dropped.
recursiveRecursively set children as drop targets.
listenerListens for filesDropped.
Since
1.0

Definition at line 95 of file FileDrop.java.

de.uni_hamburg.corpora.swing.FileDrop.FileDrop ( final java.io.PrintStream  out,
final java.awt.Component  c,
final Listener  listener 
)

Constructor with a default border and debugging optionally turned on. With Debugging turned on, more status messages will be displayed to out. A common way to use this constructor is with System.out or System.err. A null value for the parameter out will result in no debugging output.

Parameters
outPrintStream to record debugging info or null for no debugging.
out
cComponent on which files will be dropped.
listenerListens for filesDropped.
Since
1.0

Definition at line 120 of file FileDrop.java.

de.uni_hamburg.corpora.swing.FileDrop.FileDrop ( final java.io.PrintStream  out,
final java.awt.Component  c,
final boolean  recursive,
final Listener  listener 
)

Constructor with a default border, debugging optionally turned on and the option to recursively set drop targets. If your component is a java.awt.Container, then each of its children components will also listen for drops, though only the parent will change borders. With Debugging turned on, more status messages will be displayed to out. A common way to use this constructor is with System.out or System.err. A null value for the parameter out will result in no debugging output.

Parameters
outPrintStream to record debugging info or null for no debugging.
out
cComponent on which files will be dropped.
recursiveRecursively set children as drop targets.
listenerListens for filesDropped.
Since
1.0

Definition at line 150 of file FileDrop.java.

de.uni_hamburg.corpora.swing.FileDrop.FileDrop ( final java.awt.Component  c,
final javax.swing.border.Border  dragBorder,
final Listener  listener 
)

Constructor with a specified border

Parameters
cComponent on which files will be dropped.
dragBorderBorder to use on JComponent when dragging occurs.
listenerListens for filesDropped.
Since
1.0

Definition at line 173 of file FileDrop.java.

de.uni_hamburg.corpora.swing.FileDrop.FileDrop ( final java.awt.Component  c,
final javax.swing.border.Border  dragBorder,
final boolean  recursive,
final Listener  listener 
)

Constructor with a specified border and the option to recursively set drop targets. If your component is a java.awt.Container, then each of its children components will also listen for drops, though only the parent will change borders.

Parameters
cComponent on which files will be dropped.
dragBorderBorder to use on JComponent when dragging occurs.
recursiveRecursively set children as drop targets.
listenerListens for filesDropped.
Since
1.0

Definition at line 199 of file FileDrop.java.

de.uni_hamburg.corpora.swing.FileDrop.FileDrop ( final java.io.PrintStream  out,
final java.awt.Component  c,
final javax.swing.border.Border  dragBorder,
final Listener  listener 
)

Constructor with a specified border and debugging optionally turned on. With Debugging turned on, more status messages will be displayed to out. A common way to use this constructor is with System.out or System.err. A null value for the parameter out will result in no debugging output.

Parameters
outPrintStream to record debugging info or null for no debugging.
cComponent on which files will be dropped.
dragBorderBorder to use on JComponent when dragging occurs.
listenerListens for filesDropped.
Since
1.0

Definition at line 227 of file FileDrop.java.

de.uni_hamburg.corpora.swing.FileDrop.FileDrop ( final java.io.PrintStream  out,
final java.awt.Component  c,
final javax.swing.border.Border  dragBorder,
final boolean  recursive,
final Listener  listener 
)

Full constructor with a specified border and debugging optionally turned on. With Debugging turned on, more status messages will be displayed to out. A common way to use this constructor is with System.out or System.err. A null value for the parameter out will result in no debugging output.

Parameters
outPrintStream to record debugging info or null for no debugging.
cComponent on which files will be dropped.
dragBorderBorder to use on JComponent when dragging occurs.
recursiveRecursively set children as drop targets.
listenerListens for filesDropped.
Since
1.0

Definition at line 258 of file FileDrop.java.

Member Function Documentation

static boolean de.uni_hamburg.corpora.swing.FileDrop.remove ( java.awt.Component  c)
static

Removes the drag-and-drop hooks from the component and optionally from the all children. You should call this if you add and remove components after you've set up the drag-and-drop. This will recursively unregister all components contained within c if c is a java.awt.Container.

Parameters
cThe component to unregister as a drop target
Since
1.0

Definition at line 568 of file FileDrop.java.

static boolean de.uni_hamburg.corpora.swing.FileDrop.remove ( java.io.PrintStream  out,
java.awt.Component  c,
boolean  recursive 
)
static

Removes the drag-and-drop hooks from the component and optionally from the all children. You should call this if you add and remove components after you've set up the drag-and-drop.

Parameters
outOptional java.io.PrintStream for logging drag and drop messages
cThe component to unregister
recursiveRecursively unregister components within a container
Since
1.0

Definition at line 584 of file FileDrop.java.


The documentation for this class was generated from the following file: