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

📄 guiutilities.java

📁 用java 编写的源码开放的文本编辑器。有很多有用的特性
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * GUIUtilities.java - Various GUI utility functions * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 1999, 2002 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;//{{{ Importsimport javax.swing.*;import java.awt.*;import java.awt.event.*;import java.net.*;import java.util.*;import org.gjt.sp.jedit.browser.*;import org.gjt.sp.jedit.gui.*;import org.gjt.sp.jedit.syntax.SyntaxStyle;import org.gjt.sp.jedit.syntax.Token;import org.gjt.sp.util.Log;//}}}/** * Various GUI functions.<p> * * The most frequently used members of this class are: * * <ul> * <li>{@link #loadMenu(String)}</li> * <li>{@link #loadMenuItem(String)}</li> * <li>{@link #loadIcon(String)}</li> * <li>{@link #confirm(Component,String,Object[],int,int)}</li> * <li>{@link #error(Component,String,Object[])}</li> * <li>{@link #message(Component,String,Object[])}</li> * <li>{@link #showVFSFileDialog(View,String,int,boolean)}</li> * <li>{@link #loadGeometry(Window,String)}</li> * <li>{@link #saveGeometry(Window,String)}</li> * </ul> * * @author Slava Pestov * @version $Id: GUIUtilities.java,v 1.58 2003/02/17 19:48:54 spestov Exp $ */public class GUIUtilities{	//{{{ Some predefined icons	public static final Icon NEW_BUFFER_ICON = loadIcon("new.gif");	public static final Icon DIRTY_BUFFER_ICON = loadIcon("dirty.gif");	public static final Icon READ_ONLY_BUFFER_ICON = loadIcon("readonly.gif");	public static final Icon NORMAL_BUFFER_ICON = loadIcon("normal.gif");	public static final Icon WINDOW_ICON = loadIcon("jedit-icon.gif");	//}}}	//{{{ Icon methods	//{{{ loadIcon() method	/**	 * Loads an icon.	 * @param iconName The icon name	 * @since jEdit 2.6pre7	 */	public static Icon loadIcon(String iconName)	{		if(icons == null)			icons = new Hashtable();		// check if there is a cached version first		Icon icon = (Icon)icons.get(iconName);		if(icon != null)			return icon;		// get the icon		if(iconName.startsWith("file:"))		{			icon = new ImageIcon(iconName.substring(5));		}		else		{			URL url = GUIUtilities.class.getResource(				"/org/gjt/sp/jedit/icons/" + iconName);			if(url == null)			{				Log.log(Log.ERROR,GUIUtilities.class,					"Icon not found: " + iconName);				return null;			}			icon = new ImageIcon(url);		}		icons.put(iconName,icon);		return icon;	} //}}}	//{{{ getEditorIcon() method	/**	 * Returns the default editor window image.	 */	public static Image getEditorIcon()	{		return ((ImageIcon)WINDOW_ICON).getImage();	} //}}}	//{{{ getPluginIcon() method	/**	 * Returns the default plugin window image.	 */	public static Image getPluginIcon()	{		return ((ImageIcon)WINDOW_ICON).getImage();	} //}}}	//}}}	//{{{ Menus, tool bars	//{{{ loadMenuBar() method	/**	 * Creates a menubar. Plugins should not need to call this method.	 * @param name The menu bar name	 * @since jEdit 3.2pre5	 */	public static JMenuBar loadMenuBar(String name)	{		String menus = jEdit.getProperty(name);		StringTokenizer st = new StringTokenizer(menus);		JMenuBar mbar = new JMenuBar();		while(st.hasMoreTokens())		{			String menu = st.nextToken();			if(menu.equals("plugins"))				loadPluginsMenu(mbar);			else				mbar.add(loadMenu(menu));		}		return mbar;	} //}}}	//{{{ loadMenu() method	/**	 * @deprecated Use loadMenu(name) instead	 */	public static JMenu loadMenu(View view, String name)	{		return loadMenu(name);	} //}}}	//{{{ loadMenu() method	/**	 * Creates a menu. The menu label is set from the	 * <code><i>name</i>.label</code> property. The menu contents is taken	 * from the <code><i>name</i></code> property, which is a whitespace	 * separated list of action names. An action name of <code>-</code>	 * inserts a separator in the menu.	 * @param view The view to load the menu for	 * @param name The menu name	 * @see #loadMenuItem(String)	 * @since jEdit 2.6pre2	 */	public static JMenu loadMenu(String name)	{		if(name.equals("recent-files"))			return new RecentFilesMenu();		else if(name.equals("recent-directories"))			return new RecentDirectoriesMenu();		else if(name.equals("current-directory"))			return new DirectoryMenu("current-directory",null);		else if(name.equals("markers"))			return new MarkersMenu();		else if(name.equals("jedit-directory"))			return new DirectoryMenu("jedit-directory",jEdit.getJEditHome());		else if(name.equals("settings-directory"))		{			String settings = jEdit.getSettingsDirectory();			if(settings == null)				settings = jEdit.getJEditHome();			return new DirectoryMenu("settings-directory",settings);		}		else if(name.equals("macros"))			return new MacrosMenu();		else			return new EnhancedMenu(name);	} //}}}	//{{{ loadPopupMenu() method	/**	 * Creates a popup menu.	 * @param name The menu name	 * @since jEdit 2.6pre2	 */	public static JPopupMenu loadPopupMenu(String name)	{		JPopupMenu menu = new JPopupMenu();		String menuItems = jEdit.getProperty(name);		if(menuItems != null)		{			StringTokenizer st = new StringTokenizer(menuItems);			while(st.hasMoreTokens())			{				String menuItemName = st.nextToken();				if(menuItemName.equals("-"))					menu.addSeparator();				else				{					if(menuItemName.startsWith("%"))						menu.add(loadMenu(menuItemName.substring(1)));					else						menu.add(loadMenuItem(menuItemName,false));				}			}		}		return menu;	} //}}}	//{{{ loadMenuItem() method	/**	 * Creates a menu item. The menu item is bound to the action named by	 * <code>name</code> with label taken from the return value of the	 * {@link EditAction#getLabel()} method.	 *	 * @param name The menu item name	 * @see #loadMenu(String)	 * @since jEdit 2.6pre1	 */	public static JMenuItem loadMenuItem(String name)	{		return loadMenuItem(name,true);	} //}}}	//{{{ loadMenuItem() method	/**	 * Creates a menu item.	 * @param name The menu item name	 * @param setMnemonic True if the menu item should have a mnemonic	 * @since jEdit 3.1pre1	 */	public static JMenuItem loadMenuItem(String name, boolean setMnemonic)	{		EditAction action = jEdit.getAction(name);		String label = (action == null ?			jEdit.getProperty(name + ".label")			: action.getLabel());		if(label == null)			label = name;		char mnemonic;		int index = label.indexOf('$');		if(index != -1 && label.length() - index > 1)		{			mnemonic = Character.toLowerCase(label.charAt(index + 1));			label = label.substring(0,index).concat(label.substring(++index));		}		else			mnemonic = '\0';		JMenuItem mi;		if(action != null && action.isToggle())			mi = new EnhancedCheckBoxMenuItem(label,action);		else			mi = new EnhancedMenuItem(label,action);		if(!OperatingSystem.isMacOS() && setMnemonic && mnemonic != '\0')			mi.setMnemonic(mnemonic);		return mi;	} //}}}	//{{{ loadToolBar() method	/**	 * Creates a toolbar.	 * @param name The toolbar name	 */	public static JToolBar loadToolBar(String name)	{		JToolBar toolBar = new JToolBar();		toolBar.setFloatable(false);		String buttons = jEdit.getProperty(name);		if(buttons != null)		{			StringTokenizer st = new StringTokenizer(buttons);			while(st.hasMoreTokens())			{				String button = st.nextToken();				if(button.equals("-"))					toolBar.addSeparator();				else				{					JButton b = loadToolButton(button);					if(b != null)						toolBar.add(b);				}			}		}		return toolBar;	} //}}}	//{{{ loadToolButton() method	/**	 * Loads a tool bar button. The tooltip is constructed from	 * the <code><i>name</i>.label</code> and	 * <code><i>name</i>.shortcut</code> properties and the icon is loaded	 * from the resource named '/org/gjt/sp/jedit/icons/' suffixed	 * with the value of the <code><i>name</i>.icon</code> property.	 * @param name The name of the button	 */	public static EnhancedButton loadToolButton(String name)	{		EditAction action = jEdit.getAction(name);		String label = (action == null			? jEdit.getProperty(name + ".label")			: action.getLabel());		if(label == null)			label = name;		Icon icon;		String iconName = jEdit.getProperty(name + ".icon");		if(iconName == null)			icon = loadIcon("BrokenImage.png");		else		{			icon = loadIcon(iconName);			if(icon == null)				icon = loadIcon("BrokenImage.png");		}		String toolTip = prettifyMenuLabel(label);		String shortcut1 = jEdit.getProperty(name + ".shortcut");		String shortcut2 = jEdit.getProperty(name + ".shortcut2");		if(shortcut1 != null || shortcut2 != null)		{			toolTip = toolTip + " ("				+ (shortcut1 != null				? shortcut1 : "")				+ ((shortcut1 != null && shortcut2 != null)				? " or " : "")				+ (shortcut2 != null				? shortcut2				: "") + ")";		}		return new EnhancedButton(icon,toolTip,action);	} //}}}	//{{{ prettifyMenuLabel() method	/**	 * `Prettifies' a menu item label by removing the `$' sign. This	 * can be used to process the contents of an <i>action</i>.label	 * property.	 */	public static String prettifyMenuLabel(String label)	{		int index = label.indexOf('$');		if(index != -1)		{			label = label.substring(0,index)				.concat(label.substring(index + 1));		}		return label;	} //}}}	//}}}	//{{{ Canned dialog boxes	//{{{ message() method	/**	 * Displays a dialog box.	 * The title of the dialog is fetched from	 * the <code><i>name</i>.title</code> property. The message is fetched	 * from the <code><i>name</i>.message</code> property. The message	 * is formatted by the property manager with <code>args</code> as	 * positional parameters.	 * @param comp The component to display the dialog for	 * @param name The name of the dialog	 * @param args Positional parameters to be substituted into the	 * message text	 */	public static void message(Component comp, String name, Object[] args)	{		hideSplashScreen();		JOptionPane.showMessageDialog(comp,			jEdit.getProperty(name.concat(".message"),args),			jEdit.getProperty(name.concat(".title"),args),			JOptionPane.INFORMATION_MESSAGE);	} //}}}	//{{{ error() method	/**	 * Displays an error dialog box.	 * The title of the dialog is fetched from	 * the <code><i>name</i>.title</code> property. The message is fetched	 * from the <code><i>name</i>.message</code> property. The message	 * is formatted by the property manager with <code>args</code> as	 * positional parameters.	 * @param comp The component to display the dialog for	 * @param name The name of the dialog	 * @param args Positional parameters to be substituted into the	 * message text	 */	public static void error(Component comp, String name, Object[] args)	{		hideSplashScreen();		JOptionPane.showMessageDialog(comp,			jEdit.getProperty(name.concat(".message"),args),			jEdit.getProperty(name.concat(".title"),args),			JOptionPane.ERROR_MESSAGE);	} //}}}	//{{{ input() method	/**	 * Displays an input dialog box and returns any text the user entered.	 * The title of the dialog is fetched from	 * the <code><i>name</i>.title</code> property. The message is fetched

⌨️ 快捷键说明

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