X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fi18n%2Fgui%2FI18nLabel.java;h=10dbfacd197c42b26fcc562f89a653644090abc2;hb=c63257e8cc0ba1a5aca9364b22171abe7279d479;hp=c8bd0894b85a21aa43f4538a65537c2b4524bb22;hpb=2e0662538a33fbbb245bc3fe02421f22b79d0d36;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/i18n/gui/I18nLabel.java b/src/net/pterodactylus/jsite/i18n/gui/I18nLabel.java index c8bd089..10dbfac 100644 --- a/src/net/pterodactylus/jsite/i18n/gui/I18nLabel.java +++ b/src/net/pterodactylus/jsite/i18n/gui/I18nLabel.java @@ -28,29 +28,31 @@ import net.pterodactylus.jsite.i18n.I18nable; /** * Label that can update itself from {@link I18n}. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> - * @version $Id$ */ public class I18nLabel extends JLabel implements I18nable { /** The I18n basename of the label. */ private final String i18nBasename; + /** Optional arguments for i18n replacement. */ + private final Object[] arguments; + /** * Creates a new label with the given I18n basename. - * + * * @param i18nBasename * The I18n basename of the label */ public I18nLabel(String i18nBasename) { - this(i18nBasename, null); + this(i18nBasename, (Component) null); } /** * Creates a new label with the given I18n basename that optionally is a * label for the given component. - * + * * @param i18nBasename * The I18n basename of the label * @param component @@ -59,20 +61,55 @@ public class I18nLabel extends JLabel implements I18nable { * component */ public I18nLabel(String i18nBasename, Component component) { + this(i18nBasename, component, (Object[]) null); + } + + /** + * Creates a new label with the given I18n basename that optionally is a + * label for the given component. + * + * @param i18nBasename + * The I18n basename of the label + * @param arguments + * Optional arguments that are handed in to + * {@link I18n#get(String, Object...)} + */ + public I18nLabel(String i18nBasename, Object... arguments) { + this(i18nBasename, null, arguments); + } + + /** + * Creates a new label with the given I18n basename that optionally is a + * label for the given component. + * + * @param i18nBasename + * The I18n basename of the label + * @param component + * The component that is activated by the label, or + * null if this label should not activate a + * component + * @param arguments + * Optional arguments that are handed in to + * {@link I18n#get(String, Object...)} + */ + public I18nLabel(String i18nBasename, Component component, Object... arguments) { super(); this.i18nBasename = i18nBasename; - updateI18n(); + this.arguments = arguments; if (component != null) { setLabelFor(component); } + updateI18n(); } /** * {@inheritDoc} */ public void updateI18n() { - setText(I18n.get(i18nBasename + ".name")); - setDisplayedMnemonic(I18n.getKey(i18nBasename + ".mnemonic")); + setText(I18n.get(i18nBasename + ".name", arguments)); + if (getLabelFor() != null) { + setDisplayedMnemonic(I18n.getKey(i18nBasename + ".mnemonic")); + } } }