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.net.*; 22 import net.sf.jftp.system.logging.Log; 23 import net.sf.jftp.util.*; 24 25 import java.awt.*; 26 import java.awt.event.*; 27 28 import java.io.*; 29 30 import java.net.*; 31 32 import java.util.*; 33 34 import javax.swing.*; 35 36 37 public class SmbHostChooser extends HFrame implements ActionListener, 38 WindowListener 39 { 40 public static HTextField host = new HTextField("URL:", "smb://localhost/"); 41 public static HTextField user = new HTextField("Username:", "guest"); 42 43 public static HPasswordField pass = new HPasswordField("Password:", 45 "nopasswd"); 46 JCheckBox lan = new JCheckBox("Browse LAN", true); 47 public HTextField domain = new HTextField("Domain: ", "WORKGROUP"); 48 public HTextField broadcast = new HTextField("Broadcast IP: ", "AUTO"); 49 public HTextField wins = new HTextField("WINS Server IP: ", "NONE"); 50 51 public JComboBox ip = new JComboBox(); 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 SmbHostChooser(ComponentListener l, boolean local) 59 { 60 listener = l; 61 useLocal = local; 62 init(); 63 } 64 65 public SmbHostChooser(ComponentListener l) 66 { 67 listener = l; 68 init(); 69 } 70 71 public SmbHostChooser() 72 { 73 init(); 74 } 75 76 public void init() 77 { 78 setLocation(100, 150); 80 setTitle("Smb Connection..."); 81 setBackground(okP.getBackground()); 82 getContentPane().setLayout(new GridLayout(5, 2, 5, 3)); 83 84 try 86 { 87 File f = new File(Settings.appHomeDir); 88 f.mkdir(); 89 90 File f1 = new File(Settings.login); 91 f1.createNewFile(); 92 93 File f2 = new File(Settings.login_def_smb); 94 f2.createNewFile(); 95 } 96 catch(IOException ex) 97 { 98 ex.printStackTrace(); 99 } 100 101 String [] login = LoadSet.loadSet(Settings.login_def_smb); 102 103 if((login[0] != null) && (login.length > 1)) 104 { 105 host.setText(login[0]); 106 user.setText(login[1]); 107 108 domain.setText(login[5]); 114 } 115 116 123 if(Settings.getStorePasswords()) 124 { 125 if((login != null) && (login.length > 2) && (login[2] != null)) 126 { 127 pass.setText(login[2]); 128 } 129 } 130 else 131 { 132 pass.setText(""); 133 } 134 135 ip.setEditable(true); 137 138 getContentPane().add(host); 139 getContentPane().add(lan); 140 getContentPane().add(user); 141 getContentPane().add(pass); 142 143 getContentPane().add(ip); 144 getContentPane().add(domain); 145 146 getContentPane().add(broadcast); 147 getContentPane().add(okP); 148 149 getContentPane().add(wins); 150 151 JTextArea t = new JTextArea(); 152 t.setLineWrap(true); 153 t.setText("Note: URL is in form \"smb://host/\"\n" + 154 "and most people do not need WINS."); 155 156 getContentPane().add(t); 157 158 okP.add(ok); 159 ok.addActionListener(this); 160 161 host.setEnabled(!lan.isSelected()); 162 setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); 163 164 lan.addActionListener(this); 165 pass.text.addActionListener(this); 166 167 setModal(false); 168 setVisible(false); 169 addWindowListener(this); 170 171 ip.addItem("<default>"); 172 173 try 174 { 175 Enumeration e = NetworkInterface.getNetworkInterfaces(); 176 177 while(e.hasMoreElements()) 178 { 179 Enumeration f = ((NetworkInterface) e.nextElement()).getInetAddresses(); 180 181 while(f.hasMoreElements()) 182 { 183 ; 184 ip.addItem(((InetAddress) f.nextElement()).getHostAddress()); 185 } 186 } 187 } 188 catch(Exception ex) 189 { 190 Log.debug("Error determining default network interface: " + ex); 191 192 } 194 195 domain.setEnabled(false); 197 broadcast.setEnabled(false); 198 wins.setEnabled(false); 199 200 ip.addActionListener(this); 201 202 pack(); 203 setVisible(true); 204 } 205 206 private void setBCast() 207 { 208 try 209 { 210 String tmp = ((String ) ip.getSelectedItem()).trim(); 211 String x = tmp.substring(0, tmp.lastIndexOf(".") + 1) + "255"; 212 broadcast.setText(x); 213 } 214 catch(Exception ex) 215 { 216 Log.out("Error (SMBHostChooser): " + ex); 217 } 218 } 219 220 public void update() 221 { 222 fixLocation(); 223 setVisible(true); 224 toFront(); 225 host.requestFocus(); 226 } 227 228 public void actionPerformed(ActionEvent e) 229 { 230 if(e.getSource() == lan) 231 { 232 host.setEnabled(!lan.isSelected()); 233 } 234 else if(e.getSource() == ip) 235 { 236 if(ip.getSelectedItem().equals("<default>")) 237 { 238 domain.setEnabled(false); 239 broadcast.setEnabled(false); 240 wins.setEnabled(false); 241 } 242 else 243 { 244 domain.setEnabled(true); 245 broadcast.setEnabled(true); 246 wins.setEnabled(true); 247 setBCast(); 248 } 249 } 250 else if((e.getSource() == ok) || (e.getSource() == pass.text)) 251 { 252 setCursor(new Cursor(Cursor.WAIT_CURSOR)); 255 256 SmbConnection con = null; 257 258 String tmp = ((String ) ip.getSelectedItem()).trim(); 260 261 if(!tmp.equals("") && !tmp.equals("<default>")) 262 { 263 String x = tmp.trim().substring(0, tmp.lastIndexOf(".") + 1) + 264 "255"; 265 String bcast = broadcast.getText().trim(); 266 267 if(!bcast.equals("AUTO")) 268 { 269 x = bcast; 270 } 271 272 Log.debug("Setting LAN interface to: " + tmp + "/" + x); 273 jcifs.Config.setProperty("jcifs.netbios.laddr", tmp); 274 jcifs.Config.setProperty("jcifs.smb.client.laddr", tmp); 275 jcifs.Config.setProperty("jcifs.netbios.baddr", x); 276 277 String y = wins.getText().trim(); 278 279 if(!y.equals("NONE")) 280 { 281 Log.debug("Setting WINS server IP to: " + y); 282 jcifs.Config.setProperty("jcifs.netbios.wins", y); 283 } 284 } 285 286 String htmp = host.getText().trim(); 289 String utmp = user.getText().trim(); 290 String ptmp = pass.getText(); 291 String dtmp = domain.getText().trim(); 292 293 if(dtmp.equals("")) 296 { 297 dtmp = "NONE"; 298 } 299 300 if(lan.isSelected()) 302 { 303 htmp = "(LAN)"; 304 } 305 306 SaveSet s = new SaveSet(Settings.login_def_smb, htmp, utmp, ptmp, 308 "", "", dtmp); 309 310 boolean status; 313 int potmp = 0; 315 status = StartConnection.startCon("SMB", htmp, utmp, ptmp, potmp, 316 dtmp, useLocal); 317 318 345 setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); 346 this.dispose(); 347 JFtp.mainFrame.setVisible(true); 348 JFtp.mainFrame.toFront(); 349 350 if(listener != null) 351 { 352 listener.componentResized(new ComponentEvent(this, 0)); 353 } 354 } 355 } 356 357 public void windowClosing(WindowEvent e) 358 { 359 this.dispose(); 361 } 362 363 public void windowClosed(WindowEvent e) 364 { 365 } 366 367 public void windowActivated(WindowEvent e) 368 { 369 } 370 371 public void windowDeactivated(WindowEvent e) 372 { 373 } 374 375 public void windowIconified(WindowEvent e) 376 { 377 } 378 379 public void windowDeiconified(WindowEvent e) 380 { 381 } 382 383 public void windowOpened(WindowEvent e) 384 { 385 } 386 387 public Insets getInsets() 388 { 389 Insets std = super.getInsets(); 390 391 return new Insets(std.top + 10, std.left + 10, std.bottom + 10, 392 std.right + 10); 393 } 394 395 public void pause(int time) 396 { 397 try 398 { 399 Thread.sleep(time); 400 } 401 catch(Exception ex) 402 { 403 } 404 } 405 } 406 | Popular Tags |