OSDN Git Service

fixed: GUIを一新した
[importpicture/importpicture.git] / src / main / java / 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         try {
158             String path = basetime.getImageFile().getImageFile().getAbsolutePath();
159
160             // View Image File
161             int size_x = imageSPane.getWidth() - 8;
162             ImageIcon tmpIcon = new ImageIcon(path);
163             refImage = tmpIcon;
164             if (tmpIcon.getIconWidth() > size_x) {
165                 refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x, -1, Image.SCALE_DEFAULT));
166             }
167             imageLabel.setIcon(refImage);
168         }
169         catch(NullPointerException e) {
170             // 何もしない
171         }
172         repaint();
173     }
174     
175     public void zoomin_Action() {
176         if (refImage != null) {
177             int size_x = imageLabel.getWidth();
178             String path = basetime.getImageFile().getImageFile().getAbsolutePath();
179             ImageIcon tmpIcon = new ImageIcon(path);
180             refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x * 2, -1, Image.SCALE_DEFAULT));
181             imageLabel.setIcon(refImage);
182             repaint();
183         }
184     }
185
186     public void zoomout_Action() {
187         if (refImage != null) {
188             int size_x = imageLabel.getWidth();
189             ImageIcon tmpIcon = refImage;
190             refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x / 2, -1, Image.SCALE_DEFAULT));
191             imageLabel.setIcon(refImage);
192             repaint();
193         }
194     }
195     
196     /**
197      * ダイアログが閉じられるときのアクション
198      */
199     void dialog_WindowClosing() {
200         String workStr = basetime.getText();
201         arg_basetime.setText(workStr);
202         dispose();
203     }
204
205     @Override
206     public void setVisible(boolean b) {
207         if(b) {
208             Rectangle bounds = getParent().getBounds();
209             Rectangle abounds = getBounds();
210             setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
211             bounds.y + (bounds.height - abounds.height)/2);
212         }
213         super.setVisible(b);
214     }
215
216     @Override
217     @SuppressWarnings("empty-statement")
218     public void openAction() {
219        ; // 何もしない
220     }
221
222     /**
223      *  入力条件が満たされているかどうか
224      * @return
225      */
226     @Override
227     public boolean isEnable() {
228        return this.basetime.isEnable();
229     }
230 }