1 package net.pterodactylus.jsite.i18n.gui;
3 import java.awt.event.ActionListener;
5 import javax.swing.AbstractAction;
6 import javax.swing.Action;
7 import javax.swing.Icon;
9 import net.pterodactylus.jsite.i18n.I18n;
10 import net.pterodactylus.jsite.i18n.I18nable;
13 * Helper class that initializes actions with values from {@link I18n}.
15 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
17 public abstract class I18nAction extends AbstractAction implements I18nable, ActionListener {
19 /** The I18n basename. */
20 private final String i18nName;
23 * Creates a new action that uses the given name as base name to get values
27 * The base name of the action
29 public I18nAction(String i18nName) {
34 * Creates a new action that uses the given name as base name to get values
35 * from {@link I18n} and the given icon.
38 * The base name of the action
40 * The icon for the action
42 public I18nAction(String i18nName, Icon icon) {
43 this(i18nName, true, icon);
47 * Creates a new action that uses the given name as base name to get values
51 * The base name of the action
53 * Whether the action should be enabled
55 public I18nAction(String i18nName, boolean enabled) {
56 this(i18nName, enabled, null);
60 * Creates a new action that uses the given name as base name to get values
61 * from {@link I18n} and the given icon.
64 * The base name of the action
66 * Whether the action should be enabled
68 * The icon for the action
70 public I18nAction(String i18nName, boolean enabled, Icon icon) {
71 this.i18nName = i18nName;
73 putValue(Action.SMALL_ICON, icon);
82 public void updateI18n() {
83 putValue(Action.NAME, I18n.get(i18nName + ".name"));
84 putValue(Action.MNEMONIC_KEY, I18n.getKey(i18nName + ".mnemonic"));
85 putValue(Action.ACCELERATOR_KEY, I18n.getKeyStroke(i18nName + ".accelerator"));
86 putValue(Action.SHORT_DESCRIPTION, I18n.get(i18nName + ".shortDescription"));
87 putValue(Action.LONG_DESCRIPTION, I18n.get(i18nName + ".longDescription"));