⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vfsbrowser.java

📁 用java 编写的源码开放的文本编辑器。有很多有用的特性
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * VFSBrowser.java - VFS browser * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 2000, 2003 Slava Pestov * * 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 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 org.gjt.sp.jedit.browser;//{{{ Importsimport gnu.regexp.*;import javax.swing.border.EmptyBorder;import javax.swing.event.*;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.*;import java.awt.event.*;import java.awt.*;import java.io.File;import java.util.Enumeration;import java.util.Hashtable;import java.util.Vector;import org.gjt.sp.jedit.io.*;import org.gjt.sp.jedit.gui.*;import org.gjt.sp.jedit.msg.*;import org.gjt.sp.jedit.search.*;import org.gjt.sp.jedit.*;import org.gjt.sp.util.Log;//}}}/** * The main class of the VFS browser. * @author Slava Pestov * @version $Id: VFSBrowser.java,v 1.64 2003/02/18 22:03:19 spestov Exp $ */public class VFSBrowser extends JPanel implements EBComponent{	public static final String NAME = "vfs.browser";	//{{{ Browser types	/**	 * Open file dialog mode. Equals JFileChooser.OPEN_DIALOG for	 * backwards compatibility.	 */	public static final int OPEN_DIALOG = 0;	/**	 * Save file dialog mode. Equals JFileChooser.SAVE_DIALOG for	 * backwards compatibility.	 */	public static final int SAVE_DIALOG = 1;	/**	 * Choose directory dialog mode.	 */	public static final int BROWSER_DIALOG = 4;	/**	 * Choose directory dialog mode.	 */	public static final int CHOOSE_DIRECTORY_DIALOG = 3;	/**	 * Stand-alone browser mode.	 */	public static final int BROWSER = 2;	//}}}	//{{{ browseDirectoryInNewWindow() method	/**	 * Opens the specified directory in a new, floating, file system browser.	 * @param view The view	 * @param path The directory's path	 * @since jEdit 4.1pre2	 */	public static void browseDirectoryInNewWindow(View view, String path)	{		DockableWindowManager wm = view.getDockableWindowManager();		if(path != null)		{			// this is such a bad way of doing it, but oh well...			jEdit.setTemporaryProperty("vfs.browser.path.tmp",path);		}		wm.floatDockableWindow("vfs.browser");		jEdit.unsetProperty("vfs.browser.path.tmp");	} //}}}	//{{{ browseDirectory() method	/**	 * Opens the specified directory in a file system browser.	 * @param view The view	 * @param path The directory's path	 * @since jEdit 4.0pre3	 */	public static void browseDirectory(View view, String path)	{		DockableWindowManager wm = view.getDockableWindowManager();		VFSBrowser browser = (VFSBrowser)wm.getDockable(NAME);		if(browser != null)		{			wm.showDockableWindow(NAME);			browser.setDirectory(path);		}		else		{			if(path != null)			{				// this is such a bad way of doing it, but oh well...				jEdit.setTemporaryProperty("vfs.browser.path.tmp",path);			}			wm.addDockableWindow("vfs.browser");			jEdit.unsetProperty("vfs.browser.path.tmp");		}	} //}}}	//{{{ VFSBrowser constructor	/**	 * Creates a new VFS browser.	 * @param view The view to open buffers in by default	 */	public VFSBrowser(View view)	{		this(view,null,BROWSER,true,false);	} //}}}	//{{{ VFSBrowser constructor	/**	 * Creates a new VFS browser.	 * @param view The view to open buffers in by default	 * @param path The path to display	 * @param mode The browser mode	 * @param multipleSelection True if multiple selection should be allowed	 * @param floating True if this browser instance is floating	 */	public VFSBrowser(View view, String path, int mode, boolean multipleSelection,		boolean floating)	{		super(new BorderLayout());		listenerList = new EventListenerList();		this.mode = mode;		this.multipleSelection = multipleSelection;		this.floating = floating;		this.view = view;		currentEncoding = jEdit.getProperty("buffer.encoding",			System.getProperty("file.encoding"));		ActionHandler actionHandler = new ActionHandler();		Box topBox = new Box(BoxLayout.Y_AXIS);		// this is tricky, because in BROWSER mode, the menu bar		// and tool bar are stacked on top of each other, and		// the user can toggle the tool bar. In dialog modes,		// the two are side by side and the tool bar is always		// visible.		toolbarBox = new Box(mode == BROWSER			? BoxLayout.Y_AXIS			: BoxLayout.X_AXIS);		JPanel menuBar = createMenuBar();		if(mode == BROWSER)			menuBar.add(Box.createGlue());		toolbarBox.add(menuBar);		if(mode != BROWSER)		{			toolbarBox.add(Box.createHorizontalStrut(6));			toolbarBox.add(createToolBar());			toolbarBox.add(Box.createGlue());		}		topBox.add(toolbarBox);		GridBagLayout layout = new GridBagLayout();		JPanel pathAndFilterPanel = new JPanel(layout);		GridBagConstraints cons = new GridBagConstraints();		cons.gridwidth = cons.gridheight = 1;		cons.gridx = cons.gridy = 0;		cons.fill = GridBagConstraints.BOTH;		cons.anchor = GridBagConstraints.EAST;		JLabel label = new JLabel(jEdit.getProperty("vfs.browser.path"),			SwingConstants.RIGHT);		label.setBorder(new EmptyBorder(0,0,0,12));		layout.setConstraints(label,cons);		pathAndFilterPanel.add(label);		pathField = new HistoryTextField("vfs.browser.path");		pathField.setInstantPopups(true);		pathField.setEnterAddsToHistory(false);		pathField.setSelectAllOnFocus(true);		if(floating)		{			label.setDisplayedMnemonic(jEdit.getProperty(				"vfs.browser.path.mnemonic").charAt(0));			label.setLabelFor(pathField);		}		// because its preferred size can be quite wide, we		// don't want it to make the browser way too big,		// so set the preferred width to 0.		Dimension prefSize = pathField.getPreferredSize();		prefSize.width = 0;		pathField.setPreferredSize(prefSize);		pathField.addActionListener(actionHandler);		cons.gridx = 1;		cons.weightx = 1.0f;		layout.setConstraints(pathField,cons);		pathAndFilterPanel.add(pathField);		filterCheckbox = new JCheckBox(jEdit.getProperty("vfs.browser.filter"));		filterCheckbox.setMargin(new Insets(0,0,0,0));		filterCheckbox.setRequestFocusEnabled(false);		filterCheckbox.setBorder(new EmptyBorder(0,0,0,12));		filterCheckbox.setSelected(jEdit.getBooleanProperty(			"vfs.browser.filter-enabled"));		filterCheckbox.addActionListener(actionHandler);		if(mode != CHOOSE_DIRECTORY_DIALOG)		{			cons.gridx = 0;			cons.weightx = 0.0f;			cons.gridy = 1;			layout.setConstraints(filterCheckbox,cons);			pathAndFilterPanel.add(filterCheckbox);		}		filterField = new HistoryTextField("vfs.browser.filter");		filterField.setInstantPopups(true);		filterField.setSelectAllOnFocus(true);		filterField.addActionListener(actionHandler);		if(mode != CHOOSE_DIRECTORY_DIALOG)		{			cons.gridx = 1;			cons.weightx = 1.0f;			layout.setConstraints(filterField,cons);			pathAndFilterPanel.add(filterField);		}		topBox.add(pathAndFilterPanel);		add(BorderLayout.NORTH,topBox);		boolean splitHorizontally = false;		if(jEdit.getBooleanProperty("vfs.browser.splitHorizontally") && mode != BROWSER)			splitHorizontally = true;		add(BorderLayout.CENTER,browserView = new BrowserView(this,splitHorizontally));		propertiesChanged();		String filter = jEdit.getProperty("vfs.browser.last-filter");		if(filter == null)			filter = jEdit.getProperty("vfs.browser.default-filter");		filterField.setText(filter);		filterField.addCurrentToHistory();		updateFilterEnabled();		// see VFSBrowser.browseDirectory()		if(path == null)			path = jEdit.getProperty("vfs.browser.path.tmp");		if(path == null || path.length() == 0)		{			String userHome = System.getProperty("user.home");			String defaultPath = jEdit.getProperty("vfs.browser.defaultPath");			if(defaultPath.equals("home"))				path = userHome;			else if(defaultPath.equals("buffer"))			{				if(view != null)				{					Buffer buffer = view.getBuffer();					path = buffer.getDirectory();				}				else					path = userHome;			}			else if(defaultPath.equals("last"))			{				HistoryModel pathModel = HistoryModel.getModel("vfs.browser.path");				if(pathModel.getSize() == 0)					path = "~";				else					path = pathModel.getItem(0);			}			else if(defaultPath.equals("favorites"))				path = "favorites:";			else			{				// unknown value??!!!				path = userHome;			}		}		final String _path = path;		SwingUtilities.invokeLater(new Runnable()		{			public void run()			{				setDirectory(_path);			}		});	} //}}}	//{{{ requestDefaultFocus() method	public boolean requestDefaultFocus()	{		browserView.focusOnFileView();		return true;	} //}}}	//{{{ addNotify() method	public void addNotify()	{		super.addNotify();		EditBus.addToBus(this);	} //}}}	//{{{ removeNotify() method	public void removeNotify()	{		super.removeNotify();		jEdit.setBooleanProperty("vfs.browser.filter-enabled",			filterCheckbox.isSelected());		if(mode == BROWSER || !jEdit.getBooleanProperty(			"vfs.browser.currentBufferFilter"))		{			jEdit.setProperty("vfs.browser.last-filter",				filterField.getText());		}		EditBus.removeFromBus(this);	} //}}}	//{{{ handleMessage() method	public void handleMessage(EBMessage msg)	{		if(msg instanceof PropertiesChanged)			propertiesChanged();		else if(msg instanceof BufferUpdate)		{			BufferUpdate bmsg = (BufferUpdate)msg;			if(bmsg.getWhat() == BufferUpdate.CREATED				|| bmsg.getWhat() == BufferUpdate.CLOSED)				browserView.updateFileView();			// hacked BufferIORequest to send VFSUpdates in case			// two stage save is off now...			/* else if(bmsg.getWhat() == BufferUpdate.SAVED)			{				maybeReloadDirectory(MiscUtilities.getParentOfPath(					bmsg.getBuffer().getPath()));			} */		}		else if(msg instanceof VFSUpdate)		{			maybeReloadDirectory(((VFSUpdate)msg).getPath());		}	} //}}}	//{{{ getView() method	public View getView()	{		return view;	} //}}}	//{{{ getMode() method	public int getMode()	{		return mode;	} //}}}	//{{{ isMultipleSelectionEnabled() method	public boolean isMultipleSelectionEnabled()	{		return multipleSelection;	} //}}}	//{{{ getShowHiddenFiles() method	public boolean getShowHiddenFiles()	{		return showHiddenFiles;	} //}}}	//{{{ setShowHiddenFiles() method	public void setShowHiddenFiles(boolean showHiddenFiles)	{		this.showHiddenFiles = showHiddenFiles;	} //}}}	//{{{ getFilenameFilter() method	/**	 * Returns the file name filter glob.	 * @since jEdit 3.2pre2	 */	public String getFilenameFilter()	{		if(filterCheckbox.isSelected())		{			String filter = filterField.getText();			if(filter.length() == 0)				return "*";			else				return filter;		}		else			return "*";	} //}}}	//{{{ setFilenameFilter() method	public void setFilenameFilter(String filter)	{		if(filter == null || filter.length() == 0 || filter.equals("*"))			filterCheckbox.setSelected(false);		else		{			filterCheckbox.setSelected(true);			filterField.setText(filter);		}	} //}}}	//{{{ getDirectoryField() method	public HistoryTextField getDirectoryField()	{		return pathField;	} //}}}	//{{{ getDirectory() method	public String getDirectory()	{		return path;	} //}}}	//{{{ setDirectory() method	public void setDirectory(String path)	{		if(path.startsWith("file:"))			path = path.substring(5);		String strippedPath;		if(path.length() != 1 && (path.endsWith("/")			|| path.endsWith(java.io.File.separator)))			strippedPath = path.substring(0,path.length() - 1);		else			strippedPath = path;		pathField.setText(strippedPath);		if(!startRequest())			return;		updateFilenameFilter();		browserView.loadDirectory(path);		this.path = strippedPath;		VFSManager.runInAWTThread(new Runnable()		{			public void run()			{				endRequest();			}		});	} //}}}	//{{{ rootDirectory() method	/**	 * Goes to the local drives directory.	 * @since jEdit 4.0pre4	 */	public void rootDirectory()	{		if(VFSManager.getVFSByName("roots") != null)			setDirectory(FileRootsVFS.PROTOCOL + ":");		else			setDirectory("/");	} //}}}	//{{{ reloadDirectory() method

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -