1 package net.pterodactylus.util.i18n.gui;
3 import javax.swing.AbstractAction;
4 import javax.swing.Action;
5 import javax.swing.Icon;
7 import net.pterodactylus.util.i18n.I18n;
8 import net.pterodactylus.util.i18n.I18nable;
11 * Helper class that initializes actions with values from {@link I18n}.
13 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
15 public abstract class I18nAction extends AbstractAction implements I18nable {
17 /** The I18n basename. */
18 private final String i18nName;
21 * 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(I18n i18n, String i18nName) {
30 this(i18n, i18nName, null);
34 * Creates a new action that uses the given name as base name to get values
35 * from {@link I18n} and the given icon.
40 * The base name of the action
42 * The icon for the action
44 public I18nAction(I18n i18n, String i18nName, Icon icon) {
45 this(i18n, i18nName, true, icon);
49 * Creates a new action that uses the given name as base name to get values
55 * The base name of the action
57 * Whether the action should be enabled
59 public I18nAction(I18n i18n, String i18nName, boolean enabled) {
60 this(i18n, i18nName, enabled, null);
64 * Creates a new action that uses the given name as base name to get values
65 * from {@link I18n} and the given icon.
70 * The base name of the action
72 * Whether the action should be enabled
74 * The icon for the action
76 public I18nAction(I18n i18n, String i18nName, boolean enabled, Icon icon) {
77 this.i18nName = i18nName;
79 putValue(Action.SMALL_ICON, icon);
88 public void updateI18n(I18n i18n) {
89 putValue(Action.NAME, i18n.get(i18nName + ".name"));
90 putValue(Action.MNEMONIC_KEY, i18n.getKey(i18nName + ".mnemonic"));
91 putValue(Action.ACCELERATOR_KEY, i18n.getKeyStroke(i18nName + ".accelerator"));
92 putValue(Action.SHORT_DESCRIPTION, i18n.get(i18nName + ".shortDescription"));
93 putValue(Action.LONG_DESCRIPTION, i18n.get(i18nName + ".longDescription"));