001package jmri.jmrit.permission.swing;
002
003
004import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
005
006import java.util.Locale;
007
008import javax.annotation.CheckReturnValue;
009import javax.annotation.CheckForNull;
010import javax.annotation.ParametersAreNonnullByDefault;
011
012/**
013 * Provides standard access for resource bundles in a package.
014 *
015 * Convention is to provide a subclass of this name in each package, working off
016 * the local resource bundle name.
017 *
018 * @author Bob Jacobsen Copyright (C) 2012
019 * @since 3.3.1
020 */
021@ParametersAreNonnullByDefault
022@CheckReturnValue
023@SuppressFBWarnings(value = "NM_SAME_SIMPLE_NAME_AS_SUPERCLASS", justification = "Desired pattern is repeated class names with package-level access to members")
024@javax.annotation.concurrent.Immutable
025public class Bundle extends jmri.jmrit.permission.Bundle {
026
027    @CheckForNull
028    private static final String name = "jmri.jmrit.permission.swing.Bundle"; // NOI18N
029
030    //
031    // below here is boilerplate to be copied exactly
032    //
033    /**
034     * Provides a translated string for a given key from the package resource
035     * bundle or parent.
036     * <p>
037     * Note that this is intentionally package-local access.
038     *
039     * @param key Bundle key to be translated
040     * @return Internationalized text
041     */
042    static String getMessage(String key) {
043        return getBundle().handleGetMessage(key);
044    }
045
046    /**
047     * Provides a translated string for a given key in a given locale from the
048     * package resource bundle or parent.
049     * <p>
050     * Note that this is intentionally package-local access.
051     *
052     * @param locale The locale to be used
053     * @param key    Bundle key to be translated
054     * @return Internationalized text
055     */
056    static String getMessage(Locale locale, String key) {
057        return getBundle().handleGetMessage(locale, key);
058    }
059
060    /**
061     * Merges user data with a translated string for a given key from the
062     * package resource bundle or parent.
063     * <p>
064     * Uses the transformation conventions of the Java MessageFormat utility.
065     * <p>
066     * Note that this is intentionally package-local access.
067     *
068     * @see java.text.MessageFormat
069     * @param key  Bundle key to be translated
070     * @param subs One or more objects to be inserted into the message
071     * @return Internationalized text
072     */
073    static String getMessage(String key, Object... subs) {
074        return getBundle().handleGetMessage(key, subs);
075    }
076
077    /**
078     * Merges user data with a translated string for a given key in a given
079     * locale from the package resource bundle or parent.
080     * <p>
081     * Uses the transformation conventions of the Java MessageFormat utility.
082     * <p>
083     * Note that this is intentionally package-local access.
084     *
085     * @see java.text.MessageFormat
086     * @param locale The locale to be used
087     * @param key    Bundle key to be translated
088     * @param subs   One or more objects to be inserted into the message
089     * @return Internationalized text
090     */
091    static String getMessage(Locale locale, String key, Object... subs) {
092        return getBundle().handleGetMessage(locale, key, subs);
093    }
094
095    private final static Bundle b = new Bundle();
096
097    @Override
098    @CheckForNull
099    protected String bundleName() {
100        return name;
101    }
102
103    protected static jmri.Bundle getBundle() {
104        return b;
105    }
106
107    @Override
108    protected String retry(Locale locale, String key) {
109        return super.getBundle().handleGetMessage(locale,key);
110    }
111
112}