?? appmenubar.java
字號:
/* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */package net.sf.jftp.gui;import net.sf.jftp.JFtp;import net.sf.jftp.config.Settings;import net.sf.jftp.gui.framework.*;import net.sf.jftp.net.*;import net.sf.jftp.tools.*;import net.sf.jftp.util.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.lang.Integer;import java.util.*;import javax.swing.*;//***public class AppMenuBar extends JMenuBar implements ActionListener{ public static JCheckBoxMenuItem fadeMenu = new JCheckBoxMenuItem("Enable Status Animation", Settings.getEnableStatusAnimation()); public static JCheckBoxMenuItem askToDelete = new JCheckBoxMenuItem("Confirm Remove", Settings.getAskToDelete()); public static JCheckBoxMenuItem debug = new JCheckBoxMenuItem("Verbose Console Debugging", Settings.getEnableDebug()); public static JCheckBoxMenuItem disableLog = new JCheckBoxMenuItem("Disable Log", Settings.getDisableLog()); public static JMenuItem clearItems = new JMenuItem("Clear Finished Items"); private JFtp jftp; JMenu file = new JMenu("File"); JMenu opt = new JMenu("Options"); JMenu view = new JMenu("View"); JMenu tools = new JMenu("Tools"); JMenu bookmarks = new JMenu("Bookmarks"); JMenu info = new JMenu("Info"); JMenu lf = new JMenu(" Switch Look & Feel to"); JMenu background = new JMenu("Desktop Background"); JMenu ftp = new JMenu(" FTP"); JMenu smb = new JMenu(" SMB"); JMenu sftp = new JMenu(" SFTP"); JMenu security = new JMenu("Security"); JMenu experimental = new JMenu("Experimental Features"); JMenu rss = new JMenu("RSS Feed"); JMenuItem localFtpCon = new JMenuItem("Open FTP Connection in Local Tab..."); JMenuItem localSftpCon = new JMenuItem("Open SFTP Connection in Local Tab..."); JMenuItem localSmbCon = new JMenuItem("Open SMB/LAN Connection in Local Tab..."); JMenuItem localNfsCon = new JMenuItem("Open NFS Connection in Local Tab..."); JMenuItem localWebdavCon = new JMenuItem("Open WebDAV Connection in Local Tab... (ALPHA)"); JMenuItem closeLocalCon = new JMenuItem("Close Active Connection in Local Tab"); JMenuItem ftpCon = new JMenuItem("Connect to FTP Server..."); JMenuItem sftpCon = new JMenuItem("Connect to SFTP Server..."); JMenuItem smbCon = new JMenuItem("Connect to SMB Server / Browse LAN..."); JMenuItem nfsCon = new JMenuItem("Connect to NFS Server..."); JMenuItem webdavCon = new JMenuItem("Connect to WebDAV Server... (ALPHA)"); JMenuItem close = new JMenuItem("Disconnect and Connect to Filesystem"); JMenuItem exit = new JMenuItem("Exit"); JMenuItem readme = new JMenuItem("Show Readme..."); JMenuItem changelog = new JMenuItem("View Changelog..."); JMenuItem todo = new JMenuItem("What's Next..."); JMenuItem hp = new JMenuItem("Visit Project Homepage..."); JMenuItem opts = new JMenuItem("Advanced Options..."); JMenuItem http = new JMenuItem("Download File from URL..."); JMenuItem raw = new JMenuItem("Raw TCP/IP Connection..."); JMenuItem spider = new JMenuItem("Recursive HTTP Download..."); JMenuItem insomniac = new JMenuItem("Insomniac Search..."); JCheckBoxMenuItem rssDisabled = new JCheckBoxMenuItem("Slashdot RSS Feed", Settings.getEnableRSS()); JCheckBoxMenuItem stdback = new JCheckBoxMenuItem("Background Image", Settings.getUseBackground()); JCheckBoxMenuItem resuming = new JCheckBoxMenuItem("Enable Resuming", Settings.enableResuming); JCheckBoxMenuItem ask = new JCheckBoxMenuItem("Always Ask to Resume", Settings.askToResume); JMenuItem proxy = new JMenuItem("Proxy Settings..."); JCheckBoxMenuItem smbThreads = new JCheckBoxMenuItem("Multiple Connections", Settings.getEnableSmbMultiThreading()); JCheckBoxMenuItem sftpThreads = new JCheckBoxMenuItem("Multiple Connections", Settings.getEnableSftpMultiThreading()); JCheckBoxMenuItem storePasswords = new JCheckBoxMenuItem("Store passwords (plaintext)", Settings.getStorePasswords()); JMenuItem clear = new JMenuItem("Clear Log"); //*** the menu items for the last connections JMenuItem[] lastConnections = new JMenuItem[jftp.CAPACITY]; //*** information on each of the last connections //BUGFIX String[][] cons = new String[jftp.CAPACITY][JFtp.CONNECTION_DATA_LENGTH]; String[] lastConData = new String[jftp.CAPACITY]; Character charTab = new Character('\t'); String tab = charTab.toString(); JMenuItem manage = new JMenuItem("Manage Bookmarks..."); JMenuItem add = new JMenuItem("Add Bookmark..."); Hashtable marks; JMenu current = bookmarks; JMenu last = bookmarks; /* String[] lastProtocols; String[] lastHosts; String[] lastUnames; */ public AppMenuBar(JFtp jftp) { this.jftp = jftp; ftpCon.addActionListener(this); close.addActionListener(this); exit.addActionListener(this); readme.addActionListener(this); changelog.addActionListener(this); todo.addActionListener(this); resuming.addActionListener(this); ask.addActionListener(this); smbCon.addActionListener(this); clear.addActionListener(this); sftpCon.addActionListener(this); fadeMenu.addActionListener(this); askToDelete.addActionListener(this); smbThreads.addActionListener(this); sftpThreads.addActionListener(this); debug.addActionListener(this); disableLog.addActionListener(this); http.addActionListener(this); hp.addActionListener(this); raw.addActionListener(this); nfsCon.addActionListener(this); spider.addActionListener(this); proxy.addActionListener(this); stdback.addActionListener(this); insomniac.addActionListener(this); opts.addActionListener(this); webdavCon.addActionListener(this); localFtpCon.addActionListener(this); localSftpCon.addActionListener(this); localSmbCon.addActionListener(this); localNfsCon.addActionListener(this); localWebdavCon.addActionListener(this); closeLocalCon.addActionListener(this); add.addActionListener(this); storePasswords.addActionListener(this); rssDisabled.addActionListener(this); clearItems.addActionListener(JFtp.dList); clear.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); clearItems.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); changelog.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, ActionEvent.ALT_MASK)); readme.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4, ActionEvent.ALT_MASK)); todo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_5, ActionEvent.ALT_MASK)); //*** setMnemonics(); was here //*** BELOW, ADDITIONS FOR THE FILE MENU ARE PUT IN PUBLIC METHOD resetFileItems(); ftp.add(resuming); ftp.add(ask); smb.add(smbThreads); sftp.add(sftpThreads); security.add(askToDelete); security.add(storePasswords); rss.add(rssDisabled); opt.add(security); opt.addSeparator(); opt.add(ftp); opt.add(smb); opt.add(sftp); opt.addSeparator(); opt.add(proxy); opt.add(opts); tools.add(http); tools.add(spider); tools.addSeparator(); tools.add(raw); tools.addSeparator(); tools.add(insomniac); view.add(fadeMenu); view.add(clear); view.add(clearItems); view.addSeparator(); view.add(debug); view.add(disableLog); view.addSeparator(); view.add(rss); view.addSeparator(); info.add(readme); info.add(changelog); info.add(todo); info.addSeparator(); info.add(hp); UIManager.LookAndFeelInfo[] m = UIManager.getInstalledLookAndFeels(); for(int i = 0; i < m.length; i++) { //JMenuItem tmp = new JMenuItem(m[i].getName()); //tmp.addActionListener(this); //lf.add(tmp); /* * Don't add menu items for unsupported look and feel's. * * It would be nice to use something like * isSupportedLookandFeel, but the information provided by * UIManager.LookAndFeelInfo is very limited. This is * supposedly done on purpose according to the API docs, * but what good does a non-supported look and feel in a * menu item do? */ try { LookAndFeel lnf = (LookAndFeel) Class.forName(m[i].getClassName()) .newInstance(); if(lnf.isSupportedLookAndFeel()) { JMenuItem tmp = new JMenuItem(m[i].getName()); tmp.addActionListener(this); lf.add(tmp); } } catch(ClassNotFoundException cnfe) { continue; } catch(InstantiationException ie) { continue; } catch(IllegalAccessException iae) { continue; } } view.add(lf); background.add(stdback); view.add(background); manage.addActionListener(this); //UIManager.setLookAndFeel(); add(file); add(opt); add(view); add(tools); add(bookmarks); add(info); loadBookmarks(); //add(experimental); } public void loadBookmarks() { marks = new Hashtable(); bookmarks.removeAll(); bookmarks.add(add); bookmarks.add(manage); bookmarks.addSeparator(); String data = ""; try { DataInput in = new DataInputStream(new BufferedInputStream(new FileInputStream(Settings.bookmarks))); while((data = in.readLine()) != null) { if(!data.startsWith("#") && !data.trim().equals("")) { addBookmarkLine(data); } } } catch(IOException e) { Log.debug("No bookmarks.txt found, using defaults."); addBookmark("FTP", "ftp.kernel.org", "anonymous", "j-ftp@sf.net", 21, "/pub/linux/kernel", "false"); addBookmark("FTP", "upload.sourceforge.net", "anonymous", "j-ftp@sf.net", 21, "/incoming", "false"); addBookmark("SMB", "(LAN)", "guest", "guest", -1, "-", "false"); return; } } private void addBookmarkLine(String tmp) { try { StringTokenizer t = new StringTokenizer(tmp, "#", false); if(tmp.toLowerCase().trim().startsWith("<dir>")) { String dir = tmp.substring(tmp.indexOf(">") + 1, tmp.lastIndexOf("<")); //Log.debug("Dir: " + dir); JMenu m = new JMenu(dir); current.add(m); last = current; current = m; } else if(tmp.toLowerCase().trim().startsWith("<enddir>")) { current = last; } else { addBookmark(t.nextToken(), t.nextToken(), t.nextToken(), t.nextToken(), Integer.parseInt(t.nextToken()), t.nextToken(), t.nextToken()); } } catch(Exception ex) { Log.debug("Broken line: " + tmp); ex.printStackTrace(); } } public void addBookmark(String pr, String h, String u, String p, int po, String d, String l) { BookmarkItem x = new BookmarkItem(h); x.setUserdata(u, p); if(l.trim().startsWith("t")) { x.setLocal(true); }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -