1 package osm.jp.gpx.matchtime.gui;
3 import java.awt.event.ActionEvent;
10 @SuppressWarnings("serial")
11 public class AdjustTime extends JFrame
13 public static final String PROGRAM_NAME = "AdjustTime for JOSM";
14 public static final String PROGRAM_VARSION = "1.0";
15 public static final String PROGRAM_UPDATE = "2014/06/30";
17 // Used for addNotify check.
18 boolean fComponentsAdjusted = false;
21 JPanel argsPanel; // パラメータ設定パネル (上部)
22 JScrollPane imageSPane; // スクロールパネル
23 JLabel imageLabel; // 基準時刻画像表示
24 JTextArea textArea; // 実行結果表示領域
25 //ImagePreview imagePane; // 基準時刻画像表示
26 ParameterPanelFolder arg1Panel_1;
27 ParameterPanelImageFile arg1Panel_2;
28 ParameterPanelTime arg1Panel_3;
29 JPanel buttonPanel; // ボタンパネル (下部)
30 JButton openButton; // [Fit]ボタン
31 JButton zoomInButton; // [Zoom in]ボタン
32 JButton zoomOutButton; // [Zoom out]ボタン
36 java.awt.MenuBar mainMenuBar;
38 java.awt.MenuItem miDoNewFileList;
39 java.awt.MenuItem miDoDirSize;
40 java.awt.MenuItem miDoReadXML;
41 java.awt.MenuItem miExit;
43 java.awt.MenuItem miAbout;
46 class SymWindow extends java.awt.event.WindowAdapter {
49 * 終了確認のパネルを表示して、[OK]が押されたら終了する
51 public void windowClosing(java.awt.event.WindowEvent event) {
52 Object object = event.getSource();
53 if (object == AdjustTime.this) {
54 DbMang_WindowClosing(event);
59 class SymAction implements java.awt.event.ActionListener {
60 public void actionPerformed(java.awt.event.ActionEvent event) {
61 Object object = event.getSource();
62 if (object == miAbout) {
63 miAbout_Action(event);
65 else if (object == miExit) {
68 else if (object == openButton) {
69 imageView_Action(event);
71 else if (object == zoomInButton) {
74 else if (object == zoomOutButton) {
75 zoomout_Action(event);
77 else if (object == arg1Panel_2.argField) {
78 imageView_Action(event);
80 else if (object == arg1Panel_2.openButton) {
81 selectImage_Action(event);
82 imageView_Action(event);
84 else if (object == arg1Panel_3.doButton) {
85 doButton_Action(event);
91 * データベース内のテーブルを一覧で表示するFrame
96 //setLayout(new BorderLayout());
97 Container container = getContentPane();
98 container.setLayout(new BorderLayout());
100 setSize(getInsets().left + getInsets().right + 500,getInsets().top + getInsets().bottom + 480);
101 setTitle(AdjustTime.PROGRAM_NAME +" v"+ AdjustTime.PROGRAM_VARSION);
104 argsPanel = new JPanel();
105 argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS));
106 arg1Panel_1 = new ParameterPanelFolder("対象フォルダ: ", ".");
107 argsPanel.add(arg1Panel_1);
108 arg1Panel_2 = new ParameterPanelImageFile("基準時刻画像: ", "", arg1Panel_1);
109 argsPanel.add(arg1Panel_2);
110 arg1Panel_3 = new ParameterPanelTime(" 基準時刻: ", "yyyy-mm-ddTHH:MM:ss");
111 argsPanel.add(arg1Panel_3);
113 this.getContentPane().add(argsPanel, BorderLayout.NORTH);
116 imageLabel = new JLabel();
117 imageSPane = new JScrollPane(imageLabel);
118 this.getContentPane().add(imageSPane, BorderLayout.CENTER);
120 // 画像ファイル選択ダイアログを起動するボタン
121 buttonPanel = new JPanel();
122 buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
123 openButton = new JButton(createImageIcon("images/Fit16.gif"));
124 buttonPanel.add(openButton);
125 zoomInButton = new JButton(createImageIcon("images/ZoomIn16.gif"));
126 buttonPanel.add(zoomInButton);
127 zoomOutButton = new JButton(createImageIcon("images/ZoomOut16.gif"));
128 buttonPanel.add(zoomOutButton);
129 this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
132 menu1 = new java.awt.Menu("File");
133 miExit = new java.awt.MenuItem(QuitDialog.TITLE);
134 miExit.setFont(new Font("Dialog", Font.PLAIN, 12));
137 miAbout = new java.awt.MenuItem("About...");
138 miAbout.setFont(new Font("Dialog", Font.PLAIN, 12));
140 menu3 = new java.awt.Menu("Help");
141 menu3.setFont(new Font("Dialog", Font.PLAIN, 12));
144 mainMenuBar = new java.awt.MenuBar();
145 mainMenuBar.setHelpMenu(menu3);
146 mainMenuBar.add(menu1);
147 mainMenuBar.add(menu3);
148 setMenuBar(mainMenuBar);
151 //{{REGISTER_LISTENERS
152 SymWindow aSymWindow = new SymWindow();
153 this.addWindowListener(aSymWindow);
154 SymAction lSymAction = new SymAction();
155 miAbout.addActionListener(lSymAction);
156 miExit.addActionListener(lSymAction);
157 openButton.addActionListener(lSymAction);
158 zoomOutButton.addActionListener(lSymAction);
159 zoomInButton.addActionListener(lSymAction);
160 arg1Panel_2.argField.addActionListener(lSymAction);
161 arg1Panel_2.openButton.addActionListener(lSymAction);
162 arg1Panel_3.doButton.addActionListener(lSymAction);
167 * Shows or hides the component depending on the boolean flag b.
168 * @param b trueのときコンポーネントを表示; その他のとき, componentを隠す.
169 * @see java.awt.Component#isVisible
171 public void setVisible(boolean b) {
180 * このクラスをインスタンスを生成して表示する。
183 static public void main(String args[]) {
184 SwingUtilities.invokeLater(new Runnable() {
190 private static void createAndShowGUI() {
191 (new AdjustTime()).setVisible(true);
194 public void addNotify() {
195 // Record the size of the window prior to calling parents addNotify.
196 Dimension d = getSize();
200 if (fComponentsAdjusted)
203 // Adjust components according to the insets
204 setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
205 Component components[] = getComponents();
206 for (int i = 0; i < components.length; i++){
207 Point p = components[i].getLocation();
208 p.translate(getInsets().left, getInsets().top);
209 components[i].setLocation(p);
211 fComponentsAdjusted = true;
214 void DbMang_WindowClosing(java.awt.event.WindowEvent event) {
215 setVisible(false); // hide the Manager
216 dispose(); // free the system resources
217 System.exit(0); // close the application
220 void miAbout_Action(java.awt.event.ActionEvent event) {
221 // Action from About Create and show as modal
222 (new AboutDialog(this, true)).setVisible(true);
225 void miExit_Action(java.awt.event.ActionEvent event) {
226 // Action from Exit Create and show as modal
227 //(new hayashi.yuu.tools.gui.QuitDialog(this, true)).setVisible(true);
228 (new QuitDialog(this, true)).setVisible(true);
237 public void imageView_Action(ActionEvent ev) {
238 String path = (new File(arg1Panel_1.getText(), arg1Panel_2.getText())).getPath();
239 int size_x = imageSPane.getWidth() - 8;
240 ImageIcon tmpIcon = new ImageIcon(path);
242 if (tmpIcon != null) {
243 if (tmpIcon.getIconWidth() > size_x) {
244 refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x, -1, Image.SCALE_DEFAULT));
247 imageLabel.setIcon(refImage);
251 public void zoomin_Action(ActionEvent ev) {
252 if (refImage != null) {
253 int size_x = imageLabel.getWidth();
254 String path = (new File(arg1Panel_1.getText(), arg1Panel_2.getText())).getPath();
255 ImageIcon tmpIcon = new ImageIcon(path);
256 refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x * 2, -1, Image.SCALE_DEFAULT));
257 imageLabel.setIcon(refImage);
262 public void zoomout_Action(ActionEvent ev) {
263 if (refImage != null) {
264 int size_x = imageLabel.getWidth();
265 ImageIcon tmpIcon = refImage;
266 refImage = new ImageIcon(tmpIcon.getImage().getScaledInstance(size_x / 2, -1, Image.SCALE_DEFAULT));
267 imageLabel.setIcon(refImage);
272 public void selectImage_Action(ActionEvent ev) {
275 //Set up the file chooser.
276 File sdir = new File(arg1Panel_1.getText());
277 System.out.println(sdir.getPath());
278 if (sdir.isDirectory()) {
279 fc = new JFileChooser(sdir);
282 fc = new JFileChooser();
285 //Add a custom file filter and disable the default
286 //(Accept All) file filter.
287 fc.addChoosableFileFilter(new ImageFilter());
288 fc.setAcceptAllFileFilterUsed(false);
290 //Add custom icons for file types.
291 fc.setFileView(new ImageFileView());
293 //Add the preview pane.
294 fc.setAccessory(new ImagePreview(fc));
297 int returnVal = fc.showDialog(this, "選択");
299 //Process the results.
300 if (returnVal == JFileChooser.APPROVE_OPTION) {
301 File file = fc.getSelectedFile();
302 arg1Panel_2.argField.setText(file.getName());
305 //Reset the file chooser for the next time it's shown.
306 fc.setSelectedFile(null);
309 /** Returns an ImageIcon, or null if the path was invalid. */
310 public static ImageIcon createImageIcon(String path) {
311 java.net.URL imgURL = AdjustTime.class.getResource(path);
312 if (imgURL != null) {
313 return new ImageIcon(imgURL);
315 System.err.println("Couldn't find file: " + path);
321 * [実行]ボタンをクリックしたときの動作
324 void doButton_Action(java.awt.event.ActionEvent event) {
325 arg1Panel_3.doButton.setEnabled(false);
327 String[] argv = new String[4];
328 argv[0] = "list.csv";
329 argv[1] = arg1Panel_1.getText();
330 argv[2] = arg1Panel_2.getText();
331 argv[3] = arg1Panel_3.getText();
332 (new DoDialog(this, argv)).setVisible(true);
334 arg1Panel_3.doButton.setEnabled(true);