OSDN Git Service

e540e031a2c7c3ae31763aef16a1591b66bb2302
[importpicture/importpicture.git] / src / osm / jp / gpx / matchtime / gui / ParameterPanelTime.java
1 package osm.jp.gpx.matchtime.gui;
2
3 import java.awt.Dialog;
4 import java.awt.event.ActionEvent;
5 import java.io.File;
6 import java.text.DateFormat;
7 import java.text.SimpleDateFormat;
8 import java.util.Date;
9 import javax.swing.JButton;
10 import osm.jp.gpx.Restamp;
11 import osm.jp.gpx.matchtime.gui.restamp.DialogCorectTime;
12
13 /**
14  * パラメータを設定する為のパネル。
15  * この1インスタンスで、1パラメータをあらわす。
16  */
17 public class ParameterPanelTime extends ParameterPanel {
18     SimpleDateFormat sdf = (SimpleDateFormat)DateFormat.getDateTimeInstance();
19     ParameterPanelImageFile imageFile;
20     public JButton updateButton;
21     public JButton resetButton;
22     Dialog owner;
23
24     @SuppressWarnings("OverridableMethodCallInConstructor")
25     public ParameterPanelTime(
26             String label, 
27             String text, 
28             ParameterPanelImageFile imageFile
29     ) {
30         super(label, text);
31         this.imageFile = imageFile;
32         
33         // "ボタン[変更...]"
34         UpdateButtonAction buttonAction = new UpdateButtonAction(this);
35         updateButton = new JButton(i18n.getString("button.update"));
36         updateButton.addActionListener(buttonAction);
37         this.add(updateButton);
38         
39         // "ボタン[再設定...]"
40         ResetButtonAction resetAction = new ResetButtonAction(this);
41         resetButton = new JButton(i18n.getString("button.reset"));
42         resetButton.addActionListener(resetAction);
43         resetButton.setVisible(false);
44         this.add(resetButton);
45     }
46     
47     public ParameterPanelTime setOwner(Dialog owner) {
48         this.owner = owner;
49         return this;
50     }
51     
52     /**
53      * ボタンのアクション
54      */
55     class UpdateButtonAction implements java.awt.event.ActionListener
56     {
57         ParameterPanelTime param;
58         
59         public UpdateButtonAction(ParameterPanelTime param) {
60             this.param = param;
61         }
62         
63         @SuppressWarnings("override")
64         public void actionPerformed(ActionEvent e) {
65             (new DialogCorectTime(param, owner)).setVisible(true);
66         }
67     }
68     
69     /**
70      * ボタンのアクション
71      */
72     class ResetButtonAction implements java.awt.event.ActionListener
73     {
74         ParameterPanelTime param;
75         
76         public ResetButtonAction(ParameterPanelTime param) {
77             this.param = param;
78         }
79         
80         @SuppressWarnings("override")
81         public void actionPerformed(ActionEvent e) {
82             if (param.imageFile.isEnable()) {
83                 File file = param.imageFile.getImageFile();
84                 long lastModified = file.lastModified();
85                 sdf.applyPattern(Restamp.TIME_PATTERN);
86                 param.argField.setText(sdf.format(new Date(lastModified)));
87             }
88             else {
89                 param.argField.setText("");
90             }
91         }
92     }
93     
94     public ParameterPanelImageFile getImageFile() {
95         return this.imageFile;
96     }
97
98     @Override
99     public boolean isEnable() {
100         if (this.imageFile.isEnable()) {
101             String text = this.argField.getText();
102             if (text != null) {
103                 try {
104                     sdf.applyPattern(Restamp.TIME_PATTERN);
105                     sdf.parse(text);
106                     return true;
107                 }
108                 catch (Exception e) {
109                     return false;
110                 }
111             }
112         }
113         return false;
114     }
115 }