Changeset 2986 in josm


Ignore:
Timestamp:
Feb 14, 2010 7:05:36 PM (3 years ago)
Author:
jttt
Message:

Fix some of FindBugs warnings

Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r2759 r2986  
    4747        if (Main.main == null || Main.main.getEditLayer() == null) return; 
    4848        if (Main.map == null || Main.map.mapView == null) return; 
    49         Collection<OsmPrimitive> sel = new HashSet<OsmPrimitive>(); 
    50         sel = Main.main.getEditLayer().data.getSelected(); 
     49        Collection<OsmPrimitive> sel = Main.main.getEditLayer().data.getSelected(); 
    5150        if (sel.isEmpty()) { 
    5251            JOptionPane.showMessageDialog( 
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java

    r2985 r2986  
    348348        if(currentMode.equals(c) || (!drawTargetCursor && currentMode.equals(DeleteMode.none))) 
    349349            return; 
    350         try { 
    351             // We invoke this to prevent strange things from happening 
    352             EventQueue.invokeLater(new Runnable() { 
    353                 public void run() { 
    354                     // Don't change cursor when mode has changed already 
    355                     if(!(Main.map.mapMode instanceof DeleteAction)) 
    356                         return; 
    357  
    358                     Main.map.mapView.setCursor(c.cursor()); 
    359                     //System.out.println("Set cursor to: " + c.name()); 
    360                 } 
    361             }); 
    362             currentMode = c; 
    363         } catch(Exception e) {} 
     350        // We invoke this to prevent strange things from happening 
     351        EventQueue.invokeLater(new Runnable() { 
     352            public void run() { 
     353                // Don't change cursor when mode has changed already 
     354                if(!(Main.map.mapMode instanceof DeleteAction)) 
     355                    return; 
     356 
     357                Main.map.mapView.setCursor(c.cursor()); 
     358                //System.out.println("Set cursor to: " + c.name()); 
     359            } 
     360        }); 
     361        currentMode = c; 
    364362    } 
    365363 
  • trunk/src/org/openstreetmap/josm/data/osm/ChangesetCache.java

    r2801 r2986  
    6060 
    6161    public void addChangesetCacheListener(ChangesetCacheListener listener) { 
    62         synchronized(listeners) { 
    63             if (listener != null && ! listeners.contains(listener)) { 
    64                 listeners.add(listener); 
    65             } 
    66         } 
     62        listeners.addIfAbsent(listener); 
    6763    } 
    6864 
    6965    public void removeChangesetCacheListener(ChangesetCacheListener listener) { 
    70         synchronized(listeners) { 
    71             if (listener != null && listeners.contains(listener)) { 
    72                 listeners.remove(listener); 
    73             } 
    74         } 
     66        listeners.remove(listener); 
    7567    } 
    7668 
  • trunk/src/org/openstreetmap/josm/data/osm/DataSource.java

    r2013 r2986  
    44import org.openstreetmap.josm.data.Bounds; 
    55 
    6 public class DataSource implements Cloneable { 
     6public class DataSource { 
    77    public final Bounds bounds; 
    88    public final String origin; 
     
    1111        this.bounds = bounds; 
    1212        this.origin = origin; 
    13         if (bounds == null) { 
     13        if (bounds == null) 
    1414            throw new NullPointerException(); 
    15         } 
    16     } 
    17  
    18     @Override protected Object clone() throws CloneNotSupportedException { 
    19         return new DataSource(bounds, origin); 
    2015    } 
    2116} 
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r2985 r2986  
    552552            DataSet.selListeners.remove(selectionTableModel); 
    553553            getLayer().data.removeDataSetListener(memberTableModel); 
    554             getLayer().listenerDataChanged.remove(memberTableModel); 
    555554            memberTable.unlinkAsListener(); 
    556555            dispose(); 
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java

    r2621 r2986  
    4444     */ 
    4545    static private class DialogContext { 
    46         public Relation relation; 
    47         public OsmDataLayer layer; 
     46        public final Relation relation; 
     47        public final OsmDataLayer layer; 
    4848 
    4949        public DialogContext(OsmDataLayer layer, Relation relation) { 
     
    9494 
    9595    /** the map of open dialogs */ 
    96     private HashMap<DialogContext, RelationEditor> openDialogs; 
     96    private final HashMap<DialogContext, RelationEditor> openDialogs; 
    9797 
    9898    /** 
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java

    r2985 r2986  
    842842            OsmDataLayer l = (OsmDataLayer)oldLayer; 
    843843            l.data.removeDataSetListener(this); 
    844             l.listenerDataChanged.remove(this); 
    845844        } 
    846845        if (newLayer == null || ! (newLayer instanceof OsmDataLayer)) { 
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java

    r2711 r2986  
    125125            selectedRect = null; 
    126126 
    127             if (image == null) { 
    128                 return; 
    129             } 
     127            if (image == null) 
     128                return; 
    130129 
    131130            // Calculate the mouse cursor position in image coordinates, so that we can center the zoom 
     
    196195            } 
    197196 
    198             if (image == null) { 
    199                 return; 
    200             } 
    201  
    202             if (e.getButton() != DRAG_BUTTON) { 
    203                 return; 
    204             } 
     197            if (image == null) 
     198                return; 
     199 
     200            if (e.getButton() != DRAG_BUTTON) 
     201                return; 
    205202 
    206203            // Calculate the translation to set the clicked point the center of the view. 
     
    230227            } 
    231228 
    232             File file; 
    233229            Image image; 
    234230            Rectangle visibleRect; 
    235231 
    236232            synchronized (ImageDisplay.this) { 
    237                 file = ImageDisplay.this.file; 
    238233                image = ImageDisplay.this.image; 
    239234                visibleRect = ImageDisplay.this.visibleRect; 
    240235            } 
    241236 
    242             if (image == null) { 
    243                 return; 
    244             } 
     237            if (image == null) 
     238                return; 
    245239 
    246240            if (e.getButton() == DRAG_BUTTON) { 
     
    261255 
    262256        public void mouseDragged(MouseEvent e) { 
    263             if (! mouseIsDragging && selectedRect == null) { 
    264                 return; 
    265             } 
     257            if (! mouseIsDragging && selectedRect == null) 
     258                return; 
    266259 
    267260            File file; 
     
    310303 
    311304        public void mouseReleased(MouseEvent e) { 
    312             if (! mouseIsDragging && selectedRect == null) { 
    313                 return; 
    314             } 
     305            if (! mouseIsDragging && selectedRect == null) 
     306                return; 
    315307 
    316308            File file; 
    317309            Image image; 
    318             Rectangle visibleRect; 
    319310 
    320311            synchronized (ImageDisplay.this) { 
    321312                file = ImageDisplay.this.file; 
    322313                image = ImageDisplay.this.image; 
    323                 visibleRect = ImageDisplay.this.visibleRect; 
    324314            } 
    325315 
     
    424414    } 
    425415 
     416    @Override 
    426417    public void paintComponent(Graphics g) { 
    427418        Image image; 
     
    443434            Dimension size = getSize(); 
    444435            g.drawString(noImageStr, 
    445                          (int) ((size.width - noImageSize.getWidth()) / 2), 
    446                          (int) ((size.height - noImageSize.getHeight()) / 2)); 
     436                    (int) ((size.width - noImageSize.getWidth()) / 2), 
     437                    (int) ((size.height - noImageSize.getHeight()) / 2)); 
    447438        } else if (image == null) { 
    448439            g.setColor(Color.black); 
    449440            String loadingStr; 
    450441            if (! errorLoading) {; 
    451                 loadingStr = tr("Loading {0}", file.getName()); 
     442            loadingStr = tr("Loading {0}", file.getName()); 
    452443            } else { 
    453444                loadingStr = tr("Error on file {0}", file.getName()); 
     
    456447            Dimension size = getSize(); 
    457448            g.drawString(loadingStr, 
    458                          (int) ((size.width - noImageSize.getWidth()) / 2), 
    459                          (int) ((size.height - noImageSize.getHeight()) / 2)); 
     449                    (int) ((size.width - noImageSize.getWidth()) / 2), 
     450                    (int) ((size.height - noImageSize.getHeight()) / 2)); 
    460451        } else { 
    461452            Rectangle target = calculateDrawImageRectangle(visibleRect); 
    462453            g.drawImage(image, 
    463                         target.x, target.y, target.x + target.width, target.y + target.height, 
    464                         visibleRect.x, visibleRect.y, visibleRect.x + visibleRect.width, visibleRect.y + visibleRect.height, 
    465                         null); 
     454                    target.x, target.y, target.x + target.width, target.y + target.height, 
     455                    visibleRect.x, visibleRect.y, visibleRect.x + visibleRect.width, visibleRect.y + visibleRect.height, 
     456                    null); 
    466457            if (selectedRect != null) { 
    467458                Point topLeft = img2compCoord(visibleRect, selectedRect.x, selectedRect.y); 
    468459                Point bottomRight = img2compCoord(visibleRect, 
    469                                                   selectedRect.x + selectedRect.width, 
    470                                                   selectedRect.y + selectedRect.height); 
     460                        selectedRect.x + selectedRect.width, 
     461                        selectedRect.y + selectedRect.height); 
    471462                g.setColor(new Color(128, 128, 128, 180)); 
    472463                g.fillRect(target.x, target.y, target.width, topLeft.y - target.y); 
     
    482473                Dimension size = getSize(); 
    483474                g.drawString(loadingStr, 
    484                              (int) ((size.width - noImageSize.getWidth()) / 2), 
    485                              (int) ((size.height - noImageSize.getHeight()) / 2)); 
     475                        (int) ((size.width - noImageSize.getWidth()) / 2), 
     476                        (int) ((size.height - noImageSize.getHeight()) / 2)); 
    486477            } 
    487478            if (osdText != null) { 
     
    519510        Rectangle drawRect = calculateDrawImageRectangle(visibleRect); 
    520511        return new Point(drawRect.x + ((xImg - visibleRect.x) * drawRect.width) / visibleRect.width, 
    521                          drawRect.y + ((yImg - visibleRect.y) * drawRect.height) / visibleRect.height); 
     512                drawRect.y + ((yImg - visibleRect.y) * drawRect.height) / visibleRect.height); 
    522513    } 
    523514 
     
    525516        Rectangle drawRect = calculateDrawImageRectangle(visibleRect); 
    526517        return new Point(visibleRect.x + ((xComp - drawRect.x) * visibleRect.width) / drawRect.width, 
    527                          visibleRect.y + ((yComp - drawRect.y) * visibleRect.height) / drawRect.height); 
    528     } 
    529  
    530    private final Point getCenterImgCoord(Rectangle visibleRect) { 
     518                visibleRect.y + ((yComp - drawRect.y) * visibleRect.height) / drawRect.height); 
     519    } 
     520 
     521    private final Point getCenterImgCoord(Rectangle visibleRect) { 
    531522        return new Point(visibleRect.x + visibleRect.width / 2, 
    532                                  visibleRect.y + visibleRect.height / 2); 
     523                visibleRect.y + visibleRect.height / 2); 
    533524    } 
    534525 
     
    576567        } 
    577568 
    578         if (image == null) { 
     569        if (image == null) 
    579570            return; 
    580         } 
    581571 
    582572        if (visibleRect.width != image.getWidth(null) || visibleRect.height != image.getHeight(null)) { 
     
    588578            Point center = getCenterImgCoord(visibleRect); 
    589579            visibleRect = new Rectangle(center.x - getWidth() / 2, center.y - getHeight() / 2, 
    590                                         getWidth(), getHeight()); 
     580                    getWidth(), getHeight()); 
    591581            checkVisibleRectPos(image, visibleRect); 
    592582        } 
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ThumbsLoader.java

    r2931 r2986  
    22 
    33package org.openstreetmap.josm.gui.layer.geoimage; 
    4  
    5 import static org.openstreetmap.josm.tools.I18n.tr; 
    64 
    75import java.awt.Graphics2D; 
     
    119import java.awt.Toolkit; 
    1210import java.awt.image.BufferedImage; 
    13 import java.io.File; 
    1411import java.util.ArrayList; 
    1512import java.util.List; 
    1613 
     14import org.openstreetmap.josm.Main; 
    1715import org.openstreetmap.josm.io.CacheFiles; 
    18 import org.openstreetmap.josm.Main; 
    1916 
    2017public class ThumbsLoader implements Runnable { 
    21         public static final int maxSize = 120; 
    22         public static final int minSize = 22; 
    23         volatile boolean stop = false; 
    24         List<ImageEntry> data; 
    25         GeoImageLayer layer; 
    26         MediaTracker tracker; 
    27         CacheFiles cache; 
    28         boolean cacheOff = Main.pref.getBoolean("geoimage.noThumbnailCache", false); 
     18    public static final int maxSize = 120; 
     19    public static final int minSize = 22; 
     20    volatile boolean stop = false; 
     21    List<ImageEntry> data; 
     22    GeoImageLayer layer; 
     23    MediaTracker tracker; 
     24    CacheFiles cache; 
     25    boolean cacheOff = Main.pref.getBoolean("geoimage.noThumbnailCache", false); 
    2926 
    30         public ThumbsLoader(GeoImageLayer layer) { 
    31             this.layer = layer; 
    32             this.data = new ArrayList<ImageEntry>(layer.data); 
    33             if (!cacheOff) { 
    34                 cache = new CacheFiles("geoimage-thumbnails", false); 
    35                 cache.setExpire(CacheFiles.EXPIRE_NEVER, false); 
    36                 cache.setMaxSize(120, false); 
     27    public ThumbsLoader(GeoImageLayer layer) { 
     28        this.layer = layer; 
     29        this.data = new ArrayList<ImageEntry>(layer.data); 
     30        if (!cacheOff) { 
     31            cache = new CacheFiles("geoimage-thumbnails", false); 
     32            cache.setExpire(CacheFiles.EXPIRE_NEVER, false); 
     33            cache.setMaxSize(120, false); 
     34        } 
     35    } 
     36 
     37    public void run() { 
     38        System.err.println("Load Thumbnails"); 
     39        tracker = new MediaTracker(Main.map.mapView); 
     40        for (int i = 0; i < data.size(); i++) { 
     41            if (stop) return; 
     42 
     43            System.err.print("fetching image "+i); 
     44 
     45            data.get(i).thumbnail = loadThumb(data.get(i)); 
     46 
     47            if (Main.map != null && Main.map.mapView != null) { 
     48                layer.updateOffscreenBuffer = true; 
     49                Main.map.mapView.repaint(); 
     50            } 
     51        } 
     52        try { 
     53            layer.updateOffscreenBuffer = true; 
     54        } catch (Exception e) {} 
     55        Main.map.mapView.repaint(); 
     56        (new Thread() {             // clean up the garbage - shouldn't hurt 
     57            @Override 
     58            public void run() { 
     59                try { 
     60                    Thread.sleep(200); 
     61                } 
     62                catch (InterruptedException ie) {} 
     63                System.gc(); 
     64            } 
     65        }).start(); 
     66 
     67    } 
     68 
     69    private BufferedImage loadThumb(ImageEntry entry) { 
     70        final String cacheIdent = entry.getFile().toString()+":"+maxSize; 
     71 
     72        if (!cacheOff) { 
     73            BufferedImage cached = cache.getImg(cacheIdent); 
     74            if(cached != null) { 
     75                System.err.println(" from cache"); 
     76                return cached; 
    3777            } 
    3878        } 
    3979 
    40         public void run() { 
    41             System.err.println("Load Thumbnails"); 
    42             tracker = new MediaTracker(Main.map.mapView); 
    43             for (int i = 0; i < data.size(); i++) { 
    44                 if (stop) return; 
     80        Image img = Toolkit.getDefaultToolkit().createImage(entry.getFile().getPath()); 
     81        tracker.addImage(img, 0); 
     82        try { 
     83            tracker.waitForID(0); 
     84        } catch (InterruptedException e) { 
     85            System.err.println(" InterruptedException"); 
     86            return null; 
     87        } 
     88        if (tracker.isErrorID(1) || img.getWidth(null) <= 0 || img.getHeight(null) <= 0) { 
     89            System.err.println(" Invalid image"); 
     90            return null; 
     91        } 
     92        Rectangle targetSize = ImageDisplay.calculateDrawImageRectangle( 
     93                new Rectangle(0, 0, img.getWidth(null), img.getHeight(null)), 
     94                new Rectangle(0, 0, maxSize, maxSize)); 
     95        BufferedImage scaledBI = new BufferedImage(targetSize.width, targetSize.height, BufferedImage.TYPE_INT_RGB); 
     96        Graphics2D g = scaledBI.createGraphics(); 
     97        while (!g.drawImage(img, 0, 0, targetSize.width, targetSize.height, null)) 
     98        { 
     99            try { 
     100                Thread.sleep(10); 
     101            } catch(InterruptedException ie) {} 
     102        } 
     103        g.dispose(); 
     104        tracker.removeImage(img); 
    45105 
    46                 System.err.print("fetching image "+i); 
    47  
    48                 data.get(i).thumbnail = loadThumb(data.get(i)); 
    49  
    50                 if (Main.map != null && Main.map.mapView != null) { 
    51                     try { 
    52                         layer.updateOffscreenBuffer = true; 
    53                     } catch (Exception e) {} 
    54                     Main.map.mapView.repaint(); 
    55                 } 
    56             } 
    57             try { 
    58                 layer.updateOffscreenBuffer = true; 
    59             } catch (Exception e) {} 
    60             Main.map.mapView.repaint(); 
    61             (new Thread() {             // clean up the garbage - shouldn't hurt 
    62                 public void run() { 
    63                     try { 
    64                         Thread.sleep(200); 
    65                     } 
    66                     catch (InterruptedException ie) {} 
    67                     System.gc(); 
    68                 } 
    69             }).start(); 
    70  
     106        if (scaledBI.getWidth() <= 0 || scaledBI.getHeight() <= 0) { 
     107            System.err.println(" Invalid image"); 
     108            return null; 
    71109        } 
    72110 
    73         private BufferedImage loadThumb(ImageEntry entry) { 
    74             final String cacheIdent = entry.getFile().toString()+":"+maxSize; 
    75  
    76             if (!cacheOff) { 
    77                 BufferedImage cached = cache.getImg(cacheIdent); 
    78                 if(cached != null) { 
    79                     System.err.println(" from cache"); 
    80                     return cached; 
    81                 } 
    82             } 
    83  
    84             Image img = Toolkit.getDefaultToolkit().createImage(entry.getFile().getPath()); 
    85             tracker.addImage(img, 0); 
    86             try { 
    87                 tracker.waitForID(0); 
    88             } catch (InterruptedException e) { 
    89                 System.err.println(" InterruptedException"); 
    90                 return null; 
    91             } 
    92             if (tracker.isErrorID(1) || img.getWidth(null) <= 0 || img.getHeight(null) <= 0) { 
    93                 System.err.println(" Invalid image"); 
    94                 return null; 
    95             } 
    96             Rectangle targetSize = ImageDisplay.calculateDrawImageRectangle( 
    97                 new Rectangle(0, 0, img.getWidth(null), img.getHeight(null)), 
    98                 new Rectangle(0, 0, maxSize, maxSize)); 
    99             BufferedImage scaledBI = new BufferedImage(targetSize.width, targetSize.height, BufferedImage.TYPE_INT_RGB); 
    100             Graphics2D g = scaledBI.createGraphics(); 
    101             while (!g.drawImage(img, 0, 0, targetSize.width, targetSize.height, null)) 
    102             { 
    103                 try { 
    104                     Thread.sleep(10); 
    105                 } catch(InterruptedException ie) {} 
    106             } 
    107             g.dispose(); 
    108             tracker.removeImage(img); 
    109  
    110             if (scaledBI == null || scaledBI.getWidth() <= 0 || scaledBI.getHeight() <= 0) { 
    111                 System.err.println(" Invalid image"); 
    112                 return null; 
    113             } 
    114  
    115             if (!cacheOff) { 
    116                 cache.saveImg(cacheIdent, scaledBI); 
    117             } 
    118  
    119             System.err.println(""); 
    120             return scaledBI; 
     111        if (!cacheOff) { 
     112            cache.saveImg(cacheIdent, scaledBI); 
    121113        } 
    122114 
     115        System.err.println(""); 
     116        return scaledBI; 
    123117    } 
     118 
     119} 
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferencesModel.java

    r2817 r2986  
    3939            displayedPlugins.clear(); 
    4040            displayedPlugins.addAll(availablePlugins); 
    41             this.filterExpression = filter; 
     41            this.filterExpression = null; 
    4242            return; 
    4343        } 
  • trunk/src/org/openstreetmap/josm/io/CacheCustomContent.java

    r1610 r2986  
    77import java.io.FileInputStream; 
    88import java.io.FileOutputStream; 
     9import java.io.IOException; 
    910import java.util.Date; 
    1011 
     
    124125     */ 
    125126    public byte[] getData() { 
    126         if(data == null) 
     127        if(data == null) { 
    127128            loadFromDisk(); 
     129        } 
    128130        return data; 
    129131    } 
     
    146148            input.read(this.data); 
    147149            input.close(); 
    148         } catch(Exception e) { 
     150        } catch(IOException e) { 
    149151            this.data = updateForce(); 
    150152        } 
     
    160162            output.flush(); 
    161163            output.close(); 
    162         } catch(Exception e) {} 
     164        } catch(Exception e) { 
     165            e.printStackTrace(); 
     166        } 
    163167    } 
    164168 
  • trunk/src/org/openstreetmap/josm/io/CacheFiles.java

    r2817 r2986  
    4343 
    4444    // If the cache is full, we don't want to delete just one file 
    45     private final int cleanUpThreshold = 20; 
     45    private static final int cleanUpThreshold = 20; 
    4646    // We don't want to clean after every file-write 
    47     private final int cleanUpInterval = 5; 
     47    private static final int cleanUpInterval = 5; 
    4848    // Stores how many files have been written 
    4949    private int writes = 0; 
  • trunk/test/functional/org/openstreetmap/josm/gui/dialogs/changeset/query/ChangesetQueryDialogTest.java

    r2690 r2986  
    33 
    44import javax.swing.JFrame; 
    5  
    6 import org.openstreetmap.josm.fixtures.JOSMFixture; 
    75 
    86public class ChangesetQueryDialogTest extends JFrame { 
     
    1412 
    1513    public void start() { 
    16         JOSMFixture fixture = JOSMFixture.createFunctionalTestFixture(); 
    1714        dialog = new ChangesetQueryDialog(this); 
    1815        dialog.initForUserInput(); 
  • trunk/test/functional/org/openstreetmap/josm/io/UploadStrategySelectionPanelTest.java

    r2641 r2986  
    1212import javax.swing.JTextField; 
    1313 
    14 import org.openstreetmap.josm.fixtures.JOSMFixture; 
    1514import org.openstreetmap.josm.gui.io.UploadStrategySelectionPanel; 
    1615import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 
     
    5655 
    5756    public static void main(String args[]) throws OsmApiInitializationException, OsmTransferCancelledException{ 
    58         JOSMFixture josmFixture = JOSMFixture.createFunctionalTestFixture(); 
    5957        OsmApi.getOsmApi().initialize(NullProgressMonitor.INSTANCE); 
    6058        new UploadStrategySelectionPanelTest().setVisible(true); 
Note: See TracChangeset for help on using the changeset viewer.