Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.puppycrawl.tools.checkstyle.gui
Class FileDrop  view FileDrop download FileDrop.java

java.lang.Object
  extended bycom.puppycrawl.tools.checkstyle.gui.FileDrop

class FileDrop
extends java.lang.Object

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.

Original author: Robert Harder, rharder@usa.net


Nested Class Summary
private  class FileDrop.FileDropTargetListener
           
static interface FileDrop.Listener
          Implement this inner interface to listen for when files are dropped.
 
Field Summary
private static java.awt.Color DEFAULT_BORDER_COLOR
           
private  java.awt.dnd.DropTargetListener dropListener
           
private  javax.swing.border.Border normalBorder
           
 
Constructor Summary
(package private) FileDrop(java.awt.Component c, javax.swing.border.Border dragBorder, boolean recursive, FileDrop.Listener listener)
          Full constructor with a specified border and debugging optionally turned on.
(package private) FileDrop(java.awt.Component c, FileDrop.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.
 
Method Summary
private  boolean isDragOk(java.awt.dnd.DropTargetDragEvent evt)
          Determine if the dragged data is a file list.
private  void makeDropTarget(java.awt.Component c, boolean recursive)
           
(package private) static void remove(java.awt.Component c)
          Removes the drag-and-drop hooks from the component and optionally from the all children.
(package private) static void remove(java.awt.Component c, boolean recursive)
          Removes the drag-and-drop hooks from the component and optionally from the all children.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

normalBorder

private transient javax.swing.border.Border normalBorder

dropListener

private transient java.awt.dnd.DropTargetListener dropListener

DEFAULT_BORDER_COLOR

private static final java.awt.Color DEFAULT_BORDER_COLOR
Constructor Detail

FileDrop

FileDrop(java.awt.Component c,
         FileDrop.Listener listener)
   throws java.util.TooManyListenersException
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.

Since:
1.0

FileDrop

FileDrop(java.awt.Component c,
         javax.swing.border.Border dragBorder,
         boolean recursive,
         FileDrop.Listener listener)
   throws java.util.TooManyListenersException
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.

Since:
1.0
Method Detail

makeDropTarget

private void makeDropTarget(java.awt.Component c,
                            boolean recursive)
                     throws java.util.TooManyListenersException

isDragOk

private boolean isDragOk(java.awt.dnd.DropTargetDragEvent evt)
Determine if the dragged data is a file list.


remove

static void 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 a .Container.

Since:
1.0

remove

static void 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.

Since:
1.0