1 package osm.jp.gpx.matchtime.gui;
9 @SuppressWarnings("serial")
10 public class DoDialog extends JDialog {
11 public static final String TITLE = "Do Command";
13 // Used for addNotify check.
14 boolean fComponentsAdjusted = false;
18 JFrame parentFrame; // MatchTime.class
19 JPanel buttonPanel; // ボタン配置パネル (下部)
20 JButton closeButton; // [クローズ]ボタン
21 JButton doButton; // [実行]ボタン
22 TextArea textArea; // 実行結果を表示するJTextArea (中央)
25 class SymAction implements java.awt.event.ActionListener {
26 public void actionPerformed(java.awt.event.ActionEvent event) {
27 Object object = event.getSource();
28 if (object == closeButton) {
29 closeButton_Action(event);
31 else if (object == doButton) {
32 doButton_Action(event);
37 public DoDialog(JFrame parentFrame, String[] args) {
38 super(parentFrame, true); // モーダルダイアログを基盤にする
39 this.parentFrame = parentFrame;
43 Container container = getContentPane();
44 container.setLayout(new BorderLayout());
46 setSize(getInsets().left + getInsets().right + 500,getInsets().top + getInsets().bottom + 480);
47 setTitle(DoDialog.TITLE);
51 buttonPanel = new JPanel();
53 doButton = new JButton("実行");
54 doButton.setToolTipText("処理を実行します.");
55 doButton.setEnabled(true);
56 buttonPanel.add(doButton);
58 closeButton = new JButton("閉じる");
59 closeButton.setToolTipText("処理を終了します.");
60 buttonPanel.add(closeButton);
62 this.getContentPane().add("South", buttonPanel);
65 textArea = new TextArea();
66 textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 10));
68 textArea.append("> java -cp importPicture.jar osm.jp.gpx.ImportPicture");
69 for (int i = 0; i < args.length; i++) {
70 textArea.append(" '"+ args[i] +"'");
72 textArea.append("\n\n");
75 System.out.println(e.toString());
77 this.getContentPane().add("Center", textArea);
79 //{{REGISTER_LISTENERS
80 SymAction lSymAction = new SymAction();
81 closeButton.addActionListener(lSymAction);
82 doButton.addActionListener(lSymAction);
87 * Shows or hides the component depending on the boolean flag b.
88 * @param b trueのときコンポーネントを表示; その他のとき, componentを隠す.
89 * @see java.awt.Component#isVisible
91 public void setVisible(boolean b) {
98 public void addNotify() {
99 // Record the size of the window prior to calling parents addNotify.
100 Dimension d = getSize();
104 if (fComponentsAdjusted)
107 // Adjust components according to the insets
108 setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
109 Component components[] = getComponents();
110 for (int i = 0; i < components.length; i++) {
111 Point p = components[i].getLocation();
112 p.translate(getInsets().left, getInsets().top);
113 components[i].setLocation(p);
115 fComponentsAdjusted = true;
119 * [実行]ボタンをクリックしたときの動作
122 void doButton_Action(java.awt.event.ActionEvent event) {
123 doButton.setEnabled(false);
125 PrintStream defOut = System.out;
126 PrintStream defErr = System.err;
128 ByteArrayOutputStream stdout = new ByteArrayOutputStream();
130 System.setOut(new PrintStream(stdout));
131 System.setErr(new PrintStream(stdout));
133 Command command = new Command(osm.jp.gpx.ImportPicture.class);
134 command.setArgs(args);
135 command.start(); // コマンドを実行
136 while (command.isAlive()) {
138 textArea.append(stdout.toString());
141 textArea.append(stdout.toString());
142 JOptionPane.showMessageDialog(this, "'"+ TITLE +"'処理を完了しました。", "処理完了", JOptionPane.INFORMATION_MESSAGE);
146 JOptionPane.showMessageDialog(this, e.toString(), "Exception", JOptionPane.ERROR_MESSAGE);
149 System.setOut(defOut);
150 System.setErr(defErr);
151 doButton.setEnabled(true);
155 void closeButton_Action(java.awt.event.ActionEvent event) {
159 void changeSQL_Action(java.awt.event.ActionEvent event) {
160 textArea.setText("");