0001: /*
0002: * This program is free software; you can redistribute it and/or
0003: * modify it under the terms of the GNU General Public License
0004: * as published by the Free Software Foundation; either version 2
0005: * of the License, or (at your option) any later version.
0006: *
0007: * This program is distributed in the hope that it will be useful,
0008: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0009: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0010: * GNU General Public License for more details.
0011:
0012: * You should have received a copy of the GNU General Public License
0013: * along with this program; if not, write to the Free Software
0014: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
0015: */
0016: package net.sf.jftp.gui.base;
0017:
0018: import net.sf.jftp.JFtp;
0019: import net.sf.jftp.config.Settings;
0020: import net.sf.jftp.gui.framework.*;
0021: import net.sf.jftp.gui.hostchooser.HostChooser;
0022: import net.sf.jftp.gui.hostchooser.NfsHostChooser;
0023: import net.sf.jftp.gui.hostchooser.SftpHostChooser;
0024: import net.sf.jftp.gui.hostchooser.SmbHostChooser;
0025: import net.sf.jftp.gui.hostchooser.WebdavHostChooser;
0026: import net.sf.jftp.gui.tasks.AddBookmarks;
0027: import net.sf.jftp.gui.tasks.AdvancedOptions;
0028: import net.sf.jftp.gui.tasks.BookmarkItem;
0029: import net.sf.jftp.gui.tasks.BookmarkManager;
0030: import net.sf.jftp.gui.tasks.Displayer;
0031: import net.sf.jftp.gui.tasks.HttpBrowser;
0032: import net.sf.jftp.gui.tasks.HttpDownloader;
0033: import net.sf.jftp.gui.tasks.LastConnections;
0034: import net.sf.jftp.gui.tasks.ProxyChooser;
0035: import net.sf.jftp.net.*;
0036: import net.sf.jftp.system.logging.Log;
0037: import net.sf.jftp.tools.*;
0038: import net.sf.jftp.util.*;
0039:
0040: import java.awt.*;
0041: import java.awt.event.*;
0042:
0043: import java.io.*;
0044:
0045: import java.lang.Integer;
0046:
0047: import java.util.*;
0048:
0049: import javax.swing.*;
0050:
0051: import javazoom.jl.decoder.*;
0052: import javazoom.jl.player.*;
0053:
0054: //***
0055: public class AppMenuBar extends JMenuBar implements ActionListener {
0056: public static JCheckBoxMenuItem fadeMenu = new JCheckBoxMenuItem(
0057: "Enable Status Animation", Settings
0058: .getEnableStatusAnimation());
0059: public static JCheckBoxMenuItem askToDelete = new JCheckBoxMenuItem(
0060: "Confirm Remove", Settings.getAskToDelete());
0061: public static JCheckBoxMenuItem debug = new JCheckBoxMenuItem(
0062: "Verbose Console Debugging", Settings.getEnableDebug());
0063: public static JCheckBoxMenuItem disableLog = new JCheckBoxMenuItem(
0064: "Disable Log", Settings.getDisableLog());
0065: public static JMenuItem clearItems = new JMenuItem(
0066: "Clear Finished Items");
0067: private JFtp jftp;
0068: JMenu file = new JMenu("File");
0069: JMenu opt = new JMenu("Options");
0070: JMenu view = new JMenu("View");
0071: JMenu tools = new JMenu("Tools");
0072: JMenu bookmarks = new JMenu("Bookmarks");
0073: JMenu info = new JMenu("Info");
0074: JMenu lf = new JMenu(" Switch Look & Feel to");
0075: JMenu background = new JMenu("Desktop Background");
0076: JMenu ftp = new JMenu(" FTP");
0077: JMenu smb = new JMenu(" SMB");
0078: JMenu sftp = new JMenu(" SFTP");
0079: JMenu security = new JMenu("Security");
0080: JMenu experimental = new JMenu("Experimental Features");
0081: JMenu rss = new JMenu("RSS Feed");
0082: JMenu cnn = new JMenu("CNN");
0083: JMenuItem localFtpCon = new JMenuItem(
0084: "Open FTP Connection in Local Tab...");
0085: JMenuItem localSftpCon = new JMenuItem(
0086: "Open SFTP Connection in Local Tab...");
0087: JMenuItem localSmbCon = new JMenuItem(
0088: "Open SMB/LAN Connection in Local Tab...");
0089: JMenuItem localNfsCon = new JMenuItem(
0090: "Open NFS Connection in Local Tab...");
0091: JMenuItem localWebdavCon = new JMenuItem(
0092: "Open WebDAV Connection in Local Tab... (ALPHA)");
0093: JMenuItem closeLocalCon = new JMenuItem(
0094: "Close Active Connection in Local Tab");
0095: JMenuItem ftpCon = new JMenuItem("Connect to FTP Server...");
0096: JMenuItem sftpCon = new JMenuItem("Connect to SFTP Server...");
0097: JMenuItem smbCon = new JMenuItem(
0098: "Connect to SMB Server / Browse LAN...");
0099: JMenuItem nfsCon = new JMenuItem("Connect to NFS Server...");
0100: JMenuItem webdavCon = new JMenuItem(
0101: "Connect to WebDAV Server... (ALPHA)");
0102: JMenuItem close = new JMenuItem(
0103: "Disconnect and Connect to Filesystem");
0104: JMenuItem exit = new JMenuItem("Exit");
0105: JMenuItem readme = new JMenuItem("Show Readme...");
0106: JMenuItem changelog = new JMenuItem("View Changelog...");
0107: JMenuItem todo = new JMenuItem("What's Next...");
0108: JMenuItem hp = new JMenuItem("Visit Project Homepage...");
0109: JMenuItem opts = new JMenuItem("Advanced Options...");
0110: JMenuItem http = new JMenuItem("Download File from URL...");
0111: JMenuItem raw = new JMenuItem("Raw TCP/IP Connection...");
0112: JMenuItem spider = new JMenuItem("Recursive HTTP Download...");
0113: JMenuItem sshShell = new JMenuItem("SSH Shell...");
0114: JMenuItem shell = new JMenuItem("Execute /bin/bash");
0115: JMenuItem loadAudio = new JMenuItem("Play MP3");
0116: JCheckBoxMenuItem rssDisabled = new JCheckBoxMenuItem(
0117: "Enable RSS Feed", Settings.getEnableRSS());
0118: JCheckBoxMenuItem nl = new JCheckBoxMenuItem("Show Newline Option",
0119: Settings.showNewlineOption);
0120: JMenuItem loadSlash = new JMenuItem("Slashdot");
0121: JMenuItem loadCNN1 = new JMenuItem("CNN Top Stories");
0122: JMenuItem loadCNN2 = new JMenuItem("CNN World");
0123: JMenuItem loadCNN3 = new JMenuItem("CNN Tech");
0124: JMenuItem loadRss = new JMenuItem("Custom RSS Feed");
0125: JCheckBoxMenuItem stdback = new JCheckBoxMenuItem(
0126: "Background Image", Settings.getUseBackground());
0127: JCheckBoxMenuItem resuming = new JCheckBoxMenuItem(
0128: "Enable Resuming", Settings.enableResuming);
0129: JCheckBoxMenuItem ask = new JCheckBoxMenuItem(
0130: "Always Ask to Resume", Settings.askToResume);
0131: JMenuItem proxy = new JMenuItem("Proxy Settings...");
0132: JCheckBoxMenuItem smbThreads = new JCheckBoxMenuItem(
0133: "Multiple Connections", Settings
0134: .getEnableSmbMultiThreading());
0135: JCheckBoxMenuItem sftpThreads = new JCheckBoxMenuItem(
0136: "Multiple Connections", Settings
0137: .getEnableSftpMultiThreading());
0138: JCheckBoxMenuItem sshKeys = new JCheckBoxMenuItem(
0139: "Enable Host Key check", Settings.getEnableSshKeys());
0140: JCheckBoxMenuItem storePasswords = new JCheckBoxMenuItem(
0141: "Store passwords (plaintext)", Settings.getStorePasswords());
0142:
0143: JCheckBoxMenuItem useTableLayout = new JCheckBoxMenuItem(
0144: "Use JTable layout", Settings.getUseJTableLayout());
0145:
0146: JCheckBoxMenuItem useNewIcons = new JCheckBoxMenuItem(
0147: "Use Silk Icons", Settings.getUseNewIcons());
0148:
0149: JCheckBoxMenuItem hideHidden = new JCheckBoxMenuItem(
0150: "Hide local hidden files (Unix only)", Settings
0151: .getHideLocalDotNames());
0152:
0153: JMenuItem clear = new JMenuItem("Clear Log");
0154:
0155: //*** the menu items for the last connections
0156: JMenuItem[] lastConnections = new JMenuItem[jftp.CAPACITY];
0157:
0158: //*** information on each of the last connections
0159: //BUGFIX
0160: String[][] cons = new String[jftp.CAPACITY][JFtp.CONNECTION_DATA_LENGTH];
0161: String[] lastConData = new String[jftp.CAPACITY];
0162: Character charTab = new Character('\t');
0163: String tab = charTab.toString();
0164: JMenuItem manage = new JMenuItem("Manage Bookmarks...");
0165: JMenuItem add = new JMenuItem("Add Bookmark...");
0166: Hashtable marks;
0167: JMenu current = bookmarks;
0168: JMenu last = bookmarks;
0169:
0170: /*
0171: String[] lastProtocols;
0172: String[] lastHosts;
0173: String[] lastUnames;
0174: */
0175: public AppMenuBar(JFtp jftp) {
0176: this .jftp = jftp;
0177:
0178: ftpCon.addActionListener(this );
0179: close.addActionListener(this );
0180: exit.addActionListener(this );
0181: readme.addActionListener(this );
0182: changelog.addActionListener(this );
0183: todo.addActionListener(this );
0184: resuming.addActionListener(this );
0185: ask.addActionListener(this );
0186: smbCon.addActionListener(this );
0187: clear.addActionListener(this );
0188: sftpCon.addActionListener(this );
0189: fadeMenu.addActionListener(this );
0190: askToDelete.addActionListener(this );
0191: smbThreads.addActionListener(this );
0192: sftpThreads.addActionListener(this );
0193: debug.addActionListener(this );
0194: disableLog.addActionListener(this );
0195: http.addActionListener(this );
0196: hp.addActionListener(this );
0197: raw.addActionListener(this );
0198: nfsCon.addActionListener(this );
0199: spider.addActionListener(this );
0200: proxy.addActionListener(this );
0201: stdback.addActionListener(this );
0202: opts.addActionListener(this );
0203: webdavCon.addActionListener(this );
0204: sshShell.addActionListener(this );
0205: shell.addActionListener(this );
0206: nl.addActionListener(this );
0207:
0208: localFtpCon.addActionListener(this );
0209: localSftpCon.addActionListener(this );
0210: localSmbCon.addActionListener(this );
0211: localNfsCon.addActionListener(this );
0212: localWebdavCon.addActionListener(this );
0213: closeLocalCon.addActionListener(this );
0214: add.addActionListener(this );
0215: storePasswords.addActionListener(this );
0216: rssDisabled.addActionListener(this );
0217: loadRss.addActionListener(this );
0218: loadSlash.addActionListener(this );
0219: loadCNN1.addActionListener(this );
0220: loadCNN2.addActionListener(this );
0221: loadCNN3.addActionListener(this );
0222: loadAudio.addActionListener(this );
0223: useTableLayout.addActionListener(this );
0224: useNewIcons.addActionListener(this );
0225: hideHidden.addActionListener(this );
0226:
0227: clearItems.addActionListener(JFtp.dList);
0228:
0229: clear.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1,
0230: ActionEvent.ALT_MASK));
0231: clearItems.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2,
0232: ActionEvent.ALT_MASK));
0233: changelog.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3,
0234: ActionEvent.ALT_MASK));
0235: readme.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4,
0236: ActionEvent.ALT_MASK));
0237: todo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_5,
0238: ActionEvent.ALT_MASK));
0239:
0240: //*** setMnemonics(); was here
0241: //*** BELOW, ADDITIONS FOR THE FILE MENU ARE PUT IN PUBLIC METHOD
0242: resetFileItems();
0243:
0244: ftp.add(resuming);
0245: ftp.add(ask);
0246: ftp.add(nl);
0247: smb.add(smbThreads);
0248: sftp.add(sftpThreads);
0249: sftp.add(sshKeys);
0250: security.add(askToDelete);
0251: security.add(storePasswords);
0252:
0253: cnn.add(loadCNN1);
0254: cnn.add(loadCNN2);
0255: cnn.add(loadCNN3);
0256:
0257: rss.add(rssDisabled);
0258: rss.add(loadSlash);
0259: rss.add(cnn);
0260: rss.add(loadRss);
0261:
0262: opt.add(security);
0263: opt.addSeparator();
0264: opt.add(ftp);
0265: opt.add(smb);
0266: opt.add(sftp);
0267: opt.addSeparator();
0268: opt.add(proxy);
0269: opt.add(opts);
0270:
0271: tools.add(http);
0272: tools.add(spider);
0273: tools.addSeparator();
0274: tools.add(raw);
0275: tools.addSeparator();
0276: tools.add(sshShell);
0277: tools.add(shell);
0278:
0279: view.add(hideHidden);
0280: view.addSeparator();
0281: view.add(useTableLayout);
0282: view.add(useNewIcons);
0283: view.add(fadeMenu);
0284: view.add(clear);
0285: view.add(clearItems);
0286:
0287: view.addSeparator();
0288: view.add(debug);
0289: view.add(disableLog);
0290: view.addSeparator();
0291: view.add(rss);
0292: view.addSeparator();
0293:
0294: info.add(readme);
0295: info.add(changelog);
0296: info.add(todo);
0297: info.addSeparator();
0298: info.add(hp);
0299:
0300: UIManager.LookAndFeelInfo[] m = UIManager
0301: .getInstalledLookAndFeels();
0302:
0303: for (int i = 0; i < m.length; i++) {
0304: //JMenuItem tmp = new JMenuItem(m[i].getName());
0305: //tmp.addActionListener(this);
0306: //lf.add(tmp);
0307:
0308: /*
0309: * Don't add menu items for unsupported look and feel's.
0310: *
0311: * It would be nice to use something like
0312: * isSupportedLookandFeel, but the information provided by
0313: * UIManager.LookAndFeelInfo is very limited. This is
0314: * supposedly done on purpose according to the API docs,
0315: * but what good does a non-supported look and feel in a
0316: * menu item do?
0317: */
0318: try {
0319: LookAndFeel lnf = (LookAndFeel) Class.forName(
0320: m[i].getClassName()).newInstance();
0321:
0322: if (lnf.isSupportedLookAndFeel()) {
0323: JMenuItem tmp = new JMenuItem(m[i].getName());
0324: tmp.addActionListener(this );
0325: lf.add(tmp);
0326: }
0327: } catch (ClassNotFoundException cnfe) {
0328: continue;
0329: } catch (InstantiationException ie) {
0330: continue;
0331: } catch (IllegalAccessException iae) {
0332: continue;
0333: }
0334: }
0335:
0336: view.add(lf);
0337:
0338: background.add(stdback);
0339: view.add(background);
0340:
0341: manage.addActionListener(this );
0342:
0343: //UIManager.setLookAndFeel();
0344: add(file);
0345: add(opt);
0346: add(view);
0347: add(tools);
0348: add(bookmarks);
0349: add(info);
0350:
0351: loadBookmarks();
0352:
0353: //add(experimental);
0354: }
0355:
0356: public void loadBookmarks() {
0357: marks = new Hashtable();
0358: bookmarks.removeAll();
0359: bookmarks.add(add);
0360: bookmarks.add(manage);
0361: bookmarks.addSeparator();
0362:
0363: String data = "";
0364:
0365: try {
0366: DataInput in = new DataInputStream(new BufferedInputStream(
0367: new FileInputStream(Settings.bookmarks)));
0368:
0369: while ((data = in.readLine()) != null) {
0370: if (!data.startsWith("#") && !data.trim().equals("")) {
0371: addBookmarkLine(data);
0372: }
0373: }
0374: } catch (IOException e) {
0375: Log.debug("No bookmarks.txt found, using defaults.");
0376: addBookmark("FTP", "ftp.kernel.org", "anonymous",
0377: "j-ftp@sf.net", 21, "/pub/linux/kernel", "false");
0378: addBookmark("FTP", "upload.sourceforge.net", "anonymous",
0379: "j-ftp@sf.net", 21, "/incoming", "false");
0380: addBookmark("SMB", "(LAN)", "guest", "guest", -1, "-",
0381: "false");
0382:
0383: return;
0384: }
0385: }
0386:
0387: private void addBookmarkLine(String tmp) {
0388: try {
0389: StringTokenizer t = new StringTokenizer(tmp, "#", false);
0390:
0391: if (tmp.toLowerCase().trim().startsWith("<dir>")) {
0392: String dir = tmp.substring(tmp.indexOf(">") + 1, tmp
0393: .lastIndexOf("<"));
0394:
0395: //Log.debug("Dir: " + dir);
0396: JMenu m = new JMenu(dir);
0397: current.add(m);
0398:
0399: last = current;
0400: current = m;
0401: } else if (tmp.toLowerCase().trim().startsWith("<enddir>")) {
0402: current = last;
0403: } else {
0404: addBookmark(t.nextToken(), t.nextToken(),
0405: t.nextToken(), t.nextToken(), Integer
0406: .parseInt(t.nextToken()),
0407: t.nextToken(), t.nextToken());
0408: }
0409: } catch (Exception ex) {
0410: Log.debug("Broken line: " + tmp);
0411: ex.printStackTrace();
0412: }
0413: }
0414:
0415: public void addBookmark(String pr, String h, String u, String p,
0416: int po, String d, String l) {
0417: BookmarkItem x = new BookmarkItem(h);
0418: x.setUserdata(u, p);
0419:
0420: if (l.trim().startsWith("t")) {
0421: x.setLocal(true);
0422: }
0423:
0424: x.setPort(po);
0425: x.setProtocol(pr);
0426: x.setDirectory(d);
0427:
0428: //bookmarks
0429: current.add(x);
0430: marks.put(x.getLabel(), x);
0431: x.addActionListener(this );
0432: }
0433:
0434: //*** Where changes to the file menu are made (iniitalization done here too)
0435: public void resetFileItems() {
0436: file.removeAll();
0437:
0438: file.add(ftpCon);
0439: file.add(sftpCon);
0440: file.add(smbCon);
0441: file.add(nfsCon);
0442: file.add(webdavCon);
0443: file.addSeparator();
0444: file.add(close);
0445: file.addSeparator();
0446: file.addSeparator();
0447: file.add(localFtpCon);
0448: file.add(localSftpCon);
0449: file.add(localSmbCon);
0450: file.add(localNfsCon);
0451:
0452: //file.add(localWebdavCon); -> not yet
0453: file.addSeparator();
0454: file.add(closeLocalCon);
0455: file.addSeparator();
0456:
0457: //*** ADDITION OF THE REMEMBERED CONNECTIONS
0458: boolean connectionsExist = false;
0459:
0460: try {
0461: //*** get the information on the last connections
0462: cons = new String[jftp.CAPACITY][jftp.CONNECTION_DATA_LENGTH];
0463:
0464: cons = LastConnections.readFromFile(jftp.CAPACITY);
0465:
0466: String protocol;
0467:
0468: String htmp;
0469:
0470: String utmp;
0471:
0472: String conNumber;
0473: String usingLocal = new String("");
0474: Integer conNumberInt;
0475:
0476: //lastConData = new String("");
0477: //***
0478: for (int i = 0; i < jftp.CAPACITY; i++) {
0479: if (!(cons[i][0].equals("null"))) {
0480: protocol = cons[i][0];
0481: htmp = cons[i][1];
0482: utmp = cons[i][2];
0483:
0484: int j = 3;
0485:
0486: while (!(cons[i][j]
0487: .equals(LastConnections.SENTINEL))) {
0488: j++;
0489: }
0490:
0491: //usingLocal is always last piece of data!
0492: usingLocal = cons[i][j - 1];
0493:
0494: if (usingLocal.equals("true")) {
0495: usingLocal = "(in local tab)";
0496: }
0497:
0498: else {
0499: usingLocal = "";
0500: }
0501:
0502: //lastConnections[i] = new JMenuItem(cons[i]);
0503: conNumberInt = new Integer(i + 1);
0504: conNumber = conNumberInt.toString();
0505:
0506: //lastConData[i] = new String(conNumber + " " + protocol + ": Hostname: " + htmp + "; Username: " + utmp);
0507: lastConData[i] = new String(conNumber + " "
0508: + protocol + ": " + htmp + " " + usingLocal);
0509:
0510: lastConnections[i] = new JMenuItem(lastConData[i]);
0511: lastConnections[i].addActionListener(this );
0512:
0513: connectionsExist = true;
0514:
0515: //*** code repetition: maybe getting these tokens
0516: //*** should be in a separate private method
0517: //file.add(protocol + ": Hostname: " + htmp + "; Username: " + utmp);
0518: file.add(lastConnections[i]);
0519: }
0520: }
0521: } catch (Exception ex) {
0522: Log.debug("WARNING: Remembered connections broken.");
0523: ex.printStackTrace();
0524: }
0525:
0526: if (connectionsExist) {
0527: file.addSeparator();
0528: }
0529:
0530: file.add(exit);
0531:
0532: setMnemonics();
0533: }
0534:
0535: //resetFileItems
0536: public void actionPerformed(ActionEvent e) {
0537: if (e.getSource() == proxy) {
0538: //ProxyChooser p =
0539: JFtp.statusP.jftp.addToDesktop("Proxy Settings",
0540: new ProxyChooser(), 500, 110);
0541: } else if (e.getSource() == add) {
0542: Log.out("add called");
0543:
0544: AddBookmarks a = new AddBookmarks(JFtp.statusP.jftp);
0545: a.update();
0546: } else if (e.getSource() == webdavCon) {
0547: WebdavHostChooser hc = new WebdavHostChooser();
0548: hc.toFront();
0549: hc.update();
0550: } else if ((e.getSource() == localFtpCon) && (!jftp.uiBlocked)) {
0551: HostChooser hc = new HostChooser(null, true);
0552: hc.toFront();
0553:
0554: //hc.setModal(true);
0555: hc.update();
0556: } else if ((e.getSource() == localSmbCon) && (!jftp.uiBlocked)) {
0557: SmbHostChooser hc = new SmbHostChooser(null, true);
0558: hc.toFront();
0559:
0560: //hc.setModal(true);
0561: hc.update();
0562: } else if ((e.getSource() == localSftpCon) && (!jftp.uiBlocked)) {
0563: SftpHostChooser hc = new SftpHostChooser(null, true);
0564: hc.toFront();
0565:
0566: //hc.setModal(true);
0567: hc.update();
0568: } else if ((e.getSource() == localNfsCon) && (!jftp.uiBlocked)) {
0569: NfsHostChooser hc = new NfsHostChooser(null, true);
0570: hc.toFront();
0571:
0572: //hc.setModal(true);
0573: hc.update();
0574: } else if ((e.getSource() == localWebdavCon)
0575: && (!jftp.uiBlocked)) {
0576: WebdavHostChooser hc = new WebdavHostChooser(null, true);
0577: hc.toFront();
0578:
0579: //hc.setModal(true);
0580: hc.update();
0581: } else if (e.getSource() == closeLocalCon) {
0582: JFtp.statusP.jftp.closeCurrentLocalTab();
0583: } else if (e.getSource() == clear) {
0584: jftp.clearLog();
0585: } else if (e.getSource() == spider) {
0586: jftp.addToDesktop("Http recursive download",
0587: new HttpSpider(jftp.localDir.getPath()
0588: + "_httpdownload/"), 440, 250);
0589: } else if (e.getSource() == hp) {
0590: HttpBrowser h = new HttpBrowser(
0591: "http://j-ftp.sourceforge.net");
0592: JFtp.desktop.add(h, new Integer(Integer.MAX_VALUE - 10));
0593: } else if (e.getSource() == raw) {
0594: RawConnection c = new RawConnection();
0595: } else if (e.getSource() == readme) {
0596: show(Settings.readme);
0597: } else if (e.getSource() == changelog) {
0598: show(Settings.changelog);
0599: } else if (e.getSource() == todo) {
0600: show(Settings.todo);
0601: } else if (e.getSource() == shell) {
0602: UIUtils.runCommand("/bin/bash");
0603: } else if (e.getSource() == loadAudio) {
0604: try {
0605: JFileChooser f = new JFileChooser();
0606: f.showOpenDialog(jftp);
0607:
0608: File file = f.getSelectedFile();
0609:
0610: Player p = new Player(new FileInputStream(file));
0611:
0612: p.play();
0613: } catch (Exception ex) {
0614: ex.printStackTrace();
0615: Log.debug("Error: (" + ex + ")");
0616: }
0617: } else if (e.getSource() == exit) {
0618: jftp.windowClosing(null); // handles everything
0619: } else if (e.getSource() == close) {
0620: JFtp.statusP.jftp.closeCurrentTab();
0621:
0622: /*
0623: jftp.safeDisconnect();
0624: FilesystemConnection con = new FilesystemConnection();
0625: jftp.remoteDir.setCon(con);
0626: con.addConnectionListener((ConnectionListener)jftp.remoteDir);
0627: if(!con.chdir("/")) con.chdir("C:\\");
0628: */
0629: } else if ((e.getSource() == ftpCon) && (!jftp.uiBlocked)) {
0630: //jftp.safeDisconnect();
0631: HostChooser hc = new HostChooser();
0632: hc.toFront();
0633:
0634: //hc.setModal(true);
0635: hc.update();
0636: } else if ((e.getSource() == smbCon) && (!jftp.uiBlocked)) {
0637: //jftp.safeDisconnect();
0638: SmbHostChooser hc = new SmbHostChooser();
0639: hc.toFront();
0640:
0641: //hc.setModal(true);
0642: hc.update();
0643: } else if ((e.getSource() == sftpCon) && (!jftp.uiBlocked)) {
0644: //jftp.safeDisconnect();
0645: SftpHostChooser hc = new SftpHostChooser();
0646: hc.toFront();
0647:
0648: //hc.setModal(true);
0649: hc.update();
0650: } else if ((e.getSource() == nfsCon) && (!jftp.uiBlocked)) {
0651: // jftp.safeDisconnect();
0652: NfsHostChooser hc = new NfsHostChooser();
0653: hc.toFront();
0654:
0655: //hc.setModal(true);
0656: hc.update();
0657: } else if (e.getSource() == resuming) {
0658: boolean res = resuming.getState();
0659: Settings.enableResuming = res;
0660: Settings.setProperty("jftp.enableResuming", res);
0661: ask.setEnabled(Settings.enableResuming);
0662: Settings.save();
0663: } else if (e.getSource() == useTableLayout) {
0664: boolean res = useTableLayout.getState();
0665: Settings.setProperty("jftp.useJTableLayout", res);
0666: Settings.save();
0667:
0668: JOptionPane.showMessageDialog(this ,
0669: "Please restart JFtp to have the UI changed.");
0670: } else if (e.getSource() == useNewIcons) {
0671: boolean res = useNewIcons.getState();
0672: Settings.setProperty("jftp.gui.look.newIcons", res);
0673: Settings.save();
0674:
0675: JOptionPane.showMessageDialog(this ,
0676: "Please restart JFtp to have the UI changed.");
0677: } else if (e.getSource() == hideHidden) {
0678: boolean res = hideHidden.getState();
0679: Settings.setProperty("jftp.hideHiddenDotNames", res);
0680: Settings.save();
0681:
0682: JFtp.localUpdate();
0683: } else if (e.getSource() == nl) {
0684: boolean res = nl.getState();
0685: Settings.showNewlineOption = res;
0686: } else if (e.getSource() == stdback) {
0687: Settings.setProperty("jftp.useBackground", stdback
0688: .getState());
0689: Settings.save();
0690: JFtp.statusP.jftp.fireUpdate();
0691: } else if (e.getSource() == sshKeys) {
0692: Settings.setProperty("jftp.useSshKeyVerification", sshKeys
0693: .getState());
0694: Settings.save();
0695: JFtp.statusP.jftp.fireUpdate();
0696: } else if (e.getSource() == rssDisabled) {
0697: Settings.setProperty("jftp.enableRSS", rssDisabled
0698: .getState());
0699: Settings.save();
0700: JFtp.statusP.jftp.fireUpdate();
0701: } else if (e.getSource() == loadRss) {
0702: String what = JOptionPane.showInputDialog("Enter URL",
0703: "http://");
0704:
0705: if (what == null) {
0706: return;
0707: }
0708:
0709: Settings.setProperty("jftp.customRSSFeed", what);
0710: Settings.save();
0711:
0712: JFtp.statusP.jftp.feeder.switchTo(what);
0713: } else if (e.getSource() == loadSlash) {
0714: Settings.setProperty("jftp.customRSSFeed",
0715: "http://slashdot.org/rss/slashdot.rss");
0716: Settings.save();
0717:
0718: JFtp.statusP.jftp.feeder
0719: .switchTo("http://slashdot.org/rss/slashdot.rss");
0720: } else if (e.getSource() == loadCNN1) {
0721: Settings.setProperty("jftp.customRSSFeed",
0722: "http://rss.cnn.com/rss/cnn_topstories.rss");
0723: Settings.save();
0724:
0725: JFtp.statusP.jftp.feeder
0726: .switchTo("http://rss.cnn.com/rss/cnn_topstories.rss");
0727: } else if (e.getSource() == loadCNN2) {
0728: Settings.setProperty("jftp.customRSSFeed",
0729: "http://rss.cnn.com/rss/cnn_world.rss");
0730: Settings.save();
0731:
0732: JFtp.statusP.jftp.feeder
0733: .switchTo("http://rss.cnn.com/rss/cnn_world.rss");
0734: } else if (e.getSource() == loadCNN3) {
0735: Settings.setProperty("jftp.customRSSFeed",
0736: "http://rss.cnn.com/rss/cnn_tech.rss");
0737: Settings.save();
0738:
0739: JFtp.statusP.jftp.feeder
0740: .switchTo("http://rss.cnn.com/rss/cnn_tech.rss");
0741: } else if (e.getSource() == debug) {
0742: Settings.setProperty("jftp.enableDebug", debug.getState());
0743: Settings.save();
0744: } else if (e.getSource() == disableLog) {
0745: Settings.setProperty("jftp.disableLog", disableLog
0746: .getState());
0747: Settings.save();
0748: } else if (e.getSource() == smbThreads) {
0749: Settings.setProperty("jftp.enableSmbMultiThreading",
0750: smbThreads.getState());
0751: Settings.save();
0752: } else if (e.getSource() == sftpThreads) {
0753: Settings.setProperty("jftp.enableSftpMultiThreading",
0754: sftpThreads.getState());
0755: Settings.save();
0756: } else if (e.getSource() == ask) {
0757: Settings.askToResume = ask.getState();
0758: } else if (e.getSource() == http) {
0759: HttpDownloader dl = new HttpDownloader();
0760: jftp.addToDesktop("Http download", dl, 480, 100);
0761: jftp.setLocation(dl.hashCode(), 100, 150);
0762: } else if (e.getSource() == fadeMenu) {
0763: Settings.setProperty("jftp.gui.enableStatusAnimation",
0764: fadeMenu.getState());
0765: Settings.save();
0766: } else if (e.getSource() == askToDelete) {
0767: Settings.setProperty("jftp.gui.askToDelete", askToDelete
0768: .getState());
0769: Settings.save();
0770: }
0771:
0772: //***MY ADDITIONS (***how can I make this flexible enough to
0773: //*** easily add > 5 connections?)
0774: else if ((e.getSource() == lastConnections[0])
0775: && (!jftp.uiBlocked)) {
0776: connectionSelected(0);
0777: }
0778:
0779: else if ((e.getSource() == lastConnections[1])
0780: && (!jftp.uiBlocked)) {
0781: connectionSelected(1);
0782: } else if ((e.getSource() == lastConnections[2])
0783: && (!jftp.uiBlocked)) {
0784: connectionSelected(2);
0785: } else if ((e.getSource() == lastConnections[3])
0786: && (!jftp.uiBlocked)) {
0787: connectionSelected(3);
0788: } else if ((e.getSource() == lastConnections[4])
0789: && (!jftp.uiBlocked)) {
0790: connectionSelected(4);
0791: } else if ((e.getSource() == lastConnections[5])
0792: && (!jftp.uiBlocked)) {
0793: connectionSelected(5);
0794: } else if ((e.getSource() == lastConnections[6])
0795: && (!jftp.uiBlocked)) {
0796: connectionSelected(6);
0797: } else if ((e.getSource() == lastConnections[7])
0798: && (!jftp.uiBlocked)) {
0799: connectionSelected(7);
0800: } else if ((e.getSource() == lastConnections[8])
0801: && (!jftp.uiBlocked)) {
0802: connectionSelected(8);
0803: } else if (e.getSource() == opts) {
0804: AdvancedOptions adv = new AdvancedOptions();
0805: jftp.addToDesktop("Advanced Options", adv, 500, 180);
0806: jftp.setLocation(adv.hashCode(), 110, 180);
0807: } else if (e.getSource() == manage) {
0808: BookmarkManager m = new BookmarkManager();
0809: JFtp.desktop.add(m, new Integer(Integer.MAX_VALUE - 10));
0810: } else if (marks.contains(e.getSource())) {
0811: ((BookmarkItem) e.getSource()).connect();
0812: } else if (e.getSource() == storePasswords) {
0813: boolean state = storePasswords.getState();
0814:
0815: if (!state) {
0816: JOptionPane j = new JOptionPane();
0817: int x = j
0818: .showConfirmDialog(
0819: storePasswords,
0820: "You chose not to Save passwords.\n"
0821: + "Do you want your old login data to be deleted?",
0822: "Delete old passwords?",
0823: JOptionPane.YES_NO_OPTION);
0824:
0825: if (x == JOptionPane.YES_OPTION) {
0826: File f = new File(Settings.login_def);
0827: f.delete();
0828:
0829: f = new File(Settings.login_def_sftp);
0830: f.delete();
0831:
0832: f = new File(Settings.login_def_nfs);
0833: f.delete();
0834:
0835: f = new File(Settings.login_def_smb);
0836: f.delete();
0837:
0838: f = new File(Settings.login);
0839: f.delete();
0840:
0841: f = new File(Settings.last_cons);
0842: f.delete();
0843:
0844: Log
0845: .debug("Deleted old login data files.\n"
0846: + "Please edit your bookmarks file manually!");
0847: }
0848: }
0849:
0850: Settings.setProperty("jftp.security.storePasswords", state);
0851: Settings.save();
0852: } else if (e.getSource() == sshShell) {
0853: SftpHostChooser c = new SftpHostChooser(true);
0854: c.update();
0855: }
0856:
0857: //*** END OF NEW LISTENERS
0858: else {
0859: String tmp = ((JMenuItem) e.getSource()).getLabel();
0860:
0861: UIManager.LookAndFeelInfo[] m = UIManager
0862: .getInstalledLookAndFeels();
0863:
0864: for (int i = 0; i < m.length; i++) {
0865: if (m[i].getName().equals(tmp)) {
0866: JFtp.statusP.jftp.setLookAndFeel(m[i]
0867: .getClassName());
0868: Settings.setProperty("jftp.gui.look", m[i]
0869: .getClassName());
0870: Settings.save();
0871: }
0872: }
0873: }
0874: }
0875:
0876: private void show(String file) {
0877: java.net.URL url = ClassLoader.getSystemResource(file);
0878:
0879: if (url == null) {
0880: url = HImage.class.getResource("/" + file);
0881: }
0882:
0883: Displayer d = new Displayer(url, null);
0884: JFtp.desktop.add(d, new Integer(Integer.MAX_VALUE - 11));
0885: }
0886:
0887: // by jake
0888: private void setMnemonics() {
0889: //*** I added accelerators for more menu items
0890: //*** (issue: should ALL accelerators have the CTRL modifier (so that
0891: //*** the ALT modifier is for mnemonics only?)
0892: //*** I added mnemonics for the main menu items
0893: file.setMnemonic('F');
0894: opt.setMnemonic('O');
0895: view.setMnemonic('V');
0896: tools.setMnemonic('T');
0897: bookmarks.setMnemonic('B');
0898: info.setMnemonic('I');
0899:
0900: //*** set accelerators for the remote connection window
0901: ftpCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,
0902: ActionEvent.CTRL_MASK));
0903: sftpCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
0904: ActionEvent.CTRL_MASK));
0905: smbCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,
0906: ActionEvent.CTRL_MASK));
0907: nfsCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
0908: ActionEvent.CTRL_MASK));
0909:
0910: //*** IMPORTANT NOTE: Adding an accelerator for disconnecting could
0911: //*** be something of a "gotcha" that we may not want
0912: close.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
0913: ActionEvent.CTRL_MASK));
0914:
0915: //*** These next five lines can be commented out if we decide against having accelerators
0916: //*** starting with the shift key
0917: //*** version 1.44: we have chosen not to have shift as a modifier
0918: //*** as we've found this is a "gotcha"
0919: /*
0920: localFtpCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,
0921: ActionEvent.SHIFT_MASK));
0922: localSftpCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
0923: ActionEvent.SHIFT_MASK));
0924: localSmbCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,
0925: ActionEvent.SHIFT_MASK));
0926: localNfsCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
0927: ActionEvent.SHIFT_MASK));
0928:
0929: closeLocalCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
0930: ActionEvent.SHIFT_MASK));
0931:
0932: */
0933: //*** I have decided to get areound the problem by having mnemonics within the menu
0934: //*** as accelerators. So to quickly start an FTP connection in the local window,
0935: //*** the user can enter Alt+f+f, and Alt+f+s for SFTP,etc.
0936: localFtpCon.setMnemonic('F');
0937: localSftpCon.setMnemonic('S');
0938: localSmbCon.setMnemonic('L');
0939: localNfsCon.setMnemonic('N');
0940:
0941: //localNfsCon.setMnemonic('N');
0942: closeLocalCon.setMnemonic('C');
0943:
0944: //*** and here are some other menu mnemonics I thought I'd include:
0945: //*** (I'll add more if more are wanted)
0946: exit.setMnemonic('X');
0947:
0948: proxy.setMnemonic('P');
0949:
0950: http.setMnemonic('D');
0951: spider.setMnemonic('H');
0952: raw.setMnemonic('T');
0953:
0954: readme.setMnemonic('R');
0955: todo.setMnemonic('N');
0956: changelog.setMnemonic('C');
0957: hp.setMnemonic('H');
0958:
0959: opts.setMnemonic('A');
0960: manage.setMnemonic('M');
0961:
0962: clear.setMnemonic('C');
0963: clearItems.setMnemonic('F');
0964:
0965: try {
0966: //*** end of new code section
0967: Integer intI;
0968: String stringI;
0969: char charI;
0970:
0971: for (int i = 0; i < jftp.CAPACITY; i++) {
0972: //*** I should note that functionality below only allows
0973: //*** a maximum of nine connections to be remembered
0974: //BUGFIX 1.40
0975: //if (!(cons[i].equals("null"))) {
0976: if (!(cons[i][0].equals("null"))) {
0977: intI = new Integer(i + 1);
0978: stringI = intI.toString();
0979: charI = stringI.charAt(0);
0980:
0981: lastConnections[i].setMnemonic(charI);
0982:
0983: //lastConnections[i].setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
0984: }
0985: }
0986:
0987: //for
0988: } catch (Exception ex) {
0989: Log
0990: .out("WARNING: AppMenuBar produced Exception, ignored it");
0991: ex.printStackTrace();
0992: }
0993: }
0994:
0995: //setMnemonics
0996: private void connectionSelected(int position) {
0997: //*** tokenize the string to extract the required data
0998: //*** or is this the thing done elsewhere in the code,
0999: //*** when the menu is being set up?
1000: //String connectionInfo = cons[position];
1001: //StringTokenizer tokens = new StringTokenizer(connectionInfo);
1002: //StringTokenizer tokens = new StringTokenizer(cons[position], " ", false); // tab);
1003: String protocol;
1004: int numTokens;
1005:
1006: String htmp = new String("");
1007: String utmp = new String("");
1008: String ptmp = new String("");
1009: String dtmp = new String("");
1010: boolean useLocal = false;
1011: int potmp = 0;
1012: String potmpString = new String("0");
1013: String useLocalString = new String("false");
1014:
1015: /*
1016: //numTokens = tokens.countTokens();
1017: protocol = tokens.nextToken();
1018:
1019: htmp = tokens.nextToken();
1020: utmp = tokens.nextToken();
1021: ptmp = tokens.nextToken();
1022:
1023: */
1024: protocol = cons[position][0];
1025: htmp = cons[position][1];
1026: utmp = cons[position][2];
1027: ptmp = cons[position][3];
1028:
1029: if (ptmp.equals("")) {
1030: ptmp = UIUtils.getPasswordFromUser(JFtp.statusP.jftp);
1031: }
1032:
1033: //int j=4;
1034: //while (cons[i][j].equals(LastConnections.SENTINEL)) {
1035: // j++;
1036: //}
1037: //usingLocal = cons[i][j-1];
1038:
1039: /*
1040: System.out.println(position);
1041: System.out.println(protocol);
1042: System.out.println(cons[position][1]);
1043: System.out.println(cons[position][2]);
1044: System.out.println(cons[position][3]);
1045: */
1046:
1047: //
1048: if (protocol.equals("FTP")) {
1049: potmpString = cons[position][4];
1050: dtmp = cons[position][5];
1051: useLocalString = cons[position][6];
1052:
1053: /*
1054: potmpString = tokens.nextToken();
1055: dtmp = tokens.nextToken();
1056: useLocalString = tokens.nextToken();
1057:
1058:
1059: System.out.println(potmpString);
1060: System.out.println("FTP");
1061: */
1062: potmp = Integer.parseInt(potmpString);
1063:
1064: if (useLocalString.equals("true")) {
1065: useLocal = true;
1066: } else {
1067: useLocal = false;
1068: }
1069:
1070: StartConnection.startFtpCon(htmp, utmp, ptmp, potmp, dtmp,
1071: useLocal);
1072:
1073: //System.out.println(htmp + utmp + ptmp + potmpString +dtmp + useLocalString);
1074: } else if (protocol.equals("SFTP")) {
1075: /*
1076: htmp = tokens.nextToken();
1077: utmp = tokens.nextToken();
1078: ptmp = tokens.nextToken();
1079: */
1080:
1081: //useLocalString = tokens.nextToken();
1082: //System.out.println("SFTP");
1083: potmpString = cons[position][4];
1084: useLocalString = cons[position][5];
1085:
1086: //System.out.println(htmp + utmp + ptmp + useLocalString);
1087: //if (protocol == "SFTP")
1088: }
1089:
1090: else if (protocol.equals("NFS")) {
1091: useLocalString = cons[position][4];
1092: }
1093:
1094: else if (protocol.equals("SMB")) {
1095: /*
1096: htmp = tokens.nextToken();
1097: utmp = tokens.nextToken();
1098: ptmp = tokens.nextToken();
1099: */
1100: /*
1101: dtmp = tokens.nextToken();
1102: useLocalString = tokens.nextToken();
1103: */
1104: dtmp = cons[position][4];
1105: useLocalString = cons[position][5];
1106:
1107: //System.out.println(htmp+utmp+ptmp+dtmp + useLocalString);
1108: }
1109:
1110: //***StartConnection functionality to be put in each
1111: //***if statement
1112: potmp = Integer.parseInt(potmpString);
1113:
1114: if (useLocalString.equals("true")) {
1115: useLocal = true;
1116: } else {
1117: useLocal = false;
1118: }
1119:
1120: if (protocol.equals("SFTP")) {
1121: //BUGFIX 1.40: no longer setting port #
1122: //to 22, now potmp
1123: StartConnection.startCon(protocol, htmp, utmp, ptmp, potmp,
1124: dtmp, useLocal);
1125: } else if (!(protocol.equals("FTP"))) {
1126: //System.out.println(protocol);
1127: StartConnection.startCon(protocol, htmp, utmp, ptmp, potmp,
1128: dtmp, useLocal);
1129: }
1130: }
1131:
1132: //connectionSelected
1133: }
|