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

📄 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, 2004 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.menu.*;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 #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 #showPopupMenu(JPopupMenu,Component,int,int)}</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.80 2004/03/19 19:16:35 spestov Exp $ */public class GUIUtilities{	//{{{ Some predefined icons	public static Icon NEW_BUFFER_ICON;	public static Icon DIRTY_BUFFER_ICON;	public static Icon READ_ONLY_BUFFER_ICON;	public static Icon NORMAL_BUFFER_ICON;	public static Icon WINDOW_ICON;	//}}}	//{{{ Icon methods	//{{{ setIconPath() method	/**	 * Sets the path where jEdit looks for icons.	 * @since jEdit 4.2pre5	 */	public static void setIconPath(String iconPath)	{		GUIUtilities.iconPath = iconPath;		if(icons != null)			icons.clear();	} //}}}	//{{{ 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(MiscUtilities.isURL(iconName))		{			icon = new ImageIcon(iconName.substring(5));		}		else		{			try			{				URL url = new URL(iconPath + iconName);				icon = new ImageIcon(url);			}			catch(Exception e)			{				try				{					URL url = new URL(defaultIconPath + iconName);					icon = new ImageIcon(url);				}				catch(Exception ex)				{					Log.log(Log.ERROR,GUIUtilities.class,						"Icon not found: " + iconName);					Log.log(Log.ERROR,GUIUtilities.class,ex);					return null;				}			}		}		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)	{		return loadMenuBar(jEdit.getActionContext(),name);	} //}}}	//{{{ loadMenuBar() method	/**	 * Creates a menubar. Plugins should not need to call this method.	 * @param context An action context	 * @param name The menu bar name	 * @since jEdit 4.2pre1	 */	public static JMenuBar loadMenuBar(ActionContext context, String name)	{		String menus = jEdit.getProperty(name);		StringTokenizer st = new StringTokenizer(menus);		JMenuBar mbar = new JMenuBar();		while(st.hasMoreTokens())		{			mbar.add(loadMenu(context,st.nextToken()));		}		return mbar;	} //}}}	//{{{ 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 name The menu name	 * @see #loadMenuItem(String)	 * @since jEdit 2.6pre2	 */	public static JMenu loadMenu(String name)	{		return loadMenu(jEdit.getActionContext(),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 context An action context; either	 * <code>jEdit.getActionContext()</code> or	 * <code>VFSBrowser.getActionContext()</code>.	 * @param name The menu name	 * @see #loadMenuItem(String)	 * @since jEdit 4.2pre1	 */	public static JMenu loadMenu(ActionContext context, String name)	{		return new EnhancedMenu(name,			jEdit.getProperty(name.concat(".label")),			context);	} //}}}	//{{{ loadPopupMenu() method	/**	 * Creates a popup menu.	 	 * @param name The menu name	 * @since jEdit 2.6pre2	 */	public static JPopupMenu loadPopupMenu(String name)	{		return loadPopupMenu(jEdit.getActionContext(),name);	} //}}}	//{{{ loadPopupMenu() method	/**	 * Creates a popup menu.	 	 * @param context An action context; either	 * <code>jEdit.getActionContext()</code> or	 * <code>VFSBrowser.getActionContext()</code>.	 * @param name The menu name	 * @since jEdit 4.2pre1	 */	public static JPopupMenu loadPopupMenu(ActionContext context, 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					menu.add(loadMenuItem(context,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(jEdit.getActionContext(),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)	{		return loadMenuItem(jEdit.getActionContext(),name,setMnemonic);	} //}}}	//{{{ loadMenuItem() method	/**	 * Creates a menu item.	 * @param context An action context; either	 * <code>jEdit.getActionContext()</code> or	 * <code>VFSBrowser.getActionContext()</code>.	 * @param name The menu item name	 * @param setMnemonic True if the menu item should have a mnemonic	 * @since jEdit 4.2pre1	 */	public static JMenuItem loadMenuItem(ActionContext context, String name,		boolean setMnemonic)	{		if(name.startsWith("%"))			return loadMenu(context,name.substring(1));		String label = jEdit.getProperty(name + ".label");		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(jEdit.getBooleanProperty(name + ".toggle"))			mi = new EnhancedCheckBoxMenuItem(label,name,context);		else			mi = new EnhancedMenuItem(label,name,context);		if(!OperatingSystem.isMacOS() && setMnemonic && mnemonic != '\0')			mi.setMnemonic(mnemonic);		return mi;	} //}}}	//{{{ loadToolBar() method	/**	 * Creates a toolbar.	 * @param name The toolbar name	 * @since jEdit 4.2pre2	 */	public static Box loadToolBar(String name)	{		return loadToolBar(jEdit.getActionContext(),name);	} //}}}	//{{{ loadToolBar() method	/**	 * Creates a toolbar.	 * @param context An action context; either	 * <code>jEdit.getActionContext()</code> or	 * <code>VFSBrowser.getActionContext()</code>.	 * @param name The toolbar name	 * @since jEdit 4.2pre2	 */	public static Box loadToolBar(ActionContext context, String name)	{		Box toolBar = new Box(BoxLayout.X_AXIS);		String buttons = jEdit.getProperty(name);		if(buttons != null)		{			StringTokenizer st = new StringTokenizer(buttons);			while(st.hasMoreTokens())			{				String button = st.nextToken();				if(button.equals("-"))					toolBar.add(Box.createHorizontalStrut(12));				else				{					JButton b = loadToolButton(context,button);					if(b != null)						toolBar.add(b);				}			}		}		toolBar.add(Box.createGlue());		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)	{		return loadToolButton(jEdit.getActionContext(),name);	} //}}}	//{{{ 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 context An action context; either	 * <code>jEdit.getActionContext()</code> or	 * <code>VFSBrowser.getActionContext()</code>.	 * @param name The name of the button	 * @since jEdit 4.2pre1	 */	public static EnhancedButton loadToolButton(ActionContext context,		String name)	{		String label = jEdit.getProperty(name + ".label");		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,name,context);	} //}}}	//{{{ 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();

⌨️ 快捷键说明

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