OSDN Git Service

2019-02-11
[hayashilib/hayashi.git] / src / jp / co / areaweb / tools / gui / NewFileListDialog.java
1 package jp.co.areaweb.tools.gui;\r
2 import java.awt.*;\r
3 import java.io.*;\r
4 import java.text.SimpleDateFormat;\r
5 import java.util.Calendar;\r
6 \r
7 import javax.swing.*;\r
8 \r
9 /**\r
10  *      「NewFileList」処理 \r
11  */\r
12 @SuppressWarnings("serial")\r
13 public class NewFileListDialog extends JDialog {\r
14         public static final String TITLE = "NewFileList";\r
15         \r
16     // Used for addNotify check.\r
17     boolean fComponentsAdjusted = false;\r
18     \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
24     \r
25     JPanel buttonPanel;     // ボタン配置パネル (下部)\r
26     JButton closeButton;      // [クローズ]ボタン\r
27     JButton doButton;      // [実行]ボタン\r
28     TextArea textArea;      // 実行結果を表示するJTextArea     (中央)\r
29     //}}\r
30 \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
36             }\r
37             else if (object == doButton) {\r
38                 doButton_Action(event);\r
39             }\r
40         }\r
41     }\r
42 \r
43     public NewFileListDialog(JFrame parentFrame) {\r
44         super(parentFrame, true);   // モーダルダイアログを基盤にする\r
45         this.parentFrame = parentFrame;\r
46                 \r
47         // INIT_CONTROLS\r
48         Container container = getContentPane();\r
49         container.setLayout(new BorderLayout());\r
50         setVisible(false);\r
51         setSize(getInsets().left + getInsets().right + 500,getInsets().top + getInsets().bottom + 480);\r
52         setTitle(NewFileListDialog.TITLE);\r
53         setSize(500,480);\r
54         \r
55         // パラメータ設定パネル\r
56         argsPanel = new JPanel();\r
57         argsPanel.setLayout(new BoxLayout(argsPanel, BoxLayout.Y_AXIS));\r
58         \r
59         arg1Panel = new ParameterPanel("基準フォルダ: ", "C:\\TEMP");\r
60         argsPanel.add(arg1Panel);\r
61         \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
66         \r
67         this.getContentPane().add("North", argsPanel);\r
68         \r
69         // コントロールパネル\r
70         buttonPanel = new JPanel();\r
71 \r
72         doButton = new JButton("実行");\r
73         doButton.setToolTipText("処理を実行します.");\r
74         doButton.setEnabled(true);\r
75         buttonPanel.add(doButton);\r
76 \r
77         closeButton = new JButton("閉じる");\r
78         closeButton.setToolTipText("処理を終了します.");\r
79         buttonPanel.add(closeButton);\r
80         \r
81         this.getContentPane().add("South", buttonPanel);\r
82         \r
83                 // 説明文\r
84         textArea = new TextArea();\r
85         try {\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
92         }\r
93         catch (Exception e) {\r
94             System.out.println(e.toString());\r
95         }\r
96         this.getContentPane().add("Center", textArea);\r
97 \r
98         //{{REGISTER_LISTENERS\r
99         SymAction lSymAction = new SymAction();\r
100         closeButton.addActionListener(lSymAction);\r
101         doButton.addActionListener(lSymAction);\r
102         //}}\r
103     }\r
104 \r
105     /**\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
109     */\r
110     public void setVisible(boolean b) {\r
111         if(b) {\r
112             setLocation(80, 80);\r
113         }\r
114         super.setVisible(b);\r
115     }\r
116 \r
117     public void addNotify()     {\r
118         // Record the size of the window prior to calling parents addNotify.\r
119         Dimension d = getSize();\r
120 \r
121         super.addNotify();\r
122 \r
123         if (fComponentsAdjusted)\r
124             return;\r
125 \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
133         }\r
134         fComponentsAdjusted = true;\r
135     }\r
136 \r
137     /**\r
138      * [実行]ボタンをクリックしたときの動作\r
139      * @param event\r
140      */\r
141     void doButton_Action(java.awt.event.ActionEvent event) {\r
142         doButton.setEnabled(false);\r
143         \r
144         PrintStream defOut = System.out;\r
145         PrintStream defErr = System.err;\r
146 \r
147         ByteArrayOutputStream stdout = new ByteArrayOutputStream();\r
148         try {\r
149                 System.setOut(new PrintStream(stdout));\r
150                 System.setErr(new PrintStream(stdout));\r
151 \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
161                 stdout.reset();\r
162                 }\r
163                 textArea.append(stdout.toString());\r
164                 JOptionPane.showMessageDialog(this, "'"+ TITLE +"'処理を完了しました。", "処理完了", JOptionPane.INFORMATION_MESSAGE);\r
165         }\r
166         catch(Exception e) {\r
167             e.printStackTrace();\r
168             JOptionPane.showMessageDialog(this, e.toString(), "Exception", JOptionPane.ERROR_MESSAGE);\r
169         }\r
170         finally {\r
171                 System.setOut(defOut);\r
172                 System.setErr(defErr);\r
173             doButton.setEnabled(true);\r
174         }\r
175     }\r
176 \r
177     void closeButton_Action(java.awt.event.ActionEvent event) {\r
178         dispose();\r
179     }\r
180     \r
181     void changeSQL_Action(java.awt.event.ActionEvent event) {\r
182         textArea.setText("");\r
183     }\r
184 }\r