01: /*
02: * This program is free software; you can redistribute it and/or
03: * modify it under the terms of the GNU General Public License
04: * as published by the Free Software Foundation; either version 2
05: * of the License, or (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * 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;
19: import java.io.BufferedOutputStream;
20:
21: import javax.swing.JComponent;
22: import javax.swing.JOptionPane;
23: import javax.swing.JPasswordField;
24:
25: import net.sf.jftp.tools.Shell;
26:
27: public class UIUtils {
28: public static String getPasswordFromUser(JComponent parent) {
29: JOptionPane j = new JOptionPane();
30: JPasswordField pField = new JPasswordField();
31:
32: int ret = j.showOptionDialog(parent, pField,
33: "Password required", JOptionPane.YES_NO_OPTION,
34: JOptionPane.QUESTION_MESSAGE, null, null, null);
35:
36: return pField.getText();
37: }
38:
39: public static void runCommand(String cmd) {
40: Spawn s = new Spawn(cmd);
41: }
42: }
43:
44: class Spawn implements Runnable {
45: private Thread runner;
46: private String cmd;
47:
48: public Spawn(String cmd) {
49: this .cmd = cmd;
50:
51: runner = new Thread(this );
52: runner.start();
53: }
54:
55: public void run() {
56: try {
57: String str = "";
58:
59: if (cmd.startsWith("file://"))
60: cmd = cmd.substring(7);
61:
62: Process p = Runtime.getRuntime().exec(cmd);
63: new Shell(p.getInputStream(), p.getOutputStream());
64:
65: //while ((str = stdout.readLine()) !=null) {
66: // Log.debug(str);
67: //}
68: } catch (Exception ex) {
69: ex.printStackTrace();
70: }
71: }
72:
73: }
|