Ignore:
Timestamp:
2009-12-24T08:48:40+01:00 (14 years ago)
Author:
jttt
Message:

Fix some of the warnings found by FindBugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r2662 r2676  
    4040import javax.swing.AbstractListModel;
    4141import javax.swing.BorderFactory;
    42 import javax.swing.ButtonGroup;
    4342import javax.swing.JButton;
    4443import javax.swing.JCheckBox;
     
    4948import javax.swing.JOptionPane;
    5049import javax.swing.JPanel;
    51 import javax.swing.JRadioButton;
    5250import javax.swing.JScrollPane;
    5351import javax.swing.JSeparator;
     
    9088    double timezone;
    9189    long delta;
    92    
     90
    9391    public CorrelateGpxWithImages(GeoImageLayer layer) {
    9492        this.yLayer = layer;
     
    123121    JLabel statusBarText;
    124122    StatusBarListener statusBarListener;
    125    
     123
    126124    // remember the last number of matched photos
    127125    int lastNumMatched = 0;
     
    440438    public void actionPerformed(ActionEvent arg0) {
    441439        // Construct the list of loaded GPX tracks
    442         Collection<Layer> layerLst = Main.main.map.mapView.getAllLayers();
     440        Collection<Layer> layerLst = Main.map.mapView.getAllLayers();
    443441        GpxDataWrapper defaultItem = null;
    444442        Iterator<Layer> iterLayer = layerLst.iterator();
     
    491489            timezone = 0;
    492490        }
    493        
     491
    494492        tfTimezone = new JTextField(10);
    495493        tfTimezone.setText(formatTimezone(timezone));
    496494
    497495        try {
    498         delta = parseOffset(Main.pref.get("geoimage.delta", "0"));
     496            delta = parseOffset(Main.pref.get("geoimage.delta", "0"));
    499497        } catch (ParseException e) {
    500498            delta = 0;
    501499        }
    502500        delta = delta / 1000;
    503        
     501
    504502        tfOffset = new JTextField(10);
    505503        tfOffset.setText(Long.toString(delta));
    506        
    507         JPanel panelBtn = new JPanel();
    508        
     504
    509505        JButton buttonViewGpsPhoto = new JButton(tr("<html>Use photo of an accurate clock,<br>"
    510506                + "e.g. GPS receiver display</html>"));
     
    519515
    520516        JLabel labelPosition = new JLabel(tr("Override position for: "));
    521  
     517
    522518        int numAll = getSortedImgList(true, true).size();
    523519        int numExif = numAll - getSortedImgList(false, true).size();
     
    529525        cbTaggedImg = new JCheckBox(tr("Images that are already tagged ({0}/{1})", numTagged, numAll), true);
    530526        cbTaggedImg.setEnabled(numTagged != 0);
    531        
     527
    532528        labelPosition.setEnabled(cbExifImg.isEnabled() || cbTaggedImg.isEnabled());
    533529
     
    540536                    yLayer.loadThumbs();
    541537                } else {
    542                 }       
     538                }
    543539            }
    544540        });*/
     
    549545        gbc.gridy = y++;
    550546        panelTf.add(panelCb, gbc);
    551        
    552        
     547
     548
    553549        gbc = GBC.eol().fill(GBC.HORIZONTAL).insets(0,0,0,12);
    554550        gbc.gridx = 0;
     
    578574        gbc.weightx = 1.;
    579575        panelTf.add(tfOffset, gbc);
    580        
     576
    581577        gbc = GBC.std().insets(5,5,5,5);
    582578        gbc.gridx = 2;
     
    593589        gbc.weightx = 0.5;
    594590        panelTf.add(buttonAutoGuess, gbc);
    595        
     591
    596592        gbc.gridx = 3;
    597593        panelTf.add(buttonAdjust, gbc);
     
    628624        statusBarText.setFont(statusBarText.getFont().deriveFont(8));
    629625        statusBar.add(statusBarText);
    630        
     626
    631627        statusBarListener = new StatusBarListener() {
    632628            @Override
     
    639635                    delta = parseOffset(tfOffset.getText().trim());
    640636                } catch (ParseException e) {
    641                      return e.getMessage();
    642                 }
    643                
     637                    return e.getMessage();
     638                }
     639
    644640                // Construct a list of images that have a date, and sort them on the date.
    645641                ArrayList<ImageEntry> dateImgLst = getSortedImgList();
     
    647643                    ie.cleanTmp();
    648644                }
    649                
     645
    650646                GpxDataWrapper selGpx = selectedGPX(false);
    651647                if (selGpx == null)
    652648                    return tr("No gpx selected");
    653                    
     649
    654650                lastNumMatched = matchGpxTrack(dateImgLst, selGpx.data, (long) (timezone * 3600) + delta);
    655651
     
    657653            }
    658654        };
    659        
     655
    660656        tfTimezone.getDocument().addDocumentListener(statusBarListener);
    661657        tfOffset.getDocument().addDocumentListener(statusBarListener);
    662658        cbExifImg.addItemListener(statusBarListener);
    663659        cbTaggedImg.addItemListener(statusBarListener);
    664        
     660
    665661        statusBarListener.updateStatusBar();
    666662
     
    683679        syncDialog.pack();
    684680        syncDialog.addWindowListener(new WindowAdapter() {
    685             final int CANCEL = -1;
    686             final int DONE = 0;
    687             final int AGAIN = 1;
    688             final int NOTHING = 2;
     681            final static int CANCEL = -1;
     682            final static int DONE = 0;
     683            final static int AGAIN = 1;
     684            final static int NOTHING = 2;
    689685            private int checkAndSave() {
    690                 if (syncDialog.isVisible()) {
     686                if (syncDialog.isVisible())
    691687                    // nothing happened: JOSM was minimized or similar
    692                     return NOTHING;             
    693                 }
     688                    return NOTHING;
    694689                int answer = syncDialog.getValue();
    695690                if(answer != 1)
     
    704699                    return AGAIN;
    705700                }
    706                
     701
    707702                try {
    708703                    delta = parseOffset(tfOffset.getText().trim());
    709704                } catch (ParseException e) {
    710                         JOptionPane.showMessageDialog(Main.parent, e.getMessage(),
    711                                 tr("Invalid offset"), JOptionPane.ERROR_MESSAGE);
     705                    JOptionPane.showMessageDialog(Main.parent, e.getMessage(),
     706                            tr("Invalid offset"), JOptionPane.ERROR_MESSAGE);
    712707                    return AGAIN;
    713708                }
    714                
     709
    715710                if (lastNumMatched == 0) {
    716711                    if (new ExtendedDialog(
     
    718713                            tr("Correlate images with GPX track"),
    719714                            new String[] { tr("OK"), tr("Try Again") }).
    720                         setContent(tr("No images could be matched!")).
    721                         setButtonIcons(new String[] { "ok.png", "dialogs/refresh.png"}).
    722                         showDialog().getValue() == 2)
    723                             return AGAIN;
     715                            setContent(tr("No images could be matched!")).
     716                            setButtonIcons(new String[] { "ok.png", "dialogs/refresh.png"}).
     717                            showDialog().getValue() == 2)
     718                        return AGAIN;
    724719                }
    725720                return DONE;
    726721            }
    727            
     722
     723            @Override
    728724            public void windowDeactivated(WindowEvent e) {
    729725                int result = checkAndSave();
    730726                switch (result) {
    731                     case NOTHING:
    732                         break;
    733                     case CANCEL:
    734                     {
    735                         for (ImageEntry ie : yLayer.data) {
    736                             ie.tmp = null;
    737                         }
    738                         yLayer.updateBufferAndRepaint();
    739                         break;
     727                case NOTHING:
     728                    break;
     729                case CANCEL:
     730                {
     731                    for (ImageEntry ie : yLayer.data) {
     732                        ie.tmp = null;
    740733                    }
    741                     case AGAIN:
    742                         actionPerformed(null);
    743                         break;
    744                     case DONE:
    745                     {
    746                         Main.pref.put("geoimage.timezone", formatTimezone(timezone));
    747                         Main.pref.put("geoimage.delta", Long.toString(delta * 1000));
    748                         Main.pref.put("geoimage.showThumbs", yLayer.useThumbs);
    749 
    750                         yLayer.useThumbs = cbShowThumbs.isSelected();//FIXME
    751                         yLayer.loadThumbs();
    752                        
    753                         // Search whether an other layer has yet defined some bounding box.
    754                         // If none, we'll zoom to the bounding box of the layer with the photos.
    755                         boolean boundingBoxedLayerFound = false;
    756                         for (Layer l: Main.map.mapView.getAllLayers()) {
    757                             if (l != yLayer) {
    758                                 BoundingXYVisitor bbox = new BoundingXYVisitor();
    759                                 l.visitBoundingBox(bbox);
    760                                 if (bbox.getBounds() != null) {
    761                                     boundingBoxedLayerFound = true;
    762                                     break;
    763                                 }
     734                    yLayer.updateBufferAndRepaint();
     735                    break;
     736                }
     737                case AGAIN:
     738                    actionPerformed(null);
     739                    break;
     740                case DONE:
     741                {
     742                    Main.pref.put("geoimage.timezone", formatTimezone(timezone));
     743                    Main.pref.put("geoimage.delta", Long.toString(delta * 1000));
     744                    Main.pref.put("geoimage.showThumbs", yLayer.useThumbs);
     745
     746                    yLayer.useThumbs = cbShowThumbs.isSelected();//FIXME
     747                    yLayer.loadThumbs();
     748
     749                    // Search whether an other layer has yet defined some bounding box.
     750                    // If none, we'll zoom to the bounding box of the layer with the photos.
     751                    boolean boundingBoxedLayerFound = false;
     752                    for (Layer l: Main.map.mapView.getAllLayers()) {
     753                        if (l != yLayer) {
     754                            BoundingXYVisitor bbox = new BoundingXYVisitor();
     755                            l.visitBoundingBox(bbox);
     756                            if (bbox.getBounds() != null) {
     757                                boundingBoxedLayerFound = true;
     758                                break;
    764759                            }
    765760                        }
    766                         if (! boundingBoxedLayerFound) {
    767                             BoundingXYVisitor bbox = new BoundingXYVisitor();
    768                             yLayer.visitBoundingBox(bbox);
    769                             Main.map.mapView.recalculateCenterScale(bbox);
    770                         }
    771 
    772 
    773                         for (ImageEntry ie : yLayer.data) {
    774                             ie.applyTmp();
    775                         }
    776 
    777                         yLayer.updateBufferAndRepaint();
    778 
    779 
    780                         break;
    781761                    }
    782                     default:
    783                         throw new IllegalStateException();
     762                    if (! boundingBoxedLayerFound) {
     763                        BoundingXYVisitor bbox = new BoundingXYVisitor();
     764                        yLayer.visitBoundingBox(bbox);
     765                        Main.map.mapView.recalculateCenterScale(bbox);
     766                    }
     767
     768
     769                    for (ImageEntry ie : yLayer.data) {
     770                        ie.applyTmp();
     771                    }
     772
     773                    yLayer.updateBufferAndRepaint();
     774
     775
     776                    break;
     777                }
     778                default:
     779                    throw new IllegalStateException();
    784780                }
    785781            }
     
    807803     */
    808804    private class AdjustActionListener implements ActionListener {
    809    
     805
    810806        public void actionPerformed(ActionEvent arg0) {
    811807
    812808            long diff = delta + Math.round(timezone*60*60);
    813            
     809
    814810            double diffInH = (double)diff/(60*60);    // hours
    815811
    816812            // Find day difference
    817813            final int dayOffset = (int)Math.round(diffInH / 24); // days
    818             double tmz = diff - dayOffset*24*60*60;  // seconds
     814            double tmz = diff - dayOffset*24*60*60l;  // seconds
    819815
    820816            // In hours, rounded to two decimal places
     
    881877                    tfTimezone.getDocument().removeDocumentListener(statusBarListener);
    882878                    tfOffset.getDocument().removeDocumentListener(statusBarListener);
    883                    
     879
    884880                    tfTimezone.setText(formatTimezone(timezone));
    885                     tfOffset.setText(Long.toString(delta + dayOffset*24*60*60));    // add the day offset to the offset field
     881                    tfOffset.setText(Long.toString(delta + dayOffset*24*60*60l));    // add the day offset to the offset field
    886882
    887883                    tfTimezone.getDocument().addDocumentListener(statusBarListener);
     
    937933                    tr("Adjust timezone and offset"),
    938934                    new String[] { tr("Close")}).
    939                 setContent(p).setButtonIcons(new String[] {"ok.png"}).showDialog();
     935                    setContent(p).setButtonIcons(new String[] {"ok.png"}).showDialog();
    940936        }
    941937    }
    942938
    943939    private class AutoGuessActionListener implements ActionListener {
    944    
     940
    945941        public void actionPerformed(ActionEvent arg0) {
    946942            GpxDataWrapper gpxW = selectedGPX(true);
     
    948944                return;
    949945            GpxData gpx = gpxW.data;
    950            
     946
    951947            ArrayList<ImageEntry> imgs = getSortedImgList();
    952948            PrimaryDateParser dateParser = new PrimaryDateParser();
     
    996992            // Find day difference
    997993            int dayOffset = (int)Math.round(diffInH / 24); // days
    998             double tz = diff - dayOffset*24*60*60;  // seconds
     994            double tz = diff - dayOffset*24*60*60l;  // seconds
    999995
    1000996            // In hours, rounded to two decimal places
     
    10041000            // -2 minutes offset. This determines the real timezone and finds offset.
    10051001            timezone = (double)Math.round(tz * 2)/2; // hours, rounded to one decimal place
    1006             delta = (long)Math.round(diff - timezone*60*60); // seconds
     1002            delta = Math.round(diff - timezone*60*60); // seconds
    10071003
    10081004            /*System.out.println("phto " + firstExifDate);
     
    10171013            tfTimezone.getDocument().removeDocumentListener(statusBarListener);
    10181014            tfOffset.getDocument().removeDocumentListener(statusBarListener);
    1019            
     1015
    10201016            tfTimezone.setText(formatTimezone(timezone));
    10211017            tfOffset.setText(Long.toString(delta));
     
    10241020            tfTimezone.getDocument().addDocumentListener(statusBarListener);
    10251021            tfOffset.getDocument().addDocumentListener(statusBarListener);
    1026            
     1022
    10271023            statusBarListener.updateStatusBar();
    10281024            yLayer.updateBufferAndRepaint();
     
    10331029        return getSortedImgList(cbExifImg.isSelected(), cbTaggedImg.isSelected());
    10341030    }
    1035    
     1031
    10361032    /**
    10371033     * Returns a list of images that fulfill the given criteria.
    10381034     * Default setting is to return untagged images, but may be overwritten.
    10391035     * @param boolean all -- returns all available images
    1040      * @param boolean noexif -- returns untagged images without EXIF-GPS coords 
     1036     * @param boolean noexif -- returns untagged images without EXIF-GPS coords
    10411037     *                          this parameter is irrelevant if <code>all</code> is true
    10421038     * @param boolean exif -- also returns images with exif-gps info
     
    10471043        ArrayList<ImageEntry> dateImgLst = new ArrayList<ImageEntry>(yLayer.data.size());
    10481044        for (ImageEntry e : yLayer.data) {
    1049             if (e.time == null)
     1045            if (e.time == null) {
    10501046                continue;
    1051                
     1047            }
     1048
    10521049            if (e.exifCoor != null) {
    1053                 if (!exif)
     1050                if (!exif) {
    10541051                    continue;
    1055             }
    1056                
     1052                }
     1053            }
     1054
    10571055            if (e.isTagged() && e.exifCoor == null) {
    1058                 if (!tagged)
     1056                if (!tagged) {
    10591057                    continue;
    1060             }
    1061                
     1058                }
     1059            }
     1060
    10621061            dateImgLst.add(e);
    10631062        }
    1064        
     1063
    10651064        Collections.sort(dateImgLst, new Comparator<ImageEntry>() {
    10661065            public int compare(ImageEntry arg0, ImageEntry arg1) {
     
    12511250
    12521251    private double parseTimezone(String timezone) throws ParseException {
    1253  
     1252
    12541253        String error = tr("Error while parsing timezone.\nExpected format: {0}", "+H:MM");
    1255  
    1256  
     1254
     1255
    12571256        if (timezone.length() == 0)
    12581257            return 0;
     
    13241323    private long parseOffset(String offset) throws ParseException {
    13251324        String error = tr("Error while parsing offset.\nExpected format: {0}", "number");
    1326    
     1325
    13271326        if (offset.length() > 0) {
    13281327            try {
     
    13341333                throw new ParseException(error,0);
    13351334            }
    1336         } else {
     1335        } else
    13371336            return 0;
    1338         }
    13391337    }
    13401338}
Note: See TracChangeset for help on using the changeset viewer.