OSDN Git Service

refactor: 不要なコメントを削除
[importpicture/importpicture.git] / src / osm / jp / gpx / matchtime / gui / restamp / DialogCorectTime.java
1 package osm.jp.gpx.matchtime.gui.restamp;
2
3 import java.awt.BorderLayout;
4 import java.awt.Dialog;
5 import java.awt.GridLayout;
6 import java.awt.Image;
7 import java.awt.Rectangle;
8 import java.awt.Window;
9 import javax.swing.BoxLayout;
10 import javax.swing.ImageIcon;
11 import javax.swing.JButton;
12 import javax.swing.JDialog;
13 import javax.swing.JLabel;
14 import javax.swing.JPanel;
15 import javax.swing.JScrollPane;
16 import osm.jp.gpx.matchtime.gui.AdjustTime;
17 import static osm.jp.gpx.matchtime.gui.AdjustTime.createImageIcon;
18 import static osm.jp.gpx.matchtime.gui.AdjustTime.i18n;
19 import osm.jp.gpx.matchtime.gui.PanelAction;
20 import osm.jp.gpx.matchtime.gui.ParameterPanelTime;
21
22 /**
23  * [基準画像(開始)]選択パネル
24  * @author yuu
25  */
26 public class DialogCorectTime extends JDialog implements PanelAction {
27     public JPanel mainPanel;
28     ParameterPanelTime arg_basetime;    // 開始画像の基準時刻(parent)
29     ParameterPanelTime basetime;        // 開始画像の基準時刻(tempolarry)
30     java.awt.Button closeButton;
31     JButton expandButton;
32     JButton zoomInButton;
33     JButton zoomOutButton;
34     JLabel imageLabel;          // 開始画像の基準時刻画像表示
35     JScrollPane imageSPane;     // スクロールパネル
36     
37     /**
38      * コンストラクタ
39      * @param arg3_basetime       開始画像の基準時刻:
40      * @param owner
41      */
42     @SuppressWarnings("OverridableMethodCallInConstructor")
43     public DialogCorectTime(ParameterPanelTime arg3_basetime, Window owner) {
44         super(owner, AdjustTime.i18n.getString("tab.restamp.300"), Dialog.ModalityType.DOCUMENT_MODAL);
45         this.arg_basetime = arg3_basetime;
46         
47         // INIT_CONTROLS
48         setLayout(new BorderLayout());
49         setSize(
50             getInsets().left + getInsets().right + 720,
51             getInsets().top + getInsets().bottom + 480
52         );
53
54         //---- CENTER -----
55         JPanel centerPanel = new JPanel();
56         centerPanel.setLayout(new BorderLayout());
57         add(centerPanel, BorderLayout.CENTER);
58
59         //---- CENTER.NORTH -----
60         JPanel argsPanel;               // パラメータ設定パネル       (上部)
61         argsPanel = new JPanel();
62         argsPanel.setLayout(new GridLayout(2, 1));
63         
64         // 3. 正確な撮影時刻を入力してください。
65         //    カメラの時計が正確ならば、設定を変更する必要はありません。
66         JLabel label3 = new JLabel();
67         label3.setText(i18n.getString("label.300"));
68         argsPanel.add(label3);
69
70         basetime = new ParameterPanelTime(
71                 arg_basetime.argLabel.getText(),
72                 "",
73                 arg_basetime.getImageFile()
74         );
75         basetime.updateButton.setVisible(false);
76         basetime.resetButton.setVisible(true);
77         argsPanel.add(basetime);
78         centerPanel.add(argsPanel, BorderLayout.NORTH);
79
80         //---- CENTER.CENTER -----
81         // 参考画像
82         imageLabel = new JLabel();
83         imageSPane = new JScrollPane(imageLabel);
84         centerPanel.add(imageSPane, BorderLayout.CENTER);
85
86         //---- CENTER.SOUTH -----
87         // 画像ファイル選択ダイアログを起動するボタン
88         JPanel buttonPanel = new JPanel();
89         buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
90         expandButton = new JButton(createImageIcon(java.util.ResourceBundle.getBundle("i18n_ja_JP").getString("IMAGES/FIT16.GIF")));
91         buttonPanel.add(expandButton);
92         zoomInButton = new JButton(createImageIcon("images/ZoomIn16.gif"));
93         buttonPanel.add(zoomInButton);
94         zoomOutButton = new JButton(createImageIcon("images/ZoomOut16.gif"));
95         buttonPanel.add(zoomOutButton);
96         centerPanel.add(buttonPanel, BorderLayout.SOUTH);
97         
98         //---- SOUTH -----
99         closeButton = new java.awt.Button();
100         closeButton.setLabel(i18n.getString("button.close") );
101         closeButton.setBounds(145,65,66,27);
102         add(closeButton, BorderLayout.SOUTH);
103
104         // 選択された画像ファイルを表示する
105         imageView_Action();
106         
107         //{{REGISTER_LISTENERS
108         SymWindow aSymWindow = new SymWindow();
109         this.addWindowListener(aSymWindow);
110         SymAction lSymAction = new SymAction();
111         closeButton.addActionListener(lSymAction);
112         expandButton.addActionListener(lSymAction);
113         zoomInButton.addActionListener(lSymAction);
114         zoomOutButton.addActionListener(lSymAction);
115         //}}
116     }
117     
118     class SymWindow extends java.awt.event.WindowAdapter
119     {
120         @Override
121         public void windowClosing(java.awt.event.WindowEvent event) {
122             Object object = event.getSource();
123             if (object == DialogCorectTime.this) {
124                 dialog_WindowClosing();
125             }
126         }
127     }
128     
129     class SymAction implements java.awt.event.ActionListener
130     {
131         @Override
132         public void actionPerformed(java.awt.event.ActionEvent event) {
133             Object object = event.getSource();
134             if (object == closeButton) {
135                 dialog_WindowClosing();
136             }
137             else if (object == expandButton) {
138                 imageView_Action();
139             }
140             else if (object == zoomInButton) {
141                 zoomin_Action();
142             }
143             else if (object == zoomOutButton) {
144                 zoomout_Action();
145             }
146         }
147     }
148     
149     ImageIcon refImage;
150
151     /**
152      * 選択された画像ファイルを表示する
153      * 基準画像ボタンがクリックされた時に、基準時刻フィールドに基準画像の作成日時を設定する。
154      */
155     @SuppressWarnings("UseSpecificCatch")
156     public void imageView_Action() {
157         String path = basetime.getImageFile().getImageFile().getAbsolutePath();
158
159         // View Image File
160         int size_x = imageSPane.getWidth() - 8;
161         ImageIcon tmpIcon = new ImageIcon(path);
162         refImage = tmpIcon;
163         if (tmpIcon.getIconWidth() > size_x) {
164             refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x, -1, Image.SCALE_DEFAULT));
165         }
166         imageLabel.setIcon(refImage);
167         repaint();
168     }
169     
170     public void zoomin_Action() {
171         if (refImage != null) {
172             int size_x = imageLabel.getWidth();
173             String path = basetime.getImageFile().getImageFile().getAbsolutePath();
174             ImageIcon tmpIcon = new ImageIcon(path);
175             refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x * 2, -1, Image.SCALE_DEFAULT));
176             imageLabel.setIcon(refImage);
177             repaint();
178         }
179     }
180
181     public void zoomout_Action() {
182         if (refImage != null) {
183             int size_x = imageLabel.getWidth();
184             ImageIcon tmpIcon = refImage;
185             refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x / 2, -1, Image.SCALE_DEFAULT));
186             imageLabel.setIcon(refImage);
187             repaint();
188         }
189     }
190     
191     /**
192      * ダイアログが閉じられるときのアクション
193      */
194     void dialog_WindowClosing() {
195         String workStr = basetime.getText();
196         arg_basetime.setText(workStr);
197         dispose();
198     }
199
200     @Override
201     public void setVisible(boolean b) {
202         if(b) {
203             Rectangle bounds = getParent().getBounds();
204             Rectangle abounds = getBounds();
205             setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
206             bounds.y + (bounds.height - abounds.height)/2);
207         }
208         super.setVisible(b);
209     }
210
211     @Override
212     @SuppressWarnings("empty-statement")
213     public void openAction() {
214        ; // 何もしない
215     }
216
217     /**
218      *  入力条件が満たされているかどうか
219      * @return
220      */
221     @Override
222     public boolean isEnable() {
223        return this.basetime.isEnable();
224     }
225 }