Class URIDrop
- java.lang.Object
-
- jmri.util.iharder.dnd.URIDrop
-
public class URIDrop extends java.lang.Object
This class makes it easy to drag and drop files from the operating system to a Java program. AnyComponentcan be dropped onto, but onlyJComponents will indicate the drop event with a changed border.To use this class, construct a new
URIDropby passing it the target component and aListenerto receive notification when file(s) have been dropped. Here is an example:JPanel myPanel = new JPanel(); new URIDrop( myPanel, new URIDrop.Listener() { public void filesDropped( java.io.File[] files ) { // handle file drop ... } });You can specify the border that will appear when files are being dragged by calling the constructor with a
border.Border. OnlyJComponents will show any indication with a border.You can turn on some debugging features by passing a
PrintStreamobject (such asSystem.out) into the full constructor. Anullvalue will result in no extra debugging information being output.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceURIDrop.ListenerImplement this inner interface to listen for when uris are dropped.static interfaceURIDrop.ListenerExt
-
Constructor Summary
Constructors Constructor Description URIDrop(java.awt.Component c, boolean recursive, URIDrop.Listener listener)Constructor with a default border and the option to recursively set drop targets.URIDrop(java.awt.Component c, javax.swing.border.Border dragBorder, boolean recursive, URIDrop.Listener listener)Constructor with a specified border and the option to recursively set drop targets.URIDrop(java.awt.Component c, javax.swing.border.Border dragBorder, URIDrop.Listener listener)Constructor with a specified borderURIDrop(java.awt.Component c, URIDrop.Listener listener)Constructs aURIDropwith a default light-blue border and, if c is aContainer, recursively sets all elements contained within as drop targets, though only the top level container will change borders.URIDrop(java.io.PrintStream out, java.awt.Component c, boolean recursive, URIDrop.Listener listener)Constructor with a default border, debugging optionally turned on and the option to recursively set drop targets.URIDrop(java.io.PrintStream out, java.awt.Component c, javax.swing.border.Border dragBorder, boolean recursive, URIDrop.Listener listener)Full constructor with a specified border and debugging optionally turned on.URIDrop(java.io.PrintStream out, java.awt.Component c, javax.swing.border.Border dragBorder, URIDrop.Listener listener)Constructor with a specified border and debugging optionally turned on.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanremove(java.awt.Component c)Removes the drag-and-drop hooks from the component and optionally from the all children.static booleanremove(java.awt.Component c, boolean recursive)Removes the drag-and-drop hooks from the component and optionally from the all children.
-
-
-
Constructor Detail
-
URIDrop
public URIDrop(java.awt.Component c, URIDrop.Listener listener)
Constructs aURIDropwith a default light-blue border and, if c is aContainer, recursively sets all elements contained within as drop targets, though only the top level container will change borders.- Parameters:
c- Component on which files will be dropped.listener- Listens forfilesDropped.- Since:
- 1.0
-
URIDrop
public URIDrop(java.awt.Component c, boolean recursive, URIDrop.Listener listener)
Constructor with a default border and the option to recursively set drop targets. If your component is aContainer, then each of its children components will also listen for drops, though only the parent will change borders.- Parameters:
c- Component on which files will be dropped.recursive- Recursively set children as drop targets.listener- Listens forfilesDropped.- Since:
- 1.0
-
URIDrop
public URIDrop(java.io.PrintStream out, java.awt.Component c, boolean recursive, URIDrop.Listener listener)
Constructor with a default border, debugging optionally turned on and the option to recursively set drop targets. If your component is aContainer, 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 toout. A common way to use this constructor is withSystem.outorSystem.err. Anullvalue for the parameteroutwill result in no debugging output.- Parameters:
out- PrintStream to record debugging info or null for no debugging.c- Component on which files will be dropped.recursive- Recursively set children as drop targets.listener- Listens forfilesDropped.- Since:
- 1.0
-
URIDrop
public URIDrop(java.awt.Component c, javax.swing.border.Border dragBorder, URIDrop.Listener listener)
Constructor with a specified border- Parameters:
c- Component on which files will be dropped.dragBorder- Border to use onJComponentwhen dragging occurs.listener- Listens forfilesDropped.- Since:
- 1.0
-
URIDrop
public URIDrop(java.awt.Component c, javax.swing.border.Border dragBorder, boolean recursive, URIDrop.Listener listener)
Constructor with a specified border and the option to recursively set drop targets. If your component is aContainer, then each of its children components will also listen for drops, though only the parent will change borders.- Parameters:
c- Component on which files will be dropped.dragBorder- Border to use onJComponentwhen dragging occurs.recursive- Recursively set children as drop targets.listener- Listens forfilesDropped.- Since:
- 1.0
-
URIDrop
public URIDrop(java.io.PrintStream out, java.awt.Component c, javax.swing.border.Border dragBorder, URIDrop.Listener listener)
Constructor with a specified border and debugging optionally turned on. With Debugging turned on, more status messages will be displayed toout. A common way to use this constructor is withSystem.outorSystem.err. Anullvalue for the parameteroutwill result in no debugging output.- Parameters:
out- PrintStream to record debugging info or null for no debugging.c- Component on which files will be dropped.dragBorder- Border to use onJComponentwhen dragging occurs.listener- Listens forfilesDropped.- Since:
- 1.0
-
URIDrop
public URIDrop(java.io.PrintStream out, java.awt.Component c, javax.swing.border.Border dragBorder, boolean recursive, URIDrop.Listener listener)
Full constructor with a specified border and debugging optionally turned on. With Debugging turned on, more status messages will be displayed toout. A common way to use this constructor is withSystem.outorSystem.err. Anullvalue for the parameteroutwill result in no debugging output.- Parameters:
out- PrintStream to record debugging info or null for no debugging.c- Component on which files will be dropped.dragBorder- Border to use onJComponentwhen dragging occurs.recursive- Recursively set children as drop targets.listener- Listens forfilesDropped.- Since:
- 1.0
-
-
Method Detail
-
remove
public static boolean remove(java.awt.Component c)
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 aContainer.- Parameters:
c- The component to unregister as a drop target- Returns:
- true if any components were unregistered
- Since:
- 1.0
-
remove
public static boolean remove(java.awt.Component c, boolean recursive)
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:
c- The component to unregisterrecursive- Recursively unregister components within a container- Returns:
- true if any components were unregistered
- Since:
- 1.0
-
-