Modules

A translator module is a component that has been derived from the abstact module, Module. Modules are used to add the code needed to translate complex components, such as some Swing components and some third party components. If you have several third party components that require writing translateObject events it might be a good idea to derive your own translator module and write the translation code inside the module. This way you do not have to write the event every time that you use the third party component. To derive a new translator module override the translateObject method.

The following example demonstates this. The translateObject method first checks if the component to be translated is an instance of MyTabbedPane. If it is the method translates the titles of the panes.

public class MyModule extends Module
{
  protected boolean translateObject(
    BaseTranslator translator,
    Object object,
    RestrictObjectEventObject parentRestriction)
  {
    if (object instanceof MyTabbedPane)
    {
      if (translator.doesTargetsMatch("MyTabbedPane", "title"))
      {
        MyTabbedPane pane = (MyTabbedPane)object;
      
        for (int i = 0; i < pane.getTabCount(); i++)
          pane.setTitleAt(i, doTranslateString(object, "title", pane.getTitleAt(i)));
      }
      return true;
    }
  }
}

All you have to do after this is to place the MyModule on the main frame of the application.