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

📄 action.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* * Copyright (c) 2000, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: *     IBM Corporation - initial API and implementation *******************************************************************************/package org.eclipse.jface.action;import org.eclipse.jface.resource.ImageDescriptor;import org.eclipse.swt.SWT;import org.eclipse.swt.events.HelpListener;import org.eclipse.swt.widgets.Control;import org.eclipse.swt.widgets.Event;import org.eclipse.swt.widgets.Menu;/** * The standard abstract implementation of an action. * <p> * Subclasses must implement the <code>IAction.run</code> method to carry out * the action's semantics. * </p> */public abstract class Action extends AbstractAction implements IAction {	private static final IMenuCreator VAL_DROP_DOWN_MENU = new IMenuCreator() {		public void dispose() {			// do nothing		}		public Menu getMenu(Control parent) {			// do nothing			return null;		}		public Menu getMenu(Menu parent) {			// do nothing			return null;		}	};	/*	 * The list of default values the action can have. These values will	 * determine the style of the action.	 */	private static final String VAL_PUSH_BTN = "PUSH_BTN"; //$NON-NLS-1$	private static final Integer VAL_RADIO_BTN_OFF = new Integer(0);	private static final Integer VAL_RADIO_BTN_ON = new Integer(1);	private static final Boolean VAL_TOGGLE_BTN_OFF = Boolean.FALSE;	private static final Boolean VAL_TOGGLE_BTN_ON = Boolean.TRUE;	/**	 * Converts an accelerator key code to a string representation.	 * 	 * @param keyCode	 *            the key code to be translated	 * @return a string representation of the key code	 */	public static String convertAccelerator(int keyCode) {		return LegacyActionTools.convertAccelerator(keyCode);	}	/**	 * Parses the given accelerator text, and converts it to an accelerator key	 * code.	 * 	 * @param acceleratorText	 *            the accelerator text	 * @return the SWT key code, or 0 if there is no accelerator	 */	public static int convertAccelerator(String acceleratorText) {		return LegacyActionTools.convertAccelerator(acceleratorText);	}	/**	 * Maps a standard keyboard key name to an SWT key code. Key names are	 * converted to upper case before comparison. If the key name is a single	 * letter, for example "S", its character code is returned.	 * <p>	 * The following key names are known (case is ignored):	 * <ul>	 * <li><code>"BACKSPACE"</code></li>	 * <li><code>"TAB"</code></li>	 * <li><code>"RETURN"</code></li>	 * <li><code>"ENTER"</code></li>	 * <li><code>"ESC"</code></li>	 * <li><code>"ESCAPE"</code></li>	 * <li><code>"DELETE"</code></li>	 * <li><code>"SPACE"</code></li>	 * <li><code>"ARROW_UP"</code>, <code>"ARROW_DOWN"</code>,	 * <code>"ARROW_LEFT"</code>, and <code>"ARROW_RIGHT"</code></li>	 * <li><code>"PAGE_UP"</code> and <code>"PAGE_DOWN"</code></li>	 * <li><code>"HOME"</code></li>	 * <li><code>"END"</code></li>	 * <li><code>"INSERT"</code></li>	 * <li><code>"F1"</code>, <code>"F2"</code> through <code>"F12"</code></li>	 * </ul>	 * </p>	 * 	 * @param token	 *            the key name	 * @return the SWT key code, <code>-1</code> if no match was found	 * @see SWT	 */	public static int findKeyCode(String token) {		return LegacyActionTools.findKeyCode(token);	}	/**	 * Maps an SWT key code to a standard keyboard key name. The key code is	 * stripped of modifiers (SWT.CTRL, SWT.ALT, SWT.SHIFT, and SWT.COMMAND). If	 * the key code is not an SWT code (for example if it a key code for the key	 * 'S'), a string containing a character representation of the key code is	 * returned.	 * 	 * @param keyCode	 *            the key code to be translated	 * @return the string representation of the key code	 * @see SWT	 * @since 2.0	 */	public static String findKeyString(int keyCode) {		return LegacyActionTools.findKeyString(keyCode);	}	/**	 * Maps standard keyboard modifier key names to the corresponding SWT	 * modifier bit. The following modifier key names are recognized (case is	 * ignored): <code>"CTRL"</code>, <code>"SHIFT"</code>,	 * <code>"ALT"</code>, and <code>"COMMAND"</code>. The given modifier	 * key name is converted to upper case before comparison.	 * 	 * @param token	 *            the modifier key name	 * @return the SWT modifier bit, or <code>0</code> if no match was found	 * @see SWT	 */	public static int findModifier(String token) {		return LegacyActionTools.findModifier(token);	}	/**	 * Returns a string representation of an SWT modifier bit (SWT.CTRL,	 * SWT.ALT, SWT.SHIFT, and SWT.COMMAND). Returns <code>null</code> if the	 * key code is not an SWT modifier bit.	 * 	 * @param keyCode	 *            the SWT modifier bit to be translated	 * @return the string representation of the SWT modifier bit, or	 *         <code>null</code> if the key code was not an SWT modifier bit	 * @see SWT	 * @since 2.0	 */	public static String findModifierString(int keyCode) {		return LegacyActionTools.findModifierString(keyCode);	}	/**	 * Convenience method for removing any optional accelerator text from the	 * given string. The accelerator text appears at the end of the text, and is	 * separated from the main part by a single tab character <code>'\t'</code>.	 * 	 * @param text	 *            the text	 * @return the text sans accelerator	 */	public static String removeAcceleratorText(String text) {		return LegacyActionTools.removeAcceleratorText(text);	}	/**	 * Convenience method for removing any mnemonics from the given string. For	 * example, <code>removeMnemonics("&Open")</code> will return	 * <code>"Open"</code>.	 * 	 * @param text	 *            the text	 * @return the text sans mnemonics	 * 	 * @since 3.0	 */	public static String removeMnemonics(String text) {		return LegacyActionTools.removeMnemonics(text);	}	/**	 * This action's accelerator; <code>0</code> means none.	 */	private int accelerator = 0;	/**	 * This action's action definition id, or <code>null</code> if none.	 */	private String actionDefinitionId;	/**	 * This action's description, or <code>null</code> if none.	 */	private String description;	/**	 * This action's disabled image, or <code>null</code> if none.	 */	private ImageDescriptor disabledImage;	/**	 * Indicates this action is enabled.	 */	private boolean enabled = true;	/**	 * An action's help listener, or <code>null</code> if none.	 */	private HelpListener helpListener;	/**	 * This action's hover image, or <code>null</code> if none.	 */	private ImageDescriptor hoverImage;	/**	 * This action's id, or <code>null</code> if none.	 */	private String id;	/**	 * This action's image, or <code>null</code> if none.	 */	private ImageDescriptor image;	/**	 * This action's text, or <code>null</code> if none.	 */	private String text;	/**	 * This action's tool tip text, or <code>null</code> if none.	 */	private String toolTipText;	/**	 * Holds the action's menu creator (an IMenuCreator) or checked state (a	 * Boolean for toggle button, or an Integer for radio button), or	 * <code>null</code> if neither have been set.	 * <p>	 * The value of this field affects the value of <code>getStyle()</code>.	 * </p>	 */	private Object value = null;	/**	 * Creates a new action with no text and no image.	 * <p>	 * Configure the action later using the set methods.	 * </p>	 */	protected Action() {		// do nothing	}	/**	 * Creates a new action with the given text and no image. Calls the zero-arg	 * constructor, then <code>setText</code>.	 * 	 * @param text	 *            the string used as the text for the action, or	 *            <code>null</code> if there is no text	 * @see #setText	 */	protected Action(String text) {		this();		setText(text);	}	/**	 * Creates a new action with the given text and image. Calls the zero-arg	 * constructor, then <code>setText</code> and	 * <code>setImageDescriptor</code>.	 * 	 * @param text	 *            the action's text, or <code>null</code> if there is no text	 * @param image	 *            the action's image, or <code>null</code> if there is no	 *            image	 * @see #setText	 * @see #setImageDescriptor	 */	protected Action(String text, ImageDescriptor image) {		this(text);		setImageDescriptor(image);	}	/**	 * Creates a new action with the given text and style.	 * 	 * @param text	 *            the action's text, or <code>null</code> if there is no text	 * @param style	 *            one of <code>AS_PUSH_BUTTON</code>,	 *            <code>AS_CHECK_BOX</code>, <code>AS_DROP_DOWN_MENU</code>,	 *            <code>AS_RADIO_BUTTON</code>, and	 *            <code>AS_UNSPECIFIED</code>.	 */	protected Action(String text, int style) {		this(text);		switch (style) {		case AS_PUSH_BUTTON:			value = VAL_PUSH_BTN;			break;		case AS_CHECK_BOX:			value = VAL_TOGGLE_BTN_OFF;			break;		case AS_DROP_DOWN_MENU:			value = VAL_DROP_DOWN_MENU;			break;		case AS_RADIO_BUTTON:			value = VAL_RADIO_BTN_OFF;			break;		}	}	/*	 * (non-Javadoc) Method declared on IAction.	 */	public int getAccelerator() {		return accelerator;	}	/*	 * (non-Javadoc) Method declared on IAction.	 * 	 */	public String getActionDefinitionId() {		return actionDefinitionId;	}	/*	 * (non-Javadoc) Method declared on IAction.	 */	public String getDescription() {		if (description != null) {			return description;		}

⌨️ 快捷键说明

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