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