]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/correlate/Correlator.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / correlate / Correlator.java
index 248be18b11b49e24cef3cd59ab983e91c164859f..85b96e92304b0a5f1da3ea470272d8d165582972 100644 (file)
@@ -30,11 +30,13 @@ import tim.prune.I18nManager;
 import tim.prune.data.DataPoint;
 import tim.prune.data.Distance;
 import tim.prune.data.Field;
-import tim.prune.data.MediaFile;
+import tim.prune.data.MediaObject;
 import tim.prune.data.MediaList;
 import tim.prune.data.TimeDifference;
 import tim.prune.data.Timestamp;
 import tim.prune.data.Track;
+import tim.prune.data.Unit;
+import tim.prune.data.UnitSetLibrary;
 
 /**
  * Abstract superclass of the two correlator functions
@@ -115,6 +117,7 @@ public abstract class Correlator extends GenericFunction
                _cards.showCard(card);
                showCard(0); // does set up and next/prev enabling
                _okButton.setEnabled(false);
+               _tipLabel.setVisible(!isCardEnabled(1));
                _dialog.setVisible(true);
        }
 
@@ -194,10 +197,10 @@ public abstract class Correlator extends GenericFunction
                int numMedia = mediaList.getNumMedia();
                for (int i=0; i<numMedia; i++)
                {
-                       MediaFile media = mediaList.getMedia(i);
+                       MediaObject media = mediaList.getMedia(i);
                        // For working out time differences, can't use media which already had point information
                        if (media.getDataPoint() != null && media.getDataPoint().hasTimestamp()
-                               && media.getOriginalStatus() == MediaFile.Status.NOT_CONNECTED)
+                               && media.getOriginalStatus() == MediaObject.Status.NOT_CONNECTED)
                        {
                                // Calculate time difference, add to table model
                                long timeDiff = getMediaTimestamp(media).getSecondsSince(media.getDataPoint().getTimestamp());
@@ -311,8 +314,10 @@ public abstract class Correlator extends GenericFunction
        {
                JPanel card = new JPanel();
                card.setLayout(new BorderLayout(10, 10));
-               card.add(new JLabel(I18nManager.getText(
-                       "dialog.correlate." + getMediaTypeKey() + "select.intro")), BorderLayout.NORTH);
+               JLabel introLabel = new JLabel(I18nManager.getText(
+                       "dialog.correlate." + getMediaTypeKey() + "select.intro"));
+               introLabel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
+               card.add(introLabel, BorderLayout.NORTH);
                // table doesn't have model yet - that will be attached later
                _selectionTable = new JTable();
                JScrollPane photoScrollPane = new JScrollPane(_selectionTable);
@@ -367,7 +372,7 @@ public abstract class Correlator extends GenericFunction
                offsetPanelBot.setLayout(new FlowLayout());
                offsetPanelBot.setBorder(null);
                _mediaLaterOption = new JRadioButton(I18nManager.getText("dialog.correlate.options." + getMediaTypeKey() + "later"));
-               _pointLaterOption = new JRadioButton(I18nManager.getText("dialog.correlate.options.pointlaterphoto"));
+               _pointLaterOption = new JRadioButton(I18nManager.getText("dialog.correlate.options.pointlater" + getMediaTypeKey()));
                _mediaLaterOption.addItemListener(optionsChangedListener);
                _pointLaterOption.addItemListener(optionsChangedListener);
                ButtonGroup laterGroup = new ButtonGroup();
@@ -379,6 +384,12 @@ public abstract class Correlator extends GenericFunction
                offsetPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
                card2Top.add(offsetPanel);
 
+               // listener for radio buttons
+               ActionListener radioListener = new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               enableEditBoxes();
+                       }
+               };
                // time limits section
                JPanel limitsPanel = new JPanel();
                limitsPanel.setBorder(BorderFactory.createTitledBorder(I18nManager.getText("dialog.correlate.options.limitspanel")));
@@ -387,9 +398,11 @@ public abstract class Correlator extends GenericFunction
                timeLimitPanel.setLayout(new FlowLayout());
                JRadioButton noTimeLimitRadio = new JRadioButton(I18nManager.getText("dialog.correlate.options.notimelimit"));
                noTimeLimitRadio.addItemListener(optionsChangedListener);
+               noTimeLimitRadio.addActionListener(radioListener);
                timeLimitPanel.add(noTimeLimitRadio);
                _timeLimitRadio = new JRadioButton(I18nManager.getText("dialog.correlate.options.timelimit") + " : ");
                _timeLimitRadio.addItemListener(optionsChangedListener);
+               _timeLimitRadio.addActionListener(radioListener);
                timeLimitPanel.add(_timeLimitRadio);
                groupRadioButtons(noTimeLimitRadio, _timeLimitRadio);
                _limitMinBox = new JTextField(3);
@@ -406,9 +419,11 @@ public abstract class Correlator extends GenericFunction
                distLimitPanel.setLayout(new FlowLayout());
                JRadioButton noDistLimitRadio = new JRadioButton(I18nManager.getText("dialog.correlate.options.nodistancelimit"));
                noDistLimitRadio.addItemListener(optionsChangedListener);
+               noDistLimitRadio.addActionListener(radioListener);
                distLimitPanel.add(noDistLimitRadio);
                _distLimitRadio = new JRadioButton(I18nManager.getText("dialog.correlate.options.distancelimit"));
                _distLimitRadio.addItemListener(optionsChangedListener);
+               _distLimitRadio.addActionListener(radioListener);
                distLimitPanel.add(_distLimitRadio);
                groupRadioButtons(noDistLimitRadio, _distLimitRadio);
                _limitDistBox = new JTextField(4);
@@ -515,6 +530,18 @@ public abstract class Correlator extends GenericFunction
                _okButton.setEnabled(inCardNum == 2 && ((MediaPreviewTableModel) _previewTable.getModel()).hasAnySelected());
        }
 
+       /**
+        * Enable or disable the edit boxes according to the radio button selections
+        */
+       private void enableEditBoxes()
+       {
+               // enable/disable text field for distance input
+               _limitDistBox.setEnabled(_distLimitRadio.isSelected());
+               // and for time limits
+               _limitMinBox.setEnabled(_timeLimitRadio.isSelected());
+               _limitSecBox.setEnabled(_timeLimitRadio.isSelected());
+       }
+
        /**
         * Parse the time limit values entered and validate them
         * @return TimeDifference object describing limit
@@ -556,9 +583,9 @@ public abstract class Correlator extends GenericFunction
        /**
         * @return the selected distance units from the dropdown
         */
