OSDN Git Service

GUIのパネルボタンの配置を変更
[importpicture/importpicture.git] / importPicture / src / osm / jp / gpx / matchtime / gui / AdjustTime.java
1 package osm.jp.gpx.matchtime.gui;
2
3 import java.awt.*;
4 import java.awt.event.ActionEvent;
5 import java.io.File;
6 import java.io.IOException;
7 import java.text.SimpleDateFormat;
8 import java.util.Date;
9 import java.util.ResourceBundle;
10 import java.util.TimeZone;
11 import javax.swing.*;
12 import osm.jp.gpx.*;
13 import org.apache.commons.imaging.Imaging;
14 import org.apache.commons.imaging.common.ImageMetadata;
15 import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;
16 import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
17 import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
18
19 /**
20  * 本プログラムのメインクラス
21  */
22 @SuppressWarnings("serial")
23 public class AdjustTime extends JFrame
24 {
25     public static final String PROGRAM_NAME = "AdjustTime for JOSM";
26     public static final String PROGRAM_VARSION = "4.01";
27     public static final String PROGRAM_UPDATE = "2018/09/17";
28
29     AppParameters params;
30     SimpleDateFormat dfjp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
31
32     // Used for addNotify check.
33     boolean fComponentsAdjusted = false;
34     public ResourceBundle i18n = ResourceBundle.getBundle("i18n");
35     
36     //{{DECLARE_CONTROLS
37     JPanel cardPanel;       // ウィザード形式パネル(カード型)
38     JPanel[] cards;
39     int cardPanelNo = 0;
40     JPanel argsPanel;           // パラメータ設定パネル       (上部)
41     JScrollPane imageSPane;     // スクロールパネル
42     JLabel imageLabel;          // 基準時刻画像表示
43     ButtonGroup baseTimeGroup;  // 基準時刻の指定グループ
44     JRadioButton exifBase;              // EXIF日時を基準にする/ !(ファイル更新日時を基準にする)
45     JRadioButton fupdateBase;   // File更新日時を基準にする/ !(EXIF日時を基準にする)
46     JCheckBox noFirstNode;      // GPX: <trkseg>セグメントの最初の1ノードは無視する。 {ON | OFF}
47     JCheckBox gpxReuse;         // 生成されたGPXファイル(ファイル名が'_.gpx'で終わるもの)も対象にする。 {ON | OFF}
48     JTextArea textArea;         // 実行結果表示領域
49     //ImagePreview imagePane;   // 基準時刻画像表示
50     ParameterPanelFolder arg1_srcFolder;
51     ParameterPanelImageFile arg2_baseTimeImg;
52     ParameterPanel arg3_basetime;       // 基準時刻:
53     JCheckBox outputIMG;        // IMGの変換 する/しない
54     JCheckBox outputIMG_all;    // 'out of GPX time'でもIMGの変換をする {ON | OFF}
55     JCheckBox exifON;           // EXIF 書き出しモード / !(EXIFの書き換えはしない)
56     JCheckBox gpxOutputWpt;     // GPXに<WPT>を書き出す
57     JCheckBox gpxOverwriteMagvar;       // ソースGPXの<MAGVAR>を無視する
58     JCheckBox gpxOutputSpeed;   // GPXに<SPEED>を書き出す
59     ParameterPanelFolder arg5_outputFolder;       // EXIF 書き出しフォルダ
60     ParameterPanelGpx arg4_gpxFolder;           // GPXファイル・フォルダ
61     
62     JPanel buttonPanel;         // ボタンパネル   (下部)
63     JButton openButton;         // [Fit]ボタン
64     JButton zoomInButton;       // [Zoom in]ボタン
65     JButton zoomOutButton;      // [Zoom out]ボタン
66     
67     JButton nextButton;     // [次へ]ボタン
68     JButton backButton;     // [戻る]ボタン
69     JButton doButton;       // [処理実行]ボタン
70     //}}
71
72     //{{DECLARE_MENUS
73     java.awt.MenuBar mainMenuBar;
74     java.awt.Menu menu1;
75     java.awt.MenuItem miDoNewFileList;
76     java.awt.MenuItem miDoDirSize;
77     java.awt.MenuItem miDoReadXML;
78     java.awt.MenuItem miExit;
79     java.awt.Menu menu3;
80     java.awt.MenuItem miAbout;
81     //}}
82
83     class SymWindow extends java.awt.event.WindowAdapter {
84         /**
85          * このFrameが閉じられるときの動作。
86          * このパネルが閉じられたら、このアプリケーションも終了させる。
87          */
88         @Override
89         public void windowClosing(java.awt.event.WindowEvent event) {
90             Object object = event.getSource();
91             if (object == AdjustTime.this) {
92                 DbMang_WindowClosing(event);
93             }
94         }
95     }
96
97     class SymAction implements java.awt.event.ActionListener {
98         @Override
99         public void actionPerformed(java.awt.event.ActionEvent event) {
100             Object object = event.getSource();
101             if (object == miAbout) {
102                 miAbout_Action(event);
103             }
104             else if (object == miExit) {
105                 miExit_Action(event);
106             }
107             else if (object == openButton) {
108                 imageView_Action(event);
109             }
110             else if (object == zoomInButton) {
111                 zoomin_Action(event);
112             }
113             else if (object == zoomOutButton) {
114                 zoomout_Action(event);
115             }
116             else if (object == arg2_baseTimeImg.argField) {
117                 imageView_Action(event);
118             }
119             else if (object == arg2_baseTimeImg.openButton) {
120                 selectImage_Action(event);
121                 imageView_Action(event);
122             }
123             else if (object == outputIMG) {
124                 outputIMG_Action(event);
125             }
126             else if (object == outputIMG_all) {
127                 outputIMGall_Action(event);
128             }
129             else if (object == exifON) {
130                 exifON_Action(event);
131             }
132             else if (object == gpxOutputWpt) {
133                 gpxOutputWpt_Action(event);
134             }
135             else if (object == gpxOutputSpeed) {
136                 gpxOutputSpeed_Action(event);
137             }
138             else if (object == doButton) {
139                 doButton_Action(event);
140             }
141             else if (object == nextButton) {
142                 nextButton_Action(event);
143             }
144             else if (object == backButton) {
145                 backButton_Action(event);
146             }
147         }
148     }
149     
150     /**
151      * データベース内のテーブルを一覧で表示するFrame
152      * @throws IOException 
153      */
154     @SuppressWarnings("OverridableMethodCallInConstructor")
155     public AdjustTime() throws IOException
156     {
157         dfjp.setTimeZone(TimeZone.getTimeZone("JST"));
158
159         // INIT_CONTROLS
160         Container container = getContentPane();
161         container.setLayout(new BorderLayout());
162         setSize(
163             getInsets().left + getInsets().right + 720,
164             getInsets().top + getInsets().bottom + 480
165         );
166         setTitle(AdjustTime.PROGRAM_NAME +" v"+ AdjustTime.PROGRAM_VARSION);
167         
168         //---- CENTER -----
169         JPanel mainPanel = new JPanel();
170         mainPanel.setLayout(new BorderLayout());
171         container.add(mainPanel, BorderLayout.CENTER);
172         
173         //---- SOUTH -----
174         JPanel southPanel = new JPanel(new BorderLayout());
175         southPanel.add(Box.createVerticalStrut(10), BorderLayout.SOUTH);
176         southPanel.add(Box.createVerticalStrut(10), BorderLayout.NORTH);
177         container.add(southPanel, BorderLayout.SOUTH);
178         
179         //---- SPACE -----
180         container.add(Box.createVerticalStrut(30), BorderLayout.NORTH);
181         container.add(Box.createHorizontalStrut(10), BorderLayout.WEST);
182         container.add(Box.createHorizontalStrut(10), BorderLayout.EAST);
183         
184         params = new AppParameters();
185         
186         //---------------------------------------------------------------------
187         cardPanel = new JPanel();
188         cardPanel.setLayout(new CardLayout());
189         mainPanel.add(cardPanel, BorderLayout.CENTER);
190         
191         nextButton = new JButton(i18n.getString("button.next"));
192         southPanel.add(nextButton, BorderLayout.EAST);
193
194         backButton = new JButton(i18n.getString("button.previous"));
195         southPanel.add(backButton, BorderLayout.WEST);
196
197         cards = new JPanel[5];
198         for (int i=0; i < 5; i++) {
199             cards[i] = new JPanel();
200             cardPanel.add(cards[i], String.valueOf(i));
201         }
202         cardPanelNo = 0;
203
204         //---------------------------------------------------------------------
205         // 1.[対象フォルダ]設定パネル
206         int cardNo = 0;
207         cards[cardNo].setLayout(new BorderLayout());
208         JLabel label1 = new JLabel();
209         label1.setText(i18n.getString("label.100"));
210         cards[cardNo].add(label1, BorderLayout.NORTH);
211         
212         argsPanel = new JPanel();
213         argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS));
214         arg1_srcFolder = new ParameterPanelFolder(i18n.getString("label.110") +": ", params.getProperty(AppParameters.IMG_SOURCE_FOLDER));
215         argsPanel.add(arg1_srcFolder);
216         cards[cardNo].add(argsPanel, BorderLayout.CENTER);
217         
218         //---------------------------------------------------------------------
219         // 2.[基準時刻画像]設定パネル
220         cardNo++;
221         cards[cardNo].setLayout(new BorderLayout());
222         JLabel label2 = new JLabel();
223         label2.setText(i18n.getString("label.200"));
224         cards[cardNo].add(label2, BorderLayout.NORTH);
225
226         argsPanel = new JPanel();
227         
228         // 基準時刻画像
229         argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS));
230         arg2_baseTimeImg = new ParameterPanelImageFile(i18n.getString("label.210") +": ", params.getProperty(AppParameters.IMG_BASE_FILE), arg1_srcFolder);
231         argsPanel.add(arg2_baseTimeImg);
232         
233         baseTimeGroup = new ButtonGroup();
234         
235         // EXIFの日時を基準にする
236         exifBase = new JRadioButton(i18n.getString("label.220"));
237         
238         // ファイル更新日時を基準にする
239         fupdateBase = new JRadioButton(i18n.getString("label.230"));
240         baseTimeGroup.add(exifBase);
241         baseTimeGroup.add(fupdateBase);
242         argsPanel.add(exifBase);
243         argsPanel.add(fupdateBase);
244         if (params.getProperty(AppParameters.GPX_BASETIME).equals("EXIF_TIME")) {
245             fupdateBase.setSelected(false);
246             exifBase.setSelected(true);
247         }
248         else {
249             fupdateBase.setSelected(true);
250             exifBase.setSelected(false);
251         }
252         cards[cardNo].add(argsPanel, BorderLayout.CENTER);
253         
254         //---------------------------------------------------------------------
255         // 3.基準時刻の入力画面
256         cardNo++;
257         cards[cardNo].setLayout(new BorderLayout());
258         argsPanel = new JPanel();
259         argsPanel.setLayout(new GridLayout(2, 1));
260
261         // 3. 正確な撮影時刻を入力してください。
262         //    カメラの時計が正確ならば、設定を変更する必要はありません。
263         JLabel label3 = new JLabel();
264         label3.setText(i18n.getString("label.300"));
265         argsPanel.add(label3);
266         
267         // 基準時刻:
268         String str310 = String.format("  %s: ", i18n.getString("label.310"));
269         arg3_basetime = new ParameterPanel(str310, ImportPicture.TIME_FORMAT_STRING);
270         argsPanel.add(arg3_basetime);
271         cards[cardNo].add(argsPanel, BorderLayout.NORTH);
272
273         // 参考画像
274         imageLabel = new JLabel();
275         imageSPane = new JScrollPane(imageLabel);
276         cards[cardNo].add(imageSPane, BorderLayout.CENTER);
277               
278         // 画像ファイル選択ダイアログを起動するボタン
279         buttonPanel = new JPanel();
280         buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
281         openButton = new JButton(createImageIcon("images/Fit16.gif"));
282         buttonPanel.add(openButton);
283         zoomInButton = new JButton(createImageIcon("images/ZoomIn16.gif"));
284         buttonPanel.add(zoomInButton);
285         zoomOutButton = new JButton(createImageIcon("images/ZoomOut16.gif"));
286         buttonPanel.add(zoomOutButton);
287         cards[cardNo].add(buttonPanel, BorderLayout.SOUTH);
288         
289         //---------------------------------------------------------------------
290         // 4.GPXファイル設定画面
291         cardNo++;
292         cards[cardNo].setLayout(new BorderLayout());
293         
294         // 4. ヒモ付を行うGPXファイルを選択してください。
295         //    - フォルダを指定すると、フォルダ内のすべてのGPXファイルを対象とします。
296         JLabel label4 = new JLabel();
297         label4.setText(i18n.getString("label.400"));
298         cards[cardNo].add(label4, BorderLayout.NORTH);
299         
300         JPanel tmpPanel4a = new JPanel();
301         tmpPanel4a.setLayout(new BoxLayout(tmpPanel4a, BoxLayout.Y_AXIS));
302         
303         // "GPXフォルダ: "
304         arg4_gpxFolder = new ParameterPanelGpx(
305             i18n.getString("label.410") + ": ", 
306             params.getProperty(AppParameters.GPX_SOURCE_FOLDER)
307         );
308         tmpPanel4a.add(arg4_gpxFolder);
309         
310         // "セグメント'trkseg'の最初の1ノードは無視する。"
311         noFirstNode = new JCheckBox(
312             i18n.getString("label.420"), 
313             params.getProperty(AppParameters.GPX_NO_FIRST_NODE).equals("ON")
314         );
315         tmpPanel4a.add(noFirstNode);
316         
317         // "生成されたGPXファイル(ファイル名が'_.gpx'で終わるもの)も変換の対象にする"
318         gpxReuse = new JCheckBox(
319             i18n.getString("label.430"),
320             params.getProperty(AppParameters.GPX_REUSE).equals("ON")
321         );
322         gpxReuse.setEnabled(true);
323         tmpPanel4a.add(gpxReuse);
324         cards[cardNo].add(tmpPanel4a, BorderLayout.CENTER);
325         
326         //---------------------------------------------------------------------
327         // 5.EXIF更新設定画面
328         cardNo++;
329         cards[cardNo].setLayout(new BorderLayout());
330
331         // 5. EXIF変換を行うかどうかを選択してください。
332         //    - EXIF変換を行う場合には、変換ファイルを出力するフォルダも指定する必要があります。
333         //    - 出力フォルダには、書き込み権限と、十分な空き容量が必要です。
334         JLabel label5 = new JLabel();
335         label5.setText(
336             String.format(
337                 "<html><p>5. %s</p><ul><li>%s</li><li>%s</li></ul>",
338                 i18n.getString("label.500"),
339                 i18n.getString("label.501"),
340                 i18n.getString("label.502")
341             )
342         );
343         cards[cardNo].add(label5, BorderLayout.NORTH);
344         
345         JPanel tmpPanel5 = new JPanel();
346         tmpPanel5.setLayout(new BoxLayout(tmpPanel5, BoxLayout.Y_AXIS));
347
348         // "IMGの変換をする"
349         outputIMG = new JCheckBox(
350             i18n.getString("label.510"), 
351             Boolean.parseBoolean(params.getProperty(AppParameters.IMG_OUTPUT))
352         );
353         tmpPanel5.add(outputIMG);
354
355         // "GPXファイル時間外のファイルもコピーする"
356         outputIMG_all = new JCheckBox(
357             i18n.getString("label.520"),
358             Boolean.parseBoolean(params.getProperty(AppParameters.IMG_OUTPUT_ALL))
359         );
360         tmpPanel5.add(outputIMG_all);
361
362         // "出力フォルダ: "
363         arg5_outputFolder = new ParameterPanelFolder(
364             i18n.getString("label.530") + ": ",
365             params.getProperty(AppParameters.IMG_OUTPUT_FOLDER)
366         );
367         tmpPanel5.add(arg5_outputFolder);
368
369         // "EXIFの変換をする"
370         exifON = new JCheckBox(
371             i18n.getString("label.540"),
372             Boolean.parseBoolean(params.getProperty(AppParameters.IMG_OUTPUT_EXIF))
373         );
374         tmpPanel5.add(exifON);
375         
376         // "ポイントマーカー<WPT>をGPXファイルに出力する"
377         gpxOutputWpt = new JCheckBox(
378             i18n.getString("label.550"),
379             Boolean.parseBoolean(params.getProperty(AppParameters.GPX_OUTPUT_WPT))
380         );
381         gpxOutputWpt.setEnabled(true);
382         tmpPanel5.add(gpxOutputWpt);
383         
384         // "ソースGPXの<MAGVAR>を無視する"
385         gpxOverwriteMagvar = new JCheckBox(
386             i18n.getString("label.560"),
387             Boolean.parseBoolean(params.getProperty(AppParameters.GPX_OVERWRITE_MAGVAR))
388         );
389         gpxOverwriteMagvar.setEnabled(true);
390         tmpPanel5.add(gpxOverwriteMagvar);
391         
392         // "出力GPXに<SPEED>を上書きする"
393         gpxOutputSpeed = new JCheckBox(
394             i18n.getString("label.570"),
395             Boolean.parseBoolean(params.getProperty(AppParameters.GPX_OUTPUT_SPEED))
396         );
397         gpxOutputSpeed.setEnabled(true);
398         tmpPanel5.add(gpxOutputSpeed);
399         
400         cards[cardNo].add(tmpPanel5, BorderLayout.CENTER);
401         
402         // "処理実行"
403         doButton = new JButton(
404             i18n.getString("button.execute"),
405             AdjustTime.createImageIcon("images/media_playback_start.png")
406         );
407         cards[cardNo].add(doButton, BorderLayout.SOUTH);
408
409
410         //---------------------------------------------------------------------
411         // INIT_MENUS
412         menu1 = new java.awt.Menu("File");
413         miExit = new java.awt.MenuItem(i18n.getString("menu.quit"));
414         miExit.setFont(new Font("Dialog", Font.PLAIN, 12));
415         menu1.add(miExit);
416
417         miAbout = new java.awt.MenuItem("About...");
418         miAbout.setFont(new Font("Dialog", Font.PLAIN, 12));
419
420         menu3 = new java.awt.Menu("Help");
421         menu3.setFont(new Font("Dialog", Font.PLAIN, 12));
422         menu3.add(miAbout);
423
424         mainMenuBar = new java.awt.MenuBar();
425         mainMenuBar.setHelpMenu(menu3);
426         mainMenuBar.add(menu1);
427         mainMenuBar.add(menu3);
428         setMenuBar(mainMenuBar);
429
430         //{{REGISTER_LISTENERS
431         SymWindow aSymWindow = new SymWindow();
432         this.addWindowListener(aSymWindow);
433         SymAction lSymAction = new SymAction();
434         miAbout.addActionListener(lSymAction);
435         miExit.addActionListener(lSymAction);
436         openButton.addActionListener(lSymAction);
437         zoomOutButton.addActionListener(lSymAction);
438         zoomInButton.addActionListener(lSymAction);
439         arg2_baseTimeImg.argField.addActionListener(lSymAction);
440         arg2_baseTimeImg.openButton.addActionListener(lSymAction);
441         doButton.addActionListener(lSymAction);
442         outputIMG_all.addActionListener(lSymAction);
443         exifON.addActionListener(lSymAction);
444         gpxOutputSpeed.addActionListener(lSymAction);
445         noFirstNode.addActionListener(lSymAction);
446         gpxReuse.addActionListener(lSymAction);
447         //arg1Panel_4.field.addActionListener(lSymAction);
448         nextButton.addActionListener(lSymAction);
449         backButton.addActionListener(lSymAction);
450         //}}
451     }
452     
453     /**
454      * Shows or hides the component depending on the boolean flag b.
455      * @param b trueのときコンポーネントを表示; その他のとき, componentを隠す.
456      * @see java.awt.Component#isVisible
457      */
458     @Override
459     public void setVisible(boolean b) {
460         if(b) {
461             setLocation(50, 50);
462         }
463         super.setVisible(b);
464     }
465     
466     /**
467      * このクラスをインスタンスを生成して表示する。
468      * コマンドラインの引数はありません。
469      * @param args
470      */    
471     @SuppressWarnings("UseSpecificCatch")
472     static public void main(String args[]) {
473         SwingUtilities.invokeLater(() -> {
474             try {
475                 createAndShowGUI();
476             } catch (Exception e) {
477                 e.printStackTrace();
478             }
479         });
480     }
481     private static void createAndShowGUI() throws IOException {
482         (new AdjustTime()).setVisible(true);
483     }
484
485     @Override
486     public void addNotify()     {
487         // Record the size of the window prior to calling parents addNotify.
488         Dimension d = getSize();
489
490         super.addNotify();
491
492         if (fComponentsAdjusted)
493             return;
494
495         // Adjust components according to the insets
496         setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
497         Component components[] = getComponents();
498         for (Component component : components) {
499             Point p = component.getLocation();
500             p.translate(getInsets().left, getInsets().top);
501             component.setLocation(p);
502         }
503         fComponentsAdjusted = true;
504     }
505
506     void DbMang_WindowClosing(java.awt.event.WindowEvent event) {
507         setVisible(false);  // hide the Manager
508         dispose();                      // free the system resources
509         System.exit(0);         // close the application
510     }
511
512     void miAbout_Action(java.awt.event.ActionEvent event) {
513         // Action from About Create and show as modal
514         (new AboutDialog(this, true)).setVisible(true);
515     }
516     
517     void miExit_Action(java.awt.event.ActionEvent event) {
518         // Action from Exit Create and show as modal
519         //(new hayashi.yuu.tools.gui.QuitDialog(this, true)).setVisible(true);
520         (new QuitDialog(this, true)).setVisible(true);
521     }
522
523     ImageIcon refImage;
524     
525     /**
526      * 選択された画像ファイルを表示する
527      * 基準画像ボタンがクリックされた時に、基準時刻フィールドに基準画像の作成日時を設定する。
528      * @param ev 
529      */
530     @SuppressWarnings("UseSpecificCatch")
531     public void imageView_Action(ActionEvent ev) {
532         String path = (new File(arg1_srcFolder.getText(), arg2_baseTimeImg.getText())).getPath();
533         
534         File timeFile = new File(path);
535         if (exifBase.isSelected()) {
536             try {
537                 ImageMetadata meta = Imaging.getMetadata(timeFile);
538                 JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta;
539                 if (jpegMetadata != null) {
540                     TiffImageMetadata exif = jpegMetadata.getExif();
541                     if (exif != null) {
542                         String dateTimeOriginal = exif.getFieldValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL)[0];
543                         long lastModifyTime = (new SimpleDateFormat("yyyy:MM:dd HH:mm:ss")).parse(dateTimeOriginal).getTime();
544                         arg3_basetime.argField.setText(dfjp.format(new Date(lastModifyTime)));
545                     }
546                     else {
547                         arg3_basetime.argField.setText("exif == null");
548                     }
549                 }
550             }
551             catch (Exception e) {}
552         }
553         else {
554             long lastModifyTime = timeFile.lastModified();
555             arg3_basetime.argField.setText(dfjp.format(new Date(lastModifyTime)));
556         }
557         
558         int size_x = imageSPane.getWidth() - 8;
559         ImageIcon tmpIcon = new ImageIcon(path);
560         refImage = tmpIcon;
561         if (tmpIcon.getIconWidth() > size_x) {
562             refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x, -1, Image.SCALE_DEFAULT));
563         }
564         imageLabel.setIcon(refImage);
565         repaint();
566     }
567
568     public void zoomin_Action(ActionEvent ev) {
569         if (refImage != null) {
570             int size_x = imageLabel.getWidth();
571             String path = (new File(arg1_srcFolder.getText(), arg2_baseTimeImg.getText())).getPath();
572             ImageIcon tmpIcon = new ImageIcon(path);
573             refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x * 2, -1, Image.SCALE_DEFAULT));
574             imageLabel.setIcon(refImage);
575             repaint();
576         }
577     }
578
579     public void zoomout_Action(ActionEvent ev) {
580         if (refImage != null) {
581             int size_x = imageLabel.getWidth();
582             ImageIcon tmpIcon = refImage;
583             refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x / 2, -1, Image.SCALE_DEFAULT));
584             imageLabel.setIcon(refImage);
585             repaint();
586         }
587     }
588     
589     /**
590      * ソースディレクトリが選択された時のアクション
591      * → AdjustTime.ini に書き込む
592      * @param ev
593      */
594     public void selectSource_Action(ActionEvent ev) {
595     }
596     
597     public void selectImage_Action(ActionEvent ev) {
598         JFileChooser fc;
599
600         //Set up the file chooser.
601         File sdir = new File(arg1_srcFolder.getText());
602         System.out.println(sdir.getPath());
603         if (sdir.isDirectory()) {
604             fc = new JFileChooser(sdir);
605         }
606         else {
607             fc = new JFileChooser();
608         }
609
610         //Add a custom file filter and disable the default
611         //(Accept All) file filter.
612         fc.addChoosableFileFilter(new ImageFilter());
613         fc.setAcceptAllFileFilterUsed(false);
614
615         //Add custom icons for file types.
616         fc.setFileView(new ImageFileView());
617
618         //Add the preview pane.
619         fc.setAccessory(new ImagePreview(fc));
620
621         //Show it. "選択"
622         int returnVal = fc.showDialog(this, i18n.getString("dialog.select"));
623
624         //Process the results.
625         if (returnVal == JFileChooser.APPROVE_OPTION) {
626             File file = fc.getSelectedFile();
627             arg2_baseTimeImg.argField.setText(file.getName());
628         }
629
630         //Reset the file chooser for the next time it's shown.
631         fc.setSelectedFile(null);
632     }
633     
634     /** Returns an ImageIcon, or null if the path was invalid.
635      * @param path
636      * @return  */
637     public static ImageIcon createImageIcon(String path) {
638         java.net.URL imgURL = AdjustTime.class.getResource(path);
639         if (imgURL != null) {
640             return new ImageIcon(imgURL);
641         } else {
642             System.err.println("Couldn't find file: " + path);
643             return null;
644         }
645     }
646     
647     /**
648      * checkbox[IMG変換]を変更した場合のアクション
649      *  ON ー> IMG出力フォルダのフィールドを有効にする
650      *  OFF -> IMG出力フォルダのフィールドを無効にする
651      * @param event
652      */
653     void outputIMG_Action (ActionEvent event) {
654         arg5_outputFolder.setEnabled(outputIMG.isEnabled());
655     }
656
657     /**
658      * checkbox[GPXファイル時間外のファイルもコピーする]を変更した場合のアクション
659      * @param event
660      */
661     void outputIMGall_Action (ActionEvent event) {
662     }
663
664     /**
665      * checkbox[EXIF書き出し]を変更した場合のアクション
666      * @param event
667      */
668     void exifON_Action (ActionEvent event) {
669     }
670
671     /**
672      * checkbox[GPXの<WPT>を出力する]を変更した場合のアクション
673      * @param event
674      */
675     void gpxOutputWpt_Action (ActionEvent event) {
676     }
677
678     /**
679      * checkbox[GPXの<SPPED>を書き換える]を変更した場合のアクション
680      * @param event
681      */
682     void gpxOutputSpeed_Action (ActionEvent event) {
683     }
684
685     /**
686      * [実行]ボタンをクリックしたときの動作
687      * @param event
688      */
689     @SuppressWarnings("UseSpecificCatch")
690     void doButton_Action(java.awt.event.ActionEvent event) {
691         doButton.setEnabled(false);
692
693         String[] argv = new String[0];
694         /*
695         argv[0] = arg1_srcFolder.getText();
696         argv[1] = arg2_baseTimeImg.getText();
697         argv[2] = arg3_basetiome.getText();
698         argv[3] = arg5_outputFolder.getText();
699         argv[4] = arg4_gpxFolder.getText();
700         */
701         this.params.setProperty(AppParameters.GPX_NO_FIRST_NODE, String.valueOf(noFirstNode.isSelected()));
702         this.params.setProperty(AppParameters.GPX_REUSE, String.valueOf(gpxReuse.isSelected()));
703         this.params.setProperty(AppParameters.GPX_SOURCE_FOLDER, arg4_gpxFolder.getText());
704         
705         if (exifBase.isSelected()) {
706             this.params.setProperty(AppParameters.GPX_BASETIME, "EXIF_TIME");
707         }
708         else {
709             this.params.setProperty(AppParameters.GPX_BASETIME, "FILE_UPDATE");
710         }
711         try {
712             this.params.setProperty(AppParameters.IMG_SOURCE_FOLDER, arg1_srcFolder.getText());
713             this.params.setProperty(AppParameters.IMG_BASE_FILE, arg2_baseTimeImg.getText());
714             this.params.setProperty(AppParameters.IMG_TIME, ImportPicture.toUTCString(dfjp.parse(arg3_basetime.getText())));
715             this.params.setProperty(AppParameters.IMG_OUTPUT, String.valueOf(outputIMG.isSelected()));
716             this.params.setProperty(AppParameters.IMG_OUTPUT_FOLDER, arg5_outputFolder.getText());
717             this.params.setProperty(AppParameters.IMG_OUTPUT_ALL, String.valueOf(outputIMG_all.isSelected()));
718             this.params.setProperty(AppParameters.IMG_OUTPUT_EXIF, String.valueOf(exifON.isSelected()));
719             this.params.setProperty(AppParameters.GPX_OVERWRITE_MAGVAR, String.valueOf(gpxOverwriteMagvar.isSelected()));
720             this.params.setProperty(AppParameters.GPX_OUTPUT_SPEED, String.valueOf(gpxOutputSpeed.isSelected()));
721             this.params.setProperty(AppParameters.GPX_OUTPUT_WPT, String.valueOf(gpxOutputWpt.isSelected()));
722             this.params.store();
723         }
724         catch(Exception e) {
725             e.printStackTrace();
726         }
727
728         (new DoDialog(this, argv)).setVisible(true);
729                 
730         doButton.setEnabled(true);
731     }
732     
733     /**
734      * [次へ]ボタンをクリックした時の動作
735      * @param event 
736      */
737     void nextButton_Action(ActionEvent event) {
738         if ((cardPanelNo + 1) < cards.length) {
739             cardPanelNo++;
740             CardLayout cl = (CardLayout)(cardPanel.getLayout());
741             cl.show(cardPanel, String.valueOf(cardPanelNo));
742         }
743     }
744
745     /**
746      * [戻る]ボタンをクリックした時の動作
747      * @param event
748      */
749     void backButton_Action(ActionEvent event) {
750         if ((cardPanelNo - 1) >= 0) {
751             cardPanelNo--;
752             CardLayout cl = (CardLayout)(cardPanel.getLayout());
753             cl.show(cardPanel, String.valueOf(cardPanelNo));
754         }
755     }
756 }