package tim.prune.correlate; import javax.swing.JOptionPane; import javax.swing.JTable; import tim.prune.App; import tim.prune.DataSubscriber; import tim.prune.I18nManager; import tim.prune.UpdateMessageBroker; import tim.prune.data.DataPoint; import tim.prune.data.MediaList; import tim.prune.data.Photo; import tim.prune.data.PhotoList; import tim.prune.data.TimeDifference; import tim.prune.undo.UndoCorrelatePhotos; /** * Class to manage the automatic correlation of photos to points * including the GUI stuff to control the correlation options */ public class PhotoCorrelator extends Correlator { /** * Constructor * @param inApp App object to report actions to */ public PhotoCorrelator(App inApp) { super(inApp); } /** Get the name key */ public String getNameKey() { return "function.correlatephotos"; } /** @return type key */ protected String getMediaTypeKey() { return "photo"; } /** @return photo list*/ protected MediaList getMediaList() { return _app.getTrackInfo().getPhotoList(); } /** * Create a preview of the correlate action using the selected time difference * @param inTimeDiff TimeDifference to use for preview * @param inShowWarning true to show warning if all points out of range */ protected void createPreview(TimeDifference inTimeDiff, boolean inShowWarning) { TimeDifference timeLimit = parseTimeLimit(); double angDistLimit = parseDistanceLimit(); MediaPreviewTableModel model = new MediaPreviewTableModel("dialog.correlate.select.photoname"); PhotoList photos = _app.getTrackInfo().getPhotoList(); // Loop through photos deciding whether to set correlate flag or not int numPhotos = photos.getNumPhotos(); for (int i=0; i 0.0 && correlatePhoto) { final double angDistPair = DataPoint.calculateRadiansBetween(pair.getPointBefore(), pair.getPointAfter()); double frac = pair.getFraction(); if (frac > 0.5) {frac = 1 - frac;} final double angDistPhoto = angDistPair * frac; correlatePhoto = (angDistPhoto < angDistLimit); } // Don't select photos which are already correlated to the same point if (pair.getSecondsBefore() == 0L && pair.getPointBefore().isDuplicate(photo.getDataPoint())) { correlatePhoto = false; } row.setCorrelateFlag(correlatePhoto); model.addRow(row); } _previewTable.setModel(model); // Set distance units model.setDistanceUnits(getSelectedDistanceUnits()); // Set column widths _previewTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); final int[] colWidths = {150, 160, 100, 100, 50}; for (int i=0; i 0) { // make new array for added points DataPoint[] addedPoints = new DataPoint[numPointsToCreate]; int pointNum = 0; DataPoint pointToAdd = null; for (i=0; i 0L) { // interpolate point pointToAdd = DataPoint.interpolate(pair.getPointBefore(), pair.getPointAfter(), pair.getFraction()); } if (pointToAdd != null) { // link photo to point pointToAdd.setPhoto((Photo) pair.getMedia()); pair.getMedia().setDataPoint(pointToAdd); // set to start of segment so not joined in track pointToAdd.setSegmentStart(true); // add to point array addedPoints[pointNum] = pointToAdd; pointNum++; } } } // expand track _app.getTrackInfo().getTrack().appendPoints(addedPoints); } // send undo information back to controlling app undo.setNumPhotosCorrelated(numPhotos); _app.completeFunction(undo, ("" + numPhotos + " " + (numPhotos==1?I18nManager.getText("confirm.correlatephotos.single"):I18nManager.getText("confirm.correlatephotos.multi")))); // observers already informed by track update if new points created if (numPointsToCreate == 0) { UpdateMessageBroker.informSubscribers(DataSubscriber.SELECTION_CHANGED); } } }