All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.darwinsys.swingui.IntlAction Maven / Gradle / Ivy

There is a newer version: 1.8.0
Show newest version
package com.darwinsys.swingui;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;

/** Class for creating an Internationalized Swing Action.
 * See also
 
 * How to use Actions".
 */
public abstract class IntlAction extends AbstractAction {
	private static final long serialVersionUID = 1L;
	
	/** Convenience routine to make a Swing Action.
	 * @param b - ResourceBundle containting strings
	 * @param key - name such as "edit.cut" identifiying this action;
	 *		should have at least "label", "descr" and "key" values
	 * @param icon - an ImageIcon (24x24?)
	 */
	public IntlAction(
		ResourceBundle b, String key, ImageIcon icon) {

		String text =     b.getString(key + ".label");
		putValue(NAME, text);
		putValue(SMALL_ICON, icon);

		// May be a Mnemonic under ".key".
		try {
			String mnemonic = b.getString(key + ".key");
			putValue(MNEMONIC_KEY, Integer.valueOf(mnemonic.charAt(0)));
		} catch (MissingResourceException ex) {
			// Nothing to do.
		}

		// May be a ToolTip Description under ".descr".
		try {
			String ttDesc =   b.getString(key + ".descr");
			putValue(SHORT_DESCRIPTION, ttDesc);
		} catch (MissingResourceException ex) {
			putValue(SHORT_DESCRIPTION, text);
		}

	}
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy