Ignore:
Timestamp:
2015-06-02T16:40:38+02:00 (9 years ago)
Author:
Don-vip
Message:

remove extra whitespaces

File:
1 edited

Legend:

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

    r8419 r8443  
    3434import org.openstreetmap.josm.Main;
    3535import org.openstreetmap.josm.actions.OpenFileAction;
    36 import org.openstreetmap.josm.gui.FileDrop.TransferableObject;
    3736
    3837/**
     
    8584
    8685    // Default border color
    87     private static Color defaultBorderColor = new Color( 0f, 0f, 1f, 0.25f );
     86    private static Color defaultBorderColor = new Color(0f, 0f, 1f, 0.25f);
    8887
    8988    /**
     
    9190     * @param c The drop target
    9291     */
    93     public FileDrop(final Component c){
     92    public FileDrop(final Component c) {
    9493        this(
    9594                c,     // Drop target
    96                 BorderFactory.createMatteBorder( 2, 2, 2, 2, defaultBorderColor ), // Drag border
     95                BorderFactory.createMatteBorder(2, 2, 2, 2, defaultBorderColor), // Drag border
    9796                true, // Recursive
    98                 new FileDrop.Listener(){
     97                new FileDrop.Listener() {
    9998                    @Override
    100                     public void filesDropped( File[] files ){
     99                    public void filesDropped(File[] files){
    101100                        // start asynchronous loading of files
    102101                        OpenFileAction.OpenFileTask task = new OpenFileAction.OpenFileTask(Arrays.asList(files), null);
     
    126125            final Listener listener) {
    127126
    128         if( supportsDnD() ) {
     127        if (supportsDnD()) {
    129128            // Make a drop listener
    130129            dropListener = new DropTargetListener() {
    131130                @Override
    132                 public void dragEnter( DropTargetDragEvent evt ) {
     131                public void dragEnter(DropTargetDragEvent evt) {
    133132                    Main.trace("FileDrop: dragEnter event." );
    134133
    135134                    // Is this an acceptable drag event?
    136                     if( isDragOk( evt ) ) {
     135                    if (isDragOk(evt) ) {
    137136                        // If it's a Swing component, set its border
    138                         if( c instanceof JComponent ) {
     137                        if (c instanceof JComponent) {
    139138                           JComponent jc = (JComponent) c;
    140139                            normalBorder = jc.getBorder();
    141                             Main.trace("FileDrop: normal border saved." );
    142                             jc.setBorder( dragBorder );
    143                             Main.trace("FileDrop: drag border set." );
     140                            Main.trace("FileDrop: normal border saved.");
     141                            jc.setBorder(dragBorder);
     142                            Main.trace("FileDrop: drag border set.");
    144143                        }
    145144
    146145                        // Acknowledge that it's okay to enter
    147                         evt.acceptDrag( DnDConstants.ACTION_COPY );
    148                         Main.trace("FileDrop: event accepted." );
     146                        evt.acceptDrag( DnDConstants.ACTION_COPY);
     147                        Main.trace("FileDrop: event accepted.");
    149148                    } else {
    150149                        // Reject the drag event
    151150                        evt.rejectDrag();
    152                         Main.trace("FileDrop: event rejected." );
     151                        Main.trace("FileDrop: event rejected.");
    153152                    }
    154153                }
    155154
    156155                @Override
    157                 public void dragOver( DropTargetDragEvent evt ) {
     156                public void dragOver(DropTargetDragEvent evt) {
    158157                    // This is called continually as long as the mouse is over the drag target.
    159158                }
    160159
    161160                @Override
    162                 public void drop( DropTargetDropEvent evt ) {
    163                    Main.trace("FileDrop: drop event." );
     161                public void drop(DropTargetDropEvent evt) {
     162                   Main.trace("FileDrop: drop event.");
    164163                    try {
    165164                        // Get whatever was dropped
     
    180179
    181180                            // Alert listener to drop.
    182                             if( listener != null ) {
     181                            if (listener != null) {
    183182                                listener.filesDropped(files);
    184183                            }
     
    214213                                }
    215214                            }
    216                             if(!handled){
    217                                 Main.trace("FileDrop: not a file list or reader - abort." );
     215                            if (!handled) {
     216                                Main.trace("FileDrop: not a file list or reader - abort.");
    218217                                evt.rejectDrop();
    219218                            }
     
    221220                        }
    222221                    } catch (IOException | UnsupportedFlavorException e) {
    223                         Main.warn("FileDrop: "+e.getClass().getSimpleName()+" - abort:" );
     222                        Main.warn("FileDrop: "+e.getClass().getSimpleName()+" - abort:");
    224223                        Main.error(e);
    225224                        try {
     
    231230                    } finally {
    232231                        // If it's a Swing component, reset its border
    233                         if( c instanceof JComponent ) {
     232                        if (c instanceof JComponent) {
    234233                           JComponent jc = (JComponent) c;
    235                             jc.setBorder( normalBorder );
    236                             Main.debug("FileDrop: normal border restored." );
     234                            jc.setBorder(normalBorder);
     235                            Main.debug("FileDrop: normal border restored.");
    237236                        }
    238237                    }
     
    240239
    241240                @Override
    242                 public void dragExit( DropTargetEvent evt ) {
    243                     Main.debug("FileDrop: dragExit event." );
     241                public void dragExit(DropTargetEvent evt) {
     242                    Main.debug("FileDrop: dragExit event.");
    244243                    // If it's a Swing component, reset its border
    245                     if( c instanceof JComponent ) {
    246                        JComponent jc = (JComponent) c;
    247                         jc.setBorder( normalBorder );
    248                         Main.debug("FileDrop: normal border restored." );
     244                    if (c instanceof JComponent) {
     245                        JComponent jc = (JComponent) c;
     246                        jc.setBorder(normalBorder);
     247                        Main.debug("FileDrop: normal border restored.");
    249248                    }
    250249                }
    251250
    252251                @Override
    253                 public void dropActionChanged( DropTargetDragEvent evt ) {
    254                     Main.debug("FileDrop: dropActionChanged event." );
     252                public void dropActionChanged(DropTargetDragEvent evt) {
     253                    Main.debug("FileDrop: dropActionChanged event.");
    255254                    // Is this an acceptable drag event?
    256                     if( isDragOk( evt ) ) {
    257                         evt.acceptDrag( DnDConstants.ACTION_COPY );
    258                         Main.debug("FileDrop: event accepted." );
     255                    if (isDragOk(evt) ) {
     256                        evt.acceptDrag( DnDConstants.ACTION_COPY);
     257                        Main.debug("FileDrop: event accepted.");
    259258                    } else {
    260259                        evt.rejectDrag();
    261                         Main.debug("FileDrop: event rejected." );
     260                        Main.debug("FileDrop: event rejected.");
    262261                    }
    263262                }
     
    265264
    266265            // Make the component (and possibly children) drop targets
    267             makeDropTarget( c, recursive );
     266            makeDropTarget(c, recursive);
    268267        } else {
    269             Main.info("FileDrop: Drag and drop is not supported with this JVM" );
     268            Main.info("FileDrop: Drag and drop is not supported with this JVM");
    270269        }
    271270    }
    272271
    273272    private static synchronized boolean supportsDnD() {
    274         if( supportsDnD == null ) {
     273        if (supportsDnD == null) {
    275274            boolean support = false;
    276275            try {
    277                 Class.forName( "java.awt.dnd.DnDConstants" );
     276                Class.forName("java.awt.dnd.DnDConstants");
    278277                support = true;
    279             } catch( Exception e ) {
     278            } catch(Exception e) {
    280279                support = false;
    281280            }
     
    313312    // END 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added.
    314313
    315     private void makeDropTarget( final Component c, boolean recursive ) {
     314    private void makeDropTarget(final Component c, boolean recursive) {
    316315        // Make drop target
    317316        final DropTarget dt = new DropTarget();
    318317        try {
    319             dt.addDropTargetListener( dropListener );
    320         } catch( TooManyListenersException e ) {
     318            dt.addDropTargetListener(dropListener);
     319        } catch(TooManyListenersException e) {
    321320            Main.error(e);
    322             Main.warn("FileDrop: Drop will not work due to previous error. Do you have another listener attached?" );
     321            Main.warn("FileDrop: Drop will not work due to previous error. Do you have another listener attached?");
    323322        }
    324323
    325324        // Listen for hierarchy changes and remove the drop target when the parent gets cleared out.
    326         c.addHierarchyListener( new HierarchyListener() {
     325        c.addHierarchyListener(new HierarchyListener() {
    327326            @Override
    328             public void hierarchyChanged( HierarchyEvent evt ) {
    329                 Main.trace("FileDrop: Hierarchy changed." );
     327            public void hierarchyChanged(HierarchyEvent evt) {
     328                Main.trace("FileDrop: Hierarchy changed.");
    330329                Component parent = c.getParent();
    331                 if( parent == null ) {
    332                     c.setDropTarget( null );
    333                     Main.trace("FileDrop: Drop target cleared from component." );
     330                if (parent == null) {
     331                    c.setDropTarget(null);
     332                    Main.trace("FileDrop: Drop target cleared from component.");
    334333                } else {
    335334                    new DropTarget(c, dropListener);
    336                     Main.trace("FileDrop: Drop target added to component." );
     335                    Main.trace("FileDrop: Drop target added to component.");
    337336                }
    338337            }
    339338        });
    340         if( c.getParent() != null ) {
     339        if (c.getParent() != null) {
    341340            new DropTarget(c, dropListener);
    342341        }
    343342
    344         if( recursive && (c instanceof Container ) ) {
     343        if (recursive && (c instanceof Container)) {
    345344            // Get the container
    346345            Container cont = (Container) c;
     
    351350            // Set it's components as listeners also
    352351            for (Component comp : comps) {
    353                 makeDropTarget( comp, recursive);
     352                makeDropTarget(comp, recursive);
    354353            }
    355354        }
     
    357356
    358357    /** Determine if the dragged data is a file list. */
    359     private boolean isDragOk( final DropTargetDragEvent evt ) {
     358    private boolean isDragOk(final DropTargetDragEvent evt) {
    360359        boolean ok = false;
    361360
     
    365364        // See if any of the flavors are a file list
    366365        int i = 0;
    367         while( !ok && i < flavors.length ) {
     366        while(!ok && i < flavors.length) {
    368367            // BEGIN 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added.
    369368            // Is the flavor a file list?
    370369            final DataFlavor curFlavor = flavors[i];
    371             if( curFlavor.equals( DataFlavor.javaFileListFlavor ) ||
     370            if (curFlavor.equals( DataFlavor.javaFileListFlavor ) ||
    372371                    curFlavor.isRepresentationClassReader()){
    373372                ok = true;
     
    378377
    379378        // show data flavors
    380         if( flavors.length == 0 ) {
    381             Main.trace("FileDrop: no data flavors." );
    382         }
    383         for( i = 0; i < flavors.length; i++ ) {
    384             Main.trace(flavors[i].toString() );
     379        if (flavors.length == 0) {
     380            Main.trace("FileDrop: no data flavors.");
     381        }
     382        for (i = 0; i < flavors.length; i++) {
     383            Main.trace(flavors[i].toString());
    385384        }
    386385
     
    398397     * @return {@code true} if at least one item has been removed, {@code false} otherwise
    399398     */
    400     public static boolean remove( Component c) {
    401         return remove( c, true );
     399    public static boolean remove(Component c) {
     400        return remove(c, true);
    402401    }
    403402
     
    411410     * @return {@code true} if at least one item has been removed, {@code false} otherwise
    412411     */
    413     public static boolean remove( Component c, boolean recursive ) {
     412    public static boolean remove(Component c, boolean recursive) {
    414413        // Make sure we support dnd.
    415414        if (supportsDnD()) {
     
    449448         * @param files An array of <tt>File</tt>s that were dropped.
    450449         */
    451         public abstract void filesDropped( File[] files );
     450        public abstract void filesDropped(File[] files);
    452451    }
    453452
     
    512511         */
    513512        public static final DataFlavor DATA_FLAVOR =
    514             new DataFlavor( FileDrop.TransferableObject.class, MIME_TYPE );
     513            new DataFlavor(FileDrop.TransferableObject.class, MIME_TYPE);
    515514
    516515        private Fetcher fetcher;
     
    528527         * @param data The data to transfer
    529528         */
    530         public TransferableObject( Object data ) {
     529        public TransferableObject(Object data) {
    531530            this.data = data;
    532             this.customFlavor = new DataFlavor( data.getClass(), MIME_TYPE );
     531            this.customFlavor = new DataFlavor(data.getClass(), MIME_TYPE);
    533532        }
    534533
     
    542541         * @param fetcher The {@link Fetcher} that will return the data object
    543542         */
    544         public TransferableObject( Fetcher fetcher ) {
     543        public TransferableObject(Fetcher fetcher) {
    545544            this.fetcher = fetcher;
    546545        }
     
    558557         * @see Fetcher
    559558         */
    560         public TransferableObject(Class<?> dataClass, Fetcher fetcher ) {
     559        public TransferableObject(Class<?> dataClass, Fetcher fetcher) {
    561560            this.fetcher = fetcher;
    562             this.customFlavor = new DataFlavor( dataClass, MIME_TYPE );
     561            this.customFlavor = new DataFlavor(dataClass, MIME_TYPE);
    563562        }
    564563
     
    587586        @Override
    588587        public DataFlavor[] getTransferDataFlavors() {
    589             if( customFlavor != null )
     588            if (customFlavor != null)
    590589                return new DataFlavor[] {
    591590                    customFlavor,
     
    609608         */
    610609        @Override
    611         public Object getTransferData( DataFlavor flavor )
     610        public Object getTransferData(DataFlavor flavor)
    612611        throws UnsupportedFlavorException, IOException {
    613612            // Native object
    614             if( flavor.equals( DATA_FLAVOR ) )
     613            if (flavor.equals(DATA_FLAVOR))
    615614                return fetcher == null ? data : fetcher.getObject();
    616615
    617616            // String
    618             if( flavor.equals( DataFlavor.stringFlavor ) )
     617            if (flavor.equals(DataFlavor.stringFlavor))
    619618                return fetcher == null ? data.toString() : fetcher.getObject().toString();
    620619
     
    631630         */
    632631        @Override
    633         public boolean isDataFlavorSupported( DataFlavor flavor ) {
     632        public boolean isDataFlavorSupported(DataFlavor flavor) {
    634633            // Native object
    635             if( flavor.equals( DATA_FLAVOR ) )
     634            if (flavor.equals(DATA_FLAVOR))
    636635                return true;
    637636
    638637            // String
    639             if( flavor.equals( DataFlavor.stringFlavor ) )
     638            if (flavor.equals( DataFlavor.stringFlavor))
    640639                return true;
    641640
Note: See TracChangeset for help on using the changeset viewer.