1 package jp.co.areaweb.tools.gui;
\r
4 import javax.swing.*;
\r
9 @SuppressWarnings("serial")
\r
10 public class ReadXMLDialog extends JDialog {
\r
11 public static final String TITLE = "ReadXML";
\r
13 // Used for addNotify check.
\r
14 boolean fComponentsAdjusted = false;
\r
16 //{{DECLARE_CONTROLS
\r
17 JFrame parentFrame; // Manager.class
\r
18 JPanel argsPanel; // パラメータ設定パネル (上部)
\r
19 ParameterPanel arg1Panel; // parameter 1
\r
21 JPanel buttonPanel; // ボタン配置パネル (下部)
\r
22 JButton closeButton; // [クローズ]ボタン
\r
23 JButton doButton; // [実行]ボタン
\r
24 TextArea textArea; // 実行結果を表示するJTextArea (中央)
\r
27 class SymAction implements java.awt.event.ActionListener {
\r
28 public void actionPerformed(java.awt.event.ActionEvent event) {
\r
29 Object object = event.getSource();
\r
30 if (object == closeButton) {
\r
31 closeButton_Action(event);
\r
33 else if (object == doButton) {
\r
34 doButton_Action(event);
\r
39 public ReadXMLDialog(JFrame parentFrame) {
\r
40 super(parentFrame, true); // モーダルダイアログを基盤にする
\r
41 this.parentFrame = parentFrame;
\r
44 Container container = getContentPane();
\r
45 container.setLayout(new BorderLayout());
\r
47 setSize(getInsets().left + getInsets().right + 500,getInsets().top + getInsets().bottom + 480);
\r
48 setTitle(ReadXMLDialog.TITLE);
\r
52 argsPanel = new JPanel();
\r
53 argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS));
\r
55 arg1Panel = new ParameterPanel("ファイル: ", "build.xml");
\r
56 argsPanel.add(arg1Panel);
\r
58 this.getContentPane().add("North", argsPanel);
\r
61 buttonPanel = new JPanel();
\r
63 doButton = new JButton("実行");
\r
64 doButton.setToolTipText("処理を実行します.");
\r
65 doButton.setEnabled(true);
\r
66 buttonPanel.add(doButton);
\r
68 closeButton = new JButton("閉じる");
\r
69 closeButton.setToolTipText("処理を終了します.");
\r
70 buttonPanel.add(closeButton);
\r
72 this.getContentPane().add("South", buttonPanel);
\r
75 textArea = new TextArea();
\r
77 textArea.append("/**\n");
\r
78 textArea.append(" * "+ TITLE +"\n");
\r
79 textArea.append(" * 指定したファイルが整形式XML文書であるかどうかを調べる。\n");
\r
80 textArea.append(" * exp) java -cp hayashi.jar;xerces.jar jp.co.areaweb.tools.command.ReadXML build.xml\n");
\r
81 textArea.append(" */\n\n");
\r
83 catch (Exception e) {
\r
84 System.out.println(e.toString());
\r
86 this.getContentPane().add("Center", textArea);
\r
88 //{{REGISTER_LISTENERS
\r
89 SymAction lSymAction = new SymAction();
\r
90 closeButton.addActionListener(lSymAction);
\r
91 doButton.addActionListener(lSymAction);
\r
96 * Shows or hides the component depending on the boolean flag b.
\r
97 * @param b trueのときコンポーネントを表示; その他のとき, componentを隠す.
\r
98 * @see java.awt.Component#isVisible
\r
100 public void setVisible(boolean b) {
\r
102 setLocation(80, 80);
\r
104 super.setVisible(b);
\r
107 public void addNotify() {
\r
108 // Record the size of the window prior to calling parents addNotify.
\r
109 Dimension d = getSize();
\r
113 if (fComponentsAdjusted)
\r
116 // Adjust components according to the insets
\r
117 setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
\r
118 Component components[] = getComponents();
\r
119 for (int i = 0; i < components.length; i++) {
\r
120 Point p = components[i].getLocation();
\r
121 p.translate(getInsets().left, getInsets().top);
\r
122 components[i].setLocation(p);
\r
124 fComponentsAdjusted = true;
\r
128 * [実行]ボタンをクリックしたときの動作
\r
131 void doButton_Action(java.awt.event.ActionEvent event) {
\r
132 doButton.setEnabled(false);
\r
134 PrintStream defOut = System.out;
\r
135 PrintStream defErr = System.err;
\r
137 ByteArrayOutputStream stdout = new ByteArrayOutputStream();
\r
139 System.setOut(new PrintStream(stdout));
\r
140 System.setErr(new PrintStream(stdout));
\r
142 Command command = new Command(jp.co.areaweb.tools.command.ReadXML.class);
\r
143 String[] args = new String[1];
\r
144 args[0] = arg1Panel.getText();
\r
145 command.setArgs(args);
\r
146 command.start(); // コマンドを実行
\r
147 while (command.isAlive()) {
\r
148 Thread.sleep(1000);
\r
149 textArea.append(stdout.toString());
\r
152 textArea.append(stdout.toString());
\r
153 JOptionPane.showMessageDialog(this, "'"+ TITLE +"'処理を完了しました。", "処理完了", JOptionPane.INFORMATION_MESSAGE);
\r
155 catch(Exception e) {
\r
156 e.printStackTrace();
\r
157 JOptionPane.showMessageDialog(this, e.toString(), "Exception", JOptionPane.ERROR_MESSAGE);
\r
160 System.setOut(defOut);
\r
161 System.setErr(defErr);
\r
162 doButton.setEnabled(true);
\r
166 void closeButton_Action(java.awt.event.ActionEvent event) {
\r
170 void changeSQL_Action(java.awt.event.ActionEvent event) {
\r
171 textArea.setText("");
\r