1 16 17 package net.sf.jftp.gui.tasks; 19 20 import net.sf.jftp.*; 21 import net.sf.jftp.config.*; 22 import net.sf.jftp.gui.framework.*; 23 import net.sf.jftp.net.*; 24 import net.sf.jftp.system.StringUtils; 25 import net.sf.jftp.util.*; 26 27 import java.awt.*; 28 import java.awt.event.*; 29 30 import java.io.*; 31 32 import javax.swing.*; 33 34 35 public class AddBookmarks extends HFrame implements ActionListener, 36 WindowListener 37 { 38 private static JFtp jftp; 39 private HButton add = new HButton("Add Bookmark"); 40 private HButton addAndConnect = new HButton("Add Bookmark and Connect to Server"); 41 42 public HComboBox protocols = new HComboBox("Protocol:"); 44 public HTextField host = new HTextField("Hostname:", "localhost"); 45 public HTextField user = new HTextField("Username:", "anonymous"); 46 public HPasswordField pass = new HPasswordField("Password:", 47 "none@nowhere.no"); 48 public HTextField port = new HTextField("Port: ", "21"); 49 public HTextField dirOrDom = new HTextField("Directory/Domain: ", ""); 50 51 public HComboBox isLocal = new HComboBox("Local Connection:"); 53 54 public AddBookmarks(ComponentListener l, JFtp jftp) 57 { 58 this.jftp = jftp; 60 init(); 61 } 62 63 public AddBookmarks(JFtp jftp) 64 { 65 this.jftp = jftp; 66 init(); 67 } 68 69 public void init() 70 { 71 setSize(650, 400); 72 setLocation(50, 150); 73 setTitle("Add Bookmarks..."); 74 75 getContentPane().setLayout(new GridLayout(8, 1)); 77 78 getContentPane().add(protocols); 79 getContentPane().add(host); 80 getContentPane().add(port); 81 82 getContentPane().add(user); 83 getContentPane().add(pass); 84 85 getContentPane().add(dirOrDom); 86 87 getContentPane().add(isLocal); 88 89 Panel buttonPanel = new Panel(new FlowLayout(FlowLayout.CENTER, 5, 20)); 93 94 getContentPane().add(buttonPanel); 95 buttonPanel.add(add); 96 buttonPanel.add(addAndConnect); 97 98 102 add.addActionListener(this); 103 addAndConnect.addActionListener(this); 104 105 protocols.setEditable(false); 107 protocols.addItem("FTP"); 108 protocols.addItem("SFTP"); 109 protocols.addItem("SMB"); 110 protocols.addItem("NFS"); 111 112 protocols.addActionListener(this); 113 114 isLocal.setEditable(false); 116 isLocal.addItem("No"); 117 isLocal.addItem("Yes"); 118 } 119 120 public void update() 121 { 122 setVisible(true); 123 toFront(); 124 } 125 126 public void windowClosing(WindowEvent e) 127 { 128 this.dispose(); 130 } 131 132 public void windowClosed(WindowEvent e) 133 { 134 } 135 136 public void windowActivated(WindowEvent e) 137 { 138 } 139 140 public void windowDeactivated(WindowEvent e) 141 { 142 } 143 144 public void windowIconified(WindowEvent e) 145 { 146 } 147 148 public void windowDeiconified(WindowEvent e) 149 { 150 } 151 152 public void windowOpened(WindowEvent e) 153 { 154 } 155 156 public void actionPerformed(ActionEvent e) 157 { 158 if(e.getSource() == add) 159 { 160 getData(false); 161 } 162 163 else if(e.getSource() == addAndConnect) 164 { 165 getData(true); 166 } 167 168 else 170 { 171 String s = new String (""); 172 173 s = protocols.getSelectedItem().toString(); 175 System.out.println(s); 176 177 if(s.equals("FTP")) 181 { 182 port.setEnabled(true); 183 user.setEnabled(true); 184 pass.setEnabled(true); 185 dirOrDom.setEnabled(true); 186 } 187 else if(s.equals("SFTP")) 188 { 189 port.setEnabled(true); 190 user.setEnabled(true); 191 pass.setEnabled(true); 192 dirOrDom.setEnabled(false); 193 } 194 195 else if(s.equals("SMB")) 196 { 197 port.setEnabled(false); 198 user.setEnabled(true); 199 pass.setEnabled(true); 200 dirOrDom.setEnabled(true); 201 } 202 203 else 205 { 206 port.setEnabled(false); 207 user.setEnabled(true); 208 pass.setEnabled(true); 209 dirOrDom.setEnabled(false); 210 } 211 212 } 214 215 } 217 218 private void getData(boolean andConnect) 220 { 221 String protocoltmp = new String (""); 222 223 protocoltmp = protocols.getSelectedItem().toString(); 226 227 System.out.println("test"); 229 230 252 260 String htmp = checkIfEmpty(StringUtils.cut(host.getText(), " ")); 261 String utmp = checkIfEmpty(StringUtils.cut(user.getText(), " ")); 262 String ptmp = checkIfEmpty(StringUtils.cut(pass.getText(), " ")); 263 String potmp = checkIfEmpty(StringUtils.cut(port.getText(), " ")); 264 265 String dirOrDomtmp = checkIfEmpty(StringUtils.cut(dirOrDom.getText(), 266 " ")); 267 268 String local = new String (""); 269 270 Integer potmpInt = new Integer (potmp); 271 int potmpint = potmpInt.intValue(); 272 273 local = isLocal.getSelectedItem().toString(); 274 275 String localString = new String (""); 276 277 boolean localtmp = false; 278 279 if(local.equals("true")) 280 { 281 localtmp = true; 282 localString = "true"; 283 } 284 else 285 { 286 localtmp = false; 287 localString = "false"; 288 } 289 290 String addedString = new String (""); 294 295 addedString += (protocoltmp + "#"); 296 addedString += (htmp + "#"); 297 addedString += (utmp + "#"); 298 299 addedString += (ptmp + "#"); 300 addedString += (potmp + "#"); 301 addedString += (dirOrDomtmp + "#"); 302 addedString += localString; 303 304 try 307 { 308 FileOutputStream fos; 309 PrintStream out; 310 311 fos = new FileOutputStream(Settings.bookmarks, true); 312 out = new PrintStream(fos); 313 314 out.println(addedString); 316 out.println(""); 317 318 jftp.menuBar.loadBookmarks(); 320 } 321 catch(Exception e) 322 { 323 e.printStackTrace(); 324 } 325 326 if(andConnect) 327 { 328 if(protocoltmp.equals("FTP")) 329 { 330 StartConnection.startFtpCon(htmp, utmp, ptmp, potmpint, 331 dirOrDomtmp, localtmp); 332 } 333 else 334 { 335 StartConnection.startCon(protocoltmp, htmp, utmp, ptmp, 336 potmpint, dirOrDomtmp, localtmp); 337 } 338 } 339 340 this.dispose(); 343 344 JFtp.mainFrame.setVisible(true); 346 JFtp.mainFrame.toFront(); 347 } 348 349 private String checkIfEmpty(String value) 351 { 352 String retVal = new String ("0"); 353 354 if(value.equals("")) 355 { 356 return retVal; 357 } 358 else 359 { 360 return value; 361 } 362 } 363 364 } 366 | Popular Tags |