Class TranslatorTool

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants, Hidable, Tool, Translator

public class TranslatorTool extends JFrame implements Tool, Hidable, Translator
SUGGESTION: It would be good to isolate the JFrame GUI from the underlying translation functions. This provides a GUI for creating and editing string resources associated with a class. Resources are stored in properties files with the same name and located in the same folder as the class.
Version:
1.0
Author:
Douglas Brown
See Also:
  • Method Details

    • getTool

      public static TranslatorTool getTool()
      Gets the shared TranslatorTool.
      Returns:
      the shared TranslatorTool
    • show

      @Deprecated public void show()
      Deprecated.
      Shows the frame on the screen if the keep hidden flag is false.
      Overrides:
      show in class Window
    • dispose

      public void dispose()
      Disposes all resources.
      Overrides:
      dispose in class Window
    • setVisible

      public void setVisible(boolean b)
      Shows or hides this component depending on the value of parameter b and the keepHidden flag. OSP Applets often keep windows hidden.
      Specified by:
      setVisible in interface Translator
      Overrides:
      setVisible in class Window
      Parameters:
      b -
    • setKeepHidden

      public void setKeepHidden(boolean _keepHidden)
      Sets the keepHidden flag.
      Specified by:
      setKeepHidden in interface Hidable
      Parameters:
      _keepHidden -
    • isKeepHidden

      public boolean isKeepHidden()
      Reads the keepHidden flag.
      Specified by:
      isKeepHidden in interface Hidable
    • send

      public void send(Job job, Tool replyTo)
      Sends a job to this tool and specifies a tool to reply to.
      Specified by:
      send in interface Tool
      Parameters:
      job - the Job
      replyTo - the tool to notify when the job is complete (may be null)
    • getProperty

      public String getProperty(Class<?> type, String key)
      Gets the localized value of a property for the specified class. If no localized value is found, the key is returned.
      Specified by:
      getProperty in interface Translator
      Parameters:
      type - the class requesting the localized value
      key - the string to localize
      Returns:
      the localized string
    • getProperty

      public String getProperty(Class<?> type, String key, String defaultValue)
      effectively static Gets the localized value of a property for the specified class. If no localized value is found, the defaultValue is returned.
      Specified by:
      getProperty in interface Translator
      Parameters:
      type - the class requesting the localized value
      key - the string to localize
      defaultValue - the default if no localized value found
      Returns:
      the localized string
    • getProperty

      public String getProperty(Object obj, String key)
      Gets the localized value of a property for the specified object. The object must first be associated with a class. If no localized value is found, the key is returned.
      Specified by:
      getProperty in interface Translator
      Parameters:
      obj - the object requesting the localized value
      key - the string to localize
      Returns:
      the localized string
    • getProperty

      public String getProperty(Object obj, String key, String defaultValue)
      Gets the localized value of a property for the specified object. The object must first be associated with a class. If no localized value is found, the defaultValue is returned.
      Specified by:
      getProperty in interface Translator
      Parameters:
      obj - the object requesting the localized value
      key - the string to localize
      defaultValue - the default if no localized value found
      Returns:
      the localized string
    • setLocale

      public void setLocale(Locale locale)
      Sets the locale.
      Overrides:
      setLocale in class Component
      Parameters:
      locale - the locale
    • showProperties

      public void showProperties(Class<?> type)
      Shows the properties for the specified class, and sets the GUI visible.
      Specified by:
      showProperties in interface Translator
      Parameters:
      type - the class
    • setPreferredTitle

      public void setPreferredTitle(String title)
      Sets a title for the tool
    • refreshGUI

      protected void refreshGUI()
      Refreshes the GUI.
    • addProperty

      public static void addProperty(Class<?> type, String key, String defaultValue)
      Adds a property to those defined for the specified class.
      Parameters:
      type - the class
      key - the property to add
      defaultValue - the default value
    • removeProperty

      public static void removeProperty(Class<?> type, String key)
      Removes a property from those defined for the specified class.
      Parameters:
      type - the class
      key - the property to remove
    • removeProperty

      public static void removeProperty(Object obj, String key)
      Removes a property from those defined for the specified object. The object must first be associated with a class.
      Parameters:
      obj - the object
      key - the property to remove
    • getAssociates

      public static Collection<Object> getAssociates(Class<?> type)
      Gets objects associated with the specified class.
    • refreshAssociates

      protected static void refreshAssociates(Class<?> type)
      Refreshes objects associated with the specified class.
    • associate

      public void associate(Object obj, Class<?> type)
      Associates an object with a class for property lookup purposes.
      Specified by:
      associate in interface Translator
      Parameters:
      obj - the object needing translations
      type - the class
    • setPath

      public static void setPath(Class<?> type, String directory)
      Sets the path for a given class.
      Parameters:
      type - the class
      directory - the path
    • getPath

      public static String getPath(Class<?> type)
      Gets the properties file path for a class.
      Parameters:
      type - the class
      Returns:
      the path
    • isLanguage

      protected static boolean isLanguage(String lang)
      Returns true if a String is a valid 2-letter language code.
      Parameters:
      lang - the 2-letter code
      Returns:
      true if valid 2-letter language code
    • getTranslatedLocales

      public static Locale[] getTranslatedLocales(Class<?> type)
      Returns Locales for which translations exist for the specified class.