KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > gui > base > UIUtils


1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

16 package net.sf.jftp.gui.base;
17
18 import java.io.BufferedInputStream JavaDoc;
19 import java.io.BufferedOutputStream JavaDoc;
20
21 import javax.swing.JComponent JavaDoc;
22 import javax.swing.JOptionPane JavaDoc;
23 import javax.swing.JPasswordField JavaDoc;
24
25 import net.sf.jftp.tools.Shell;
26
27
28 public class UIUtils
29 {
30     public static String JavaDoc getPasswordFromUser(JComponent JavaDoc parent)
31     {
32         JOptionPane JavaDoc j = new JOptionPane JavaDoc();
33         JPasswordField JavaDoc pField = new JPasswordField JavaDoc();
34
35         int ret = j.showOptionDialog(parent, pField, "Password required",
36                                      JOptionPane.YES_NO_OPTION,
37                                      JOptionPane.QUESTION_MESSAGE, null, null,
38                                      null);
39
40         return pField.getText();
41     }
42     
43     public static void runCommand(String JavaDoc cmd) {
44         Spawn s = new Spawn(cmd);
45     }
46 }
47
48 class Spawn implements Runnable JavaDoc {
49     private Thread JavaDoc runner;
50     private String JavaDoc cmd;
51     
52     public Spawn(String JavaDoc cmd) {
53         this.cmd = cmd;
54         
55         runner = new Thread JavaDoc(this);
56         runner.start();
57     }
58     
59     public void run() {
60         try {
61             String JavaDoc str = "";
62             
63             if(cmd.startsWith("file://")) cmd = cmd.substring(7);
64             
65             Process JavaDoc p = Runtime.getRuntime().exec(cmd);
66             new Shell(p.getInputStream(), p.getOutputStream());
67              
68             //while ((str = stdout.readLine()) !=null) {
69
// Log.debug(str);
70
//}
71
}
72          catch(Exception JavaDoc ex) {
73              ex.printStackTrace();
74          }
75     }
76     
77 }
78
79
80
Popular Tags