From: David ‘Bombe’ Roden Date: Fri, 4 Apr 2008 21:27:34 +0000 (+0000) Subject: i18nable action X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=2eb7b9b9251e39a4a17c06d3cdde9ca106fb6943;p=jSite2.git i18nable action git-svn-id: http://trooper/svn/projects/jSite/trunk@586 c3eda9e8-030b-0410-8277-bc7414b0a119 --- diff --git a/src/net/pterodactylus/jsite/gui/I18nAction.java b/src/net/pterodactylus/jsite/gui/I18nAction.java new file mode 100644 index 0000000..4fa2950 --- /dev/null +++ b/src/net/pterodactylus/jsite/gui/I18nAction.java @@ -0,0 +1,77 @@ +package net.pterodactylus.jsite.gui; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.Icon; + +import net.pterodactylus.jsite.i18n.I18n; + +/** + * Helper class that initializes actions with values from {@link I18n}. + * + * @author David ‘Bombe’ Roden <bombe@freenetproject.org> + * @version $Id$ + */ +public abstract class I18nAction extends AbstractAction { + + /** + * Creates a new action that uses the given name as base name to get values + * from {@link I18n}. + * + * @param i18nName + * The base name of the action + */ + public I18nAction(String i18nName) { + this(i18nName, null); + } + + /** + * Creates a new action that uses the given name as base name to get values + * from {@link I18n} and the given icon. + * + * @param i18nName + * The base name of the action + * @param icon + * The icon for the action + */ + public I18nAction(String i18nName, Icon icon) { + this(i18nName, true, icon); + } + + /** + * Creates a new action that uses the given name as base name to get values + * from {@link I18n}. + * + * @param i18nName + * The base name of the action + * @param enabled + * Whether the action should be enabled + */ + public I18nAction(String i18nName, boolean enabled) { + this(i18nName, enabled, null); + } + + /** + * Creates a new action that uses the given name as base name to get values + * from {@link I18n} and the given icon. + * + * @param i18nName + * The base name of the action + * @param enabled + * Whether the action should be enabled + * @param icon + * The icon for the action + */ + public I18nAction(String i18nName, boolean enabled, Icon icon) { + putValue(Action.NAME, I18n.get(i18nName + ".name")); + putValue(Action.MNEMONIC_KEY, (int) I18n.get(i18nName + ".mnemonic").charAt(0)); + putValue(Action.ACCELERATOR_KEY, I18n.getKeyStroke(i18nName + ".accelerator")); + putValue(Action.SHORT_DESCRIPTION, I18n.get(i18nName + ".shortDescription")); + putValue(Action.LONG_DESCRIPTION, I18n.get(i18nName + ".longDescription")); + if (icon != null) { + putValue(Action.SMALL_ICON, icon); + } + setEnabled(enabled); + } + +} \ No newline at end of file