Newer
Older
adjustgpx-gui / src / main / java / osm / jp / gpx / matchtime / gui / AdjustTerra.java
@yuuhayashi yuuhayashi on 11 Feb 2022 12 KB Project name changed to "AdjustGpx".
  1. package osm.jp.gpx.matchtime.gui;
  2.  
  3. import java.awt.*;
  4. import java.io.IOException;
  5. import java.text.SimpleDateFormat;
  6. import java.util.ResourceBundle;
  7. import java.util.TimeZone;
  8. import java.util.logging.Logger;
  9.  
  10. import javax.swing.*;
  11.  
  12. import osm.jp.hayashi.tools.log.LoggerFactory;
  13. import osm.jp.gpx.*;
  14. import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelGpx;
  15. import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelImageFile;
  16. import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelOutput;
  17. import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelSourceFolder;
  18. import osm.jp.gpx.matchtime.gui.parameters.ParameterPanelTime;
  19.  
  20. /**
  21. * 本プログラムのメインクラス
  22. */
  23. @SuppressWarnings("serial")
  24. public class AdjustTerra extends JFrame
  25. {
  26. public static final String PROGRAM_NAME = "AdjustGpx";
  27. public static Logger logger = LoggerFactory.getInstance();
  28.  
  29.  
  30. AppParameters params;
  31. public static SimpleDateFormat dfjp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
  32.  
  33. // Used for addNotify check.
  34. boolean fComponentsAdjusted = false;
  35. public static ResourceBundle i18n = ResourceBundle.getBundle("i18n");
  36. //{{DECLARE_CONTROLS
  37. JTabbedPane cardPanel; // ウィザード形式パネル(タブ型)
  38. Card[] cards;
  39. //}}
  40.  
  41. //---入力フィールド----------------------------------------------------
  42. ParameterPanelSourceFolder arg1_srcFolder; // 対象フォルダ
  43. ParameterPanelImageFile arg2_baseTimeImg; // 開始画像ファイルパス
  44. ParameterPanelTime arg2_basetime; // 開始画像の基準時刻:
  45. ParameterPanelGpx arg3_gpxFile; // GPX file or Folder
  46. ParameterPanelOutput arg4_output; // EXIF & 書き出しフォルダ
  47.  
  48. //{{DECLARE_MENUS
  49. java.awt.MenuBar mainMenuBar;
  50. java.awt.Menu menu1;
  51. java.awt.MenuItem miDoNewFileList;
  52. java.awt.MenuItem miDoDirSize;
  53. java.awt.MenuItem miDoReadXML;
  54. java.awt.MenuItem miExit;
  55. java.awt.Menu menu3;
  56. java.awt.MenuItem miAbout;
  57. //}}
  58.  
  59. class SymWindow extends java.awt.event.WindowAdapter {
  60. /**
  61. * このFrameが閉じられるときの動作。
  62. * このパネルが閉じられたら、このアプリケーションも終了させる。
  63. */
  64. @Override
  65. public void windowClosing(java.awt.event.WindowEvent event) {
  66. Object object = event.getSource();
  67. if (object == AdjustTerra.this) {
  68. DbMang_WindowClosing(event);
  69. }
  70. }
  71. }
  72.  
  73. class SymAction implements java.awt.event.ActionListener {
  74. @Override
  75. public void actionPerformed(java.awt.event.ActionEvent event) {
  76. Object object = event.getSource();
  77. if (object == miAbout) {
  78. miAbout_Action(event);
  79. }
  80. else if (object == miExit) {
  81. miExit_Action(event);
  82. }
  83. }
  84. }
  85.  
  86. /**
  87. * データベース内のテーブルを一覧で表示するFrame
  88. * @throws IOException
  89. */
  90. public AdjustTerra() throws Exception
  91. {
  92. logger.info("start!");
  93. dfjp.setTimeZone(TimeZone.getTimeZone("JST"));
  94.  
  95. // INIT_CONTROLS
  96. Container container = getContentPane();
  97. container.setLayout(new BorderLayout());
  98. setSize(
  99. getInsets().left + getInsets().right + 720,
  100. getInsets().top + getInsets().bottom + 480
  101. );
  102. setTitle(AdjustTerra.PROGRAM_NAME);
  103. //---- CENTER -----
  104. JPanel mainPanel = new JPanel();
  105. mainPanel.setLayout(new BorderLayout());
  106. container.add(mainPanel, BorderLayout.CENTER);
  107. //---- SOUTH -----
  108. JPanel southPanel = new JPanel(new BorderLayout());
  109. southPanel.add(Box.createVerticalStrut(10), BorderLayout.SOUTH);
  110. southPanel.add(Box.createVerticalStrut(10), BorderLayout.NORTH);
  111. container.add(southPanel, BorderLayout.SOUTH);
  112. //---- SPACE -----
  113. container.add(Box.createVerticalStrut(30), BorderLayout.NORTH);
  114. container.add(Box.createHorizontalStrut(10), BorderLayout.WEST);
  115. container.add(Box.createHorizontalStrut(10), BorderLayout.EAST);
  116. params = new AppParameters();
  117. //---------------------------------------------------------------------
  118. cardPanel = new JTabbedPane(JTabbedPane.LEFT);
  119. mainPanel.add(cardPanel, BorderLayout.CENTER);
  120. cards = new Card[4];
  121. int cardNo = 0;
  122.  
  123. //---------------------------------------------------------------------
  124. // 1.[対象フォルダ]設定パネル
  125. {
  126. arg1_srcFolder = new ParameterPanelSourceFolder(
  127. AppParameters.IMG_SOURCE_FOLDER,
  128. i18n.getString("label.110") +": ",
  129. params.getProperty(AppParameters.IMG_SOURCE_FOLDER)
  130. );
  131. arg1_srcFolder.addPropertyChangeListener(new SimpleCardListener(cards, cardPanel, 0, arg1_srcFolder));
  132. Card card = new CardSourceFolder(cardPanel, arg1_srcFolder);
  133. cardPanel.addTab(card.getTitle(), card);
  134. cardPanel.setEnabledAt(cardNo, true);
  135. cards[cardNo] = card;
  136. cardNo++;
  137. }
  138. //---------------------------------------------------------------------
  139. // 2.[基準時刻]パネル
  140. // 2a.基準画像を選択フィールド
  141. // 2b.基準時刻の入力フィールド
  142. {
  143. // 2a. 基準時刻画像
  144. arg2_baseTimeImg = new ParameterPanelImageFile(
  145. AppParameters.IMG_BASE_FILE,
  146. i18n.getString("label.210") +": ",
  147. null,
  148. arg1_srcFolder
  149. );
  150.  
  151. // 2a. 基準時刻:
  152. arg2_basetime = new ParameterPanelTime(
  153. AppParameters.GPX_BASETIME,
  154. i18n.getString("label.310"),
  155. null,
  156. arg2_baseTimeImg
  157. );
  158. arg2_basetime.addPropertyChangeListener(new SimpleCardListener(cards, cardPanel, 1, arg2_basetime));
  159. // EXIFの日時を基準にする
  160. arg2_basetime.addExifBase(i18n.getString("label.220"), params);
  161.  
  162. // ファイル更新日時を基準にする
  163. arg2_basetime.addFileUpdate(i18n.getString("label.230"), params);
  164.  
  165. CardImageFile card = new CardImageFile(
  166. cardPanel, arg2_basetime, (Window)this,
  167. AdjustTerra.i18n.getString("tab.300"), 0, 2);
  168. cardPanel.addTab(card.getTitle(), card);
  169. cardPanel.setEnabledAt(cardNo, false);
  170. cards[cardNo] = card;
  171. cardNo++;
  172. }
  173. //---------------------------------------------------------------------
  174. // 3.GPXファイル設定画面
  175. {
  176. // 3. GPXファイル選択パラメータ
  177. arg3_gpxFile = new ParameterPanelGpx(
  178. AppParameters.GPX_SOURCE_FOLDER,
  179. i18n.getString("label.410") + ": ",
  180. params.getProperty(AppParameters.GPX_SOURCE_FOLDER)
  181. );
  182. arg3_gpxFile.addPropertyChangeListener(
  183. new SimpleCardListener(cards, cardPanel, 2, arg3_gpxFile)
  184. );
  185.  
  186. // "セグメント'trkseg'の最初の1ノードは無視する。"
  187. arg3_gpxFile.addNoFirstNode(i18n.getString("label.420"), params);
  188.  
  189. // 3. GPXファイルを選択
  190. CardGpxFile card = new CardGpxFile(
  191. cardPanel, arg3_gpxFile,
  192. AdjustTerra.i18n.getString("tab.400"), 1, 3);
  193. cardPanel.addTab(card.getTitle(), card);
  194. cardPanel.setEnabledAt(cardNo, false);
  195. cards[cardNo] = card;
  196. cardNo++;
  197. }
  198. //---------------------------------------------------------------------
  199. // 4.EXIF更新設定画面 & 実行画面
  200. {
  201. // 4. ファイル変換・実行パラメータ
  202. // "出力フォルダ: "
  203. arg4_output = new ParameterPanelOutput(
  204. AppParameters.IMG_OUTPUT_FOLDER,
  205. i18n.getString("label.530") + ": ",
  206. params.getProperty(AppParameters.IMG_OUTPUT_FOLDER)
  207. );
  208. arg4_output.addPropertyChangeListener(
  209. new SimpleCardListener(cards, cardPanel, 3, arg4_output)
  210. );
  211.  
  212. // パネル表示
  213. CardExifPerform card = new CardExifPerform(
  214. cardPanel,
  215. arg2_basetime, arg3_gpxFile, arg4_output,
  216. AdjustTerra.i18n.getString("tab.500"),
  217. 2, -1
  218. );
  219. cardPanel.addTab(card.getTitle(), card);
  220. cardPanel.setEnabledAt(cardNo, false);
  221. cards[cardNo] = card;
  222. }
  223.  
  224. //---------------------------------------------------------------------
  225. // INIT_MENUS
  226. menu1 = new java.awt.Menu("File");
  227. miExit = new java.awt.MenuItem(i18n.getString("menu.quit"));
  228. miExit.setFont(new Font("Dialog", Font.PLAIN, 12));
  229. menu1.add(miExit);
  230.  
  231. miAbout = new java.awt.MenuItem("About...");
  232. miAbout.setFont(new Font("Dialog", Font.PLAIN, 12));
  233.  
  234. menu3 = new java.awt.Menu("Help");
  235. menu3.setFont(new Font("Dialog", Font.PLAIN, 12));
  236. menu3.add(miAbout);
  237.  
  238. mainMenuBar = new java.awt.MenuBar();
  239. mainMenuBar.setHelpMenu(menu3);
  240. mainMenuBar.add(menu1);
  241. mainMenuBar.add(menu3);
  242. setMenuBar(mainMenuBar);
  243.  
  244. //{{REGISTER_LISTENERS
  245. SymWindow aSymWindow = new SymWindow();
  246. this.addWindowListener(aSymWindow);
  247. SymAction lSymAction = new SymAction();
  248. miAbout.addActionListener(lSymAction);
  249. miExit.addActionListener(lSymAction);
  250. arg2_baseTimeImg.openButton.addActionListener(lSymAction);
  251. //}}
  252. }
  253. /**
  254. * Shows or hides the component depending on the boolean flag b.
  255. * @param b trueのときコンポーネントを表示; その他のとき, componentを隠す.
  256. * @see java.awt.Component#isVisible
  257. */
  258. @Override
  259. public void setVisible(boolean b) {
  260. if(b) {
  261. setLocation(50, 50);
  262. }
  263. super.setVisible(b);
  264. }
  265. /**
  266. * このクラスをインスタンスを生成して表示する。
  267. * コマンドラインの引数はありません。
  268. * @param args
  269. */
  270. static public void main(String args[]) {
  271. SwingUtilities.invokeLater(() -> {
  272. try {
  273. createAndShowGUI();
  274. } catch (Exception e) {
  275. e.printStackTrace();
  276. }
  277. });
  278. }
  279. private static void createAndShowGUI() throws Exception {
  280. (new AdjustTerra()).setVisible(true);
  281. }
  282.  
  283. @Override
  284. public void addNotify() {
  285. // Record the size of the window prior to calling parents addNotify.
  286. Dimension d = getSize();
  287.  
  288. super.addNotify();
  289.  
  290. if (fComponentsAdjusted)
  291. return;
  292.  
  293. // Adjust components according to the insets
  294. setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
  295. Component components[] = getComponents();
  296. for (Component component : components) {
  297. Point p = component.getLocation();
  298. p.translate(getInsets().left, getInsets().top);
  299. component.setLocation(p);
  300. }
  301. fComponentsAdjusted = true;
  302. }
  303.  
  304. void DbMang_WindowClosing(java.awt.event.WindowEvent event) {
  305. setVisible(false); // hide the Manager
  306. dispose(); // free the system resources
  307. System.exit(0); // close the application
  308. }
  309.  
  310. void miAbout_Action(java.awt.event.ActionEvent event) {
  311. // Action from About Create and show as modal
  312. (new AboutDialog(this, true)).setVisible(true);
  313. }
  314. void miExit_Action(java.awt.event.ActionEvent event) {
  315. // Action from Exit Create and show as modal
  316. //(new hayashi.yuu.tools.gui.QuitDialog(this, true)).setVisible(true);
  317. (new QuitDialog(this, true)).setVisible(true);
  318. }
  319. //ImageIcon refImage;
  320. /** Returns an ImageIcon, or null if the path was invalid.
  321. * @param path
  322. * @return */
  323. public static ImageIcon createImageIcon(String path) {
  324. java.net.URL imgURL = AdjustTerra.class.getResource(path);
  325. if (imgURL != null) {
  326. return new ImageIcon(imgURL);
  327. } else {
  328. System.err.println("Couldn't find file: " + path);
  329. return null;
  330. }
  331. }
  332. }