2 package net.pterodactylus.jsite.i18n.gui;
4 import javax.swing.AbstractAction;
5 import javax.swing.Action;
6 import javax.swing.Icon;
8 import net.pterodactylus.jsite.i18n.I18n;
9 import net.pterodactylus.jsite.i18n.I18nable;
12 * Helper class that initializes actions with values from {@link I18n}.
14 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
16 public abstract class I18nAction extends AbstractAction implements I18nable {
18 /** The I18n basename. */
19 private final String i18nName;
22 * Creates a new action that uses the given name as base name to get values
26 * The base name of the action
28 public I18nAction(String i18nName) {
33 * Creates a new action that uses the given name as base name to get values
34 * from {@link I18n} and the given icon.
37 * The base name of the action
39 * The icon for the action
41 public I18nAction(String i18nName, Icon icon) {
42 this(i18nName, true, icon);
46 * Creates a new action that uses the given name as base name to get values
50 * The base name of the action
52 * Whether the action should be enabled
54 public I18nAction(String i18nName, boolean enabled) {
55 this(i18nName, enabled, null);
59 * Creates a new action that uses the given name as base name to get values
60 * from {@link I18n} and the given icon.
63 * The base name of the action
65 * Whether the action should be enabled
67 * The icon for the action
69 public I18nAction(String i18nName, boolean enabled, Icon icon) {
70 this.i18nName = i18nName;
72 putValue(Action.SMALL_ICON, icon);
81 public void updateI18n() {
82 putValue(Action.NAME, I18n.get(i18nName + ".name"));
83 putValue(Action.MNEMONIC_KEY, I18n.getKey(i18nName + ".mnemonic"));
84 putValue(Action.ACCELERATOR_KEY, I18n.getKeyStroke(i18nName + ".accelerator"));
85 putValue(Action.SHORT_DESCRIPTION, I18n.get(i18nName + ".shortDescription"));
86 putValue(Action.LONG_DESCRIPTION, I18n.get(i18nName + ".longDescription"));