1 package osm.jp.gpx.matchtime.gui;
3 import java.awt.event.ActionEvent;
7 import osm.jp.gpx.ImportPicture;
12 @SuppressWarnings("serial")
13 public class AdjustTime extends JFrame
15 public static final String PROGRAM_NAME = "AdjustTime for JOSM";
16 public static final String PROGRAM_VARSION = "3.0";
17 public static final String PROGRAM_UPDATE = "2015/07/26";
19 // Used for addNotify check.
20 boolean fComponentsAdjusted = false;
23 JPanel cardPanel; // ウィザード形式パネル(カード型)
26 JPanel argsPanel; // パラメータ設定パネル (上部)
27 JScrollPane imageSPane; // スクロールパネル
28 JLabel imageLabel; // 基準時刻画像表示
29 JTextArea textArea; // 実行結果表示領域
30 //ImagePreview imagePane; // 基準時刻画像表示
31 ParameterPanelFolder arg1Panel_1;
32 ParameterPanelImageFile arg1Panel_2;
33 ParameterPanelTime arg1Panel_3;
34 ParameterPanelSelecter arg1Panel_4; // EXIF 書き出しモード
35 ParameterPanelFolder arg1Panel_5; // GPXファイル・フォルダ
37 JPanel buttonPanel; // ボタンパネル (下部)
38 JButton openButton; // [Fit]ボタン
39 JButton zoomInButton; // [Zoom in]ボタン
40 JButton zoomOutButton; // [Zoom out]ボタン
41 JButton nextButton; // [次へ]ボタン
42 JButton backButton; // [戻る]ボタン
46 java.awt.MenuBar mainMenuBar;
48 java.awt.MenuItem miDoNewFileList;
49 java.awt.MenuItem miDoDirSize;
50 java.awt.MenuItem miDoReadXML;
51 java.awt.MenuItem miExit;
53 java.awt.MenuItem miAbout;
56 class SymWindow extends java.awt.event.WindowAdapter {
59 * このパネルが閉じられたら、このアプリケーションも終了させる。
62 public void windowClosing(java.awt.event.WindowEvent event) {
63 Object object = event.getSource();
64 if (object == AdjustTime.this) {
65 DbMang_WindowClosing(event);
70 class SymAction implements java.awt.event.ActionListener {
72 public void actionPerformed(java.awt.event.ActionEvent event) {
73 Object object = event.getSource();
74 if (object == miAbout) {
75 miAbout_Action(event);
77 else if (object == miExit) {
80 else if (object == openButton) {
81 imageView_Action(event);
83 else if (object == zoomInButton) {
86 else if (object == zoomOutButton) {
87 zoomout_Action(event);
89 else if (object == arg1Panel_2.argField) {
90 imageView_Action(event);
92 else if (object == arg1Panel_2.openButton) {
93 selectImage_Action(event);
94 imageView_Action(event);
96 else if (object == arg1Panel_3.doButton) {
97 doButton_Action(event);
99 else if (object == arg1Panel_4.field) {
100 doButton_Action(event);
102 else if (object == nextButton) {
103 nextButton_Action(event);
105 else if (object == backButton) {
106 backButton_Action(event);
112 * データベース内のテーブルを一覧で表示するFrame
117 Container container = getContentPane();
118 container.setLayout(new BorderLayout());
119 setSize(getInsets().left + getInsets().right + 960,getInsets().top + getInsets().bottom + 480);
120 setTitle(AdjustTime.PROGRAM_NAME +" v"+ AdjustTime.PROGRAM_VARSION);
122 //---------------------------------------------------------------------
123 cardPanel = new JPanel();
124 cardPanel.setLayout(new CardLayout());
125 container.add(cardPanel, BorderLayout.CENTER);
127 nextButton = new JButton("次へ");
128 container.add(nextButton, BorderLayout.EAST);
130 backButton = new JButton("戻る");
131 container.add(backButton, BorderLayout.WEST);
133 cards = new JPanel[5];
134 for (int i=0; i < 5; i++) {
135 cards[i] = new JPanel();
136 cardPanel.add(cards[i], String.valueOf(i));
140 //---------------------------------------------------------------------
143 cards[cardNo].setLayout(new BorderLayout());
144 JLabel label1 = new JLabel();
145 label1.setText("<html><p>位置情報を付加したい画像ファイルが格納されているフォルダを選択してください。</p><ul><li>コピー動作を行うと、ファイル更新時刻がコピーを実行した時刻に書き換わってしまうことがあります。オリジナルのカメラUSB内のフォルダを直接指定することをおすすめします。</li></ul>");
146 cards[cardNo].add(label1, BorderLayout.NORTH);
148 argsPanel = new JPanel();
149 argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS));
150 arg1Panel_1 = new ParameterPanelFolder("対象フォルダ: ", ".");
151 argsPanel.add(arg1Panel_1);
152 cards[cardNo].add(argsPanel, BorderLayout.CENTER);
154 //---------------------------------------------------------------------
157 cards[cardNo].setLayout(new BorderLayout());
158 JLabel label2 = new JLabel();
159 label2.setText("<html><p>正確な撮影時刻が判明できる画像を選んでください。</p><ul><li>スマートフォンの時計画面(秒が判別できること)を撮影した画像</li><li>カメラの時計が正確ならば、どの画像を選んでも構いません。</li></ul>");
160 cards[cardNo].add(label2, BorderLayout.NORTH);
162 argsPanel = new JPanel();
163 argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS));
164 arg1Panel_2 = new ParameterPanelImageFile("基準時刻画像: ", "", arg1Panel_1);
165 argsPanel.add(arg1Panel_2);
166 cards[cardNo].add(argsPanel, BorderLayout.CENTER);
168 //---------------------------------------------------------------------
171 cards[cardNo].setLayout(new BorderLayout());
172 argsPanel = new JPanel();
173 argsPanel.setLayout(new GridLayout(2, 1));
175 JLabel label3 = new JLabel();
176 label3.setText("<html><p>正確な撮影時刻を入力してください。</p><ul><li>カメラの時計が正確ならば、設定を変更する必要はありません。</li></ul>");
177 argsPanel.add(label3);
178 arg1Panel_3 = new ParameterPanelTime(" 基準時刻: ", ImportPicture.TIME_FORMAT_STRING);
179 argsPanel.add(arg1Panel_3);
180 cards[cardNo].add(argsPanel, BorderLayout.NORTH);
183 imageLabel = new JLabel();
184 imageSPane = new JScrollPane(imageLabel);
185 cards[cardNo].add(imageSPane, BorderLayout.CENTER);
187 // 画像ファイル選択ダイアログを起動するボタン
188 buttonPanel = new JPanel();
189 buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
190 openButton = new JButton(createImageIcon("images/Fit16.gif"));
191 buttonPanel.add(openButton);
192 zoomInButton = new JButton(createImageIcon("images/ZoomIn16.gif"));
193 buttonPanel.add(zoomInButton);
194 zoomOutButton = new JButton(createImageIcon("images/ZoomOut16.gif"));
195 buttonPanel.add(zoomOutButton);
196 cards[cardNo].add(buttonPanel, BorderLayout.SOUTH);
198 //---------------------------------------------------------------------
201 cards[cardNo].setLayout(new BorderLayout());
202 JPanel tmpPanel4 = new JPanel();
203 tmpPanel4.setLayout(new BoxLayout(tmpPanel4, BoxLayout.Y_AXIS));
204 File gpxDir = new File(".");
205 arg1Panel_5 = new ParameterPanelFolder("GPXフォルダ: ", gpxDir.getAbsolutePath());
206 tmpPanel4.add(arg1Panel_5);
207 cards[cardNo].add(tmpPanel4, BorderLayout.CENTER);
209 //---------------------------------------------------------------------
212 cards[cardNo].setLayout(new BorderLayout());
213 JPanel tmpPanel5 = new JPanel();
214 tmpPanel5.setLayout(new BoxLayout(tmpPanel5, BoxLayout.Y_AXIS));
215 String[] combodata = {"更新しない", "更新する"};
216 arg1Panel_4 = new ParameterPanelSelecter("EXIF変更: ", combodata);
217 tmpPanel5.add(arg1Panel_4);
218 cards[cardNo].add(tmpPanel5, BorderLayout.CENTER);
220 //---------------------------------------------------------------------
222 menu1 = new java.awt.Menu("File");
223 miExit = new java.awt.MenuItem(QuitDialog.TITLE);
224 miExit.setFont(new Font("Dialog", Font.PLAIN, 12));
227 miAbout = new java.awt.MenuItem("About...");
228 miAbout.setFont(new Font("Dialog", Font.PLAIN, 12));
230 menu3 = new java.awt.Menu("Help");
231 menu3.setFont(new Font("Dialog", Font.PLAIN, 12));
234 mainMenuBar = new java.awt.MenuBar();
235 mainMenuBar.setHelpMenu(menu3);
236 mainMenuBar.add(menu1);
237 mainMenuBar.add(menu3);
238 setMenuBar(mainMenuBar);
241 //{{REGISTER_LISTENERS
242 SymWindow aSymWindow = new SymWindow();
243 this.addWindowListener(aSymWindow);
244 SymAction lSymAction = new SymAction();
245 miAbout.addActionListener(lSymAction);
246 miExit.addActionListener(lSymAction);
247 openButton.addActionListener(lSymAction);
248 zoomOutButton.addActionListener(lSymAction);
249 zoomInButton.addActionListener(lSymAction);
250 arg1Panel_2.argField.addActionListener(lSymAction);
251 arg1Panel_2.openButton.addActionListener(lSymAction);
252 arg1Panel_3.doButton.addActionListener(lSymAction);
253 arg1Panel_4.field.addActionListener(lSymAction);
254 nextButton.addActionListener(lSymAction);
255 backButton.addActionListener(lSymAction);
260 * Shows or hides the component depending on the boolean flag b.
261 * @param b trueのときコンポーネントを表示; その他のとき, componentを隠す.
262 * @see java.awt.Component#isVisible
265 public void setVisible(boolean b) {
273 * このクラスをインスタンスを生成して表示する。
277 static public void main(String args[]) {
278 SwingUtilities.invokeLater(() -> {
282 private static void createAndShowGUI() {
283 (new AdjustTime()).setVisible(true);
287 public void addNotify() {
288 // Record the size of the window prior to calling parents addNotify.
289 Dimension d = getSize();
293 if (fComponentsAdjusted)
296 // Adjust components according to the insets
297 setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
298 Component components[] = getComponents();
299 for (Component component : components) {
300 Point p = component.getLocation();
301 p.translate(getInsets().left, getInsets().top);
302 component.setLocation(p);
304 fComponentsAdjusted = true;
307 void DbMang_WindowClosing(java.awt.event.WindowEvent event) {
308 setVisible(false); // hide the Manager
309 dispose(); // free the system resources
310 System.exit(0); // close the application
313 void miAbout_Action(java.awt.event.ActionEvent event) {
314 // Action from About Create and show as modal
315 (new AboutDialog(this, true)).setVisible(true);
318 void miExit_Action(java.awt.event.ActionEvent event) {
319 // Action from Exit Create and show as modal
320 //(new hayashi.yuu.tools.gui.QuitDialog(this, true)).setVisible(true);
321 (new QuitDialog(this, true)).setVisible(true);
328 * 基準画像ボタンがクリックされた時に、基準時刻フィールドに基準画像の作成日時を設定する。
331 public void imageView_Action(ActionEvent ev) {
332 String path = (new File(arg1Panel_1.getText(), arg1Panel_2.getText())).getPath();
334 File timeFile = new File(path);
335 long lastModifyTime = timeFile.lastModified();
336 arg1Panel_3.argField.setText(ImportPicture.dfjp.format(new Date(lastModifyTime)));
338 int size_x = imageSPane.getWidth() - 8;
339 ImageIcon tmpIcon = new ImageIcon(path);
341 if (tmpIcon.getIconWidth() > size_x) {
342 refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x, -1, Image.SCALE_DEFAULT));
344 imageLabel.setIcon(refImage);
348 public void zoomin_Action(ActionEvent ev) {
349 if (refImage != null) {
350 int size_x = imageLabel.getWidth();
351 String path = (new File(arg1Panel_1.getText(), arg1Panel_2.getText())).getPath();
352 ImageIcon tmpIcon = new ImageIcon(path);
353 refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x * 2, -1, Image.SCALE_DEFAULT));
354 imageLabel.setIcon(refImage);
359 public void zoomout_Action(ActionEvent ev) {
360 if (refImage != null) {
361 int size_x = imageLabel.getWidth();
362 ImageIcon tmpIcon = refImage;
363 refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x / 2, -1, Image.SCALE_DEFAULT));
364 imageLabel.setIcon(refImage);
369 public void selectImage_Action(ActionEvent ev) {
372 //Set up the file chooser.
373 File sdir = new File(arg1Panel_1.getText());
374 System.out.println(sdir.getPath());
375 if (sdir.isDirectory()) {
376 fc = new JFileChooser(sdir);
379 fc = new JFileChooser();
382 //Add a custom file filter and disable the default
383 //(Accept All) file filter.
384 fc.addChoosableFileFilter(new ImageFilter());
385 fc.setAcceptAllFileFilterUsed(false);
387 //Add custom icons for file types.
388 fc.setFileView(new ImageFileView());
390 //Add the preview pane.
391 fc.setAccessory(new ImagePreview(fc));
394 int returnVal = fc.showDialog(this, "選択");
396 //Process the results.
397 if (returnVal == JFileChooser.APPROVE_OPTION) {
398 File file = fc.getSelectedFile();
399 arg1Panel_2.argField.setText(file.getName());
402 //Reset the file chooser for the next time it's shown.
403 fc.setSelectedFile(null);
406 /** Returns an ImageIcon, or null if the path was invalid.
409 public static ImageIcon createImageIcon(String path) {
410 java.net.URL imgURL = AdjustTime.class.getResource(path);
411 if (imgURL != null) {
412 return new ImageIcon(imgURL);
414 System.err.println("Couldn't find file: " + path);
420 * [実行]ボタンをクリックしたときの動作
423 void doButton_Action(java.awt.event.ActionEvent event) {
424 arg1Panel_3.doButton.setEnabled(false);
426 String[] argv = new String[4];
427 argv[0] = arg1Panel_1.getText();
428 argv[1] = arg1Panel_2.getText();
429 argv[2] = arg1Panel_3.getText();
430 String value = (String) arg1Panel_4.field.getSelectedItem();
431 argv[3] = (value.equals("更新する") ? "EXIF" : "none");
433 (new DoDialog(this, argv)).setVisible(true);
435 arg1Panel_3.doButton.setEnabled(true);
442 void nextButton_Action(ActionEvent event) {
443 if ((cardPanelNo + 1) < cards.length) {
445 CardLayout cl = (CardLayout)(cardPanel.getLayout());
446 cl.show(cardPanel, String.valueOf(cardPanelNo));
454 void backButton_Action(ActionEvent event) {
455 if ((cardPanelNo - 1) >= 0) {
457 CardLayout cl = (CardLayout)(cardPanel.getLayout());
458 cl.show(cardPanel, String.valueOf(cardPanelNo));