standardaction.java

来自「具有不同语法高亮的编辑器实例」· Java 代码 · 共 156 行

JAVA
156
字号
/*
 * 11/27/2004
 *
 * StandardAction.java - An action used by a GUIApplication implementation.
 * Copyright (C) 2004 Robert Futrell
 * email@address.com
 * www.website.com
 *
 * 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.fife.ui;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Icon;
import javax.swing.KeyStroke;


/**
 * The action type used by all instances of <code>GUIApplication</code>.  This
 * is merely an action with many ease-of-use methods.
 *
 * @author Robert Futrell
 * @version 0.5
 * @see org.fife.ui.app.GUIApplication
 */
public abstract class StandardAction extends AbstractAction {


/*****************************************************************************/


	/**
	 * Constructor.
	 *
	 * @param text The text (name) associated with the action.
	 */
	public StandardAction(String text) {
		this(text, null, null, null, null);
	}


/*****************************************************************************/


	/**
	 * Constructor.
	 *
	 * @param text The text (name) associated with the action.
	 * @param icon The icon associated with the action.
	 * @param desc The description of the action (used in tooltips???).
	 * @param mnemonic The mnemonic for the action.
	 * @param accelerator The accelerator key for the action.
	 */
	public StandardAction(String text, Icon icon, String desc,
					Integer mnemonic, KeyStroke accelerator) {
		super(text);
		putValue(SMALL_ICON, icon);
		putValue(SHORT_DESCRIPTION, desc);
		putValue(ACCELERATOR_KEY, accelerator);
		putValue(MNEMONIC_KEY, mnemonic);
	}


/*****************************************************************************/


	/**
	 * This method should be overridden with the action's stuff.
	 *
	 * @param e The action being performed.
	 */
	public abstract void actionPerformed(ActionEvent e);


/*****************************************************************************/


	/**
	 * Returns the accelerator for this action.
	 *
	 * @return The accelerator.
	 */
	public KeyStroke getAccelerator() {
		return (KeyStroke)getValue(ACCELERATOR_KEY);
	}


/*****************************************************************************/


	/**
	 * Returns the description for this action.
	 *
	 * @return The description.
	 */
	public String getDescription() {
		return (String)getValue(SHORT_DESCRIPTION);
	}


/*****************************************************************************/


	/**
	 * Returns the icon for this action.
	 *
	 * @return The icon.
	 */
	public Icon getIcon() {
		return (Icon)getValue(SMALL_ICON);
	}


/*****************************************************************************/


	/**
	 * Returns the mnemonic for this action.
	 *
	 * @return The mnemonic, or <code>-1</code> if not defined.
	 */
	public int getMnemonic() {
		Integer i = (Integer)getValue(MNEMONIC_KEY);
		return i!=null ? i.intValue() : -1;
	}


/*****************************************************************************/


	/**
	 * Returns the name of this action.
	 *
	 * @return The name of this action.
	 */
	public String getName() {
		return (String)getValue(NAME);
	}


/*****************************************************************************/

}

⌨️ 快捷键说明

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