1 16 package net.sf.jftp.gui.hostchooser; 17 18 import net.sf.jftp.*; 19 import net.sf.jftp.config.*; 20 import net.sf.jftp.gui.framework.*; 21 import net.sf.jftp.gui.tasks.ExternalDisplayer; 22 import net.sf.jftp.net.*; 23 import net.sf.jftp.system.logging.Log; 24 import net.sf.jftp.util.*; 25 26 import java.awt.*; 27 import java.awt.event.*; 28 29 import java.io.*; 30 31 import java.net.*; 32 33 import javax.swing.*; 34 35 36 public class NfsHostChooser extends HFrame implements ActionListener, 37 WindowListener 38 { 39 public static HTextField host = new HTextField("URL:", 40 "nfs://localhost:v2m/tmp", 20); 41 public static HTextField user = new HTextField("Username:", "<anonymous>", 42 15); 43 44 public static HPasswordField pass = new HPasswordField("Password:", 46 "nopasswd"); 47 public static HButton info = new HButton("Read me!"); 48 private HPanel okP = new HPanel(); 49 private HButton ok = new HButton("Connect"); 50 private ComponentListener listener = null; 51 private boolean useLocal = false; 52 53 public NfsHostChooser(ComponentListener l, boolean local) 54 { 55 listener = l; 56 useLocal = local; 57 init(); 58 } 59 60 public NfsHostChooser(ComponentListener l) 61 { 62 listener = l; 63 init(); 64 } 65 66 public NfsHostChooser() 67 { 68 init(); 69 } 70 71 public void init() 72 { 73 setLocation(100, 150); 75 setTitle("NFS Connection..."); 76 setBackground(okP.getBackground()); 77 getContentPane().setLayout(new GridLayout(4, 2, 5, 3)); 78 79 JPanel p = new JPanel(); 80 p.add(info); 81 82 try 84 { 85 File f = new File(Settings.appHomeDir); 86 f.mkdir(); 87 88 File f1 = new File(Settings.login); 89 f1.createNewFile(); 90 91 File f2 = new File(Settings.login_def_nfs); 92 f2.createNewFile(); 93 } 94 catch(IOException ex) 95 { 96 ex.printStackTrace(); 97 } 98 99 LoadSet l = new LoadSet(); 100 String [] login = l.loadSet(Settings.login_def_nfs); 101 102 if((login[0] != null) && (login.length > 1)) 103 { 104 host.setText(login[0]); 105 user.setText(login[1]); 106 } 107 108 116 if(Settings.getStorePasswords()) 117 { 118 if((login[0] != null) && (login.length > 2) && (login[2] != null)) 119 { 120 pass.setText(login[2]); 121 } 122 } 123 else 124 { 125 pass.setText(""); 126 } 127 128 getContentPane().add(host); 130 getContentPane().add(p); 131 getContentPane().add(user); 132 getContentPane().add(pass); 133 134 getContentPane().add(new JLabel("")); 135 getContentPane().add(okP); 136 137 okP.add(ok); 138 ok.addActionListener(this); 139 info.addActionListener(this); 140 141 setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); 142 143 pass.text.addActionListener(this); 144 145 pack(); 146 setModal(false); 147 setVisible(false); 148 addWindowListener(this); 149 } 150 151 public void update() 152 { 153 fixLocation(); 154 setVisible(true); 155 toFront(); 156 host.requestFocus(); 157 } 158 159 public void actionPerformed(ActionEvent e) 160 { 161 if(e.getSource() == info) 162 { 163 java.net.URL url = ClassLoader.getSystemResource(Settings.nfsinfo); 164 165 if(url == null) 166 { 167 url = HImage.class.getResource("/" + Settings.nfsinfo); 168 } 169 170 ExternalDisplayer d = new ExternalDisplayer(url); 171 } 172 else if((e.getSource() == ok) || (e.getSource() == pass.text)) 173 { 174 setCursor(new Cursor(Cursor.WAIT_CURSOR)); 177 178 NfsConnection con = null; 179 180 String htmp = host.getText().trim(); 181 String utmp = user.getText().trim(); 182 String ptmp = pass.getText(); 183 184 int potmp = 0; 187 String userName = user.text.getText(); 188 189 try 191 { 192 boolean status; 193 status = StartConnection.startCon("NFS", htmp, userName, ptmp, 194 potmp, "", useLocal); 195 196 221 } 222 catch(Exception ex) 223 { 224 Log.debug("Could not create NfsConnection!"); 225 } 226 227 setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 228 this.dispose(); 229 JFtp.mainFrame.setVisible(true); 230 JFtp.mainFrame.toFront(); 231 232 if(listener != null) 233 { 234 listener.componentResized(new ComponentEvent(this, 0)); 235 } 236 } 237 } 238 239 public void windowClosing(WindowEvent e) 240 { 241 this.dispose(); 243 } 244 245 public void windowClosed(WindowEvent e) 246 { 247 } 248 249 public void windowActivated(WindowEvent e) 250 { 251 } 252 253 public void windowDeactivated(WindowEvent e) 254 { 255 } 256 257 public void windowIconified(WindowEvent e) 258 { 259 } 260 261 public void windowDeiconified(WindowEvent e) 262 { 263 } 264 265 public void windowOpened(WindowEvent e) 266 { 267 } 268 269 public Insets getInsets() 270 { 271 Insets std = super.getInsets(); 272 273 return new Insets(std.top + 10, std.left + 10, std.bottom + 10, 274 std.right + 10); 275 } 276 277 public void pause(int time) 278 { 279 try 280 { 281 Thread.sleep(time); 282 } 283 catch(Exception ex) 284 { 285 } 286 } 287 } 288 | Popular Tags |