package osm.jp.gpx.matchtime.gui;
-import java.awt.Dialog;
+import java.awt.Window;
import java.awt.event.ActionEvent;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
+import javax.swing.ButtonGroup;
import javax.swing.JButton;
+import javax.swing.JRadioButton;
+import org.apache.commons.imaging.Imaging;
+import org.apache.commons.imaging.common.ImageMetadata;
+import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;
+import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
+import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
+import osm.jp.gpx.AppParameters;
import osm.jp.gpx.Restamp;
+import static osm.jp.gpx.matchtime.gui.AdjustTime.dfjp;
import osm.jp.gpx.matchtime.gui.restamp.DialogCorectTime;
/**
*/
public class ParameterPanelTime extends ParameterPanel {
SimpleDateFormat sdf = (SimpleDateFormat)DateFormat.getDateTimeInstance();
- ParameterPanelImageFile imageFile;
+ ParameterPanelImageFile imageFile; // 基準時刻画像
+
+
+ // 基準時刻の指定グループ (排他選択)
+ public ButtonGroup baseTimeGroup = new ButtonGroup();
+ public JRadioButton exifBase = null; // EXIF日時を基準にする/ !(ファイル更新日時を基準にする)
+ public JRadioButton fupdateBase = null; // File更新日時を基準にする/ !(EXIF日時を基準にする)
+
public JButton updateButton;
public JButton resetButton;
- Dialog owner;
+ Window owner;
@SuppressWarnings("OverridableMethodCallInConstructor")
public ParameterPanelTime(
this.add(resetButton);
}
- public ParameterPanelTime setOwner(Dialog owner) {
+ public ParameterPanelTime setOwner(Window owner) {
this.owner = owner;
return this;
}
/**
- * ボタンのアクション
+ * 「EXIFの日時を基準にする」
+ * @param label テキスト
+ * @param params プロパティ
+ */
+ public void addExifBase(String label, AppParameters params) {
+ boolean selected = false;
+ if (params.getProperty(AppParameters.GPX_BASETIME).equals("EXIF_TIME")) {
+ selected = true;
+ }
+ exifBase = new JRadioButton(label, selected);
+ baseTimeGroup.add(exifBase);
+ }
+
+ /**
+ * 「File更新日時を基準にする」
+ * @param label テキスト
+ * @param params プロパティ
+ */
+ public void addFileUpdate(String label, AppParameters params) {
+ boolean selected = false;
+ if (params.getProperty(AppParameters.GPX_BASETIME).equals("FILE_UPDATE_TIME")) {
+ selected = true;
+ }
+ fupdateBase = new JRadioButton(label, selected);
+ baseTimeGroup.add(fupdateBase);
+ }
+
+ public ParameterPanelImageFile getImageFile() {
+ return this.imageFile;
+ }
+
+
+ /**
+ * [変更...]ボタンのアクション
*/
class UpdateButtonAction implements java.awt.event.ActionListener
{
@SuppressWarnings("override")
public void actionPerformed(ActionEvent e) {
+ fileSelect_Action(param);
(new DialogCorectTime(param, owner)).setVisible(true);
}
}
/**
- * ボタンのアクション
+ * [再設定...]ボタンのアクション
*/
class ResetButtonAction implements java.awt.event.ActionListener
{
- ParameterPanelTime param;
+ ParameterPanelTime paramPanelTime;
public ResetButtonAction(ParameterPanelTime param) {
- this.param = param;
+ this.paramPanelTime = param;
}
@SuppressWarnings("override")
public void actionPerformed(ActionEvent e) {
- if (param.imageFile.isEnable()) {
- File file = param.imageFile.getImageFile();
- long lastModified = file.lastModified();
- sdf.applyPattern(Restamp.TIME_PATTERN);
- param.argField.setText(sdf.format(new Date(lastModified)));
+ fileSelect_Action(paramPanelTime);
+ }
+ }
+
+ /**
+ * 画像ファイルが選択されたときのアクション
+ * 1.ラジオボタンの選択を参照してTEXTフィールドにファイルの「日時」を設定する
+ * @param param
+ */
+ void fileSelect_Action(ParameterPanelTime param) {
+ if (imageFile.isEnable()) {
+ File timeFile = imageFile.getImageFile();
+
+ // Radio Selecter
+ sdf.applyPattern(Restamp.TIME_PATTERN);
+ if ((exifBase != null) && exifBase.isSelected()) {
+ try {
+ ImageMetadata meta = Imaging.getMetadata(timeFile);
+ JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta;
+ if (jpegMetadata != null) {
+ TiffImageMetadata exif = jpegMetadata.getExif();
+ if (exif != null) {
+ String dateTimeOriginal = exif.getFieldValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL)[0];
+ long lastModifyTime = sdf.parse(dateTimeOriginal).getTime();
+ param.argField.setText(dfjp.format(new Date(lastModifyTime)));
+ }
+ else {
+ param.argField.setText("exif == null");
+ }
+ }
+ }
+ catch (Exception ex) {
+ while(true);
+ }
}
else {
- param.argField.setText("");
+ long lastModified = timeFile.lastModified();
+ param.argField.setText(sdf.format(new Date(lastModified)));
}
}
+ else {
+ param.argField.setText("");
+ }
}
- public ParameterPanelImageFile getImageFile() {
- return this.imageFile;
- }
-
@Override
public boolean isEnable() {
if (this.imageFile.isEnable()) {