1 package jp.co.areaweb.tools.gui;
\r
4 import java.text.SimpleDateFormat;
\r
5 import java.util.Calendar;
\r
7 import javax.swing.*;
\r
12 @SuppressWarnings("serial")
\r
13 public class NewFileListDialog extends JDialog {
\r
14 public static final String TITLE = "NewFileList";
\r
16 // Used for addNotify check.
\r
17 boolean fComponentsAdjusted = false;
\r
19 //{{DECLARE_CONTROLS
\r
20 JFrame parentFrame; // Manager.class
\r
21 JPanel argsPanel; // パラメータ設定パネル (上部)
\r
22 ParameterPanel arg1Panel; // parameter 1
\r
23 ParameterPanel arg2Panel; // parameter 2
\r
25 JPanel buttonPanel; // ボタン配置パネル (下部)
\r
26 JButton closeButton; // [クローズ]ボタン
\r
27 JButton doButton; // [実行]ボタン
\r
28 TextArea textArea; // 実行結果を表示するJTextArea (中央)
\r
31 class SymAction implements java.awt.event.ActionListener {
\r
32 public void actionPerformed(java.awt.event.ActionEvent event) {
\r
33 Object object = event.getSource();
\r
34 if (object == closeButton) {
\r
35 closeButton_Action(event);
\r
37 else if (object == doButton) {
\r
38 doButton_Action(event);
\r
43 public NewFileListDialog(JFrame parentFrame) {
\r
44 super(parentFrame, true); // モーダルダイアログを基盤にする
\r
45 this.parentFrame = parentFrame;
\r
48 Container container = getContentPane();
\r
49 container.setLayout(new BorderLayout());
\r
51 setSize(getInsets().left + getInsets().right + 500,getInsets().top + getInsets().bottom + 480);
\r
52 setTitle(NewFileListDialog.TITLE);
\r
56 argsPanel = new JPanel();
\r
57 argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS));
\r
59 arg1Panel = new ParameterPanel("基準フォルダ: ", "C:\\TEMP");
\r
60 argsPanel.add(arg1Panel);
\r
62 Calendar cal = Calendar.getInstance();
\r
63 cal.add(Calendar.DATE, -1); // 前日にする
\r
64 arg2Panel = new ParameterPanel("基準日時: ", (new SimpleDateFormat("yyyy.MM.dd-HH:mm:ss")).format(cal.getTime()));
\r
65 argsPanel.add(arg2Panel);
\r
67 this.getContentPane().add("North", argsPanel);
\r
70 buttonPanel = new JPanel();
\r
72 doButton = new JButton("実行");
\r
73 doButton.setToolTipText("処理を実行します.");
\r
74 doButton.setEnabled(true);
\r
75 buttonPanel.add(doButton);
\r
77 closeButton = new JButton("閉じる");
\r
78 closeButton.setToolTipText("処理を終了します.");
\r
79 buttonPanel.add(closeButton);
\r
81 this.getContentPane().add("South", buttonPanel);
\r
84 textArea = new TextArea();
\r
86 textArea.append("/**\n");
\r
87 textArea.append(" * "+ TITLE +"\n");
\r
88 textArea.append(" * 指定された時刻以降に更新されたファイルをリストアップし、その絶対パス名を標準出力に出力する。\n");
\r
89 textArea.append(" * jp.co.areaweb.tools.command.NewFileList [directory] [CCYY.MM.DD-HH:mm:ss]\n");
\r
90 textArea.append(" * exp) java -cp hayashi.jar jp.co.areaweb.tools.command.NewFileList \\Server01\\Share\\フォルダ 2002.05.29-00:50:00\n");
\r
91 textArea.append(" */\n\n");
\r
93 catch (Exception e) {
\r
94 System.out.println(e.toString());
\r
96 this.getContentPane().add("Center", textArea);
\r
98 //{{REGISTER_LISTENERS
\r
99 SymAction lSymAction = new SymAction();
\r
100 closeButton.addActionListener(lSymAction);
\r
101 doButton.addActionListener(lSymAction);
\r
106 * Shows or hides the component depending on the boolean flag b.
\r
107 * @param b trueのときコンポーネントを表示; その他のとき, componentを隠す.
\r
108 * @see java.awt.Component#isVisible
\r
110 public void setVisible(boolean b) {
\r
112 setLocation(80, 80);
\r
114 super.setVisible(b);
\r
117 public void addNotify() {
\r
118 // Record the size of the window prior to calling parents addNotify.
\r
119 Dimension d = getSize();
\r
123 if (fComponentsAdjusted)
\r
126 // Adjust components according to the insets
\r
127 setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
\r
128 Component components[] = getComponents();
\r
129 for (int i = 0; i < components.length; i++) {
\r
130 Point p = components[i].getLocation();
\r
131 p.translate(getInsets().left, getInsets().top);
\r
132 components[i].setLocation(p);
\r
134 fComponentsAdjusted = true;
\r
138 * [実行]ボタンをクリックしたときの動作
\r
141 void doButton_Action(java.awt.event.ActionEvent event) {
\r
142 doButton.setEnabled(false);
\r
144 PrintStream defOut = System.out;
\r
145 PrintStream defErr = System.err;
\r
147 ByteArrayOutputStream stdout = new ByteArrayOutputStream();
\r
149 System.setOut(new PrintStream(stdout));
\r
150 System.setErr(new PrintStream(stdout));
\r
152 Command command = new Command(jp.co.areaweb.tools.command.NewFileList.class);
\r
153 String[] args = new String[2];
\r
154 args[0] = arg1Panel.getText();
\r
155 args[1] = arg2Panel.getText();
\r
156 command.setArgs(args);
\r
157 command.start(); // コマンドを実行
\r
158 while (command.isAlive()) {
\r
159 Thread.sleep(1000);
\r
160 textArea.append(stdout.toString());
\r
163 textArea.append(stdout.toString());
\r
164 JOptionPane.showMessageDialog(this, "'"+ TITLE +"'処理を完了しました。", "処理完了", JOptionPane.INFORMATION_MESSAGE);
\r
166 catch(Exception e) {
\r
167 e.printStackTrace();
\r
168 JOptionPane.showMessageDialog(this, e.toString(), "Exception", JOptionPane.ERROR_MESSAGE);
\r
171 System.setOut(defOut);
\r
172 System.setErr(defErr);
\r
173 doButton.setEnabled(true);
\r
177 void closeButton_Action(java.awt.event.ActionEvent event) {
\r
181 void changeSQL_Action(java.awt.event.ActionEvent event) {
\r
182 textArea.setText("");
\r