1 16 package net.sf.jftp.gui.hostchooser; 17 18 import java.awt.BorderLayout ; 19 import java.awt.Cursor ; 20 import java.awt.Dimension ; 21 import java.awt.GridLayout ; 22 import java.awt.Insets ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.awt.event.ComponentEvent ; 26 import java.awt.event.ComponentListener ; 27 import java.awt.event.WindowEvent ; 28 import java.awt.event.WindowListener ; 29 30 import javax.swing.JDialog ; 31 import javax.swing.JLabel ; 32 33 import net.sf.jftp.JFtp; 34 import net.sf.jftp.gui.framework.HButton; 35 import net.sf.jftp.gui.framework.HFrame; 36 import net.sf.jftp.gui.framework.HPanel; 37 import net.sf.jftp.gui.framework.HPasswordField; 38 import net.sf.jftp.gui.framework.HTextField; 39 import net.sf.jftp.net.ConnectionListener; 40 import net.sf.jftp.net.WebdavConnection; 41 42 43 public class WebdavHostChooser extends HFrame implements ActionListener , 44 WindowListener 45 { 46 public static HTextField host = new HTextField("URL:", "http://localhost", 47 35); 48 public static HTextField user = new HTextField("Username:", "guest"); 49 50 public static HPasswordField pass = new HPasswordField("Password:", 52 "nopasswd"); 53 private HPanel okP = new HPanel(); 54 private HButton ok = new HButton("Connect"); 55 private ComponentListener listener = null; 56 private boolean useLocal = false; 57 58 public WebdavHostChooser(ComponentListener l, boolean local) 59 { 60 listener = l; 61 useLocal = local; 62 init(); 63 } 64 65 public WebdavHostChooser(ComponentListener l) 66 { 67 listener = l; 68 init(); 69 } 70 71 public WebdavHostChooser() 72 { 73 init(); 74 } 75 76 public void init() 77 { 78 setLocation(100, 150); 80 setTitle("WebDAV Connection... (ALPHA STATE)"); 81 setBackground(okP.getBackground()); 82 83 host.setMinimumSize(new Dimension (500, 50)); 84 getContentPane().setLayout(new BorderLayout (5, 5)); 85 getContentPane().add("North", host); 86 87 HPanel p = new HPanel(); 88 p.setLayout(new GridLayout (2, 2, 5, 3)); 89 90 121 128 138 p.add(user); 143 144 p.add(pass); 146 147 p.add(new JLabel ("")); 149 150 p.add(okP); 152 153 okP.add(ok); 154 155 getContentPane().add("South", p); 156 157 ok.addActionListener(this); 158 159 setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); 160 161 pass.text.addActionListener(this); 162 163 setModal(false); 164 setVisible(false); 165 addWindowListener(this); 166 167 host.setText("http://www.planetpdf.com/planetpdf/webdavdemo/"); 169 user.setText("guest"); 170 pass.setText("guest"); 171 172 pack(); 173 } 174 175 public void update() 176 { 177 setVisible(true); 178 toFront(); 179 host.requestFocus(); 180 } 181 182 public void actionPerformed(ActionEvent e) 183 { 184 if((e.getSource() == ok) || (e.getSource() == pass.text)) 185 { 186 setCursor(new Cursor (Cursor.WAIT_CURSOR)); 187 188 String htmp = host.getText().trim(); 189 String utmp = user.getText().trim(); 190 String ptmp = pass.getText(); 191 192 WebdavConnection con; 193 194 if(useLocal) 195 { 196 con = new WebdavConnection(htmp, utmp, ptmp, 197 (ConnectionListener) JFtp.localDir); 198 JFtp.statusP.jftp.addLocalConnection("Webdav", con); 199 con.chdir(htmp); 200 } 201 else 202 { 203 con = new WebdavConnection(htmp, utmp, ptmp, 204 (ConnectionListener) JFtp.remoteDir); 205 JFtp.statusP.jftp.addConnection("Webdav", con); 206 con.chdir(htmp); 207 } 208 209 setCursor(new Cursor (Cursor.DEFAULT_CURSOR)); 210 this.dispose(); 211 JFtp.mainFrame.setVisible(true); 212 JFtp.mainFrame.toFront(); 213 214 if(listener != null) 215 { 216 listener.componentResized(new ComponentEvent (this, 0)); 217 } 218 } 219 } 220 221 public void windowClosing(WindowEvent e) 222 { 223 this.dispose(); 225 } 226 227 public void windowClosed(WindowEvent e) 228 { 229 } 230 231 public void windowActivated(WindowEvent e) 232 { 233 } 234 235 public void windowDeactivated(WindowEvent e) 236 { 237 } 238 239 public void windowIconified(WindowEvent e) 240 { 241 } 242 243 public void windowDeiconified(WindowEvent e) 244 { 245 } 246 247 public void windowOpened(WindowEvent e) 248 { 249 } 250 251 public Insets getInsets() 252 { 253 Insets std = super.getInsets(); 254 255 return new Insets (std.top + 10, std.left + 10, std.bottom + 10, 256 std.right + 10); 257 } 258 259 public void pause(int time) 260 { 261 try 262 { 263 Thread.sleep(time); 264 } 265 catch(Exception ex) 266 { 267 } 268 } 269 } 270 | Popular Tags |