1 /* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License 4 * as published by the Free Software Foundation; either version 2 5 * of the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software 14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 */ 16 package net.sf.jftp.gui.base; 17 18 import net.sf.jftp.JFtp; 19 import net.sf.jftp.config.Settings; 20 import net.sf.jftp.gui.framework.*; 21 import net.sf.jftp.gui.hostchooser.HostChooser; 22 import net.sf.jftp.gui.hostchooser.NfsHostChooser; 23 import net.sf.jftp.gui.hostchooser.SftpHostChooser; 24 import net.sf.jftp.gui.hostchooser.SmbHostChooser; 25 import net.sf.jftp.gui.hostchooser.WebdavHostChooser; 26 import net.sf.jftp.gui.tasks.AddBookmarks; 27 import net.sf.jftp.gui.tasks.AdvancedOptions; 28 import net.sf.jftp.gui.tasks.BookmarkItem; 29 import net.sf.jftp.gui.tasks.BookmarkManager; 30 import net.sf.jftp.gui.tasks.Displayer; 31 import net.sf.jftp.gui.tasks.HttpBrowser; 32 import net.sf.jftp.gui.tasks.HttpDownloader; 33 import net.sf.jftp.gui.tasks.LastConnections; 34 import net.sf.jftp.gui.tasks.NativeHttpBrowser; 35 import net.sf.jftp.gui.tasks.ProxyChooser; 36 import net.sf.jftp.net.*; 37 import net.sf.jftp.net.wrappers.StartConnection; 38 import net.sf.jftp.system.logging.Log; 39 import net.sf.jftp.tools.*; 40 import net.sf.jftp.util.*; 41 42 import java.awt.*; 43 import java.awt.event.*; 44 45 import java.io.*; 46 47 import java.lang.Integer; 48 49 import java.util.*; 50 51 import javax.swing.*; 52 53 import javazoom.jl.decoder.*; 54 import javazoom.jl.player.*; 55 56 57 //*** 58 public class AppMenuBar extends JMenuBar implements ActionListener 59 { 60 public static JCheckBoxMenuItem fadeMenu = new JCheckBoxMenuItem("Enable Status Animation", 61 Settings.getEnableStatusAnimation()); 62 public static JCheckBoxMenuItem askToDelete = new JCheckBoxMenuItem("Confirm Remove", 63 Settings.getAskToDelete()); 64 public static JCheckBoxMenuItem debug = new JCheckBoxMenuItem("Verbose Console Debugging", 65 Settings.getEnableDebug()); 66 public static JCheckBoxMenuItem disableLog = new JCheckBoxMenuItem("Disable Log", 67 Settings.getDisableLog()); 68 public static JMenuItem clearItems = new JMenuItem("Clear Finished Items"); 69 private JFtp jftp; 70 JMenu file = new JMenu("File"); 71 JMenu opt = new JMenu("Options"); 72 JMenu view = new JMenu("View"); 73 JMenu tools = new JMenu("Tools"); 74 JMenu bookmarks = new JMenu("Bookmarks"); 75 JMenu info = new JMenu("Info"); 76 JMenu lf = new JMenu("Switch Look & Feel to"); 77 JMenu background = new JMenu("Desktop Background"); 78 JMenu ftp = new JMenu(" FTP"); 79 JMenu smb = new JMenu(" SMB"); 80 JMenu sftp = new JMenu(" SFTP"); 81 JMenu security = new JMenu("Security"); 82 JMenu experimental = new JMenu("Experimental Features"); 83 JMenu rss = new JMenu("RSS Feed"); 84 JMenu cnn = new JMenu("CNN"); 85 JMenuItem localFtpCon = new JMenuItem("Open FTP Connection in Local Tab..."); 86 JMenuItem localSftpCon = new JMenuItem("Open SFTP Connection in Local Tab..."); 87 JMenuItem localSmbCon = new JMenuItem("Open SMB/LAN Connection in Local Tab..."); 88 JMenuItem localNfsCon = new JMenuItem("Open NFS Connection in Local Tab..."); 89 JMenuItem localWebdavCon = new JMenuItem("Open WebDAV Connection in Local Tab... (ALPHA)"); 90 JMenuItem closeLocalCon = new JMenuItem("Close Active Connection in Local Tab"); 91 JMenuItem ftpCon = new JMenuItem("Connect to FTP Server..."); 92 JMenuItem sftpCon = new JMenuItem("Connect to SFTP Server..."); 93 JMenuItem smbCon = new JMenuItem("Connect to SMB Server / Browse LAN..."); 94 JMenuItem nfsCon = new JMenuItem("Connect to NFS Server..."); 95 JMenuItem webdavCon = new JMenuItem("Connect to WebDAV Server... (ALPHA)"); 96 JMenuItem close = new JMenuItem("Disconnect and Connect to Filesystem"); 97 JMenuItem exit = new JMenuItem("Exit"); 98 JMenuItem readme = new JMenuItem("Show Readme..."); 99 JMenuItem changelog = new JMenuItem("View Changelog..."); 100 JMenuItem todo = new JMenuItem("What's Next..."); 101 JMenuItem hp = new JMenuItem("Visit Project Homepage..."); 102 JMenuItem opts = new JMenuItem("Advanced Options..."); 103 JMenuItem http = new JMenuItem("Download File from URL..."); 104 JMenuItem raw = new JMenuItem("Raw TCP/IP Connection..."); 105 JMenuItem spider = new JMenuItem("Recursive HTTP Download..."); 106 JMenuItem shell = new JMenuItem("Execute /bin/bash"); 107 JMenuItem loadAudio = new JMenuItem("Play MP3"); 108 JCheckBoxMenuItem rssDisabled = new JCheckBoxMenuItem("Enable RSS Feed", 109 Settings.getEnableRSS()); 110 JCheckBoxMenuItem nl = new JCheckBoxMenuItem("Show Newline Option", 111 Settings.showNewlineOption); 112 JMenuItem loadSlash = new JMenuItem("Slashdot"); 113 JMenuItem loadCNN1 = new JMenuItem("CNN Top Stories"); 114 JMenuItem loadCNN2 = new JMenuItem("CNN World"); 115 JMenuItem loadCNN3 = new JMenuItem("CNN Tech"); 116 JMenuItem loadRss = new JMenuItem("Custom RSS Feed"); 117 JCheckBoxMenuItem stdback = new JCheckBoxMenuItem("Background Image", 118 Settings.getUseBackground()); 119 JCheckBoxMenuItem resuming = new JCheckBoxMenuItem("Enable Resuming", 120 Settings.enableResuming); 121 JCheckBoxMenuItem ask = new JCheckBoxMenuItem("Always Ask to Resume", 122 Settings.askToResume); 123 JMenuItem proxy = new JMenuItem("Proxy Settings..."); 124 JCheckBoxMenuItem smbThreads = new JCheckBoxMenuItem("Multiple Connections", 125 Settings.getEnableSmbMultiThreading()); 126 JCheckBoxMenuItem sftpThreads = new JCheckBoxMenuItem("Multiple Connections", 127 Settings.getEnableSftpMultiThreading()); 128 JCheckBoxMenuItem sshKeys = new JCheckBoxMenuItem("Enable Host Key check", 129 Settings.getEnableSshKeys()); 130 JCheckBoxMenuItem storePasswords = new JCheckBoxMenuItem("Store passwords (encrypted using internal password)", 131 Settings.getStorePasswords()); 132 133 JCheckBoxMenuItem useNewIcons = new JCheckBoxMenuItem("Use Silk Icons", 134 Settings.getUseNewIcons()); 135 136 JCheckBoxMenuItem hideHidden = new JCheckBoxMenuItem("Hide local hidden files (Unix only)", 137 Settings.getHideLocalDotNames()); 138 139 JMenuItem clear = new JMenuItem("Clear Log"); 140 141 //*** the menu items for the last connections 142 JMenuItem[] lastConnections = new JMenuItem[jftp.CAPACITY]; 143 144 //*** information on each of the last connections 145 //BUGFIX 146 String[][] cons = new String[jftp.CAPACITY][JFtp.CONNECTION_DATA_LENGTH]; 147 String[] lastConData = new String[jftp.CAPACITY]; 148 Character charTab = new Character('\t'); 149 String tab = charTab.toString(); 150 JMenuItem manage = new JMenuItem("Manage Bookmarks..."); 151 JMenuItem add = new JMenuItem("Add Bookmark..."); 152 Hashtable marks; 153 JMenu current = bookmarks; 154 JMenu last = bookmarks; 155 156 /* 157 String[] lastProtocols; 158 String[] lastHosts; 159 String[] lastUnames; 160 */ AppMenuBar(JFtp jftp)161 public AppMenuBar(JFtp jftp) 162 { 163 this.jftp = jftp; 164 165 ftpCon.addActionListener(this); 166 close.addActionListener(this); 167 exit.addActionListener(this); 168 readme.addActionListener(this); 169 changelog.addActionListener(this); 170 todo.addActionListener(this); 171 resuming.addActionListener(this); 172 ask.addActionListener(this); 173 smbCon.addActionListener(this); 174 clear.addActionListener(this); 175 sftpCon.addActionListener(this); 176 fadeMenu.addActionListener(this); 177 askToDelete.addActionListener(this); 178 smbThreads.addActionListener(this); 179 sftpThreads.addActionListener(this); 180 debug.addActionListener(this); 181 disableLog.addActionListener(this); 182 http.addActionListener(this); 183 hp.addActionListener(this); 184 raw.addActionListener(this); 185 nfsCon.addActionListener(this); 186 spider.addActionListener(this); 187 proxy.addActionListener(this); 188 stdback.addActionListener(this); 189 opts.addActionListener(this); 190 webdavCon.addActionListener(this); 191 shell.addActionListener(this); 192 nl.addActionListener(this); 193 194 localFtpCon.addActionListener(this); 195 localSftpCon.addActionListener(this); 196 localSmbCon.addActionListener(this); 197 localNfsCon.addActionListener(this); 198 localWebdavCon.addActionListener(this); 199 closeLocalCon.addActionListener(this); 200 add.addActionListener(this); 201 storePasswords.addActionListener(this); 202 rssDisabled.addActionListener(this); 203 loadRss.addActionListener(this); 204 loadSlash.addActionListener(this); 205 loadCNN1.addActionListener(this); 206 loadCNN2.addActionListener(this); 207 loadCNN3.addActionListener(this); 208 loadAudio.addActionListener(this); 209 useNewIcons.addActionListener(this); 210 hideHidden.addActionListener(this); 211 212 clearItems.addActionListener(JFtp.dList); 213 214 clear.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, 215 ActionEvent.ALT_MASK)); 216 clearItems.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, 217 ActionEvent.ALT_MASK)); 218 changelog.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, 219 ActionEvent.ALT_MASK)); 220 readme.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4, 221 ActionEvent.ALT_MASK)); 222 todo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_5, 223 ActionEvent.ALT_MASK)); 224 225 //*** setMnemonics(); was here 226 //*** BELOW, ADDITIONS FOR THE FILE MENU ARE PUT IN PUBLIC METHOD 227 resetFileItems(); 228 229 ftp.add(resuming); 230 ftp.add(ask); 231 ftp.add(nl); 232 smb.add(smbThreads); 233 sftp.add(sftpThreads); 234 sftp.add(sshKeys); 235 security.add(askToDelete); 236 security.add(storePasswords); 237 238 cnn.add(loadCNN1); 239 cnn.add(loadCNN2); 240 cnn.add(loadCNN3); 241 242 rss.add(rssDisabled); 243 rss.add(loadSlash); 244 rss.add(cnn); 245 rss.add(loadRss); 246 247 opt.add(security); 248 opt.addSeparator(); 249 opt.add(ftp); 250 opt.add(smb); 251 opt.add(sftp); 252 opt.addSeparator(); 253 opt.add(proxy); 254 opt.add(opts); 255 256 tools.add(http); 257 tools.add(spider); 258 tools.addSeparator(); 259 tools.add(raw); 260 tools.addSeparator(); 261 tools.add(shell); 262 263 view.add(hideHidden); 264 view.addSeparator(); 265 view.add(useNewIcons); 266 view.add(fadeMenu); 267 view.add(clear); 268 view.add(clearItems); 269 270 view.addSeparator(); 271 view.add(debug); 272 view.add(disableLog); 273 view.addSeparator(); 274 view.add(rss); 275 view.addSeparator(); 276 277 info.add(readme); 278 info.add(changelog); 279 //info.add(todo); 280 //info.addSeparator(); 281 info.add(hp); 282 283 UIManager.LookAndFeelInfo[] m = UIManager.getInstalledLookAndFeels(); 284 285 for(int i = 0; i < m.length; i++) 286 { 287 //JMenuItem tmp = new JMenuItem(m[i].getName()); 288 //tmp.addActionListener(this); 289 //lf.add(tmp); 290 291 /* 292 * Don't add menu items for unsupported look and feel's. 293 * 294 * It would be nice to use something like 295 * isSupportedLookandFeel, but the information provided by 296 * UIManager.LookAndFeelInfo is very limited. This is 297 * supposedly done on purpose according to the API docs, 298 * but what good does a non-supported look and feel in a 299 * menu item do? 300 */ 301 try 302 { 303 LookAndFeel lnf = (LookAndFeel) Class.forName(m[i].getClassName()) 304 .newInstance(); 305 306 if(lnf.isSupportedLookAndFeel()) 307 { 308 JMenuItem tmp = new JMenuItem(m[i].getName()); 309 tmp.addActionListener(this); 310 lf.add(tmp); 311 } 312 } 313 catch(ClassNotFoundException cnfe) 314 { 315 continue; 316 } 317 catch(InstantiationException ie) 318 { 319 continue; 320 } 321 catch(IllegalAccessException iae) 322 { 323 continue; 324 } 325 } 326 327 view.add(lf); 328 329 background.add(stdback); 330 view.add(background); 331 332 manage.addActionListener(this); 333 334 //UIManager.setLookAndFeel(); 335 add(file); 336 add(opt); 337 add(view); 338 add(tools); 339 add(bookmarks); 340 add(info); 341 342 loadBookmarks(); 343 344 //add(experimental); 345 } 346 loadBookmarks()347 public void loadBookmarks() 348 { 349 marks = new Hashtable(); 350 bookmarks.removeAll(); 351 bookmarks.add(add); 352 bookmarks.add(manage); 353 bookmarks.addSeparator(); 354 355 String data = ""; 356 357 try 358 { 359 DataInput in = new DataInputStream(new BufferedInputStream(new FileInputStream(Settings.bookmarks))); 360 361 while((data = in.readLine()) != null) 362 { 363 if(!data.startsWith("#") && !data.trim().equals("")) 364 { 365 addBookmarkLine(data); 366 } 367 } 368 } 369 catch(IOException e) 370 { 371 Log.out("No bookmarks.txt found, using defaults."); 372 373 addBookmark("FTP", "ftp.kernel.org", "anonymous", "j-ftp@sf.net", 374 21, "/pub/linux/kernel", "false"); 375 addBookmark("FTP", "upload.sourceforge.net", "anonymous", 376 "j-ftp@sf.net", 21, "/incoming", "false"); 377 addBookmark("SMB", "(LAN)", "guest", "guest", -1, "-", "false"); 378 379 return; 380 } 381 } 382 addBookmarkLine(String tmp)383 private void addBookmarkLine(String tmp) 384 { 385 try 386 { 387 StringTokenizer t = new StringTokenizer(tmp, "#", false); 388 389 if(tmp.toLowerCase().trim().startsWith("<dir>")) 390 { 391 String dir = tmp.substring(tmp.indexOf(">") + 1, 392 tmp.lastIndexOf("<")); 393 394 //Log.debug("Dir: " + dir); 395 JMenu m = new JMenu(dir); 396 current.add(m); 397 398 last = current; 399 current = m; 400 } 401 else if(tmp.toLowerCase().trim().startsWith("<enddir>")) 402 { 403 current = last; 404 } 405 else 406 { 407 addBookmark(t.nextToken(), t.nextToken(), t.nextToken(), 408 t.nextToken(), Integer.parseInt(t.nextToken()), 409 t.nextToken(), t.nextToken()); 410 } 411 } 412 catch(Exception ex) 413 { 414 Log.debug("Broken line: " + tmp); 415 ex.printStackTrace(); 416 } 417 } 418 addBookmark(String pr, String h, String u, String p, int po, String d, String l)419 public void addBookmark(String pr, String h, String u, String p, int po, 420 String d, String l) 421 { 422 BookmarkItem x = new BookmarkItem(h); 423 x.setUserdata(u, p); 424 425 if(l.trim().startsWith("t")) 426 { 427 x.setLocal(true); 428 } 429 430 x.setPort(po); 431 x.setProtocol(pr); 432 x.setDirectory(d); 433 434 //bookmarks 435 current.add(x); 436 marks.put(x.getLabel(), x); 437 x.addActionListener(this); 438 } 439 440 //*** Where changes to the file menu are made (iniitalization done here too) resetFileItems()441 public void resetFileItems() 442 { 443 file.removeAll(); 444 445 file.add(ftpCon); 446 file.add(sftpCon); 447 file.add(smbCon); 448 file.add(nfsCon); 449 file.add(webdavCon); 450 file.addSeparator(); 451 file.add(close); 452 file.addSeparator(); 453 file.addSeparator(); 454 file.add(localFtpCon); 455 file.add(localSftpCon); 456 file.add(localSmbCon); 457 file.add(localNfsCon); 458 459 //file.add(localWebdavCon); -> not yet 460 file.addSeparator(); 461 file.add(closeLocalCon); 462 file.addSeparator(); 463 464 //*** ADDITION OF THE REMEMBERED CONNECTIONS 465 boolean connectionsExist = false; 466 467 try 468 { 469 //*** get the information on the last connections 470 cons = new String[jftp.CAPACITY][jftp.CONNECTION_DATA_LENGTH]; 471 472 cons = LastConnections.readFromFile(jftp.CAPACITY); 473 474 String protocol; 475 476 String htmp; 477 478 String utmp; 479 480 String conNumber; 481 String usingLocal = new String(""); 482 Integer conNumberInt; 483 484 //lastConData = new String(""); 485 //*** 486 for(int i = 0; i < jftp.CAPACITY; i++) 487 { 488 if(!(cons[i][0].equals("null"))) 489 { 490 protocol = cons[i][0]; 491 htmp = cons[i][1]; 492 utmp = cons[i][2]; 493 494 int j = 3; 495 496 while(!(cons[i][j].equals(LastConnections.SENTINEL))) 497 { 498 j++; 499 } 500 501 //usingLocal is always last piece of data! 502 usingLocal = cons[i][j - 1]; 503 504 if(usingLocal.equals("true")) 505 { 506 usingLocal = "(in local tab)"; 507 } 508 509 else 510 { 511 usingLocal = ""; 512 } 513 514 //lastConnections[i] = new JMenuItem(cons[i]); 515 conNumberInt = new Integer(i + 1); 516 conNumber = conNumberInt.toString(); 517 518 //lastConData[i] = new String(conNumber + " " + protocol + ": Hostname: " + htmp + "; Username: " + utmp); 519 lastConData[i] = new String(conNumber + " " + protocol + 520 ": " + htmp + " " + usingLocal); 521 522 lastConnections[i] = new JMenuItem(lastConData[i]); 523 lastConnections[i].addActionListener(this); 524 525 connectionsExist = true; 526 527 //*** code repetition: maybe getting these tokens 528 //*** should be in a separate private method 529 //file.add(protocol + ": Hostname: " + htmp + "; Username: " + utmp); 530 file.add(lastConnections[i]); 531 } 532 } 533 } 534 catch(Exception ex) 535 { 536 Log.debug("WARNING: Remembered connections broken."); 537 ex.printStackTrace(); 538 } 539 540 if(connectionsExist) 541 { 542 file.addSeparator(); 543 } 544 545 file.add(exit); 546 547 setMnemonics(); 548 } 549 550 //resetFileItems actionPerformed(ActionEvent e)551 public void actionPerformed(ActionEvent e) 552 { 553 try { 554 if(e.getSource() == proxy) 555 { 556 //ProxyChooser p = 557 JFtp.statusP.jftp.addToDesktop("Proxy Settings", 558 new ProxyChooser(), 500, 110); 559 } 560 else if(e.getSource() == add) 561 { 562 Log.out("add called"); 563 564 AddBookmarks a = new AddBookmarks(JFtp.statusP.jftp); 565 a.update(); 566 } 567 else if(e.getSource() == webdavCon) 568 { 569 WebdavHostChooser hc = new WebdavHostChooser(); 570 hc.toFront(); 571 hc.update(); 572 } 573 else if((e.getSource() == localFtpCon) && (!jftp.uiBlocked)) 574 { 575 HostChooser hc = new HostChooser(null, true); 576 hc.toFront(); 577 578 //hc.setModal(true); 579 hc.update(); 580 } 581 else if((e.getSource() == localSmbCon) && (!jftp.uiBlocked)) 582 { 583 SmbHostChooser hc = new SmbHostChooser(null, true); 584 hc.toFront(); 585 586 //hc.setModal(true); 587 hc.update(); 588 } 589 else if((e.getSource() == localSftpCon) && (!jftp.uiBlocked)) 590 { 591 SftpHostChooser hc = new SftpHostChooser(null, true); 592 hc.toFront(); 593 594 //hc.setModal(true); 595 hc.update(); 596 } 597 else if((e.getSource() == localNfsCon) && (!jftp.uiBlocked)) 598 { 599 NfsHostChooser hc = new NfsHostChooser(null, true); 600 hc.toFront(); 601 602 //hc.setModal(true); 603 hc.update(); 604 } 605 else if((e.getSource() == localWebdavCon) && (!jftp.uiBlocked)) 606 { 607 WebdavHostChooser hc = new WebdavHostChooser(null, true); 608 hc.toFront(); 609 610 //hc.setModal(true); 611 hc.update(); 612 } 613 else if(e.getSource() == closeLocalCon) 614 { 615 JFtp.statusP.jftp.closeCurrentLocalTab(); 616 } 617 else if(e.getSource() == clear) 618 { 619 jftp.clearLog(); 620 } 621 else if(e.getSource() == spider) 622 { 623 jftp.addToDesktop("Http recursive download", 624 new HttpSpider(jftp.localDir.getPath() + 625 "_httpdownload/"), 440, 250); 626 } 627 else if(e.getSource() == hp) 628 { 629 try { 630 NativeHttpBrowser.main(new String[] {"http://j-ftp.sourceforge.net"}); 631 } 632 catch(Throwable ex) { 633 ex.printStackTrace(); 634 Log.debug("Native browser intialization failed, using JContentPane..."); 635 636 HttpBrowser h = new HttpBrowser("http://j-ftp.sourceforge.net"); 637 JFtp.desktop.add(h, new Integer(Integer.MAX_VALUE - 10)); 638 } 639 } 640 else if(e.getSource() == raw) 641 { 642 RawConnection c = new RawConnection(); 643 } 644 else if(e.getSource() == readme) 645 { 646 show(Settings.readme); 647 } 648 else if(e.getSource() == changelog) 649 { 650 show(Settings.changelog); 651 } 652 else if(e.getSource() == todo) 653 { 654 show(Settings.todo); 655 } 656 else if(e.getSource() == shell) 657 { 658 UIUtils.runCommand("/bin/bash"); 659 } 660 else if(e.getSource() == loadAudio) 661 { 662 try 663 { 664 JFileChooser f = new JFileChooser(); 665 f.showOpenDialog(jftp); 666 667 File file = f.getSelectedFile(); 668 669 Player p = new Player(new FileInputStream(file)); 670 671 p.play(); 672 } 673 catch(Exception ex) 674 { 675 ex.printStackTrace(); 676 Log.debug("Error: (" + ex + ")"); 677 } 678 } 679 else if(e.getSource() == exit) 680 { 681 jftp.windowClosing(null); // handles everything 682 } 683 else if(e.getSource() == close) 684 { 685 JFtp.statusP.jftp.closeCurrentTab(); 686 687 /* 688 jftp.safeDisconnect(); 689 FilesystemConnection con = new FilesystemConnection(); 690 jftp.remoteDir.setCon(con); 691 con.addConnectionListener((ConnectionListener)jftp.remoteDir); 692 if(!con.chdir("/")) con.chdir("C:\\"); 693 */ 694 } 695 else if((e.getSource() == ftpCon) && (!jftp.uiBlocked)) 696 { 697 //jftp.safeDisconnect(); 698 HostChooser hc = new HostChooser(); 699 hc.toFront(); 700 701 //hc.setModal(true); 702 hc.update(); 703 } 704 else if((e.getSource() == smbCon) && (!jftp.uiBlocked)) 705 { 706 //jftp.safeDisconnect(); 707 SmbHostChooser hc = new SmbHostChooser(); 708 hc.toFront(); 709 710 //hc.setModal(true); 711 hc.update(); 712 } 713 else if((e.getSource() == sftpCon) && (!jftp.uiBlocked)) 714 { 715 //jftp.safeDisconnect(); 716 SftpHostChooser hc = new SftpHostChooser(); 717 hc.toFront(); 718 719 //hc.setModal(true); 720 hc.update(); 721 } 722 else if((e.getSource() == nfsCon) && (!jftp.uiBlocked)) 723 { 724 // jftp.safeDisconnect(); 725 NfsHostChooser hc = new NfsHostChooser(); 726 hc.toFront(); 727 728 //hc.setModal(true); 729 hc.update(); 730 } 731 else if(e.getSource() == resuming) 732 { 733 boolean res = resuming.getState(); 734 Settings.enableResuming = res; 735 Settings.setProperty("jftp.enableResuming", res); 736 ask.setEnabled(Settings.enableResuming); 737 Settings.save(); 738 } 739 else if(e.getSource() == useNewIcons) 740 { 741 boolean res = useNewIcons.getState(); 742 Settings.setProperty("jftp.gui.look.newIcons", res); 743 Settings.save(); 744 745 JOptionPane.showMessageDialog(this, "Please restart JFtp to have the UI changed."); 746 } 747 else if(e.getSource() == hideHidden) 748 { 749 boolean res = hideHidden.getState(); 750 Settings.setProperty("jftp.hideHiddenDotNames", res); 751 Settings.save(); 752 753 JFtp.localUpdate(); 754 } 755 else if(e.getSource() == nl) 756 { 757 boolean res = nl.getState(); 758 Settings.showNewlineOption = res; 759 } 760 else if(e.getSource() == stdback) 761 { 762 Settings.setProperty("jftp.useBackground", stdback.getState()); 763 Settings.save(); 764 JFtp.statusP.jftp.fireUpdate(); 765 } 766 else if(e.getSource() == sshKeys) 767 { 768 Settings.setProperty("jftp.useSshKeyVerification", 769 sshKeys.getState()); 770 Settings.save(); 771 JFtp.statusP.jftp.fireUpdate(); 772 } 773 else if(e.getSource() == rssDisabled) 774 { 775 Settings.setProperty("jftp.enableRSS", rssDisabled.getState()); 776 Settings.save(); 777 778 JFtp.statusP.jftp.fireUpdate(); 779 780 String feed = Settings.getProperty("jftp.customRSSFeed"); 781 if(feed != null && !feed.equals("")) feed = "http://slashdot.org/rss/slashdot.rss"; 782 783 switchRSS(feed); 784 } 785 else if(e.getSource() == loadRss) 786 { 787 String what = JOptionPane.showInputDialog("Enter URL", "http://"); 788 789 if(what == null) 790 { 791 return; 792 } 793 794 switchRSS(what); 795 } 796 else if(e.getSource() == loadSlash) 797 { 798 switchRSS("http://slashdot.org/rss/slashdot.rss"); 799 } 800 else if(e.getSource() == loadCNN1) 801 { 802 switchRSS("http://rss.cnn.com/rss/cnn_topstories.rss"); 803 } 804 else if(e.getSource() == loadCNN2) 805 { 806 switchRSS("http://rss.cnn.com/rss/cnn_world.rss"); 807 } 808 else if(e.getSource() == loadCNN3) 809 { 810 switchRSS("http://rss.cnn.com/rss/cnn_tech.rss"); 811 } 812 else if(e.getSource() == debug) 813 { 814 Settings.setProperty("jftp.enableDebug", debug.getState()); 815 Settings.save(); 816 } 817 else if(e.getSource() == disableLog) 818 { 819 Settings.setProperty("jftp.disableLog", disableLog.getState()); 820 Settings.save(); 821 } 822 else if(e.getSource() == smbThreads) 823 { 824 Settings.setProperty("jftp.enableSmbMultiThreading", 825 smbThreads.getState()); 826 Settings.save(); 827 } 828 else if(e.getSource() == sftpThreads) 829 { 830 Settings.setProperty("jftp.enableSftpMultiThreading", 831 sftpThreads.getState()); 832 Settings.save(); 833 } 834 else if(e.getSource() == ask) 835 { 836 Settings.askToResume = ask.getState(); 837 } 838 else if(e.getSource() == http) 839 { 840 HttpDownloader dl = new HttpDownloader(); 841 jftp.addToDesktop("Http download", dl, 480, 100); 842 jftp.setLocation(dl.hashCode(), 100, 150); 843 } 844 else if(e.getSource() == fadeMenu) 845 { 846 Settings.setProperty("jftp.gui.enableStatusAnimation", 847 fadeMenu.getState()); 848 Settings.save(); 849 } 850 else if(e.getSource() == askToDelete) 851 { 852 Settings.setProperty("jftp.gui.askToDelete", askToDelete.getState()); 853 Settings.save(); 854 } 855 856 //***MY ADDITIONS (***how can I make this flexible enough to 857 //*** easily add > 5 connections?) 858 else if((e.getSource() == lastConnections[0]) && (!jftp.uiBlocked)) 859 { 860 connectionSelected(0); 861 } 862 863 else if((e.getSource() == lastConnections[1]) && (!jftp.uiBlocked)) 864 { 865 connectionSelected(1); 866 } 867 else if((e.getSource() == lastConnections[2]) && (!jftp.uiBlocked)) 868 { 869 connectionSelected(2); 870 } 871 else if((e.getSource() == lastConnections[3]) && (!jftp.uiBlocked)) 872 { 873 connectionSelected(3); 874 } 875 else if((e.getSource() == lastConnections[4]) && (!jftp.uiBlocked)) 876 { 877 connectionSelected(4); 878 } 879 else if((e.getSource() == lastConnections[5]) && (!jftp.uiBlocked)) 880 { 881 connectionSelected(5); 882 } 883 else if((e.getSource() == lastConnections[6]) && (!jftp.uiBlocked)) 884 { 885 connectionSelected(6); 886 } 887 else if((e.getSource() == lastConnections[7]) && (!jftp.uiBlocked)) 888 { 889 connectionSelected(7); 890 } 891 else if((e.getSource() == lastConnections[8]) && (!jftp.uiBlocked)) 892 { 893 connectionSelected(8); 894 } 895 else if(e.getSource() == opts) 896 { 897 AdvancedOptions adv = new AdvancedOptions(); 898 jftp.addToDesktop("Advanced Options", adv, 500, 180); 899 jftp.setLocation(adv.hashCode(), 110, 180); 900 } 901 else if(e.getSource() == manage) 902 { 903 BookmarkManager m = new BookmarkManager(); 904 JFtp.desktop.add(m, new Integer(Integer.MAX_VALUE - 10)); 905 } 906 else if(marks.contains(e.getSource())) 907 { 908 ((BookmarkItem) e.getSource()).connect(); 909 } 910 else if(e.getSource() == storePasswords) 911 { 912 boolean state = storePasswords.getState(); 913 914 if(!state) 915 { 916 JOptionPane j = new JOptionPane(); 917 int x = j.showConfirmDialog(storePasswords, 918 "You chose not to Save passwords.\n" + 919 "Do you want your old login data to be deleted?", 920 "Delete old passwords?", 921 JOptionPane.YES_NO_OPTION); 922 923 if(x == JOptionPane.YES_OPTION) 924 { 925 File f = new File(Settings.login_def); 926 f.delete(); 927 928 f = new File(Settings.login_def_sftp); 929 f.delete(); 930 931 f = new File(Settings.login_def_nfs); 932 f.delete(); 933 934 f = new File(Settings.login_def_smb); 935 f.delete(); 936 937 f = new File(Settings.login); 938 f.delete(); 939 940 f = new File(Settings.last_cons); 941 f.delete(); 942 943 Log.debug("Deleted old login data files.\n" + 944 "Please edit your bookmarks file manually!"); 945 } 946 } 947 948 Settings.setProperty("jftp.security.storePasswords", state); 949 Settings.save(); 950 } 951 952 //*** END OF NEW LISTENERS 953 else 954 { 955 String tmp = ((JMenuItem) e.getSource()).getLabel(); 956 957 UIManager.LookAndFeelInfo[] m = UIManager.getInstalledLookAndFeels(); 958 959 for(int i = 0; i < m.length; i++) 960 { 961 if(m[i].getName().equals(tmp)) 962 { 963 JFtp.statusP.jftp.setLookAndFeel(m[i].getClassName()); 964 Settings.setProperty("jftp.gui.look", m[i].getClassName()); 965 Settings.save(); 966 } 967 } 968 } 969 } 970 catch(Exception ex) { 971 ex.printStackTrace(); 972 Log.debug(ex.toString()); 973 } 974 } 975 switchRSS(String url)976 private void switchRSS(String url) { 977 Settings.setProperty("jftp.customRSSFeed", url); 978 Settings.save(); 979 980 981 if(JFtp.statusP.jftp.feeder == null) { 982 JFtp.statusP.jftp.addRSS(); 983 } 984 985 JFtp.statusP.jftp.feeder.switchTo(url); 986 } 987 show(String file)988 private void show(String file) 989 { 990 java.net.URL url = ClassLoader.getSystemResource(file); 991 992 if(url == null) 993 { 994 url = HImage.class.getResource("/" + file); 995 } 996 997 Displayer d = new Displayer(url, null); 998 JFtp.desktop.add(d, new Integer(Integer.MAX_VALUE - 11)); 999 } 1000 1001 // by jake setMnemonics()1002 private void setMnemonics() 1003 { 1004 //*** I added accelerators for more menu items 1005 //*** (issue: should ALL accelerators have the CTRL modifier (so that 1006 //*** the ALT modifier is for mnemonics only?) 1007 //*** I added mnemonics for the main menu items 1008 file.setMnemonic('F'); 1009 opt.setMnemonic('O'); 1010 view.setMnemonic('V'); 1011 tools.setMnemonic('T'); 1012 bookmarks.setMnemonic('B'); 1013 info.setMnemonic('I'); 1014 1015 //*** set accelerators for the remote connection window 1016 ftpCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, 1017 ActionEvent.CTRL_MASK)); 1018 sftpCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, 1019 ActionEvent.CTRL_MASK)); 1020 smbCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, 1021 ActionEvent.CTRL_MASK)); 1022 nfsCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, 1023 ActionEvent.CTRL_MASK)); 1024 1025 //*** IMPORTANT NOTE: Adding an accelerator for disconnecting could 1026 //*** be something of a "gotcha" that we may not want 1027 close.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 1028 ActionEvent.CTRL_MASK)); 1029 1030 //*** These next five lines can be commented out if we decide against having accelerators 1031 //*** starting with the shift key 1032 //*** version 1.44: we have chosen not to have shift as a modifier 1033 //*** as we've found this is a "gotcha" 1034 /* 1035 localFtpCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, 1036 ActionEvent.SHIFT_MASK)); 1037 localSftpCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, 1038 ActionEvent.SHIFT_MASK)); 1039 localSmbCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, 1040 ActionEvent.SHIFT_MASK)); 1041 localNfsCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, 1042 ActionEvent.SHIFT_MASK)); 1043 1044 closeLocalCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 1045 ActionEvent.SHIFT_MASK)); 1046 1047 */ 1048 //*** I have decided to get areound the problem by having mnemonics within the menu 1049 //*** as accelerators. So to quickly start an FTP connection in the local window, 1050 //*** the user can enter Alt+f+f, and Alt+f+s for SFTP,etc. 1051 localFtpCon.setMnemonic('F'); 1052 localSftpCon.setMnemonic('S'); 1053 localSmbCon.setMnemonic('L'); 1054 localNfsCon.setMnemonic('N'); 1055 1056 //localNfsCon.setMnemonic('N'); 1057 closeLocalCon.setMnemonic('C'); 1058 1059 //*** and here are some other menu mnemonics I thought I'd include: 1060 //*** (I'll add more if more are wanted) 1061 exit.setMnemonic('X'); 1062 1063 proxy.setMnemonic('P'); 1064 1065 http.setMnemonic('D'); 1066 spider.setMnemonic('H'); 1067 raw.setMnemonic('T'); 1068 1069 readme.setMnemonic('R'); 1070 todo.setMnemonic('N'); 1071 changelog.setMnemonic('C'); 1072 hp.setMnemonic('H'); 1073 1074 opts.setMnemonic('A'); 1075 manage.setMnemonic('M'); 1076 1077 clear.setMnemonic('C'); 1078 clearItems.setMnemonic('F'); 1079 1080 try 1081 { 1082 //*** end of new code section 1083 Integer intI; 1084 String stringI; 1085 char charI; 1086 1087 for(int i = 0; i < jftp.CAPACITY; i++) 1088 { 1089 //*** I should note that functionality below only allows 1090 //*** a maximum of nine connections to be remembered 1091 //BUGFIX 1.40 1092 //if (!(cons[i].equals("null"))) { 1093 if(!(cons[i][0].equals("null"))) 1094 { 1095 intI = new Integer(i + 1); 1096 stringI = intI.toString(); 1097 charI = stringI.charAt(0); 1098 1099 lastConnections[i].setMnemonic(charI); 1100 1101 //lastConnections[i].setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); 1102 } 1103 } 1104 1105 //for 1106 } 1107 catch(Exception ex) 1108 { 1109 Log.out("WARNING: AppMenuBar produced Exception, ignored it"); 1110 ex.printStackTrace(); 1111 } 1112 } 1113 1114 //setMnemonics connectionSelected(int position)1115 private void connectionSelected(int position) 1116 { 1117 //*** tokenize the string to extract the required data 1118 //*** or is this the thing done elsewhere in the code, 1119 //*** when the menu is being set up? 1120 //String connectionInfo = cons[position]; 1121 //StringTokenizer tokens = new StringTokenizer(connectionInfo); 1122 //StringTokenizer tokens = new StringTokenizer(cons[position], " ", false); // tab); 1123 String protocol; 1124 int numTokens; 1125 1126 String htmp = new String(""); 1127 String utmp = new String(""); 1128 String ptmp = new String(""); 1129 String dtmp = new String(""); 1130 boolean useLocal = false; 1131 int potmp = 0; 1132 String potmpString = new String("0"); 1133 String useLocalString = new String("false"); 1134 1135 /* 1136 //numTokens = tokens.countTokens(); 1137 protocol = tokens.nextToken(); 1138 1139 htmp = tokens.nextToken(); 1140 utmp = tokens.nextToken(); 1141 ptmp = tokens.nextToken(); 1142 1143 */ 1144 protocol = cons[position][0]; 1145 htmp = cons[position][1]; 1146 utmp = cons[position][2]; 1147 ptmp = cons[position][3]; 1148 1149 if(ptmp.equals("")) 1150 { 1151 ptmp = UIUtils.getPasswordFromUser(JFtp.statusP.jftp); 1152 } 1153 1154 //int j=4; 1155 //while (cons[i][j].equals(LastConnections.SENTINEL)) { 1156 // j++; 1157 //} 1158 //usingLocal = cons[i][j-1]; 1159 1160 /* 1161 System.out.println(position); 1162 System.out.println(protocol); 1163 System.out.println(cons[position][1]); 1164 System.out.println(cons[position][2]); 1165 System.out.println(cons[position][3]); 1166 */ 1167 1168 // 1169 if(protocol.equals("FTP")) 1170 { 1171 potmpString = cons[position][4]; 1172 dtmp = cons[position][5]; 1173 useLocalString = cons[position][6]; 1174 1175 /* 1176 potmpString = tokens.nextToken(); 1177 dtmp = tokens.nextToken(); 1178 useLocalString = tokens.nextToken(); 1179 1180 1181 System.out.println(potmpString); 1182 System.out.println("FTP"); 1183 */ 1184 potmp = Integer.parseInt(potmpString); 1185 1186 if(useLocalString.equals("true")) 1187 { 1188 useLocal = true; 1189 } 1190 else 1191 { 1192 useLocal = false; 1193 } 1194 1195 StartConnection.startFtpCon(htmp, utmp, ptmp, potmp, dtmp, useLocal); 1196 1197 //System.out.println(htmp + utmp + ptmp + potmpString +dtmp + useLocalString); 1198 } 1199 else if(protocol.equals("SFTP")) 1200 { 1201 /* 1202 htmp = tokens.nextToken(); 1203 utmp = tokens.nextToken(); 1204 ptmp = tokens.nextToken(); 1205 */ 1206 1207 //useLocalString = tokens.nextToken(); 1208 //System.out.println("SFTP"); 1209 potmpString = cons[position][4]; 1210 useLocalString = cons[position][5]; 1211 1212 //System.out.println(htmp + utmp + ptmp + useLocalString); 1213 //if (protocol == "SFTP") 1214 } 1215 1216 else if(protocol.equals("NFS")) 1217 { 1218 useLocalString = cons[position][4]; 1219 } 1220 1221 else if(protocol.equals("SMB")) 1222 { 1223 /* 1224 htmp = tokens.nextToken(); 1225 utmp = tokens.nextToken(); 1226 ptmp = tokens.nextToken(); 1227 */ 1228 /* 1229 dtmp = tokens.nextToken(); 1230 useLocalString = tokens.nextToken(); 1231 */ 1232 dtmp = cons[position][4]; 1233 useLocalString = cons[position][5]; 1234 1235 //System.out.println(htmp+utmp+ptmp+dtmp + useLocalString); 1236 } 1237 1238 //***StartConnection functionality to be put in each 1239 //***if statement 1240 potmp = Integer.parseInt(potmpString); 1241 1242 if(useLocalString.equals("true")) 1243 { 1244 useLocal = true; 1245 } 1246 else 1247 { 1248 useLocal = false; 1249 } 1250 1251 if(protocol.equals("SFTP")) 1252 { 1253 //BUGFIX 1.40: no longer setting port # 1254 //to 22, now potmp 1255 StartConnection.startCon(protocol, htmp, utmp, ptmp, potmp, dtmp, 1256 useLocal); 1257 } 1258 else if(!(protocol.equals("FTP"))) 1259 { 1260 //System.out.println(protocol); 1261 StartConnection.startCon(protocol, htmp, utmp, ptmp, potmp, dtmp, 1262 useLocal); 1263 } 1264 } 1265 1266 //connectionSelected 1267 } 1268