Changeset 3052 in josm


Ignore:
Timestamp:
Feb 27, 2010 2:25:57 PM (3 years ago)
Author:
bastiK
Message:

fixed geoimage issues:

  • no update on the map when another gpx track is selected
  • reset all images before each update
File:
1 edited

Legend:

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

    r2931 r3052  
    1616import java.awt.event.ActionEvent; 
    1717import java.awt.event.ActionListener; 
     18import java.awt.event.FocusEvent; 
     19import java.awt.event.FocusListener; 
    1820import java.awt.event.ItemEvent; 
    1921import java.awt.event.ItemListener; 
     
    120122    JCheckBox cbShowThumbs; 
    121123    JLabel statusBarText; 
    122     StatusBarListener statusBarListener; 
    123124 
    124125    // remember the last number of matched photos 
     
    216217    } 
    217218 
    218     /** This action listener is called when the user has a photo of the time of his GPS receiver. It 
     219    /**  
     220     * This action listener is called when the user has a photo of the time of his GPS receiver. It 
    219221     * displays the list of photos of the layer, and upon selection displays the selected photo. 
    220222     * From that photo, the user can key in the time of the GPS. 
     
    433435 
    434436            } 
    435             statusBarListener.updateStatusBar(); 
     437            statusBarUpdater.updateStatusBar(); 
    436438            yLayer.updateBufferAndRepaint(); 
    437439        } 
     
    446448            Layer cur = iterLayer.next(); 
    447449            if (cur instanceof GpxLayer) { 
    448                 GpxDataWrapper gdw = new GpxDataWrapper(((GpxLayer) cur).getName(), 
    449                         ((GpxLayer) cur).data, 
    450                         ((GpxLayer) cur).data.storageFile); 
     450                GpxLayer curGpx = (GpxLayer) cur; 
     451                GpxDataWrapper gdw = new GpxDataWrapper(curGpx.getName(), curGpx.data, curGpx.data.storageFile); 
    451452                gpxLst.add(gdw); 
    452453                if (cur == yLayer.gpxLayer) { 
     
    473474            cbGpx.setSelectedItem(defaultItem); 
    474475        } 
     476        cbGpx.addActionListener(statusBarUpdaterWithRepaint); 
    475477        panelCb.add(cbGpx); 
    476478 
     
    500502            delta = 0; 
    501503        } 
    502         delta = delta / 1000; 
     504        delta = delta / 1000;  // milliseconds -> seconds 
    503505 
    504506        tfOffset = new JTextField(10); 
     
    625627        statusBar.add(statusBarText); 
    626628 
    627         statusBarListener = new StatusBarListener() { 
    628             @Override 
    629             public void updateStatusBar() { 
    630                 statusBarText.setText(statusText()); 
    631             } 
    632             private String statusText() { 
    633                 try { 
    634                     timezone = parseTimezone(tfTimezone.getText().trim()); 
    635                     delta = parseOffset(tfOffset.getText().trim()); 
    636                 } catch (ParseException e) { 
    637                     return e.getMessage(); 
    638                 } 
    639  
    640                 // Construct a list of images that have a date, and sort them on the date. 
    641                 ArrayList<ImageEntry> dateImgLst = getSortedImgList(); 
    642                 for (ImageEntry ie : dateImgLst) { 
    643                     ie.cleanTmp(); 
    644                 } 
    645  
    646                 GpxDataWrapper selGpx = selectedGPX(false); 
    647                 if (selGpx == null) 
    648                     return tr("No gpx selected"); 
    649  
    650                 final long offset_ms = ((long) (timezone * 3600) + delta) * 1000; // in milliseconds 
    651                 lastNumMatched = matchGpxTrack(dateImgLst, selGpx.data, offset_ms); 
    652  
    653                 return trn("<html>Matched <b>{0}</b> of <b>{1}</b> photo to GPX track.</html>", 
    654                         "<html>Matched <b>{0}</b> of <b>{1}</b> photos to GPX track.</html>", 
    655                         dateImgLst.size(), lastNumMatched, dateImgLst.size()); 
    656             } 
    657         }; 
    658  
    659         tfTimezone.getDocument().addDocumentListener(statusBarListener); 
    660         tfOffset.getDocument().addDocumentListener(statusBarListener); 
    661         cbExifImg.addItemListener(statusBarListener); 
    662         cbTaggedImg.addItemListener(statusBarListener); 
    663  
    664         statusBarListener.updateStatusBar(); 
     629        tfTimezone.addFocusListener(repaintTheMap); 
     630        tfOffset.addFocusListener(repaintTheMap); 
     631         
     632        tfTimezone.getDocument().addDocumentListener(statusBarUpdater); 
     633        tfOffset.getDocument().addDocumentListener(statusBarUpdater); 
     634        cbExifImg.addItemListener(statusBarUpdaterWithRepaint); 
     635        cbTaggedImg.addItemListener(statusBarUpdaterWithRepaint); 
     636 
     637        statusBarUpdater.updateStatusBar(); 
    665638 
    666639        outerPanel = new JPanel(); 
     
    784757    } 
    785758 
    786     private static abstract class StatusBarListener implements  DocumentListener, ItemListener { 
     759    StatusBarUpdater statusBarUpdater = new StatusBarUpdater(false); 
     760    StatusBarUpdater statusBarUpdaterWithRepaint = new StatusBarUpdater(true); 
     761     
     762    private class StatusBarUpdater implements  DocumentListener, ItemListener, ActionListener { 
     763        private boolean doRepaint; 
     764 
     765        public StatusBarUpdater(boolean doRepaint) { 
     766            this.doRepaint = doRepaint; 
     767        } 
     768         
    787769        public void insertUpdate(DocumentEvent ev) { 
    788770            updateStatusBar(); 
     
    796778            updateStatusBar(); 
    797779        } 
    798         abstract public void updateStatusBar(); 
     780        public void actionPerformed(ActionEvent e) { 
     781            updateStatusBar(); 
     782        } 
     783 
     784        public void updateStatusBar() { 
     785            statusBarText.setText(statusText()); 
     786            if (doRepaint) { 
     787                yLayer.updateBufferAndRepaint(); 
     788            } 
     789        } 
     790         
     791        private String statusText() { 
     792            try { 
     793                timezone = parseTimezone(tfTimezone.getText().trim()); 
     794                delta = parseOffset(tfOffset.getText().trim()); 
     795            } catch (ParseException e) { 
     796                return e.getMessage(); 
     797            } 
     798 
     799            // The selection of images we are about to correlate may have changed. 
     800            // So reset all images. 
     801            for (ImageEntry ie: yLayer.data) { 
     802                ie.tmp = null; 
     803            } 
     804             
     805            // Construct a list of images that have a date, and sort them on the date. 
     806            ArrayList<ImageEntry> dateImgLst = getSortedImgList(); 
     807            // Create a temporary copy for each image 
     808            for (ImageEntry ie : dateImgLst) { 
     809                ie.cleanTmp(); 
     810            } 
     811 
     812            GpxDataWrapper selGpx = selectedGPX(false); 
     813            if (selGpx == null) 
     814                return tr("No gpx selected"); 
     815 
     816            final long offset_ms = ((long) (timezone * 3600) + delta) * 1000; // in milliseconds 
     817            lastNumMatched = matchGpxTrack(dateImgLst, selGpx.data, offset_ms); 
     818 
     819            return trn("<html>Matched <b>{0}</b> of <b>{1}</b> photo to GPX track.</html>", 
     820                    "<html>Matched <b>{0}</b> of <b>{1}</b> photos to GPX track.</html>", 
     821                    dateImgLst.size(), lastNumMatched, dateImgLst.size()); 
     822        } 
     823    } 
     824 
     825    RepaintTheMapListener repaintTheMap = new RepaintTheMapListener(); 
     826    private class RepaintTheMapListener implements FocusListener { 
     827        public void focusGained(FocusEvent e) { // do nothing 
     828        } 
     829         
     830        public void focusLost(FocusEvent e) { 
     831            yLayer.updateBufferAndRepaint(); 
     832        } 
    799833    } 
    800834 
     
    875909                    delta = sldMinutes.getValue()*60 + sldSeconds.getValue(); 
    876910 
    877                     tfTimezone.getDocument().removeDocumentListener(statusBarListener); 
    878                     tfOffset.getDocument().removeDocumentListener(statusBarListener); 
     911                    tfTimezone.getDocument().removeDocumentListener(statusBarUpdater); 
     912                    tfOffset.getDocument().removeDocumentListener(statusBarUpdater); 
    879913 
    880914                    tfTimezone.setText(formatTimezone(timezone)); 
    881915                    tfOffset.setText(Long.toString(delta + 24*60*60L*dayOffset));    // add the day offset to the offset field 
    882916 
    883                     tfTimezone.getDocument().addDocumentListener(statusBarListener); 
    884                     tfOffset.getDocument().addDocumentListener(statusBarListener); 
     917                    tfTimezone.getDocument().addDocumentListener(statusBarUpdater); 
     918                    tfOffset.getDocument().addDocumentListener(statusBarUpdater); 
    885919 
    886920                    lblMatches.setText(statusBarText.getText() + "<br>" + trn("(Time difference of {0} day)", "Time difference of {0} days", Math.abs(dayOffset), Math.abs(dayOffset))); 
    887921 
    888                     statusBarListener.updateStatusBar(); 
     922                    statusBarUpdater.updateStatusBar(); 
    889923                    yLayer.updateBufferAndRepaint(); 
    890924                } 
     
    10091043            System.out.println("offt " + delta);*/ 
    10101044 
    1011             tfTimezone.getDocument().removeDocumentListener(statusBarListener); 
    1012             tfOffset.getDocument().removeDocumentListener(statusBarListener); 
     1045            tfTimezone.getDocument().removeDocumentListener(statusBarUpdater); 
     1046            tfOffset.getDocument().removeDocumentListener(statusBarUpdater); 
    10131047 
    10141048            tfTimezone.setText(formatTimezone(timezone)); 
     
    10161050            tfOffset.requestFocus(); 
    10171051 
    1018             tfTimezone.getDocument().addDocumentListener(statusBarListener); 
    1019             tfOffset.getDocument().addDocumentListener(statusBarListener); 
    1020  
    1021             statusBarListener.updateStatusBar(); 
     1052            tfTimezone.getDocument().addDocumentListener(statusBarUpdater); 
     1053            tfOffset.getDocument().addDocumentListener(statusBarUpdater); 
     1054 
     1055            statusBarUpdater.updateStatusBar(); 
    10221056            yLayer.updateBufferAndRepaint(); 
    10231057        } 
Note: See TracChangeset for help on using the changeset viewer.