Ignore:
Timestamp:
2013-08-03T00:12:29+02:00 (11 years ago)
Author:
Don-vip
Message:

see #8902 - Small performance enhancements / coding style (patch by shinigami):

  • while -> foreach
  • for -> for each

plus:

  • cleanup of FileDrop class to make it more integrated into JOSM core + remove warnings
Location:
trunk/src/org/openstreetmap/josm/gui
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/FileDrop.java

    r6084 r6104  
    33package org.openstreetmap.josm.gui;
    44
     5import java.awt.Color;
     6import java.awt.Component;
     7import java.awt.Container;
    58import java.awt.datatransfer.DataFlavor;
     9import java.awt.datatransfer.Transferable;
     10import java.awt.datatransfer.UnsupportedFlavorException;
     11import java.awt.dnd.DnDConstants;
     12import java.awt.dnd.DropTarget;
     13import java.awt.dnd.DropTargetDragEvent;
     14import java.awt.dnd.DropTargetDropEvent;
     15import java.awt.dnd.DropTargetEvent;
     16import java.awt.dnd.DropTargetListener;
     17import java.awt.event.HierarchyEvent;
     18import java.awt.event.HierarchyListener;
    619import java.io.BufferedReader;
    720import java.io.File;
    821import java.io.IOException;
    9 import java.io.PrintStream;
    1022import java.io.Reader;
     23import java.net.URI;
     24import java.util.ArrayList;
    1125import java.util.Arrays;
     26import java.util.EventObject;
    1227import java.util.List;
     28import java.util.TooManyListenersException;
    1329
    1430import javax.swing.BorderFactory;
     31import javax.swing.JComponent;
     32import javax.swing.border.Border;
    1533
    1634import org.openstreetmap.josm.Main;
     
    5573 * @author  rharder@users.sf.net
    5674 * @version 1.0.1
     75 * @since 1231
    5776 */
    5877public class FileDrop
    5978{
    60     private transient javax.swing.border.Border normalBorder;
    61     private transient java.awt.dnd.DropTargetListener dropListener;
     79    private transient Border normalBorder;
     80    private transient DropTargetListener dropListener;
    6281
    6382    /** Discover if the running JVM is modern enough to have drag and drop. */
     
    6584
    6685    // Default border color
    67     private static java.awt.Color defaultBorderColor = new java.awt.Color( 0f, 0f, 1f, 0.25f );
    68 
    69     /* Constructor for JOSM file drop */
    70     public FileDrop(final java.awt.Component c){
     86    private static Color defaultBorderColor = new Color( 0f, 0f, 1f, 0.25f );
     87
     88    /**
     89     * Constructor for JOSM file drop
     90     * @param c The drop target
     91     */
     92    public FileDrop(final Component c){
    7193        this(
    72                 null,  // Logging stream
    7394                c,     // Drop target
    7495                BorderFactory.createMatteBorder( 2, 2, 2, 2, defaultBorderColor ), // Drag border
     
    7697                new FileDrop.Listener(){
    7798                    @Override
    78                     public void filesDropped( java.io.File[] files ){
     99                    public void filesDropped( File[] files ){
    79100                        // start asynchronous loading of files
    80101                        OpenFileAction.OpenFileTask task = new OpenFileAction.OpenFileTask(Arrays.asList(files), null);
     
    87108
    88109    /**
    89      * Constructs a {@link FileDrop} with a default light-blue border
    90      * and, if <var>c</var> is a {@link java.awt.Container}, recursively
    91      * sets all elements contained within as drop targets, though only
    92      * the top level container will change borders.
    93      *
    94      * @param c Component on which files will be dropped.
    95      * @param listener Listens for <tt>filesDropped</tt>.
    96      * @since 1.0
    97      */
    98     public FileDrop(
    99             final java.awt.Component c,
    100             final Listener listener )
    101     {   this( null,  // Logging stream
    102             c,     // Drop target
    103             javax.swing.BorderFactory.createMatteBorder( 2, 2, 2, 2, defaultBorderColor ), // Drag border
    104             true, // Recursive
    105             listener );
    106     }   // end constructor
    107 
    108     /**
    109      * Constructor with a default border and the option to recursively set drop targets.
    110      * If your component is a <tt>java.awt.Container</tt>, then each of its children
    111      * components will also listen for drops, though only the parent will change borders.
    112      *
    113      * @param c Component on which files will be dropped.
    114      * @param recursive Recursively set children as drop targets.
    115      * @param listener Listens for <tt>filesDropped</tt>.
    116      * @since 1.0
    117      */
    118     public FileDrop(
    119             final java.awt.Component c,
    120             final boolean recursive,
    121             final Listener listener )
    122     {   this( null,  // Logging stream
    123             c,     // Drop target
    124             javax.swing.BorderFactory.createMatteBorder( 2, 2, 2, 2, defaultBorderColor ), // Drag border
    125             recursive, // Recursive
    126             listener );
    127     }   // end constructor
    128 
    129     /**
    130      * Constructor with a default border and debugging optionally turned on.
    131      * With Debugging turned on, more status messages will be displayed to
    132      * <tt>out</tt>. A common way to use this constructor is with
    133      * <tt>System.out</tt> or <tt>System.err</tt>. A <tt>null</tt> value for
    134      * the parameter <tt>out</tt> will result in no debugging output.
    135      *
    136      * @param out PrintStream to record debugging info or null for no debugging.
    137      * @param c Component on which files will be dropped.
    138      * @param listener Listens for <tt>filesDropped</tt>.
    139      * @since 1.0
    140      */
    141     public FileDrop(
    142             final java.io.PrintStream out,
    143             final java.awt.Component c,
    144             final Listener listener )
    145     {   this( out,  // Logging stream
    146             c,    // Drop target
    147             javax.swing.BorderFactory.createMatteBorder( 2, 2, 2, 2, defaultBorderColor ),
    148             false, // Recursive
    149             listener );
    150     }   // end constructor
    151 
    152     /**
    153      * Constructor with a default border, debugging optionally turned on
    154      * and the option to recursively set drop targets.
    155      * If your component is a <tt>java.awt.Container</tt>, then each of its children
    156      * components will also listen for drops, though only the parent will change borders.
    157      * With Debugging turned on, more status messages will be displayed to
    158      * <tt>out</tt>. A common way to use this constructor is with
    159      * <tt>System.out</tt> or <tt>System.err</tt>. A <tt>null</tt> value for
    160      * the parameter <tt>out</tt> will result in no debugging output.
    161      *
    162      * @param out PrintStream to record debugging info or null for no debugging.
    163      * @param c Component on which files will be dropped.
    164      * @param recursive Recursively set children as drop targets.
    165      * @param listener Listens for <tt>filesDropped</tt>.
    166      * @since 1.0
    167      */
    168     public FileDrop(
    169             final java.io.PrintStream out,
    170             final java.awt.Component c,
    171             final boolean recursive,
    172             final Listener listener)
    173     {   this( out,  // Logging stream
    174             c,    // Drop target
    175             javax.swing.BorderFactory.createMatteBorder( 2, 2, 2, 2, defaultBorderColor ), // Drag border
    176             recursive, // Recursive
    177             listener );
    178     }   // end constructor
    179 
    180     /**
    181      * Constructor with a specified border
    182      *
    183      * @param c Component on which files will be dropped.
    184      * @param dragBorder Border to use on <tt>JComponent</tt> when dragging occurs.
    185      * @param listener Listens for <tt>filesDropped</tt>.
    186      * @since 1.0
    187      */
    188     public FileDrop(
    189             final java.awt.Component c,
    190             final javax.swing.border.Border dragBorder,
    191             final Listener listener)
    192     {   this(
    193             null,   // Logging stream
    194             c,      // Drop target
    195             dragBorder, // Drag border
    196             false,  // Recursive
    197             listener );
    198     }   // end constructor
    199 
    200     /**
    201      * Constructor with a specified border and the option to recursively set drop targets.
    202      * If your component is a <tt>java.awt.Container</tt>, then each of its children
    203      * components will also listen for drops, though only the parent will change borders.
    204      *
    205      * @param c Component on which files will be dropped.
    206      * @param dragBorder Border to use on <tt>JComponent</tt> when dragging occurs.
    207      * @param recursive Recursively set children as drop targets.
    208      * @param listener Listens for <tt>filesDropped</tt>.
    209      * @since 1.0
    210      */
    211     public FileDrop(
    212             final java.awt.Component c,
    213             final javax.swing.border.Border dragBorder,
    214             final boolean recursive,
    215             final Listener listener)
    216     {   this(
    217             null,
    218             c,
    219             dragBorder,
    220             recursive,
    221             listener );
    222     }   // end constructor
    223 
    224     /**
    225      * Constructor with a specified border and debugging optionally turned on.
    226      * With Debugging turned on, more status messages will be displayed to
    227      * <tt>out</tt>. A common way to use this constructor is with
    228      * <tt>System.out</tt> or <tt>System.err</tt>. A <tt>null</tt> value for
    229      * the parameter <tt>out</tt> will result in no debugging output.
    230      *
    231      * @param out PrintStream to record debugging info or null for no debugging.
    232      * @param c Component on which files will be dropped.
    233      * @param dragBorder Border to use on <tt>JComponent</tt> when dragging occurs.
    234      * @param listener Listens for <tt>filesDropped</tt>.
    235      * @since 1.0
    236      */
    237     public FileDrop(
    238             final java.io.PrintStream out,
    239             final java.awt.Component c,
    240             final javax.swing.border.Border dragBorder,
    241             final Listener listener)
    242     {   this(
    243             out,    // Logging stream
    244             c,      // Drop target
    245             dragBorder, // Drag border
    246             false,  // Recursive
    247             listener );
    248     }   // end constructor
    249 
    250     /**
    251110     * Full constructor with a specified border and debugging optionally turned on.
    252111     * With Debugging turned on, more status messages will be displayed to
     
    255114     * the parameter <tt>out</tt> will result in no debugging output.
    256115     *
    257      * @param out PrintStream to record debugging info or null for no debugging.
    258116     * @param c Component on which files will be dropped.
    259117     * @param dragBorder Border to use on <tt>JComponent</tt> when dragging occurs.
    260118     * @param recursive Recursively set children as drop targets.
    261119     * @param listener Listens for <tt>filesDropped</tt>.
    262      * @since 1.0
    263120     */
    264121    public FileDrop(
    265             final java.io.PrintStream out,
    266             final java.awt.Component c,
    267             final javax.swing.border.Border dragBorder,
     122            final Component c,
     123            final Border dragBorder,
    268124            final boolean recursive,
    269125            final Listener listener)
     
    272128        if( supportsDnD() )
    273129        {   // Make a drop listener
    274             dropListener = new java.awt.dnd.DropTargetListener()
     130            dropListener = new DropTargetListener()
    275131            {   @Override
    276                 public void dragEnter( java.awt.dnd.DropTargetDragEvent evt )
    277             {       log( out, "FileDrop: dragEnter event." );
     132                public void dragEnter( DropTargetDragEvent evt )
     133            {       Main.debug("FileDrop: dragEnter event." );
    278134
    279135            // Is this an acceptable drag event?
    280             if( isDragOk( out, evt ) )
     136            if( isDragOk( evt ) )
    281137            {
    282138                // If it's a Swing component, set its border
    283                 if( c instanceof javax.swing.JComponent )
    284                 {   javax.swing.JComponent jc = (javax.swing.JComponent) c;
     139                if( c instanceof JComponent )
     140                {   JComponent jc = (JComponent) c;
    285141                normalBorder = jc.getBorder();
    286                 log( out, "FileDrop: normal border saved." );
     142                Main.debug("FileDrop: normal border saved." );
    287143                jc.setBorder( dragBorder );
    288                 log( out, "FileDrop: drag border set." );
     144                Main.debug("FileDrop: drag border set." );
    289145                }   // end if: JComponent
    290146
    291147                // Acknowledge that it's okay to enter
    292                 //evt.acceptDrag( java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE );
    293                 evt.acceptDrag( java.awt.dnd.DnDConstants.ACTION_COPY );
    294                 log( out, "FileDrop: event accepted." );
     148                evt.acceptDrag( DnDConstants.ACTION_COPY );
     149                Main.debug("FileDrop: event accepted." );
    295150            }   // end if: drag ok
    296151            else
    297152            {   // Reject the drag event
    298153                evt.rejectDrag();
    299                 log( out, "FileDrop: event rejected." );
     154                Main.debug("FileDrop: event rejected." );
    300155            }   // end else: drag not ok
    301156            }   // end dragEnter
    302157
    303158            @Override
    304             public void dragOver( java.awt.dnd.DropTargetDragEvent evt )
     159            public void dragOver( DropTargetDragEvent evt )
    305160            {   // This is called continually as long as the mouse is
    306161                // over the drag target.
     
    308163
    309164            @Override
    310             public void drop( java.awt.dnd.DropTargetDropEvent evt )
    311             {   log( out, "FileDrop: drop event." );
     165            public void drop( DropTargetDropEvent evt )
     166            {   Main.debug("FileDrop: drop event." );
    312167            try
    313168            {   // Get whatever was dropped
    314                 java.awt.datatransfer.Transferable tr = evt.getTransferable();
     169                Transferable tr = evt.getTransferable();
    315170
    316171                // Is it a file list?
    317                 if (tr.isDataFlavorSupported (java.awt.datatransfer.DataFlavor.javaFileListFlavor))
     172                if (tr.isDataFlavorSupported (DataFlavor.javaFileListFlavor))
    318173                {
    319174                    // Say we'll take it.
    320                     //evt.acceptDrop ( java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE );
    321                     evt.acceptDrop ( java.awt.dnd.DnDConstants.ACTION_COPY );
    322                     log( out, "FileDrop: file list accepted." );
     175                    evt.acceptDrop ( DnDConstants.ACTION_COPY );
     176                    Main.debug("FileDrop: file list accepted." );
    323177
    324178                    // Get a useful list
    325                     List<?> fileList = (List<?>)tr.getTransferData(java.awt.datatransfer.DataFlavor.javaFileListFlavor);
     179                    List<?> fileList = (List<?>)tr.getTransferData(DataFlavor.javaFileListFlavor);
    326180
    327181                    // Convert list to array
     
    335189                    // Mark that drop is completed.
    336190                    evt.getDropTargetContext().dropComplete(true);
    337                     log( out, "FileDrop: drop complete." );
     191                    Main.debug("FileDrop: drop complete." );
    338192                }   // end if: file list
    339193                else // this section will check for a reader flavor.
     
    343197                    DataFlavor[] flavors = tr.getTransferDataFlavors();
    344198                    boolean handled = false;
    345                     for (int zz = 0; zz < flavors.length; zz++) {
    346                         if (flavors[zz].isRepresentationClassReader()) {
     199                    for (DataFlavor flavor : flavors) {
     200                        if (flavor.isRepresentationClassReader()) {
    347201                            // Say we'll take it.
    348                             //evt.acceptDrop ( java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE );
    349                             evt.acceptDrop(java.awt.dnd.DnDConstants.ACTION_COPY);
    350                             log(out, "FileDrop: reader accepted.");
    351 
    352                             Reader reader = flavors[zz].getReaderForText(tr);
     202                            evt.acceptDrop(DnDConstants.ACTION_COPY);
     203                            Main.debug("FileDrop: reader accepted.");
     204
     205                            Reader reader = flavor.getReaderForText(tr);
    353206
    354207                            BufferedReader br = new BufferedReader(reader);
    355208
    356                             if(listener != null) {
    357                                 listener.filesDropped(createFileArray(br, out));
     209                            if (listener != null) {
     210                                listener.filesDropped(createFileArray(br));
    358211                            }
    359212
    360213                            // Mark that drop is completed.
    361214                            evt.getDropTargetContext().dropComplete(true);
    362                             log(out, "FileDrop: drop complete.");
     215                            Main.debug("FileDrop: drop complete.");
    363216                            handled = true;
    364217                            break;
     
    366219                    }
    367220                    if(!handled){
    368                         log( out, "FileDrop: not a file list or reader - abort." );
     221                        Main.debug("FileDrop: not a file list or reader - abort." );
    369222                        evt.rejectDrop();
    370223                    }
     
    372225                }   // end else: not a file list
    373226            }   // end try
    374             catch ( java.io.IOException io)
    375             {   log( out, "FileDrop: IOException - abort:" );
    376             io.printStackTrace( out );
     227            catch ( IOException io)
     228            {   Main.warn("FileDrop: IOException - abort:" );
     229            io.printStackTrace();
    377230            evt.rejectDrop();
    378231            }   // end catch IOException
    379             catch (java.awt.datatransfer.UnsupportedFlavorException ufe)
    380             {   log( out, "FileDrop: UnsupportedFlavorException - abort:" );
    381             ufe.printStackTrace( out );
     232            catch (UnsupportedFlavorException ufe)
     233            {   Main.warn("FileDrop: UnsupportedFlavorException - abort:" );
     234            ufe.printStackTrace();
    382235            evt.rejectDrop();
    383236            }   // end catch: UnsupportedFlavorException
     
    385238            {
    386239                // If it's a Swing component, reset its border
    387                 if( c instanceof javax.swing.JComponent )
    388                 {   javax.swing.JComponent jc = (javax.swing.JComponent) c;
     240                if( c instanceof JComponent )
     241                {   JComponent jc = (JComponent) c;
    389242                jc.setBorder( normalBorder );
    390                 log( out, "FileDrop: normal border restored." );
     243                Main.debug("FileDrop: normal border restored." );
    391244                }   // end if: JComponent
    392245            }   // end finally
     
    394247
    395248            @Override
    396             public void dragExit( java.awt.dnd.DropTargetEvent evt )
    397             {   log( out, "FileDrop: dragExit event." );
     249            public void dragExit( DropTargetEvent evt )
     250            {   Main.debug("FileDrop: dragExit event." );
    398251            // If it's a Swing component, reset its border
    399             if( c instanceof javax.swing.JComponent )
    400             {   javax.swing.JComponent jc = (javax.swing.JComponent) c;
     252            if( c instanceof JComponent )
     253            {   JComponent jc = (JComponent) c;
    401254            jc.setBorder( normalBorder );
    402             log( out, "FileDrop: normal border restored." );
     255            Main.debug("FileDrop: normal border restored." );
    403256            }   // end if: JComponent
    404257            }   // end dragExit
    405258
    406259            @Override
    407             public void dropActionChanged( java.awt.dnd.DropTargetDragEvent evt )
    408             {   log( out, "FileDrop: dropActionChanged event." );
     260            public void dropActionChanged( DropTargetDragEvent evt )
     261            {   Main.debug("FileDrop: dropActionChanged event." );
    409262            // Is this an acceptable drag event?
    410             if( isDragOk( out, evt ) )
    411             {   //evt.acceptDrag( java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE );
    412                 evt.acceptDrag( java.awt.dnd.DnDConstants.ACTION_COPY );
    413                 log( out, "FileDrop: event accepted." );
     263            if( isDragOk( evt ) )
     264            {
     265                evt.acceptDrag( DnDConstants.ACTION_COPY );
     266                Main.debug("FileDrop: event accepted." );
    414267            }   // end if: drag ok
    415268            else
    416269            {   evt.rejectDrag();
    417             log( out, "FileDrop: event rejected." );
     270            Main.debug("FileDrop: event rejected." );
    418271            }   // end else: drag not ok
    419272            }   // end dropActionChanged
     
    421274
    422275            // Make the component (and possibly children) drop targets
    423             makeDropTarget( out, c, recursive );
     276            makeDropTarget( c, recursive );
    424277        }   // end if: supports dnd
    425278        else
    426         {   log( out, "FileDrop: Drag and drop is not supported with this JVM" );
     279        {   Main.info("FileDrop: Drag and drop is not supported with this JVM" );
    427280        }   // end else: does not support DnD
    428281    }   // end constructor
     
    446299    // BEGIN 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added.
    447300    private static String ZERO_CHAR_STRING = "" + (char)0;
    448     private static File[] createFileArray(BufferedReader bReader, PrintStream out)
     301    private static File[] createFileArray(BufferedReader bReader)
    449302    {
    450303        try {
    451             java.util.List<File> list = new java.util.ArrayList<File>();
    452             java.lang.String line = null;
     304            List<File> list = new ArrayList<File>();
     305            String line = null;
    453306            while ((line = bReader.readLine()) != null) {
    454307                try {
    455308                    // kde seems to append a 0 char to the end of the reader
    456                     if(ZERO_CHAR_STRING.equals(line)) {
     309                    if (ZERO_CHAR_STRING.equals(line)) {
    457310                        continue;
    458311                    }
    459312
    460                     java.io.File file = new java.io.File(new java.net.URI(line));
     313                    File file = new File(new URI(line));
    461314                    list.add(file);
    462315                } catch (Exception ex) {
    463                     log(out, "Error with " + line + ": " + ex.getMessage());
     316                    Main.warn("Error with " + line + ": " + ex.getMessage());
    464317                }
    465318            }
     
    467320            return list.toArray(new File[list.size()]);
    468321        } catch (IOException ex) {
    469             log(out, "FileDrop: IOException");
     322            Main.warn("FileDrop: IOException");
    470323        }
    471324        return new File[0];
     
    473326    // END 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added.
    474327
    475     private void makeDropTarget( final java.io.PrintStream out, final java.awt.Component c, boolean recursive )
     328    private void makeDropTarget( final Component c, boolean recursive )
    476329    {
    477330        // Make drop target
    478         final java.awt.dnd.DropTarget dt = new java.awt.dnd.DropTarget();
     331        final DropTarget dt = new DropTarget();
    479332        try
    480333        {   dt.addDropTargetListener( dropListener );
    481334        }   // end try
    482         catch( java.util.TooManyListenersException e )
     335        catch( TooManyListenersException e )
    483336        {   e.printStackTrace();
    484         log(out, "FileDrop: Drop will not work due to previous error. Do you have another listener attached?" );
     337        Main.warn("FileDrop: Drop will not work due to previous error. Do you have another listener attached?" );
    485338        }   // end catch
    486339
    487340        // Listen for hierarchy changes and remove the drop target when the parent gets cleared out.
    488         c.addHierarchyListener( new java.awt.event.HierarchyListener()
     341        c.addHierarchyListener( new HierarchyListener()
    489342        {   @Override
    490             public void hierarchyChanged( java.awt.event.HierarchyEvent evt )
    491         {   log( out, "FileDrop: Hierarchy changed." );
    492         java.awt.Component parent = c.getParent();
     343            public void hierarchyChanged( HierarchyEvent evt )
     344        {   Main.debug("FileDrop: Hierarchy changed." );
     345        Component parent = c.getParent();
    493346        if( parent == null )
    494347        {   c.setDropTarget( null );
    495         log( out, "FileDrop: Drop target cleared from component." );
     348        Main.debug("FileDrop: Drop target cleared from component." );
    496349        }   // end if: null parent
    497350        else
    498         {   new java.awt.dnd.DropTarget(c, dropListener);
    499         log( out, "FileDrop: Drop target added to component." );
     351        {   new DropTarget(c, dropListener);
     352        Main.debug("FileDrop: Drop target added to component." );
    500353        }   // end else: parent not null
    501354        }   // end hierarchyChanged
    502355        }); // end hierarchy listener
    503356        if( c.getParent() != null ) {
    504             new java.awt.dnd.DropTarget(c, dropListener);
     357            new DropTarget(c, dropListener);
    505358        }
    506359
    507         if( recursive && (c instanceof java.awt.Container ) )
     360        if( recursive && (c instanceof Container ) )
    508361        {
    509362            // Get the container
    510             java.awt.Container cont = (java.awt.Container) c;
     363            Container cont = (Container) c;
    511364
    512365            // Get it's components
    513             java.awt.Component[] comps = cont.getComponents();
     366            Component[] comps = cont.getComponents();
    514367
    515368            // Set it's components as listeners also
    516             for( int i = 0; i < comps.length; i++ ) {
    517                 makeDropTarget( out, comps[i], recursive );
     369            for (Component comp : comps) {
     370                makeDropTarget( comp, recursive);
    518371            }
    519372        }   // end if: recursively set components as listener
     
    521374
    522375    /** Determine if the dragged data is a file list. */
    523     private boolean isDragOk( final java.io.PrintStream out, final java.awt.dnd.DropTargetDragEvent evt )
     376    private boolean isDragOk( final DropTargetDragEvent evt )
    524377    {   boolean ok = false;
    525378
    526379    // Get data flavors being dragged
    527     java.awt.datatransfer.DataFlavor[] flavors = evt.getCurrentDataFlavors();
     380    DataFlavor[] flavors = evt.getCurrentDataFlavors();
    528381
    529382    // See if any of the flavors are a file list
     
    534387        // Is the flavor a file list?
    535388        final DataFlavor curFlavor = flavors[i];
    536         if( curFlavor.equals( java.awt.datatransfer.DataFlavor.javaFileListFlavor ) ||
     389        if( curFlavor.equals( DataFlavor.javaFileListFlavor ) ||
    537390                curFlavor.isRepresentationClassReader()){
    538391            ok = true;
     
    542395    }   // end while: through flavors
    543396
    544     // If logging is enabled, show data flavors
    545     if( out != null )
    546     {   if( flavors.length == 0 ) {
    547         log( out, "FileDrop: no data flavors." );
     397    // show data flavors
     398    if( flavors.length == 0 ) {
     399        Main.debug("FileDrop: no data flavors." );
    548400    }
    549401    for( i = 0; i < flavors.length; i++ ) {
    550         log( out, flavors[i].toString() );
     402        Main.debug(flavors[i].toString() );
    551403    }
    552     }   // end if: logging enabled
    553404
    554405    return ok;
    555406    }   // end isDragOk
    556 
    557     /** Outputs <tt>message</tt> to <tt>out</tt> if it's not null. */
    558     private static void log( java.io.PrintStream out, String message )
    559     {   // Log message if requested
    560         if( out != null ) {
    561             out.println( message );
    562         }
    563     }   // end log
    564407
    565408    /**
     
    571414     *
    572415     * @param c The component to unregister as a drop target
    573      * @since 1.0
     416     * @return {@code true} if at least one item has been removed, {@code false} otherwise
    574417     */
    575     public static boolean remove( java.awt.Component c)
    576     {   return remove( null, c, true );
     418    public static boolean remove( Component c)
     419    {   return remove( c, true );
    577420    }   // end remove
    578421
     
    582425     * components after you've set up the drag-and-drop.
    583426     *
    584      * @param out Optional {@link java.io.PrintStream} for logging drag and drop messages
    585427     * @param c The component to unregister
    586428     * @param recursive Recursively unregister components within a container
    587      * @since 1.0
     429     * @return {@code true} if at least one item has been removed, {@code false} otherwise
    588430     */
    589     public static boolean remove( java.io.PrintStream out, java.awt.Component c, boolean recursive )
     431    public static boolean remove( Component c, boolean recursive )
    590432    {   // Make sure we support dnd.
    591         if( supportsDnD() )
    592         {   log( out, "FileDrop: Removing drag-and-drop hooks." );
    593         c.setDropTarget( null );
    594         if( recursive && ( c instanceof java.awt.Container ) )
    595         {   java.awt.Component[] comps = ((java.awt.Container)c).getComponents();
    596         for( int i = 0; i < comps.length; i++ ) {
    597             remove( out, comps[i], recursive );
    598         }
    599         return true;
    600         }   // end if: recursive
    601         else return false;
     433        if (supportsDnD()) {
     434            Main.debug("FileDrop: Removing drag-and-drop hooks.");
     435            c.setDropTarget(null);
     436            if (recursive && (c instanceof Container)) {
     437                for (Component comp : ((Container) c).getComponents()) {
     438                    remove(comp, recursive);
     439                }
     440                return true;
     441            }   // end if: recursive
     442            else return false;
    602443        }   // end if: supports DnD
    603444        else return false;
     
    618459     *      ...
    619460     * </pre></code>
    620      *
    621      * @since 1.1
    622461     */
    623462    public static interface Listener {
     
    627466         *
    628467         * @param files An array of <tt>File</tt>s that were dropped.
    629          * @since 1.0
    630          */
    631         public abstract void filesDropped( java.io.File[] files );
     468         */
     469        public abstract void filesDropped( File[] files );
    632470
    633471    }   // end inner-interface Listener
     
    647485     * @version 1.2
    648486     */
    649     public static class Event extends java.util.EventObject {
    650 
    651         private java.io.File[] files;
     487    public static class Event extends EventObject {
     488
     489        private File[] files;
    652490
    653491        /**
     
    658496         * @param files The array of files that were dropped
    659497         * @param source The event source
    660          * @since 1.1
    661          */
    662         public Event( java.io.File[] files, Object source ) {
     498         */
     499        public Event( File[] files, Object source ) {
    663500            super( source );
    664501            this.files = files;
     
    670507         *
    671508         * @return array of files that were dropped
    672          * @since 1.1
    673          */
    674         public java.io.File[] getFiles() {
     509         */
     510        public File[] getFiles() {
    675511            return files;
    676512        }   // end getFiles
     
    722558     * @version 1.2
    723559     */
    724     public static class TransferableObject implements java.awt.datatransfer.Transferable
     560    public static class TransferableObject implements Transferable
    725561    {
    726562        /**
    727563         * The MIME type for {@link #DATA_FLAVOR} is
    728564         * <tt>application/x-net.iharder.dnd.TransferableObject</tt>.
    729          *
    730          * @since 1.1
    731565         */
    732566        public final static String MIME_TYPE = "application/x-net.iharder.dnd.TransferableObject";
     
    738572         * and the MIME type
    739573         * <tt>application/x-net.iharder.dnd.TransferableObject</tt>.
    740          *
    741          * @since 1.1
    742          */
    743         public final static java.awt.datatransfer.DataFlavor DATA_FLAVOR =
    744             new java.awt.datatransfer.DataFlavor( FileDrop.TransferableObject.class, MIME_TYPE );
     574         */
     575        public final static DataFlavor DATA_FLAVOR =
     576            new DataFlavor( FileDrop.TransferableObject.class, MIME_TYPE );
    745577
    746578        private Fetcher fetcher;
    747579        private Object data;
    748580
    749         private java.awt.datatransfer.DataFlavor customFlavor;
     581        private DataFlavor customFlavor;
    750582
    751583        /**
     
    757589         *
    758590         * @param data The data to transfer
    759          * @since 1.1
    760591         */
    761592        public TransferableObject( Object data )
    762593        {   this.data = data;
    763         this.customFlavor = new java.awt.datatransfer.DataFlavor( data.getClass(), MIME_TYPE );
     594            this.customFlavor = new DataFlavor( data.getClass(), MIME_TYPE );
    764595        }   // end constructor
    765596
     
    772603         * @see Fetcher
    773604         * @param fetcher The {@link Fetcher} that will return the data object
    774          * @since 1.1
    775605         */
    776606        public TransferableObject( Fetcher fetcher )
     
    789619         * @param dataClass The {@link java.lang.Class} to use in the custom data flavor
    790620         * @param fetcher The {@link Fetcher} that will return the data object
    791          * @since 1.1
    792621         */
    793622        public TransferableObject(Class<?> dataClass, Fetcher fetcher )
    794623        {   this.fetcher = fetcher;
    795         this.customFlavor = new java.awt.datatransfer.DataFlavor( dataClass, MIME_TYPE );
     624        this.customFlavor = new DataFlavor( dataClass, MIME_TYPE );
    796625        }   // end constructor
    797626
     
    802631         *
    803632         * @return The custom data flavor for the encapsulated object
    804          * @since 1.1
    805          */
    806         public java.awt.datatransfer.DataFlavor getCustomDataFlavor()
     633         */
     634        public DataFlavor getCustomDataFlavor()
    807635        {   return customFlavor;
    808636        }   // end getCustomDataFlavor
     
    815643         * second the default {@link #DATA_FLAVOR} associated with
    816644         * {@link TransferableObject}, and third the
    817          * {@link java.awt.datatransfer.DataFlavor.stringFlavor}.
     645         * {@link java.awt.datatransfer.DataFlavor#stringFlavor}.
    818646         *
    819647         * @return An array of supported data flavors
    820          * @since 1.1
    821648         */
    822649        @Override
    823         public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
     650        public DataFlavor[] getTransferDataFlavors()
    824651        {
    825652            if( customFlavor != null )
    826                 return new java.awt.datatransfer.DataFlavor[]
     653                return new DataFlavor[]
    827654                                                            {   customFlavor,
    828655                    DATA_FLAVOR,
    829                     java.awt.datatransfer.DataFlavor.stringFlavor
     656                    DataFlavor.stringFlavor
    830657                                                            };  // end flavors array
    831658            else
    832                 return new java.awt.datatransfer.DataFlavor[]
     659                return new DataFlavor[]
    833660                                                            {   DATA_FLAVOR,
    834                     java.awt.datatransfer.DataFlavor.stringFlavor
     661                    DataFlavor.stringFlavor
    835662                                                            };  // end flavors array
    836663        }   // end getTransferDataFlavors
     
    845672         * @param flavor The data flavor for the data to return
    846673         * @return The dropped data
    847          * @since 1.1
    848674         */
    849675        @Override
    850         public Object getTransferData( java.awt.datatransfer.DataFlavor flavor )
    851         throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOException
     676        public Object getTransferData( DataFlavor flavor )
     677        throws UnsupportedFlavorException, IOException
    852678        {
    853679            // Native object
     
    856682
    857683            // String
    858             if( flavor.equals( java.awt.datatransfer.DataFlavor.stringFlavor ) )
     684            if( flavor.equals( DataFlavor.stringFlavor ) )
    859685                return fetcher == null ? data.toString() : fetcher.getObject().toString();
    860686
    861687                // We can't do anything else
    862                 throw new java.awt.datatransfer.UnsupportedFlavorException(flavor);
     688                throw new UnsupportedFlavorException(flavor);
    863689        }   // end getTransferData
    864690
     
    869695         * @param flavor The data flavor to check
    870696         * @return Whether or not the flavor is supported
    871          * @since 1.1
    872697         */
    873698        @Override
    874         public boolean isDataFlavorSupported( java.awt.datatransfer.DataFlavor flavor )
     699        public boolean isDataFlavorSupported( DataFlavor flavor )
    875700        {
    876701            // Native object
     
    879704
    880705            // String
    881             if( flavor.equals( java.awt.datatransfer.DataFlavor.stringFlavor ) )
     706            if( flavor.equals( DataFlavor.stringFlavor ) )
    882707                return true;
    883708
     
    897722         *
    898723         * @author Robert Harder
    899          * @since 1.1
    900724         */
    901725        public static interface Fetcher
     
    906730             *
    907731             * @return The dropped object
    908              * @since 1.1
    909732             */
    910733            public abstract Object getObject();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r6084 r6104  
    1616import java.util.Collection;
    1717import java.util.HashSet;
    18 import java.util.Iterator;
    1918import java.util.LinkedList;
    2019import java.util.Set;
     
    382381                    getSize()
    383382            );
    384             Iterator<ListDataListener> it = listeners.iterator();
    385             while(it.hasNext()) {
    386                 it.next().contentsChanged(evt);
     383            for (ListDataListener listener : listeners) {
     384                listener.contentsChanged(evt);
    387385            }
    388386        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r6093 r6104  
    391391    protected void setContentVisible(boolean visible) {
    392392        Component[] comps = getComponents();
    393         for(int i=0; i<comps.length; i++) {
    394             if (comps[i] != titleBar && (!visible || comps[i] != buttonsPanel || buttonHiding != ButtonHiddingType.ALWAYS_HIDDEN)) {
    395                 comps[i].setVisible(visible);
     393        for (Component comp : comps) {
     394            if (comp != titleBar && (!visible || comp != buttonsPanel || buttonHiding != ButtonHiddingType.ALWAYS_HIDDEN)) {
     395                comp.setVisible(visible);
    396396            }
    397397        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r6092 r6104  
    2626import java.util.Collections;
    2727import java.util.EnumSet;
    28 import java.util.HashMap;
    2928import java.util.HashSet;
    30 import java.util.Iterator;
    3129import java.util.List;
    32 import java.util.Map;
    3330import java.util.Set;
    3431
     
    773770                return primitives;
    774771            ArrayList<OsmPrimitive> ret = new ArrayList<OsmPrimitive>();
    775             Iterator<OsmPrimitive> it = primitives.iterator();
    776             while(it.hasNext()) {
    777                 OsmPrimitive primitive = it.next();
     772            for (OsmPrimitive primitive : primitives) {
    778773                if (primitive instanceof Relation && getRelation() != null && getRelation().equals(primitive)) {
    779774                    warnOfCircularReferences(primitive);
    780775                    continue;
    781776                }
    782                 if (isPotentialDuplicate(primitive))  {
     777                if (isPotentialDuplicate(primitive)) {
    783778                    if (confirmAddingPrimitive(primitive)) {
    784779                        ret.add(primitive);
  • trunk/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java

    r6101 r6104  
    4949    protected void registerBoundingBoxBuilder() {
    5050        BoundingBoxBuilder bboxbuilder = new BoundingBoxBuilder();
    51         for (int i = 0;i < latlon.length; i++) {
    52             latlon[i].addFocusListener(bboxbuilder);
    53             latlon[i].addActionListener(bboxbuilder);
     51        for (JosmTextField ll : latlon) {
     52            ll.addFocusListener(bboxbuilder);
     53            ll.addActionListener(bboxbuilder);
    5454        }
    5555    }
  • trunk/src/org/openstreetmap/josm/gui/io/ActionFlagsTableCell.java

    r6084 r6104  
    5555
    5656        ActionMap am = getActionMap();
    57         for(int i=0; i<checkBoxes.length; i++) {
    58             final JCheckBox b = checkBoxes[i];
     57        for (final JCheckBox b : checkBoxes) {
    5958            add(b, GBC.eol().fill(GBC.HORIZONTAL));
    6059            b.setPreferredSize(new Dimension(b.getPreferredSize().width, 19));
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r5969 r6104  
    274274        images = new GeorefImage[dax][day];
    275275        if (old != null) {
    276             for (int i=0; i<old.length; i++) {
    277                 for (int k=0; k<old[i].length; k++) {
    278                     GeorefImage o = old[i][k];
    279                     images[modulo(o.getXIndex(),dax)][modulo(o.getYIndex(),day)] = old[i][k];
     276            for (GeorefImage[] row : old) {
     277                for (GeorefImage image : row) {
     278                    images[modulo(image.getXIndex(), dax)][modulo(image.getYIndex(), day)] = image;
    280279                }
    281280            }
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r6093 r6104  
    3434import java.util.Date;
    3535import java.util.Hashtable;
    36 import java.util.Iterator;
    3736import java.util.List;
    3837import java.util.TimeZone;
     
    452451        Collection<Layer> layerLst = Main.map.mapView.getAllLayers();
    453452        GpxDataWrapper defaultItem = null;
    454         Iterator<Layer> iterLayer = layerLst.iterator();
    455         while (iterLayer.hasNext()) {
    456             Layer cur = iterLayer.next();
     453        for (Layer cur : layerLst) {
    457454            if (cur instanceof GpxLayer) {
    458455                GpxLayer curGpx = (GpxLayer) cur;
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java

    r6083 r6104  
    9191            }
    9292            String names = null;
    93             for (int i = 0; i < sel.length; i++) {
     93            for (File file : sel) {
    9494                if (names == null) {
    9595                    names = " (";
     
    9797                    names += ", ";
    9898                }
    99                 names += sel[i].getName();
     99                names += file.getName();
    100100            }
    101101            if (names != null) {
     
    107107            double firstStartTime = sel[0].lastModified() / 1000.0 - AudioUtil.getCalibratedDuration(sel[0]);
    108108            Markers m = new Markers();
    109             for (int i = 0; i < sel.length; i++) {
    110                 importAudio(sel[i], ml, firstStartTime, m);
     109            for (File file : sel) {
     110                importAudio(file, ml, firstStartTime, m);
    111111            }
    112112            Main.main.addLayer(ml);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r6083 r6104  
    1111import java.util.Arrays;
    1212import java.util.Collection;
    13 import java.util.Iterator;
    1413import java.util.LinkedList;
    1514import java.util.List;
     
    135134            StyleList styleList = getStyles().generateStyles(virtualNode, 0.5, null, false).a;
    136135            if (styleList != null) {
    137                 for (Iterator<ElemStyle> it = styleList.iterator(); it.hasNext(); ) {
    138                     ElemStyle style = it.next();
     136                for (ElemStyle style : styleList) {
    139137                    if (style instanceof NodeElemStyle) {
    140138                        MapImage mapImage = ((NodeElemStyle) style).mapImage;
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java

    r6084 r6104  
    514514                Set<String> acceptedEulas = new HashSet<String>();
    515515
    516                 outer: for (int i = 0; i < lines.length; i++) {
    517                     ImageryInfo info = defaultModel.getRow(lines[i]);
     516                outer:
     517                for (int line : lines) {
     518                    ImageryInfo info = defaultModel.getRow(line);
    518519
    519520                    // Check if an entry with exactly the same values already
Note: See TracChangeset for help on using the changeset viewer.