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>
35 public class I18nLabel extends JLabel implements I18nable {
37 /** The I18n basename of the label. */
38 private final String i18nBasename;
40 /** Optional arguments for i18n replacement. */
41 private final Object[] arguments;
44 * Creates a new label with the given I18n basename.
47 * The I18n basename of the label
49 public I18nLabel(String i18nBasename) {
50 this(i18nBasename, (Component) null);
54 * Creates a new label with the given I18n basename that optionally is a
55 * label for the given component.
58 * The I18n basename of the label
60 * The component that is activated by the label, or
61 * <code>null</code> if this label should not activate a
64 public I18nLabel(String i18nBasename, Component component) {
65 this(i18nBasename, component, (Object[]) null);
69 * Creates a new label with the given I18n basename that optionally is a
70 * label for the given component.
73 * The I18n basename of the label
75 * Optional arguments that are handed in to
76 * {@link I18n#get(String, Object...)}
78 public I18nLabel(String i18nBasename, Object... arguments) {
79 this(i18nBasename, null, arguments);
83 * Creates a new label with the given I18n basename that optionally is a
84 * label for the given component.
87 * The I18n basename of the label
89 * The component that is activated by the label, or
90 * <code>null</code> if this label should not activate a
93 * Optional arguments that are handed in to
94 * {@link I18n#get(String, Object...)}
96 public I18nLabel(String i18nBasename, Component component, Object... arguments) {
98 this.i18nBasename = i18nBasename;
99 this.arguments = arguments;
101 if (component != null) {
102 setLabelFor(component);
109 public void updateI18n() {
110 setText(I18n.get(i18nBasename + ".name", arguments));
111 setDisplayedMnemonic(I18n.getKey(i18nBasename + ".mnemonic"));