001: /*
002: * This program is free software; you can redistribute it and/or
003: * modify it under the terms of the GNU General Public License
004: * as published by the Free Software Foundation; either version 2
005: * of the License, or (at your option) any later version.
006: *
007: * This program is distributed in the hope that it will be useful,
008: * but WITHOUT ANY WARRANTY; without even the implied warranty of
009: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
010: * GNU General Public License for more details.
011:
012: * You should have received a copy of the GNU General Public License
013: * along with this program; if not, write to the Free Software
014: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
015: */
016: package net.sf.jftp.gui.hostchooser;
017:
018: import java.awt.BorderLayout;
019: import java.awt.Cursor;
020: import java.awt.Dimension;
021: import java.awt.GridLayout;
022: import java.awt.Insets;
023: import java.awt.event.ActionEvent;
024: import java.awt.event.ActionListener;
025: import java.awt.event.ComponentEvent;
026: import java.awt.event.ComponentListener;
027: import java.awt.event.WindowEvent;
028: import java.awt.event.WindowListener;
029:
030: import javax.swing.JDialog;
031: import javax.swing.JLabel;
032:
033: import net.sf.jftp.JFtp;
034: import net.sf.jftp.gui.framework.HButton;
035: import net.sf.jftp.gui.framework.HFrame;
036: import net.sf.jftp.gui.framework.HPanel;
037: import net.sf.jftp.gui.framework.HPasswordField;
038: import net.sf.jftp.gui.framework.HTextField;
039: import net.sf.jftp.net.ConnectionListener;
040: import net.sf.jftp.net.WebdavConnection;
041:
042: public class WebdavHostChooser extends HFrame implements
043: ActionListener, WindowListener {
044: public static HTextField host = new HTextField("URL:",
045: "http://localhost", 35);
046: public static HTextField user = new HTextField("Username:", "guest");
047:
048: //public static HTextField port = new HTextField("Port:","22");
049: public static HPasswordField pass = new HPasswordField("Password:",
050: "nopasswd");
051: private HPanel okP = new HPanel();
052: private HButton ok = new HButton("Connect");
053: private ComponentListener listener = null;
054: private boolean useLocal = false;
055:
056: public WebdavHostChooser(ComponentListener l, boolean local) {
057: listener = l;
058: useLocal = local;
059: init();
060: }
061:
062: public WebdavHostChooser(ComponentListener l) {
063: listener = l;
064: init();
065: }
066:
067: public WebdavHostChooser() {
068: init();
069: }
070:
071: public void init() {
072: //setSize(500, 200);
073: setLocation(100, 150);
074: setTitle("WebDAV Connection... (ALPHA STATE)");
075: setBackground(okP.getBackground());
076:
077: host.setMinimumSize(new Dimension(500, 50));
078: getContentPane().setLayout(new BorderLayout(5, 5));
079: getContentPane().add("North", host);
080:
081: HPanel p = new HPanel();
082: p.setLayout(new GridLayout(2, 2, 5, 3));
083:
084: //***MY CHANGES
085: /*
086: try {
087: File f = new File(Settings.appHomeDir);
088: f.mkdir();
089: File f1 = new File(Settings.login);
090: f1.createNewFile();
091: File f2 = new File(Settings.login_def_sftp);
092: f2.createNewFile();
093: File f3 = new File(Settings.ls_out);
094: f3.createNewFile();
095: File f4 = new File(Settings.sortls_out);
096: f4.createNewFile();
097: File f5 = new File(Settings.sortsize_out);
098: f5.createNewFile();
099: File f6 = new File(Settings.permissions_out);
100: f6.createNewFile();
101: } catch (IOException ex) {
102: ex.printStackTrace();
103: }
104:
105: LoadSet l = new LoadSet();
106: String login[] = l.loadSet(Settings.login_def_sftp);
107:
108:
109: if (login[0] != null) {
110: host.setText(login[0]);
111: user.setText(login[1]);
112:
113: }
114: */
115: /*
116: else {
117: host.setText("localhost");
118: user.setText("guest");
119:
120: }
121: */
122: /*
123: if (Settings.getStorePasswords()) {
124: if (login != null) {
125: pass.setText(login[2]);
126: }
127:
128: } else
129: pass.setText("");
130:
131: */
132: //***end of my changes (for this section)
133: //getContentPane().add(host);
134: //getContentPane().add(new JLabel(" "));//port);
135: //getContentPane()
136: p.add(user);
137:
138: //getContentPane()
139: p.add(pass);
140:
141: //getContentPane()
142: p.add(new JLabel(""));
143:
144: //getContentPane()
145: p.add(okP);
146:
147: okP.add(ok);
148:
149: getContentPane().add("South", p);
150:
151: ok.addActionListener(this );
152:
153: setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
154:
155: pass.text.addActionListener(this );
156:
157: setModal(false);
158: setVisible(false);
159: addWindowListener(this );
160:
161: //novell webdav test site
162: host.setText("http://www.planetpdf.com/planetpdf/webdavdemo/");
163: user.setText("guest");
164: pass.setText("guest");
165:
166: pack();
167: }
168:
169: public void update() {
170: setVisible(true);
171: toFront();
172: host.requestFocus();
173: }
174:
175: public void actionPerformed(ActionEvent e) {
176: if ((e.getSource() == ok) || (e.getSource() == pass.text)) {
177: setCursor(new Cursor(Cursor.WAIT_CURSOR));
178:
179: String htmp = host.getText().trim();
180: String utmp = user.getText().trim();
181: String ptmp = pass.getText();
182:
183: WebdavConnection con;
184:
185: if (useLocal) {
186: con = new WebdavConnection(htmp, utmp, ptmp,
187: (ConnectionListener) JFtp.localDir);
188: JFtp.statusP.jftp.addLocalConnection("Webdav", con);
189: con.chdir(htmp);
190: } else {
191: con = new WebdavConnection(htmp, utmp, ptmp,
192: (ConnectionListener) JFtp.remoteDir);
193: JFtp.statusP.jftp.addConnection("Webdav", con);
194: con.chdir(htmp);
195: }
196:
197: setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
198: this .dispose();
199: JFtp.mainFrame.setVisible(true);
200: JFtp.mainFrame.toFront();
201:
202: if (listener != null) {
203: listener.componentResized(new ComponentEvent(this , 0));
204: }
205: }
206: }
207:
208: public void windowClosing(WindowEvent e) {
209: //System.exit(0);
210: this .dispose();
211: }
212:
213: public void windowClosed(WindowEvent e) {
214: }
215:
216: public void windowActivated(WindowEvent e) {
217: }
218:
219: public void windowDeactivated(WindowEvent e) {
220: }
221:
222: public void windowIconified(WindowEvent e) {
223: }
224:
225: public void windowDeiconified(WindowEvent e) {
226: }
227:
228: public void windowOpened(WindowEvent e) {
229: }
230:
231: public Insets getInsets() {
232: Insets std = super .getInsets();
233:
234: return new Insets(std.top + 10, std.left + 10, std.bottom + 10,
235: std.right + 10);
236: }
237:
238: public void pause(int time) {
239: try {
240: Thread.sleep(time);
241: } catch (Exception ex) {
242: }
243: }
244: }
|