2 * jSite2 - I18nLabel.java -
3 * Copyright © 2008 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package net.pterodactylus.jsite.i18n.gui;
22 import java.awt.Component;
24 import javax.swing.JLabel;
26 import net.pterodactylus.jsite.i18n.I18n;
27 import net.pterodactylus.jsite.i18n.I18nable;
30 * Label that can update itself from {@link I18n}.
32 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
34 public class I18nLabel extends JLabel implements I18nable {
36 /** The I18n basename of the label. */
37 private final String i18nBasename;
39 /** Optional arguments for i18n replacement. */
40 private final Object[] arguments;
43 * Creates a new label with the given I18n basename.
46 * The I18n basename of the label
48 public I18nLabel(String i18nBasename) {
49 this(i18nBasename, (Component) null);
53 * Creates a new label with the given I18n basename that optionally is a
54 * label for the given component.
57 * The I18n basename of the label
59 * The component that is activated by the label, or
60 * <code>null</code> if this label should not activate a
63 public I18nLabel(String i18nBasename, Component component) {
64 this(i18nBasename, component, (Object[]) null);
68 * Creates a new label with the given I18n basename that optionally is a
69 * label for the given component.
72 * The I18n basename of the label
74 * Optional arguments that are handed in to
75 * {@link I18n#get(String, Object...)}
77 public I18nLabel(String i18nBasename, Object... arguments) {
78 this(i18nBasename, null, arguments);
82 * Creates a new label with the given I18n basename that optionally is a
83 * label for the given component.
86 * The I18n basename of the label
88 * The component that is activated by the label, or
89 * <code>null</code> if this label should not activate a
92 * Optional arguments that are handed in to
93 * {@link I18n#get(String, Object...)}
95 public I18nLabel(String i18nBasename, Component component, Object... arguments) {
97 this.i18nBasename = i18nBasename;
98 this.arguments = arguments;
99 if (component != null) {
100 setLabelFor(component);
108 public void updateI18n() {
109 setText(I18n.get(i18nBasename + ".name", arguments));
110 if (getLabelFor() != null) {
111 setDisplayedMnemonic(I18n.getKey(i18nBasename + ".mnemonic"));