1 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.ProxyChooser; 35 import net.sf.jftp.net.*; 36 import net.sf.jftp.system.logging.Log; 37 import net.sf.jftp.tools.*; 38 import net.sf.jftp.util.*; 39 40 import java.awt.*; 41 import java.awt.event.*; 42 43 import java.io.*; 44 45 import java.lang.Integer ; 46 47 import java.util.*; 48 49 import javax.swing.*; 50 51 import javazoom.jl.decoder.*; 52 import javazoom.jl.player.*; 53 54 55 public class AppMenuBar extends JMenuBar implements ActionListener 57 { 58 public static JCheckBoxMenuItem fadeMenu = new JCheckBoxMenuItem("Enable Status Animation", 59 Settings.getEnableStatusAnimation()); 60 public static JCheckBoxMenuItem askToDelete = new JCheckBoxMenuItem("Confirm Remove", 61 Settings.getAskToDelete()); 62 public static JCheckBoxMenuItem debug = new JCheckBoxMenuItem("Verbose Console Debugging", 63 Settings.getEnableDebug()); 64 public static JCheckBoxMenuItem disableLog = new JCheckBoxMenuItem("Disable Log", 65 Settings.getDisableLog()); 66 public static JMenuItem clearItems = new JMenuItem("Clear Finished Items"); 67 private JFtp jftp; 68 JMenu file = new JMenu("File"); 69 JMenu opt = new JMenu("Options"); 70 JMenu view = new JMenu("View"); 71 JMenu tools = new JMenu("Tools"); 72 JMenu bookmarks = new JMenu("Bookmarks"); 73 JMenu info = new JMenu("Info"); 74 JMenu lf = new JMenu(" Switch Look & Feel to"); 75 JMenu background = new JMenu("Desktop Background"); 76 JMenu ftp = new JMenu(" FTP"); 77 JMenu smb = new JMenu(" SMB"); 78 JMenu sftp = new JMenu(" SFTP"); 79 JMenu security = new JMenu("Security"); 80 JMenu experimental = new JMenu("Experimental Features"); 81 JMenu rss = new JMenu("RSS Feed"); 82 JMenu cnn = new JMenu("CNN"); 83 JMenuItem localFtpCon = new JMenuItem("Open FTP Connection in Local Tab..."); 84 JMenuItem localSftpCon = new JMenuItem("Open SFTP Connection in Local Tab..."); 85 JMenuItem localSmbCon = new JMenuItem("Open SMB/LAN Connection in Local Tab..."); 86 JMenuItem localNfsCon = new JMenuItem("Open NFS Connection in Local Tab..."); 87 JMenuItem localWebdavCon = new JMenuItem("Open WebDAV Connection in Local Tab... (ALPHA)"); 88 JMenuItem closeLocalCon = new JMenuItem("Close Active Connection in Local Tab"); 89 JMenuItem ftpCon = new JMenuItem("Connect to FTP Server..."); 90 JMenuItem sftpCon = new JMenuItem("Connect to SFTP Server..."); 91 JMenuItem smbCon = new JMenuItem("Connect to SMB Server / Browse LAN..."); 92 JMenuItem nfsCon = new JMenuItem("Connect to NFS Server..."); 93 JMenuItem webdavCon = new JMenuItem("Connect to WebDAV Server... (ALPHA)"); 94 JMenuItem close = new JMenuItem("Disconnect and Connect to Filesystem"); 95 JMenuItem exit = new JMenuItem("Exit"); 96 JMenuItem readme = new JMenuItem("Show Readme..."); 97 JMenuItem changelog = new JMenuItem("View Changelog..."); 98 JMenuItem todo = new JMenuItem("What's Next..."); 99 JMenuItem hp = new JMenuItem("Visit Project Homepage..."); 100 JMenuItem opts = new JMenuItem("Advanced Options..."); 101 JMenuItem http = new JMenuItem("Download File from URL..."); 102 JMenuItem raw = new JMenuItem("Raw TCP/IP Connection..."); 103 JMenuItem spider = new JMenuItem("Recursive HTTP Download..."); 104 JMenuItem sshShell = new JMenuItem("SSH Shell..."); 105 JMenuItem shell = new JMenuItem("Execute /bin/bash"); 106 JMenuItem loadAudio = new JMenuItem("Play MP3"); 107 JCheckBoxMenuItem rssDisabled = new JCheckBoxMenuItem("Enable RSS Feed", 108 Settings.getEnableRSS()); 109 JCheckBoxMenuItem nl = new JCheckBoxMenuItem("Show Newline Option", 110 Settings.showNewlineOption); 111 JMenuItem loadSlash = new JMenuItem("Slashdot"); 112 JMenuItem loadCNN1 = new JMenuItem("CNN Top Stories"); 113 JMenuItem loadCNN2 = new JMenuItem("CNN World"); 114 JMenuItem loadCNN3 = new JMenuItem("CNN Tech"); 115 JMenuItem loadRss = new JMenuItem("Custom RSS Feed"); 116 JCheckBoxMenuItem stdback = new JCheckBoxMenuItem("Background Image", 117 Settings.getUseBackground()); 118 JCheckBoxMenuItem resuming = new JCheckBoxMenuItem("Enable Resuming", 119 Settings.enableResuming); 120 JCheckBoxMenuItem ask = new JCheckBoxMenuItem("Always Ask to Resume", 121 Settings.askToResume); 122 JMenuItem proxy = new JMenuItem("Proxy Settings..."); 123 JCheckBoxMenuItem smbThreads = new JCheckBoxMenuItem("Multiple Connections", 124 Settings.getEnableSmbMultiThreading()); 125 JCheckBoxMenuItem sftpThreads = new JCheckBoxMenuItem("Multiple Connections", 126 Settings.getEnableSftpMultiThreading()); 127 JCheckBoxMenuItem sshKeys = new JCheckBoxMenuItem("Enable Host Key check", 128 Settings.getEnableSshKeys()); 129 JCheckBoxMenuItem storePasswords = new JCheckBoxMenuItem("Store passwords (plaintext)", 130 Settings.getStorePasswords()); 131 132 JCheckBoxMenuItem useTableLayout = new JCheckBoxMenuItem("Use JTable layout", 133 Settings.getUseJTableLayout()); 134 135 JCheckBoxMenuItem useNewIcons = new JCheckBoxMenuItem("Use Silk Icons", 136 Settings.getUseNewIcons()); 137 138 JCheckBoxMenuItem hideHidden = new JCheckBoxMenuItem("Hide local hidden files (Unix only)", 139 Settings.getHideLocalDotNames()); 140 141 JMenuItem clear = new JMenuItem("Clear Log"); 142 143 JMenuItem[] lastConnections = new JMenuItem[jftp.CAPACITY]; 145 146 String [][] cons = new String [jftp.CAPACITY][JFtp.CONNECTION_DATA_LENGTH]; 149 String [] lastConData = new String [jftp.CAPACITY]; 150 Character charTab = new Character ('\t'); 151 String tab = charTab.toString(); 152 JMenuItem manage = new JMenuItem("Manage Bookmarks..."); 153 JMenuItem add = new JMenuItem("Add Bookmark..."); 154 Hashtable marks; 155 JMenu current = bookmarks; 156 JMenu last = bookmarks; 157 158 163 public AppMenuBar(JFtp jftp) 164 { 165 this.jftp = jftp; 166 167 ftpCon.addActionListener(this); 168 close.addActionListener(this); 169 exit.addActionListener(this); 170 readme.addActionListener(this); 171 changelog.addActionListener(this); 172 todo.addActionListener(this); 173 resuming.addActionListener(this); 174 ask.addActionListener(this); 175 smbCon.addActionListener(this); 176 clear.addActionListener(this); 177 sftpCon.addActionListener(this); 178 fadeMenu.addActionListener(this); 179 askToDelete.addActionListener(this); 180 smbThreads.addActionListener(this); 181 sftpThreads.addActionListener(this); 182 debug.addActionListener(this); 183 disableLog.addActionListener(this); 184 http.addActionListener(this); 185 hp.addActionListener(this); 186 raw.addActionListener(this); 187 nfsCon.addActionListener(this); 188 spider.addActionListener(this); 189 proxy.addActionListener(this); 190 stdback.addActionListener(this); 191 opts.addActionListener(this); 192 webdavCon.addActionListener(this); 193 sshShell.addActionListener(this); 194 shell.addActionListener(this); 195 nl.addActionListener(this); 196 197 localFtpCon.addActionListener(this); 198 localSftpCon.addActionListener(this); 199 localSmbCon.addActionListener(this); 200 localNfsCon.addActionListener(this); 201 localWebdavCon.addActionListener(this); 202 closeLocalCon.addActionListener(this); 203 add.addActionListener(this); 204 storePasswords.addActionListener(this); 205 rssDisabled.addActionListener(this); 206 loadRss.addActionListener(this); 207 loadSlash.addActionListener(this); 208 loadCNN1.addActionListener(this); 209 loadCNN2.addActionListener(this); 210 loadCNN3.addActionListener(this); 211 loadAudio.addActionListener(this); 212 useTableLayout.addActionListener(this); 213 useNewIcons.addActionListener(this); 214 hideHidden.addActionListener(this); 215 216 clearItems.addActionListener(JFtp.dList); 217 218 clear.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, 219 ActionEvent.ALT_MASK)); 220 clearItems.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, 221 ActionEvent.ALT_MASK)); 222 changelog.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, 223 ActionEvent.ALT_MASK)); 224 readme.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4, 225 ActionEvent.ALT_MASK)); 226 todo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_5, 227 ActionEvent.ALT_MASK)); 228 229 resetFileItems(); 232 233 ftp.add(resuming); 234 ftp.add(ask); 235 ftp.add(nl); 236 smb.add(smbThreads); 237 sftp.add(sftpThreads); 238 sftp.add(sshKeys); 239 security.add(askToDelete); 240 security.add(storePasswords); 241 242 cnn.add(loadCNN1); 243 cnn.add(loadCNN2); 244 cnn.add(loadCNN3); 245 246 rss.add(rssDisabled); 247 rss.add(loadSlash); 248 rss.add(cnn); 249 rss.add(loadRss); 250 251 opt.add(security); 252 opt.addSeparator(); 253 opt.add(ftp); 254 opt.add(smb); 255 opt.add(sftp); 256 opt.addSeparator(); 257 opt.add(proxy); 258 opt.add(opts); 259 260 tools.add(http); 261 tools.add(spider); 262 tools.addSeparator(); 263 tools.add(raw); 264 tools.addSeparator(); 265 tools.add(sshShell); 266 tools.add(shell); 267 268 view.add(hideHidden); 269 view.addSeparator(); 270 view.add(useTableLayout); 271 view.add(useNewIcons); 272 view.add(fadeMenu); 273 view.add(clear); 274 view.add(clearItems); 275 276 view.addSeparator(); 277 view.add(debug); 278 view.add(disableLog); 279 view.addSeparator(); 280 view.add(rss); 281 view.addSeparator(); 282 283 info.add(readme); 284 info.add(changelog); 285 info.add(todo); 286 info.addSeparator(); 287 info.add(hp); 288 289 UIManager.LookAndFeelInfo[] m = UIManager.getInstalledLookAndFeels(); 290 291 for(int i = 0; i < m.length; i++) 292 { 293 297 307 try 308 { 309 LookAndFeel lnf = (LookAndFeel) Class.forName(m[i].getClassName()) 310 .newInstance(); 311 312 if(lnf.isSupportedLookAndFeel()) 313 { 314 JMenuItem tmp = new JMenuItem(m[i].getName()); 315 tmp.addActionListener(this); 316 lf.add(tmp); 317 } 318 } 319 catch(ClassNotFoundException cnfe) 320 { 321 continue; 322 } 323 catch(InstantiationException ie) 324 { 325 continue; 326 } 327 catch(IllegalAccessException iae) 328 { 329 continue; 330 } 331 } 332 333 view.add(lf); 334 335 background.add(stdback); 336 view.add(background); 337 338 manage.addActionListener(this); 339 340 add(file); 342 add(opt); 343 add(view); 344 add(tools); 345 add(bookmarks); 346 add(info); 347 348 loadBookmarks(); 349 350 } 352 353 public void loadBookmarks() 354 { 355 marks = new Hashtable(); 356 bookmarks.removeAll(); 357 bookmarks.add(add); 358 bookmarks.add(manage); 359 bookmarks.addSeparator(); 360 361 String data = ""; 362 363 try 364 { 365 DataInput in = new DataInputStream(new BufferedInputStream(new FileInputStream(Settings.bookmarks))); 366 367 while((data = in.readLine()) != null) 368 { 369 if(!data.startsWith("#") && !data.trim().equals("")) 370 { 371 addBookmarkLine(data); 372 } 373 } 374 } 375 catch(IOException e) 376 { 377 Log.debug("No bookmarks.txt found, using defaults."); 378 addBookmark("FTP", "ftp.kernel.org", "anonymous", "j-ftp@sf.net", 379 21, "/pub/linux/kernel", "false"); 380 addBookmark("FTP", "upload.sourceforge.net", "anonymous", 381 "j-ftp@sf.net", 21, "/incoming", "false"); 382 addBookmark("SMB", "(LAN)", "guest", "guest", -1, "-", "false"); 383 384 return; 385 } 386 } 387 388 private void addBookmarkLine(String tmp) 389 { 390 try 391 { 392 StringTokenizer t = new StringTokenizer(tmp, "#", false); 393 394 if(tmp.toLowerCase().trim().startsWith("<dir>")) 395 { 396 String dir = tmp.substring(tmp.indexOf(">") + 1, 397 tmp.lastIndexOf("<")); 398 399 JMenu m = new JMenu(dir); 401 current.add(m); 402 403 last = current; 404 current = m; 405 } 406 else if(tmp.toLowerCase().trim().startsWith("<enddir>")) 407 { 408 current = last; 409 } 410 else 411 { 412 addBookmark(t.nextToken(), t.nextToken(), t.nextToken(), 413 t.nextToken(), Integer.parseInt(t.nextToken()), 414 t.nextToken(), t.nextToken()); 415 } 416 } 417 catch(Exception ex) 418 { 419 Log.debug("Broken line: " + tmp); 420 ex.printStackTrace(); 421 } 422 } 423 424 public void addBookmark(String pr, String h, String u, String p, int po, 425 String d, String l) 426 { 427 BookmarkItem x = new BookmarkItem(h); 428 x.setUserdata(u, p); 429 430 if(l.trim().startsWith("t")) 431 { 432 x.setLocal(true); 433 } 434 435 x.setPort(po); 436 x.setProtocol(pr); 437 x.setDirectory(d); 438 439 current.add(x); 441 marks.put(x.getLabel(), x); 442 x.addActionListener(this); 443 } 444 445 public void resetFileItems() 447 { 448 file.removeAll(); 449 450 file.add(ftpCon); 451 file.add(sftpCon); 452 file.add(smbCon); 453 file.add(nfsCon); 454 file.add(webdavCon); 455 file.addSeparator(); 456 file.add(close); 457 file.addSeparator(); 458 file.addSeparator(); 459 file.add(localFtpCon); 460 file.add(localSftpCon); 461 file.add(localSmbCon); 462 file.add(localNfsCon); 463 464 file.addSeparator(); 466 file.add(closeLocalCon); 467 file.addSeparator(); 468 469 boolean connectionsExist = false; 471 472 try 473 { 474 cons = new String [jftp.CAPACITY][jftp.CONNECTION_DATA_LENGTH]; 476 477 cons = LastConnections.readFromFile(jftp.CAPACITY); 478 479 String protocol; 480 481 String htmp; 482 483 String utmp; 484 485 String conNumber; 486 String usingLocal = new String (""); 487 Integer conNumberInt; 488 489 for(int i = 0; i < jftp.CAPACITY; i++) 492 { 493 if(!(cons[i][0].equals("null"))) 494 { 495 protocol = cons[i][0]; 496 htmp = cons[i][1]; 497 utmp = cons[i][2]; 498 499 int j = 3; 500 501 while(!(cons[i][j].equals(LastConnections.SENTINEL))) 502 { 503 j++; 504 } 505 506 usingLocal = cons[i][j - 1]; 508 509 if(usingLocal.equals("true")) 510 { 511 usingLocal = "(in local tab)"; 512 } 513 514 else 515 { 516 usingLocal = ""; 517 } 518 519 conNumberInt = new Integer (i + 1); 521 conNumber = conNumberInt.toString(); 522 523 lastConData[i] = new String (conNumber + " " + protocol + 525 ": " + htmp + " " + usingLocal); 526 527 lastConnections[i] = new JMenuItem(lastConData[i]); 528 lastConnections[i].addActionListener(this); 529 530 connectionsExist = true; 531 532 file.add(lastConnections[i]); 536 } 537 } 538 } 539 catch(Exception ex) 540 { 541 Log.debug("WARNING: Remembered connections broken."); 542 ex.printStackTrace(); 543 } 544 545 if(connectionsExist) 546 { 547 file.addSeparator(); 548 } 549 550 file.add(exit); 551 552 setMnemonics(); 553 } 554 555 public void actionPerformed(ActionEvent e) 557 { 558 if(e.getSource() == proxy) 559 { 560 JFtp.statusP.jftp.addToDesktop("Proxy Settings", 562 new ProxyChooser(), 500, 110); 563 } 564 else if(e.getSource() == add) 565 { 566 Log.out("add called"); 567 568 AddBookmarks a = new AddBookmarks(JFtp.statusP.jftp); 569 a.update(); 570 } 571 else if(e.getSource() == webdavCon) 572 { 573 WebdavHostChooser hc = new WebdavHostChooser(); 574 hc.toFront(); 575 hc.update(); 576 } 577 else if((e.getSource() == localFtpCon) && (!jftp.uiBlocked)) 578 { 579 HostChooser hc = new HostChooser(null, true); 580 hc.toFront(); 581 582 hc.update(); 584 } 585 else if((e.getSource() == localSmbCon) && (!jftp.uiBlocked)) 586 { 587 SmbHostChooser hc = new SmbHostChooser(null, true); 588 hc.toFront(); 589 590 hc.update(); 592 } 593 else if((e.getSource() == localSftpCon) && (!jftp.uiBlocked)) 594 { 595 SftpHostChooser hc = new SftpHostChooser(null, true); 596 hc.toFront(); 597 598 hc.update(); 600 } 601 else if((e.getSource() == localNfsCon) && (!jftp.uiBlocked)) 602 { 603 NfsHostChooser hc = new NfsHostChooser(null, true); 604 hc.toFront(); 605 606 hc.update(); 608 } 609 else if((e.getSource() == localWebdavCon) && (!jftp.uiBlocked)) 610 { 611 WebdavHostChooser hc = new WebdavHostChooser(null, true); 612 hc.toFront(); 613 614 hc.update(); 616 } 617 else if(e.getSource() == closeLocalCon) 618 { 619 JFtp.statusP.jftp.closeCurrentLocalTab(); 620 } 621 else if(e.getSource() == clear) 622 { 623 jftp.clearLog(); 624 } 625 else if(e.getSource() == spider) 626 { 627 jftp.addToDesktop("Http recursive download", 628 new HttpSpider(jftp.localDir.getPath() + 629 "_httpdownload/"), 440, 250); 630 } 631 else if(e.getSource() == hp) 632 { 633 HttpBrowser h = new HttpBrowser("http://j-ftp.sourceforge.net"); 634 JFtp.desktop.add(h, new Integer (Integer.MAX_VALUE - 10)); 635 } 636 else if(e.getSource() == raw) 637 { 638 RawConnection c = new RawConnection(); 639 } 640 else if(e.getSource() == readme) 641 { 642 show(Settings.readme); 643 } 644 else if(e.getSource() == changelog) 645 { 646 show(Settings.changelog); 647 } 648 else if(e.getSource() == todo) 649 { 650 show(Settings.todo); 651 } 652 else if(e.getSource() == shell) 653 { 654 UIUtils.runCommand("/bin/bash"); 655 } 656 else if(e.getSource() == loadAudio) 657 { 658 try 659 { 660 JFileChooser f = new JFileChooser(); 661 f.showOpenDialog(jftp); 662 663 File file = f.getSelectedFile(); 664 665 Player p = new Player(new FileInputStream(file)); 666 667 p.play(); 668 } 669 catch(Exception ex) 670 { 671 ex.printStackTrace(); 672 Log.debug("Error: (" + ex + ")"); 673 } 674 } 675 else if(e.getSource() == exit) 676 { 677 jftp.windowClosing(null); } 679 else if(e.getSource() == close) 680 { 681 JFtp.statusP.jftp.closeCurrentTab(); 682 683 690 } 691 else if((e.getSource() == ftpCon) && (!jftp.uiBlocked)) 692 { 693 HostChooser hc = new HostChooser(); 695 hc.toFront(); 696 697 hc.update(); 699 } 700 else if((e.getSource() == smbCon) && (!jftp.uiBlocked)) 701 { 702 SmbHostChooser hc = new SmbHostChooser(); 704 hc.toFront(); 705 706 hc.update(); 708 } 709 else if((e.getSource() == sftpCon) && (!jftp.uiBlocked)) 710 { 711 SftpHostChooser hc = new SftpHostChooser(); 713 hc.toFront(); 714 715 hc.update(); 717 } 718 else if((e.getSource() == nfsCon) && (!jftp.uiBlocked)) 719 { 720 NfsHostChooser hc = new NfsHostChooser(); 722 hc.toFront(); 723 724 hc.update(); 726 } 727 else if(e.getSource() == resuming) 728 { 729 boolean res = resuming.getState(); 730 Settings.enableResuming = res; 731 Settings.setProperty("jftp.enableResuming", res); 732 ask.setEnabled(Settings.enableResuming); 733 Settings.save(); 734 } 735 else if(e.getSource() == useTableLayout) 736 { 737 boolean res = useTableLayout.getState(); 738 Settings.setProperty("jftp.useJTableLayout", res); 739 Settings.save(); 740 741 JOptionPane.showMessageDialog(this, "Please restart JFtp to have the UI changed."); 742 } 743 else if(e.getSource() == useNewIcons) 744 { 745 boolean res = useNewIcons.getState(); 746 Settings.setProperty("jftp.gui.look.newIcons", res); 747 Settings.save(); 748 749 JOptionPane.showMessageDialog(this, "Please restart JFtp to have the UI changed."); 750 } 751 else if(e.getSource() == hideHidden) 752 { 753 boolean res = hideHidden.getState(); 754 Settings.setProperty("jftp.hideHiddenDotNames", res); 755 Settings.save(); 756 757 JFtp.localUpdate(); 758 } 759 else if(e.getSource() == nl) 760 { 761 boolean res = nl.getState(); 762 Settings.showNewlineOption = res; 763 } 764 else if(e.getSource() == stdback) 765 { 766 Settings.setProperty("jftp.useBackground", stdback.getState()); 767 Settings.save(); 768 JFtp.statusP.jftp.fireUpdate(); 769 } 770 else if(e.getSource() == sshKeys) 771 { 772 Settings.setProperty("jftp.useSshKeyVerification", 773 sshKeys.getState()); 774 Settings.save(); 775 JFtp.statusP.jftp.fireUpdate(); 776 } 777 else if(e.getSource() == rssDisabled) 778 { 779 Settings.setProperty("jftp.enableRSS", rssDisabled.getState()); 780 Settings.save(); 781 JFtp.statusP.jftp.fireUpdate(); 782 } 783 else if(e.getSource() == loadRss) 784 { 785 String what = JOptionPane.showInputDialog("Enter URL", "http://"); 786 787 if(what == null) 788 { 789 return; 790 } 791 792 Settings.setProperty("jftp.customRSSFeed", what); 793 Settings.save(); 794 795 JFtp.statusP.jftp.feeder.switchTo(what); 796 } 797 else if(e.getSource() == loadSlash) 798 { 799 Settings.setProperty("jftp.customRSSFeed", 800 "http://slashdot.org/rss/slashdot.rss"); 801 Settings.save(); 802 803 JFtp.statusP.jftp.feeder.switchTo("http://slashdot.org/rss/slashdot.rss"); 804 } 805 else if(e.getSource() == loadCNN1) 806 { 807 Settings.setProperty("jftp.customRSSFeed", 808 "http://rss.cnn.com/rss/cnn_topstories.rss"); 809 Settings.save(); 810 811 JFtp.statusP.jftp.feeder.switchTo("http://rss.cnn.com/rss/cnn_topstories.rss"); 812 } 813 else if(e.getSource() == loadCNN2) 814 { 815 Settings.setProperty("jftp.customRSSFeed", 816 "http://rss.cnn.com/rss/cnn_world.rss"); 817 Settings.save(); 818 819 JFtp.statusP.jftp.feeder.switchTo("http://rss.cnn.com/rss/cnn_world.rss"); 820 } 821 else if(e.getSource() == loadCNN3) 822 { 823 Settings.setProperty("jftp.customRSSFeed", 824 "http://rss.cnn.com/rss/cnn_tech.rss"); 825 Settings.save(); 826 827 JFtp.statusP.jftp.feeder.switchTo("http://rss.cnn.com/rss/cnn_tech.rss"); 828 } 829 else if(e.getSource() == debug) 830 { 831 Settings.setProperty("jftp.enableDebug", debug.getState()); 832 Settings.save(); 833 } 834 else if(e.getSource() == disableLog) 835 { 836 Settings.setProperty("jftp.disableLog", disableLog.getState()); 837 Settings.save(); 838 } 839 else if(e.getSource() == smbThreads) 840 { 841 Settings.setProperty("jftp.enableSmbMultiThreading", 842 smbThreads.getState()); 843 Settings.save(); 844 } 845 else if(e.getSource() == sftpThreads) 846 { 847 Settings.setProperty("jftp.enableSftpMultiThreading", 848 sftpThreads.getState()); 849 Settings.save(); 850 } 851 else if(e.getSource() == ask) 852 { 853 Settings.askToResume = ask.getState(); 854 } 855 else if(e.getSource() == http) 856 { 857 HttpDownloader dl = new HttpDownloader(); 858 jftp.addToDesktop("Http download", dl, 480, 100); 859 jftp.setLocation(dl.hashCode(), 100, 150); 860 } 861 else if(e.getSource() == fadeMenu) 862 { 863 Settings.setProperty("jftp.gui.enableStatusAnimation", 864 fadeMenu.getState()); 865 Settings.save(); 866 } 867 else if(e.getSource() == askToDelete) 868 { 869 Settings.setProperty("jftp.gui.askToDelete", askToDelete.getState()); 870 Settings.save(); 871 } 872 873 else if((e.getSource() == lastConnections[0]) && (!jftp.uiBlocked)) 876 { 877 connectionSelected(0); 878 } 879 880 else if((e.getSource() == lastConnections[1]) && (!jftp.uiBlocked)) 881 { 882 connectionSelected(1); 883 } 884 else if((e.getSource() == lastConnections[2]) && (!jftp.uiBlocked)) 885 { 886 connectionSelected(2); 887 } 888 else if((e.getSource() == lastConnections[3]) && (!jftp.uiBlocked)) 889 { 890 connectionSelected(3); 891 } 892 else if((e.getSource() == lastConnections[4]) && (!jftp.uiBlocked)) 893 { 894 connectionSelected(4); 895 } 896 else if((e.getSource() == lastConnections[5]) && (!jftp.uiBlocked)) 897 { 898 connectionSelected(5); 899 } 900 else if((e.getSource() == lastConnections[6]) && (!jftp.uiBlocked)) 901 { 902 connectionSelected(6); 903 } 904 else if((e.getSource() == lastConnections[7]) && (!jftp.uiBlocked)) 905 { 906 connectionSelected(7); 907 } 908 else if((e.getSource() == lastConnections[8]) && (!jftp.uiBlocked)) 909 { 910 connectionSelected(8); 911 } 912 else if(e.getSource() == opts) 913 { 914 AdvancedOptions adv = new AdvancedOptions(); 915 jftp.addToDesktop("Advanced Options", adv, 500, 180); 916 jftp.setLocation(adv.hashCode(), 110, 180); 917 } 918 else if(e.getSource() == manage) 919 { 920 BookmarkManager m = new BookmarkManager(); 921 JFtp.desktop.add(m, new Integer (Integer.MAX_VALUE - 10)); 922 } 923 else if(marks.contains(e.getSource())) 924 { 925 ((BookmarkItem) e.getSource()).connect(); 926 } 927 else if(e.getSource() == storePasswords) 928 { 929 boolean state = storePasswords.getState(); 930 931 if(!state) 932 { 933 JOptionPane j = new JOptionPane(); 934 int x = j.showConfirmDialog(storePasswords, 935 "You chose not to Save passwords.\n" + 936 "Do you want your old login data to be deleted?", 937 "Delete old passwords?", 938 JOptionPane.YES_NO_OPTION); 939 940 if(x == JOptionPane.YES_OPTION) 941 { 942 File f = new File(Settings.login_def); 943 f.delete(); 944 945 f = new File(Settings.login_def_sftp); 946 f.delete(); 947 948 f = new File(Settings.login_def_nfs); 949 f.delete(); 950 951 f = new File(Settings.login_def_smb); 952 f.delete(); 953 954 f = new File(Settings.login); 955 f.delete(); 956 957 f = new File(Settings.last_cons); 958 f.delete(); 959 960 Log.debug("Deleted old login data files.\n" + 961 "Please edit your bookmarks file manually!"); 962 } 963 } 964 965 Settings.setProperty("jftp.security.storePasswords", state); 966 Settings.save(); 967 } 968 else if(e.getSource() == sshShell) 969 { 970 SftpHostChooser c = new SftpHostChooser(true); 971 c.update(); 972 } 973 974 else 976 { 977 String tmp = ((JMenuItem) e.getSource()).getLabel(); 978 979 UIManager.LookAndFeelInfo[] m = UIManager.getInstalledLookAndFeels(); 980 981 for(int i = 0; i < m.length; i++) 982 { 983 if(m[i].getName().equals(tmp)) 984 { 985 JFtp.statusP.jftp.setLookAndFeel(m[i].getClassName()); 986 Settings.setProperty("jftp.gui.look", m[i].getClassName()); 987 Settings.save(); 988 } 989 } 990 } 991 } 992 993 private void show(String file) 994 { 995 java.net.URL url = ClassLoader.getSystemResource(file); 996 997 if(url == null) 998 { 999 url = HImage.class.getResource("/" + file); 1000 } 1001 1002 Displayer d = new Displayer(url, null); 1003 JFtp.desktop.add(d, new Integer (Integer.MAX_VALUE - 11)); 1004 } 1005 1006 private void setMnemonics() 1008 { 1009 file.setMnemonic('F'); 1014 opt.setMnemonic('O'); 1015 view.setMnemonic('V'); 1016 tools.setMnemonic('T'); 1017 bookmarks.setMnemonic('B'); 1018 info.setMnemonic('I'); 1019 1020 ftpCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, 1022 ActionEvent.CTRL_MASK)); 1023 sftpCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, 1024 ActionEvent.CTRL_MASK)); 1025 smbCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, 1026 ActionEvent.CTRL_MASK)); 1027 nfsCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, 1028 ActionEvent.CTRL_MASK)); 1029 1030 close.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 1033 ActionEvent.CTRL_MASK)); 1034 1035 1053 localFtpCon.setMnemonic('F'); 1057 localSftpCon.setMnemonic('S'); 1058 localSmbCon.setMnemonic('L'); 1059 localNfsCon.setMnemonic('N'); 1060 1061 closeLocalCon.setMnemonic('C'); 1063 1064 exit.setMnemonic('X'); 1067 1068 proxy.setMnemonic('P'); 1069 1070 http.setMnemonic('D'); 1071 spider.setMnemonic('H'); 1072 raw.setMnemonic('T'); 1073 1074 readme.setMnemonic('R'); 1075 todo.setMnemonic('N'); 1076 changelog.setMnemonic('C'); 1077 hp.setMnemonic('H'); 1078 1079 opts.setMnemonic('A'); 1080 manage.setMnemonic('M'); 1081 1082 clear.setMnemonic('C'); 1083 clearItems.setMnemonic('F'); 1084 1085 try 1086 { 1087 Integer intI; 1089 String stringI; 1090 char charI; 1091 1092 for(int i = 0; i < jftp.CAPACITY; i++) 1093 { 1094 if(!(cons[i][0].equals("null"))) 1099 { 1100 intI = new Integer (i + 1); 1101 stringI = intI.toString(); 1102 charI = stringI.charAt(0); 1103 1104 lastConnections[i].setMnemonic(charI); 1105 1106 } 1108 } 1109 1110 } 1112 catch(Exception ex) 1113 { 1114 Log.out("WARNING: AppMenuBar produced Exception, ignored it"); 1115 ex.printStackTrace(); 1116 } 1117 } 1118 1119 private void connectionSelected(int position) 1121 { 1122 String protocol; 1129 int numTokens; 1130 1131 String htmp = new String (""); 1132 String utmp = new String (""); 1133 String ptmp = new String (""); 1134 String dtmp = new String (""); 1135 boolean useLocal = false; 1136 int potmp = 0; 1137 String potmpString = new String ("0"); 1138 String useLocalString = new String ("false"); 1139 1140 1149 protocol = cons[position][0]; 1150 htmp = cons[position][1]; 1151 utmp = cons[position][2]; 1152 ptmp = cons[position][3]; 1153 1154 if(ptmp.equals("")) 1155 { 1156 ptmp = UIUtils.getPasswordFromUser(JFtp.statusP.jftp); 1157 } 1158 1159 1165 1172 1173 if(protocol.equals("FTP")) 1175 { 1176 potmpString = cons[position][4]; 1177 dtmp = cons[position][5]; 1178 useLocalString = cons[position][6]; 1179 1180 1189 potmp = Integer.parseInt(potmpString); 1190 1191 if(useLocalString.equals("true")) 1192 { 1193 useLocal = true; 1194 } 1195 else 1196 { 1197 useLocal = false; 1198 } 1199 1200 StartConnection.startFtpCon(htmp, utmp, ptmp, potmp, dtmp, useLocal); 1201 1202 } 1204 else if(protocol.equals("SFTP")) 1205 { 1206 1211 1212 potmpString = cons[position][4]; 1215 useLocalString = cons[position][5]; 1216 1217 } 1220 1221 else if(protocol.equals("NFS")) 1222 { 1223 useLocalString = cons[position][4]; 1224 } 1225 1226 else if(protocol.equals("SMB")) 1227 { 1228 1233 1237 dtmp = cons[position][4]; 1238 useLocalString = cons[position][5]; 1239 1240 } 1242 1243 potmp = Integer.parseInt(potmpString); 1246 1247 if(useLocalString.equals("true")) 1248 { 1249 useLocal = true; 1250 } 1251 else 1252 { 1253 useLocal = false; 1254 } 1255 1256 if(protocol.equals("SFTP")) 1257 { 1258 StartConnection.startCon(protocol, htmp, utmp, ptmp, potmp, dtmp, 1261 useLocal); 1262 } 1263 else if(!(protocol.equals("FTP"))) 1264 { 1265 StartConnection.startCon(protocol, htmp, utmp, ptmp, potmp, dtmp, 1267 useLocal); 1268 } 1269 } 1270 1271 } 1273 | Popular Tags |