-       protected Distance.Units getSelectedDistanceUnits()
+       protected Unit getSelectedDistanceUnits()
        {
-               final Distance.Units[] distUnits = {Distance.Units.KILOMETRES, Distance.Units.METRES, Distance.Units.MILES};
+               final Unit[] distUnits = {UnitSetLibrary.UNITS_KILOMETRES, UnitSetLibrary.UNITS_METRES, UnitSetLibrary.UNITS_MILES};
                return distUnits[_distUnitsDropdown.getSelectedIndex()];
        }
 
@@ -583,7 +610,7 @@ public abstract class Correlator extends GenericFunction
         * @param inTimeDiff time difference to use for time offsets
         * @param inFirstMedia first media object to use for calculating timezone
         */
-       protected void setupPreviewCard(TimeDifference inTimeDiff, MediaFile inFirstMedia)
+       protected void setupPreviewCard(TimeDifference inTimeDiff, MediaObject inFirstMedia)
        {
                _previewEnabled = false;
                TimeDifference timeDiff = inTimeDiff;
@@ -603,6 +630,7 @@ public abstract class Correlator extends GenericFunction
                _mediaLaterOption.setSelected(timeDiff.getIsPositive());
                _pointLaterOption.setSelected(!timeDiff.getIsPositive());
                _previewEnabled = true;
+               enableEditBoxes();
                createPreview(timeDiff, true);
        }
 
@@ -619,7 +647,7 @@ public abstract class Correlator extends GenericFunction
         * @param inMedia media object
         * @return normally just returns the media timestamp, overridden by audio correlator
         */
-       protected Timestamp getMediaTimestamp(MediaFile inMedia)
+       protected Timestamp getMediaTimestamp(MediaObject inMedia)
        {
                return inMedia.getTimestamp();
        }
@@ -631,22 +659,25 @@ public abstract class Correlator extends GenericFunction
         * @param inOffset time offset to apply
         * @return point pair resulting from correlation
         */
-       protected PointMediaPair getPointPairForMedia(Track inTrack, MediaFile inMedia, TimeDifference inOffset)
+       protected PointMediaPair getPointPairForMedia(Track inTrack, MediaObject inMedia, TimeDifference inOffset)
        {
                PointMediaPair pair = new PointMediaPair(inMedia);
-               // Add/subtract offset to media timestamp
-               Timestamp mediaStamp = getMediaTimestamp(inMedia).createMinusOffset(inOffset);
-               int numPoints = inTrack.getNumPoints();
-               for (int i=0; i<numPoints; i++)
+               if (inMedia.hasTimestamp())
                {
-                       DataPoint point = inTrack.getPoint(i);
-                       if (point.getPhoto() == null && point.getAudio() == null)
+                       // Add/subtract offset to media timestamp
+                       Timestamp mediaStamp = getMediaTimestamp(inMedia).createMinusOffset(inOffset);
+                       int numPoints = inTrack.getNumPoints();
+                       for (int i=0; i<numPoints; i++)
                        {
-                               Timestamp pointStamp = point.getTimestamp();
-                               if (pointStamp != null && pointStamp.isValid())
+                               DataPoint point = inTrack.getPoint(i);
+                               if (point.getPhoto() == null && point.getAudio() == null)
                                {
-                                       long numSeconds = pointStamp.getSecondsSince(mediaStamp);
-                                       pair.addPoint(point, numSeconds);
+                                       Timestamp pointStamp = point.getTimestamp();
+                                       if (pointStamp != null && pointStamp.isValid())
+                                       {
+                                               long numSeconds = pointStamp.getSecondsSince(mediaStamp);
+                                               pair.addPoint(point, numSeconds);
+                                       }
                                }
                        }
                }