1 package osm.jp.gpx.matchtime.gui;
3 import java.awt.Window;
4 import java.awt.event.ActionEvent;
6 import java.text.DateFormat;
7 import java.text.SimpleDateFormat;
9 import javax.swing.ButtonGroup;
10 import javax.swing.JButton;
11 import javax.swing.JRadioButton;
12 import org.apache.commons.imaging.Imaging;
13 import org.apache.commons.imaging.common.ImageMetadata;
14 import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;
15 import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
16 import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
17 import osm.jp.gpx.AppParameters;
18 import osm.jp.gpx.Restamp;
19 import static osm.jp.gpx.matchtime.gui.AdjustTime.dfjp;
20 import osm.jp.gpx.matchtime.gui.restamp.DialogCorectTime;
24 * この1インスタンスで、1パラメータをあらわす。
26 public class ParameterPanelTime extends ParameterPanel {
27 SimpleDateFormat sdf = (SimpleDateFormat)DateFormat.getDateTimeInstance();
28 ParameterPanelImageFile imageFile; // 基準時刻画像
32 public ButtonGroup baseTimeGroup = new ButtonGroup();
33 public JRadioButton exifBase = null; // EXIF日時を基準にする/ !(ファイル更新日時を基準にする)
34 public JRadioButton fupdateBase = null; // File更新日時を基準にする/ !(EXIF日時を基準にする)
36 public JButton updateButton;
37 public JButton resetButton;
40 @SuppressWarnings("OverridableMethodCallInConstructor")
41 public ParameterPanelTime(
44 ParameterPanelImageFile imageFile
47 this.imageFile = imageFile;
50 UpdateButtonAction buttonAction = new UpdateButtonAction(this);
51 updateButton = new JButton(i18n.getString("button.update"));
52 updateButton.addActionListener(buttonAction);
53 this.add(updateButton);
56 ResetButtonAction resetAction = new ResetButtonAction(this);
57 resetButton = new JButton(i18n.getString("button.reset"));
58 resetButton.addActionListener(resetAction);
59 resetButton.setVisible(false);
60 this.add(resetButton);
63 public ParameterPanelTime setOwner(Window owner) {
73 public void addExifBase(String label, AppParameters params) {
74 boolean selected = false;
75 if (params.getProperty(AppParameters.GPX_BASETIME).equals("EXIF_TIME")) {
78 exifBase = new JRadioButton(label, selected);
79 baseTimeGroup.add(exifBase);
87 public void addFileUpdate(String label, AppParameters params) {
88 boolean selected = false;
89 if (params.getProperty(AppParameters.GPX_BASETIME).equals("FILE_UPDATE_TIME")) {
92 fupdateBase = new JRadioButton(label, selected);
93 baseTimeGroup.add(fupdateBase);
96 public ParameterPanelImageFile getImageFile() {
97 return this.imageFile;
104 class UpdateButtonAction implements java.awt.event.ActionListener
106 ParameterPanelTime param;
108 public UpdateButtonAction(ParameterPanelTime param) {
112 @SuppressWarnings("override")
113 public void actionPerformed(ActionEvent e) {
114 fileSelect_Action(param);
115 (new DialogCorectTime(param, owner)).setVisible(true);
122 class ResetButtonAction implements java.awt.event.ActionListener
124 ParameterPanelTime paramPanelTime;
126 public ResetButtonAction(ParameterPanelTime param) {
127 this.paramPanelTime = param;
130 @SuppressWarnings("override")
131 public void actionPerformed(ActionEvent e) {
132 fileSelect_Action(paramPanelTime);
137 * 画像ファイルが選択されたときのアクション
138 * 1.ラジオボタンの選択を参照してTEXTフィールドにファイルの「日時」を設定する
141 void fileSelect_Action(ParameterPanelTime param) {
142 if (imageFile.isEnable()) {
143 File timeFile = imageFile.getImageFile();
146 sdf.applyPattern(Restamp.TIME_PATTERN);
147 if ((exifBase != null) && exifBase.isSelected()) {
149 ImageMetadata meta = Imaging.getMetadata(timeFile);
150 JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta;
151 if (jpegMetadata != null) {
152 TiffImageMetadata exif = jpegMetadata.getExif();
154 String dateTimeOriginal = exif.getFieldValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL)[0];
155 long lastModifyTime = sdf.parse(dateTimeOriginal).getTime();
156 param.argField.setText(dfjp.format(new Date(lastModifyTime)));
159 param.argField.setText("exif == null");
163 catch (Exception ex) {
168 long lastModified = timeFile.lastModified();
169 param.argField.setText(sdf.format(new Date(lastModified)));
173 param.argField.setText("");
178 public boolean isEnable() {
179 if (this.imageFile.isEnable()) {
180 String text = this.argField.getText();
183 sdf.applyPattern(Restamp.TIME_PATTERN);
187 catch (Exception e) {