1 package osm.jp.gpx.matchtime.gui;
3 import java.awt.Window;
4 import java.awt.event.ActionEvent;
6 import java.io.IOException;
7 import java.text.DateFormat;
8 import java.text.ParseException;
9 import java.text.SimpleDateFormat;
10 import java.util.Date;
11 import javax.swing.ButtonGroup;
12 import javax.swing.JButton;
13 import javax.swing.JRadioButton;
14 import org.apache.commons.imaging.ImageReadException;
15 import org.apache.commons.imaging.Imaging;
16 import org.apache.commons.imaging.common.ImageMetadata;
17 import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;
18 import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
19 import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
20 import osm.jp.gpx.AppParameters;
21 import osm.jp.gpx.Restamp;
22 import static osm.jp.gpx.matchtime.gui.AdjustTerra.dfjp;
23 import osm.jp.gpx.matchtime.gui.restamp.DialogCorectTime;
27 * この1インスタンスで、1パラメータをあらわす。
29 public class ParameterPanelTime extends ParameterPanel {
30 private static final long serialVersionUID = 1683226418990348336L;
31 SimpleDateFormat sdf = (SimpleDateFormat)DateFormat.getDateTimeInstance();
32 ParameterPanelImageFile imageFile; // 基準時刻画像
36 public ButtonGroup baseTimeGroup = new ButtonGroup();
37 public JRadioButton exifBase = null; // EXIF日時を基準にする/ !(ファイル更新日時を基準にする)
38 public JRadioButton fupdateBase = null; // File更新日時を基準にする/ !(EXIF日時を基準にする)
40 public JButton updateButton;
41 public JButton resetButton;
44 public ParameterPanelTime(
47 ParameterPanelImageFile imageFile
50 this.imageFile = imageFile;
53 UpdateButtonAction buttonAction = new UpdateButtonAction(this);
54 updateButton = new JButton(i18n.getString("button.update"));
55 updateButton.addActionListener(buttonAction);
56 this.add(updateButton);
59 ResetButtonAction resetAction = new ResetButtonAction(this);
60 resetButton = new JButton(i18n.getString("button.reset"));
61 resetButton.addActionListener(resetAction);
62 resetButton.setVisible(false);
63 this.add(resetButton);
66 public ParameterPanelTime setOwner(Window owner) {
76 public void addExifBase(String label, AppParameters params) {
77 boolean selected = false;
78 if (params.getProperty(AppParameters.GPX_BASETIME).equals("EXIF_TIME")) {
81 exifBase = new JRadioButton(label, selected);
82 baseTimeGroup.add(exifBase);
90 public void addFileUpdate(String label, AppParameters params) {
91 boolean selected = false;
92 if (params.getProperty(AppParameters.GPX_BASETIME).equals("FILE_UPDATE")) {
95 fupdateBase = new JRadioButton(label, selected);
96 baseTimeGroup.add(fupdateBase);
99 public ParameterPanelImageFile getImageFile() {
100 return this.imageFile;
107 class UpdateButtonAction implements java.awt.event.ActionListener
109 ParameterPanelTime param;
111 public UpdateButtonAction(ParameterPanelTime param) {
115 public void actionPerformed(ActionEvent e) {
116 fileSelect_Action(param);
117 (new DialogCorectTime(param, owner)).setVisible(true);
124 class ResetButtonAction implements java.awt.event.ActionListener
126 ParameterPanelTime paramPanelTime;
128 public ResetButtonAction(ParameterPanelTime param) {
129 this.paramPanelTime = param;
132 public void actionPerformed(ActionEvent e) {
133 fileSelect_Action(paramPanelTime);
138 * 画像ファイルが選択されたときのアクション
139 * 1.ラジオボタンの選択を参照してTEXTフィールドにファイルの「日時」を設定する
142 void fileSelect_Action(ParameterPanelTime param) {
143 if (imageFile.isEnable()) {
144 File timeFile = imageFile.getImageFile();
147 sdf.applyPattern(Restamp.TIME_PATTERN);
148 if ((exifBase != null) && exifBase.isSelected()) {
150 ImageMetadata meta = Imaging.getMetadata(timeFile);
151 JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta;
152 if (jpegMetadata != null) {
153 TiffImageMetadata exif = jpegMetadata.getExif();
155 String dateTimeOriginal = exif.getFieldValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL)[0];
156 long lastModifyTime = sdf.parse(dateTimeOriginal).getTime();
157 param.argField.setText(dfjp.format(new Date(lastModifyTime)));
160 param.argField.setText("exif == null");
164 catch (IOException | ParseException | ImageReadException ex) {}
167 long lastModified = timeFile.lastModified();
168 param.argField.setText(sdf.format(new Date(lastModified)));
172 param.argField.setText("");
177 public boolean isEnable() {
178 if (this.imageFile.isEnable()) {
179 String text = this.argField.getText();
182 sdf.applyPattern(Restamp.TIME_PATTERN);
186 catch (ParseException e) {