Changeset 31380 in osm for applications


Ignore:
Timestamp:
2015-07-15T16:35:08+02:00 (9 years ago)
Author:
nokutu
Message:

Improved export GUI and when exporting an imported image, the EXIF tags that aren't used aren't deleted

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryExportAction.java

    r31350 r31380  
    55import java.awt.Dimension;
    66import java.awt.event.ActionEvent;
     7import java.awt.event.ActionListener;
    78import java.awt.event.KeyEvent;
    89import java.io.IOException;
     
    1011import java.util.List;
    1112
     13import javax.swing.JButton;
    1214import javax.swing.JDialog;
    1315import javax.swing.JOptionPane;
     
    4446  @Override
    4547  public void actionPerformed(ActionEvent e) {
    46     dialog = new MapillaryExportDialog();
    47     JOptionPane pane = new JOptionPane(dialog, JOptionPane.PLAIN_MESSAGE,
    48         JOptionPane.OK_CANCEL_OPTION);
     48    JOptionPane pane = new JOptionPane();
     49
     50    JButton ok = new JButton("Ok");
     51    ok.addActionListener(new OKAction(pane));
     52    JButton cancel = new JButton(tr("Cancel"));
     53    cancel.addActionListener(new CancelAction(pane));
     54
     55
     56    dialog = new MapillaryExportDialog(ok);
     57    pane.setMessage(dialog);
     58    pane.setOptions(new JButton[] { ok, cancel });
     59
    4960    JDialog dlg = pane.createDialog(Main.parent, tr("Export images"));
    5061    dlg.setMinimumSize(new Dimension(400, 150));
     
    95106  }
    96107
     108  private class OKAction implements ActionListener {
     109    private JOptionPane pane;
     110
     111    public OKAction(JOptionPane pane) {
     112      this.pane = pane;
     113    }
     114
     115    @Override
     116    public void actionPerformed(ActionEvent e) {
     117      pane.setValue(JOptionPane.OK_OPTION);
     118    }
     119  }
     120
     121  private class CancelAction implements ActionListener {
     122    private JOptionPane pane;
     123
     124    public CancelAction(JOptionPane pane) {
     125      this.pane = pane;
     126    }
     127
     128    @Override
     129    public void actionPerformed(ActionEvent e) {
     130      pane.setValue(JOptionPane.CANCEL_OPTION);
     131    }
     132  }
    97133}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportWriterThread.java

    r31350 r31380  
    1313import org.apache.commons.imaging.ImageReadException;
    1414import org.apache.commons.imaging.ImageWriteException;
     15import org.apache.commons.imaging.Imaging;
     16import org.apache.commons.imaging.common.ImageMetadata;
    1517import org.apache.commons.imaging.common.RationalNumber;
     18import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;
    1619import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter;
     20import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
    1721import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
    1822import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;
     
    6771        } else if (mimg instanceof MapillaryImage)
    6872          finalPath = path + "/" + ((MapillaryImage) mimg).getKey();
    69         else
    70           finalPath = path + "/" + i;
     73        else if (mimg instanceof MapillaryImportedImage)
     74          finalPath = path + "/"
     75              + ((MapillaryImportedImage) mimg).getFile().getName();
     76        ;
    7177        // Creates a temporal file that is going to be deleted after
    7278        // writing the EXIF tags.
     
    7581
    7682        // Write EXIF tags
    77         TiffOutputSet outputSet = new TiffOutputSet();
    78         TiffOutputDirectory exifDirectory = outputSet
    79             .getOrCreateExifDirectory();
     83        TiffOutputSet outputSet = null;
     84        TiffOutputDirectory exifDirectory = null;
     85        // If the image is imported, loads the rest of the EXIF data.
     86        if (mimg instanceof MapillaryImportedImage) {
     87          final ImageMetadata metadata = Imaging
     88              .getMetadata(((MapillaryImportedImage) mimg).getFile());
     89          final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
     90          if (null != jpegMetadata) {
     91            final TiffImageMetadata exif = jpegMetadata.getExif();
     92            if (null != exif) {
     93              outputSet = exif.getOutputSet();
     94            }
     95          }
     96        }
     97        if (null == outputSet) {
     98          outputSet = new TiffOutputSet();
     99        }
     100        exifDirectory = outputSet.getOrCreateExifDirectory();
     101
     102        exifDirectory
     103            .removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF);
    80104        exifDirectory.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF,
    81105            GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF_VALUE_TRUE_NORTH);
     106
     107        exifDirectory.removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);
    82108        exifDirectory.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION,
    83109            RationalNumber.valueOf(mimg.getCa()));
    84         if (mimg instanceof MapillaryImportedImage) {
     110
     111        exifDirectory.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
     112        if (mimg instanceof MapillaryImportedImage)
    85113          exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL,
    86114              ((MapillaryImportedImage) mimg).getDate("yyyy/MM/dd hh:mm:ss"));
    87         } else if (mimg instanceof MapillaryImage)
     115        else if (mimg instanceof MapillaryImage)
    88116          exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL,
    89117              ((MapillaryImage) mimg).getDate("yyyy/MM/dd hh/mm/ss"));
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryExportDialog.java

    r31350 r31380  
    4848  public JFileChooser chooser;
    4949  protected String exportDirectory;
     50  private JButton ok;
    5051
    51   public MapillaryExportDialog() {
     52  public MapillaryExportDialog(JButton ok) {
     53    this.ok = ok;
     54    ok.setEnabled(false);
     55   
    5256    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    5357
     
    101105
    102106  /**
    103    * Creates the folder choser GUI.
     107   * Creates the folder chooser GUI.
    104108   */
    105109  @Override
     
    115119      path.setText(chooser.getSelectedFile().toString());
    116120      this.updateUI();
     121      ok.setEnabled(true);
    117122    }
    118123  }
Note: See TracChangeset for help on using the changeset viewer.