0d36f0186c4285005b7c7eeb5c426a86e02043a1
[jSite2.git] / src / net / pterodactylus / jsite / gui / I18nAction.java
1 package net.pterodactylus.jsite.gui;
2
3 import javax.swing.AbstractAction;
4 import javax.swing.Action;
5 import javax.swing.Icon;
6
7 import net.pterodactylus.jsite.i18n.I18n;
8
9 /**
10  * Helper class that initializes actions with values from {@link I18n}.
11  * 
12  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
13  * @version $Id$
14  */
15 public abstract class I18nAction extends AbstractAction {
16
17         /**
18          * Creates a new action that uses the given name as base name to get values
19          * from {@link I18n}.
20          * 
21          * @param i18nName
22          *            The base name of the action
23          */
24         public I18nAction(String i18nName) {
25                 this(i18nName, null);
26         }
27
28         /**
29          * Creates a new action that uses the given name as base name to get values
30          * from {@link I18n} and the given icon.
31          * 
32          * @param i18nName
33          *            The base name of the action
34          * @param icon
35          *            The icon for the action
36          */
37         public I18nAction(String i18nName, Icon icon) {
38                 this(i18nName, true, icon);
39         }
40
41         /**
42          * Creates a new action that uses the given name as base name to get values
43          * from {@link I18n}.
44          * 
45          * @param i18nName
46          *            The base name of the action
47          * @param enabled
48          *            Whether the action should be enabled
49          */
50         public I18nAction(String i18nName, boolean enabled) {
51                 this(i18nName, enabled, null);
52         }
53
54         /**
55          * Creates a new action that uses the given name as base name to get values
56          * from {@link I18n} and the given icon.
57          * 
58          * @param i18nName
59          *            The base name of the action
60          * @param enabled
61          *            Whether the action should be enabled
62          * @param icon
63          *            The icon for the action
64          */
65         public I18nAction(String i18nName, boolean enabled, Icon icon) {
66                 putValue(Action.NAME, I18n.get(i18nName + ".name"));
67                 putValue(Action.MNEMONIC_KEY, I18n.getKey(i18nName + ".mnemonic"));
68                 putValue(Action.ACCELERATOR_KEY, I18n.getKeyStroke(i18nName + ".accelerator"));
69                 putValue(Action.SHORT_DESCRIPTION, I18n.get(i18nName + ".shortDescription"));
70                 putValue(Action.LONG_DESCRIPTION, I18n.get(i18nName + ".longDescription"));
71                 if (icon != null) {
72                         putValue(Action.SMALL_ICON, icon);
73                 }
74                 setEnabled(enabled);
75         }
76
77 }