Ignore:
Timestamp:
2003-09-26T14:58:33+12:00 (21 years ago)
Author:
mdewsnip
Message:

Many more tooltips and improvements to the Dictionary. Still more to come.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/Dictionary.java

    r5529 r5536  
    1 package org.greenstone.gatherer;
    21/**
    32 *#########################################################################
     
    3635 *########################################################################
    3736 */
     37package org.greenstone.gatherer;
     38
    3839import java.awt.Component;
    3940import java.io.*;
     
    4344import javax.swing.text.*;
    4445import javax.swing.tree.*;
    45 import org.greenstone.gatherer.gui.GComboBox;
    46 import org.greenstone.gatherer.gui.border.TitledBorder;
    47 import org.greenstone.gatherer.util.DictionaryTreeNode;
    48 import org.greenstone.gatherer.util.MutableComboBoxEntry;
    49 import org.greenstone.gatherer.util.ArrayTools;
    5046import org.greenstone.gatherer.util.Utility;
     47
    5148/** Extends the ResourceBundle class to allow for the automatic insertion of  arguments. Note that the key names beginning Farg are reserved for formatting. <BR>
    5249 * <BR>
     
    9188    /**  Constructs the Dictionary class by first checking if a Locale has been set. If not the default locale is used, and a ResourceBundle is created. Finally a single important String, Language, is made available outside the class so a more read-able version of the Locale of this Dictionary is present.
    9289     * @param locale The <strong>Locale</strong> used to load the desired dictionary resource bundle.
    93       */
     90     */
    9491    public Dictionary(Locale locale, FontUIResource font) {
    9592    super();
    9693    this.self = this;
    9794
    98     if(KEY_LIST_DEBUG) {
     95    if (KEY_LIST_DEBUG) {
    9996        // Reload the keylist
    10097        File file = new File(KEY_LIST_FILENAME);
     
    116113    // Initialize.
    117114    this.font = font;
    118     if(locale == null) {
     115    if (locale == null) {
    119116        this.locale = Locale.getDefault();
    120117    }
     
    127124    language = dictionary.getString("Language");
    128125    }
    129     /** Change the currently loaded dictionary and update registered (ie dynamic) components as possible. */
    130     public void changeDictionary(Locale locale) {
     126
     127
     128    /** Change the currently loaded dictionary and update registered components */
     129    public void changeDictionary(Locale locale)
     130    {
    131131    this.locale = locale;
     132
    132133    // Load new dictionary
    133134    dictionary = ResourceBundle.getBundle(Utility.DICTIONARY, locale);
    134135    language = dictionary.getString("Language");
    135     Gatherer.println("Having loaded new dictionary: " + language);
     136    Gatherer.println("Loaded new dictionary: " + language);
     137
    136138    // Refresh all registered component
    137     Gatherer.println("Updating components");
    138     for(Iterator keys = keySet().iterator(); keys.hasNext(); ) {
    139         Object component = keys.next();
    140         String[] args = (String[]) get(component);
    141         if(component instanceof AbstractButton) {
    142         register((AbstractButton)component, args, true);
    143         }
    144         else if(component instanceof JComboBox) {
    145         register((JComboBox)component, args, true);
    146         }
    147         else if(component instanceof JDialog) {
    148         register((JDialog)component, args, true);
    149         }
    150         else if(component instanceof JFrame) {
    151         register((JFrame)component, args, true);
    152         }
    153         else if(component instanceof JLabel) {
    154         register((JLabel)component, args, true);
    155         }
    156         else if(component instanceof JTabbedPane) {
    157         register((JTabbedPane)component, args, true);
    158         }
    159         else if(component instanceof JTextComponent) {
    160         register((JTextComponent)component, args, true);
    161         }
    162         else if(component instanceof JTree) {
    163         register((JTree)component, args, true);
    164         }
    165         else if(component instanceof TitledBorder) {
    166         register((TitledBorder)component, args, true);
    167         }
    168         args = null;
    169         component = null;
    170     }
    171     }
     139    // !! TO FINISH !!
     140    Gatherer.println("Updating components...");
     141//      ArrayList temp_list = new ArrayList();
     142//      Iterator components = keySet().iterator();
     143//      while (components.hasNext()) {
     144//          Component component = (Component) components.next();
     145//          temp_list.add(component);
     146//      }
     147
     148//      for (int i = 0; i < temp_list.size(); i++) {
     149//          Component component = (Component) temp_list.get(i);
     150//          ComponentDetails details = (ComponentDetails) get(component);
     151//          oldSetBoth(component, details.text_key, details.text_args, details.tooltip_key);
     152//      }
     153
     154//      for (Iterator keys = keySet().iterator(); keys.hasNext(); ) {
     155//          Component component = (Component) keys.next();
     156//          ComponentDetails details = (ComponentDetails) get(component);
     157//          oldSetBoth(component, details.text_key, details.text_args, details.tooltip_key);
     158//      }
     159    }
     160
     161
     162    /** Change the currently loaded dictionary and update registered (ie dynamic) components as possible. */
     163//      public void oldChangeDictionary(Locale locale) {
     164//      this.locale = locale;
     165//      // Load new dictionary
     166//      dictionary = ResourceBundle.getBundle(Utility.DICTIONARY, locale);
     167//      language = dictionary.getString("Language");
     168//      Gatherer.println("Having loaded new dictionary: " + language);
     169//      // Refresh all registered component
     170//      Gatherer.println("Updating components");
     171//      for(Iterator keys = keySet().iterator(); keys.hasNext(); ) {
     172//          Object component = keys.next();
     173//          String[] args = (String[]) get(component);
     174//          if(component instanceof AbstractButton) {
     175//          register((AbstractButton)component, args, true);
     176//          }
     177//          else if(component instanceof JComboBox) {
     178//          register((JComboBox)component, args, true);
     179//          }
     180//          else if(component instanceof JDialog) {
     181//          register((JDialog)component, args, true);
     182//          }
     183//          else if(component instanceof JFrame) {
     184//          register((JFrame)component, args, true);
     185//          }
     186//          else if(component instanceof JLabel) {
     187//          register((JLabel)component, args, true);
     188//          }
     189//          else if(component instanceof JTabbedPane) {
     190//          register((JTabbedPane)component, args, true);
     191//          }
     192//          else if(component instanceof JTextComponent) {
     193//          register((JTextComponent)component, args, true);
     194//          }
     195//          else if(component instanceof JTree) {
     196//          register((JTree)component, args, true);
     197//          }
     198//          else if(component instanceof TitledBorder) {
     199//          register((TitledBorder)component, args, true);
     200//          }
     201//          args = null;
     202//          component = null;
     203//      }
     204//      }
     205
    172206    /** Remove the component from our registered components list. */
    173207    public void deregister(Object component) {
     
    207241
    208242
    209     /** Overloaded to call get with both a key and an empty argument array.
     243    /**
     244     * @deprecated
     245     * Overloaded to call get with both a key and an empty argument array.
    210246     * @param key A <strong>String</strong> which is mapped to a initial String within the ResourceBundle.
    211247     * @return A <strong>String</strong> which has been referenced by the key String and that either contains no argument fields, or has had the argument fields automatiically populated with formatting Strings of with argument String provided in the get call.
     
    214250    return get(key, (String[])null);
    215251    }
    216     /** Convienence method with transforms the second string argument into a string array. */
     252    /**
     253     * @deprecated
     254     * Convienence method with transforms the second string argument into a string array. */
    217255    public String get(String key, String arg) {
    218256    String[] args = new String[1];
     
    220258    return get(key, args);
    221259    }
     260
    222261    /** Used to retrieve a property value from the Locale specific ResourceBundle, based upon the key and arguments supplied. If the key cannot be found or if some other part of the call fails a default (English) error message is returned. <BR>
    223       * Here the get recieves a second argument which is an array of Strings used to populate argument fields, denoted {<I>n</I>}, within the value String returned. Note that argument numbers greater than or equal to 32 are automatically mapped to the formatting String named Farg<I>n</I>.
    224       * @param key A <strong>String</strong> which is mapped to a initial String within the ResourceBundle.
    225       * @param args A <strong>String[]</strong> used to populate argument fields within the complete String.
    226       * @return A <strong>String</strong> which has been referenced by the key String and that either contains no argument fields, or has had the argument fields automatiically populated with formatting Strings of with argument String provided in the get call.
    227       */
     262     * Here the get recieves a second argument which is an array of Strings used to populate argument fields, denoted {<I>n</I>}, within the value String returned. Note that argument numbers greater than or equal to 32 are automatically mapped to the formatting String named Farg<I>n</I>.
     263     * @param key A <strong>String</strong> which is mapped to a initial String within the ResourceBundle.
     264     * @param args A <strong>String[]</strong> used to populate argument fields within the complete String.
     265     * @return A <strong>String</strong> which has been referenced by the key String and that either contains no argument fields, or has had the argument fields automatiically populated with formatting Strings of with argument String provided in the get call.
     266     */
    228267    public String get(String key, String args[]) {
    229268    if(key_list != null) {
     
    269308    }
    270309    catch (Exception e) {
    271         // if(!key.endsWith("_Tooltip")) {
    272         System.err.println("Missing value for key: " + key);
    273         // }
    274         //e.printStackTrace();
     310        System.err.println("Missing value for key: " + key);
    275311        return key;
    276312    }
     
    287323    static public void setBoth(Component component, String text_key, String tooltip_key)
    288324    {
    289     self.oldSetBoth(component, text_key, null, tooltip_key);
     325    setText(component, text_key);
     326    setTooltip(component, tooltip_key);
    290327    }
    291328
     
    293330    static public void setText(Component component, String text_key)
    294331    {
    295     self.oldSetText(component, text_key, null);
     332    setText(component, text_key, null);
    296333    }
    297334
     
    299336    static public void setText(Component component, String text_key, String[] args)
    300337    {
    301     self.oldSetText(component, text_key, args);
     338    if (component != null) {
     339        // Update the component using the AWTEvent queue
     340        ComponentDetails details = new ComponentDetails(true, text_key, args, false, null);
     341        ComponentUpdateTask task = new ComponentUpdateTask(component, details);
     342        SwingUtilities.invokeLater(task);
     343    }
    302344    }
    303345
     
    305347    static public void setTooltip(Component component, String tooltip_key)
    306348    {
    307     self.oldSetTooltip(component, tooltip_key);
    308     }
    309 
    310 
    311     private void oldSetBoth(Component component, String text_key, String[] args, String tooltip_key)
    312     {
    313     oldSetText(component, text_key, args);
    314     oldSetTooltip(component, tooltip_key);
    315     }
    316 
    317 
    318     private void oldSetText(Component component, String text_key, String[] args)
     349    if (component != null) {
     350        // Update the component using the AWTEvent queue
     351        ComponentDetails details = new ComponentDetails(false, null, null, true, tooltip_key);
     352        ComponentUpdateTask task = new ComponentUpdateTask(component, details);
     353        SwingUtilities.invokeLater(task);
     354    }
     355    }
     356
     357
     358    static public void registerBoth(Component component, String text_key, String tooltip_key)
     359    {
     360    registerText(component, text_key, null);
     361    registerTooltip(component, tooltip_key);
     362    }
     363
     364
     365    static public void registerText(Component component, String text_key)
     366    {
     367    registerText(component, text_key, null);
     368    }
     369
     370
     371    static public void registerText(Component component, String text_key, String[] args)
    319372    {
    320373    if (component != null) {
    321374        // Update the component's details
    322         ComponentDetails details = (ComponentDetails) remove(component);
     375        ComponentDetails details = (ComponentDetails) self.remove(component);
    323376        if (details == null) {
    324377        details = new ComponentDetails(true, text_key, args, false, null);
     
    329382        details.text_args = args;
    330383        }
    331         put(component, details);
     384        self.put(component, details);
    332385
    333386        // Update the component using the AWTEvent queue
    334         RegisteredComponentUpdateTask task = new RegisteredComponentUpdateTask(component);
     387        ComponentUpdateTask task = new ComponentUpdateTask(component, details);
    335388        SwingUtilities.invokeLater(task);
    336389    }
     
    338391
    339392
    340     private void oldSetTooltip(Component component, String tooltip_key)
     393    static public void registerTooltip(Component component, String tooltip_key)
    341394    {
    342395    if (component != null) {
    343396        // Update the component's details
    344         ComponentDetails details = (ComponentDetails) remove(component);
     397        ComponentDetails details = (ComponentDetails) self.remove(component);
    345398        if (details == null) {
    346399        details = new ComponentDetails(false, null, null, true, tooltip_key);
     
    350403        details.tooltip_key = tooltip_key;
    351404        }
    352         put(component, details);
     405        self.put(component, details);
    353406
    354407        // Update the component using the AWTEvent queue
    355         RegisteredComponentUpdateTask task = new RegisteredComponentUpdateTask(component);
     408        ComponentUpdateTask task = new ComponentUpdateTask(component, details);
    356409        SwingUtilities.invokeLater(task);
    357410    }
     
    359412
    360413
    361     private class ComponentDetails
     414    static private class ComponentDetails
    362415    {
    363416    public boolean has_text;
     
    379432
    380433
    381     private class RegisteredComponentUpdateTask
     434    static private class ComponentUpdateTask
    382435    implements Runnable {
    383436
    384437    private Component component;
    385     private ComponentDetails details;
    386438    private String text = null;
    387439    private String tooltip = null;
    388440
    389     public RegisteredComponentUpdateTask(Component component)
     441    public ComponentUpdateTask(Component component, ComponentDetails details)
    390442    {
    391443        this.component = component;
    392         this.details = (ComponentDetails) get(component);
    393444
    394445        if (details.has_text) {
    395         text = get(details.text_key, details.text_args);
     446        text = self.get(details.text_key, details.text_args);
    396447        }
    397448        if (details.has_tooltip) {
    398         tooltip = get(details.tooltip_key, (String[]) null);
     449        tooltip = self.get(details.tooltip_key, (String[]) null);
    399450        }
    400451    }
     
    416467        else if (component instanceof JTextComponent) {
    417468            ((JTextComponent) component).setText(text);
     469            ((JTextComponent) component).setCaretPosition(0);
    418470        }
    419471        else {
     
    434486    /**
    435487     * @deprecated
    436      * Register an abstract button component */
    437     public void register(AbstractButton component, String[] args, boolean already_registered)
     488     * Register a tab pane component. */
     489    static public void register(JTabbedPane component)
    438490    {
    439491    if(component != null) {
    440         // Determine the key
    441         String key = "";
    442         if(!already_registered) {
    443         key = component.getText();
    444         }
    445         else {
    446         key = args[args.length - 1];
    447         }
    448         // Update the component using the AWTEvent queue
    449         String value = get(key, args);
    450         String tooltip = get(key + "_Tooltip", (String[])null);
    451         ChangeTask task = new AbstractButtonChangeTask(component, key, value, tooltip);
    452         SwingUtilities.invokeLater(task);
    453         // Register as necessary
    454         if(!already_registered) {
    455         args = ArrayTools.add(args, key);
    456         put(component, args);
    457         }
    458     }
    459     }
    460 
    461     /**
    462      * @deprecated
    463      * Register a JCheckBox component */
    464     public void register(JCheckBox component, String[] args, boolean already_registered)
    465     {
    466     }
    467 
    468     /**
    469      * @deprecated
    470      * Register a combobox component. */
    471     public void register(JComboBox component, String[] args, boolean already_registered) {
    472     if(component != null) {
    473         // If not already registered then args will be null.
    474         if(!already_registered) {
    475         args = new String[component.getItemCount()];
    476         }
    477         // Retrieve the tooltip. The key is mostly derived from the comboboxes name.
    478         String key = component.getName();
    479         String tooltip = get(key + "_Tooltip", (String[])null);
    480         ChangeTask task = new JComboBoxChangeTask(component, key, -1, tooltip);
    481         SwingUtilities.invokeLater(task);
    482         // Iterate through the combobox, updating values and recording the original key of each item in args.
    483         for(int i = 0; i < args.length; i++) {
    484         if(args[i] == null) {
    485             args[i] = component.getItemAt(i).toString();
    486         }
    487         String value = get(args[i], (String[])null);
    488         task = new JComboBoxChangeTask(component, key, i, value);
    489         SwingUtilities.invokeLater(task);
    490         }
    491         // Register if necessary
    492         if(!already_registered) {
    493         put(component, args);
    494         }
    495     }
    496     }
    497 
    498     /**
    499      * @deprecated
    500      * Register a dialog component. */
    501     public void register(JDialog component, String[] args, boolean already_registered) {
    502     if(component != null) {
    503         // Determine the key
    504         String key = "";
    505         if(!already_registered) {
    506         key = component.getTitle();
    507         }
    508         else {
    509         key = args[args.length - 1];
    510         }
    511         // Update the component using the AWTEvent queue
    512         String value = get(key, args);
    513         ChangeTask task = new JDialogChangeTask(component, key, value);
    514         SwingUtilities.invokeLater(task);
    515         // Register as necessary
    516         if(!already_registered) {
    517         args = ArrayTools.add(args, key);
    518         put(component, args);
    519         }
    520     }
    521     }
    522 
    523     /**
    524      * @deprecated
    525      * Register a frame component. */
    526     public void register(JFrame component, String[] args, boolean already_registered) {
    527     if(component != null) {
    528         // Determine the key
    529         String key = "";
    530         if(!already_registered) {
    531         key = component.getTitle();
    532         }
    533         else {
    534         key = args[args.length - 1];
    535         }
    536         // Update the component using the AWTEvent queue
    537         String value = get(key, args);
    538         ChangeTask task = new JFrameChangeTask(component, key, value);
    539         SwingUtilities.invokeLater(task);
    540         // Register as necessary
    541         if(!already_registered) {
    542         args = ArrayTools.add(args, key);
    543         put(component, args);
    544         }
    545     }
    546     }
    547 
    548     /**
    549      * @deprecated
    550      * Register a label component. */
    551     public void register(JLabel component, String[] args, boolean already_registered) {
    552     if(component != null) {
    553         // Determine the key
    554         String key = "";
    555         if(!already_registered) {
    556         key = component.getText();
    557         }
    558         else {
    559         key = args[args.length - 1];
    560         }
    561         // Update the component using the AWTEvent queue
    562         String value = get(key, args);
    563         ChangeTask task = new JLabelChangeTask(component, key, value);
    564         SwingUtilities.invokeLater(task);
    565         // Register as necessary
    566         if(!already_registered) {
    567         args = ArrayTools.add(args, key);
    568         put(component, args);
    569         }
    570     }
    571     }
    572 
    573     /**
    574      * @deprecated
    575      * Register a tab pane component. */
    576     public void register(JTabbedPane component, String[] args, boolean already_registered) {
    577     if(component != null) {
    578         // If not already registered then args will be null.
    579         if(!already_registered) {
    580         args = new String[component.getTabCount()];
    581         }
     492        String[] args = new String[component.getTabCount()];
     493
    582494        // Iterate through the tabbed panes tabs, updating values and recording the original key of each item in args.
    583495        for(int i = 0; i < args.length; i++) {
     
    585497            args[i] = component.getTitleAt(i);
    586498        }
    587         String value = get(args[i], (String[])null);
    588         String tooltip = get(args[i] + "_Tooltip", (String[])null);
    589         ChangeTask task = new JTabbedPaneChangeTask(component, args[i], i, value, tooltip);
     499        String value = self.get(args[i], (String[])null);
     500        String tooltip = self.get(args[i] + "_Tooltip", (String[])null);
     501        JTabbedPaneChangeTask task = new JTabbedPaneChangeTask(component, args[i], i, value, tooltip);
    590502        SwingUtilities.invokeLater(task);
    591503        }
    592         // Register if necessary
    593         if(!already_registered) {
    594         put(component, args);
    595         }
    596     }
    597     }
    598 
    599     /**
    600      * @deprecated
    601      * Register a text component. */
    602     public void register(JTextComponent component, String[] args, boolean already_registered)
    603     {
    604     if (component != null) {
    605         // Determine the key
    606         String key = "";
    607         if (!already_registered) {
    608         key = component.getText();
    609         }
    610         else {
    611         key = args[args.length - 1];
    612         }
    613 
    614         // Update the component using the AWTEvent queue
    615         String value = get(key, args);
    616         String tooltip = get(key + "_Tooltip", (String[])null);
    617         ChangeTask task = new JTextComponentChangeTask(component, key, value, tooltip);
    618         SwingUtilities.invokeLater(task);
    619         // Register as necessary
    620         if (!already_registered) {
    621         args = ArrayTools.add(args, key);
    622         put(component, args);
    623         }
    624     }
    625     }
    626 
    627     /**
    628      * @deprecated
    629      * Register a tree component. */
    630     public void register(JTree component, String[] args, boolean already_registered) {
    631     if(component != null) {
    632         // Retrieve the tooltip using the components name
    633         String key = component.getName();
    634         String tooltip = get(key + "_Tooltip", (String[])null);
    635         ChangeTask task = new JTreeChangeTask(component, key, tooltip);
    636         SwingUtilities.invokeLater(task);
    637         // A tree can never be previously registered. In otherwords the keys are harvested each time. Thus for a tree to remain consistant its up to the implementer to implement DictionaryTreeNode for the tree nodes!
    638         ArrayList nodes = new ArrayList();
    639         nodes.add(component.getModel().getRoot());
    640         while(nodes.size() > 0) {
    641         DictionaryTreeNode node = (DictionaryTreeNode) nodes.remove(0);
    642         // Update
    643         String value = get(node.getKey(), (String[])null);
    644         task = new JTreeChangeTask(component, node.getKey(), node, value);
    645         SwingUtilities.invokeLater(task);
    646         // Add children to nodes
    647         for(int i = 0; i < node.getChildCount(); i++) {
    648             nodes.add(node.getChildAt(i));
    649         }
    650         }
    651     }
    652     }
    653 
    654     /**
    655      * @deprecated
    656      * Register a titled border component. */
    657     public void register(TitledBorder component, String[] args, boolean already_registered) {
    658     if(component != null) {
    659         // Determine the key
    660         String key = "";
    661         if(!already_registered) {
    662         key = component.getTitle();
    663         }
    664         else {
    665         key = args[args.length - 1];
    666         }
    667         // Update the component using the AWTEvent queue
    668         String value = get(key, args);
    669         ChangeTask task = new TitledBorderChangeTask(component, key, value);
    670         SwingUtilities.invokeLater(task);
    671         // Register as necessary
    672         if(!already_registered) {
    673         args = ArrayTools.add(args, key);
    674         put(component, args);
    675         }
    676     }
    677     }
    678 
    679     /** A get method called internally by components that have been previously been registered, which means that arg[index] is the original key value. Index is usually the last entry in the array, however this is not true for comboboxes, tabbed panes and trees. */
    680     private String get(String[] args, int index) {
    681     return get(args[index], args);
    682     }
    683 
    684 
    685     private abstract class ChangeTask
    686     implements Runnable {
    687     protected String key;
    688     protected String value;
    689     public ChangeTask(String key, String value) {
    690         this.key = key;
     504    }
     505    }
     506
     507
     508    /** Updates a tabbed panes tab title and tooltip. */
     509    static private class JTabbedPaneChangeTask
     510    implements Runnable {
     511    protected String key;
     512    protected String value;
     513    private int index;
     514    private JTabbedPane component;
     515    private String tooltip;
     516
     517    public JTabbedPaneChangeTask(JTabbedPane component, String key, int index, String value, String tooltip) {
     518        this.key = key;
    691519        this.value = value;
    692     }
    693     public void run() {
    694     }
    695     }
    696 
    697     /** Update the text and tooltip for this button. */
    698     private class AbstractButtonChangeTask
    699     extends ChangeTask {
    700     private AbstractButton component;
    701     private String tooltip;
    702     public AbstractButtonChangeTask(AbstractButton component, String key, String value, String tooltip) {
    703         super(key, value);
    704         this.component = component;
    705         this.tooltip = tooltip;
    706     }
    707     public void run() {
    708         component.setText(value);
    709         // if(!tooltip.equals(key+"_Tooltip")) {
    710         component.setToolTipText(tooltip);
    711         // }
    712         // else {
    713         // component.setToolTipText(null);
    714         // }
    715     }
    716     }
    717     /** Update the text associated with a combobox. If the index used is -1 then we are setting the tooltip for this combobox. */
    718     private class JComboBoxChangeTask
    719     extends ChangeTask {
    720     private int index;
    721     private JComboBox component;
    722     public JComboBoxChangeTask(JComboBox component, String key, int index, String value) {
    723         super(key, value);
    724         this.component = component;
    725         this.index = index;
    726     }
    727     public void run() {
    728         if(index != -1) {
    729         try {
    730             MutableComboBoxEntry entry = (MutableComboBoxEntry)component.getItemAt(index);
    731             entry.setText(value);
    732         }
    733         catch (Exception error) {
    734         }
    735         }
    736         else {
    737         if(!value.equals(key+"_Tooltip")) {
    738             component.setToolTipText(value);
    739         }
    740         else {
    741             component.setToolTipText(null);
    742         }
    743         }
    744     }
    745     }
    746     /** Update the title of this dialog. */
    747     private class JDialogChangeTask
    748     extends ChangeTask {
    749     private JDialog component;
    750     public JDialogChangeTask(JDialog component, String key, String value) {
    751         super(key, value);
    752         this.component = component;
    753     }
    754     public void run() {
    755         component.setTitle(value);
    756     }
    757     }
    758     /** Update the title of this frame. */
    759     private class JFrameChangeTask
    760     extends ChangeTask {
    761     private JFrame component;
    762     public JFrameChangeTask(JFrame component, String key, String value) {
    763         super(key, value);
    764         this.component = component;
    765     }
    766     public void run() {
    767         component.setTitle(value);
    768     }
    769     }
    770 
    771     /** Update the text of this label. */
    772     private class JLabelChangeTask
    773     extends ChangeTask {
    774     private JLabel component;
    775 
    776     public JLabelChangeTask(JLabel component, String key, String value) {
    777         super(key, value);
    778         this.component = component;
    779     }
    780 
    781     public void run() {
    782         component.setText(value);
    783     }
    784     }
    785 
    786     /** Updates a tabbed panes tab title and tooltip. */
    787     private class JTabbedPaneChangeTask
    788     extends ChangeTask {
    789     private int index;
    790     private JTabbedPane component;
    791     private String tooltip;
    792     public JTabbedPaneChangeTask(JTabbedPane component, String key, int index, String value, String tooltip) {
    793         super(key, value);
    794         this.component = component;
    795         this.index = index;
    796         this.tooltip = tooltip;
    797     }
    798     public void run() {
    799         component.setTitleAt(index, value);
    800         if(!tooltip.equals(key+"_Tooltip")) {
    801         component.setToolTipTextAt(index, tooltip);
    802         }
    803         else {
    804         component.setToolTipTextAt(index, null);
    805         }
    806     }
    807     }
    808     /** Update the text and tooltip of this text component. */
    809     private class JTextComponentChangeTask
    810     extends ChangeTask {
    811     private JTextComponent component;
    812     private String tooltip;
    813     public JTextComponentChangeTask(JTextComponent component, String key, String value, String tooltip) {
    814         super(key, value);
    815         this.component = component;
    816         this.tooltip = tooltip;
    817     }
    818     public void run() {
    819         component.setText(value);
    820         if(!tooltip.equals(key+"_Tooltip")) {
    821         component.setToolTipText(tooltip);
    822         }
    823         else {
    824         component.setToolTipText(null);
    825         }
    826     }
    827     }
    828     /** Update the tooltip of a tree and its tree node's labels. Shouldn't really ever be used on a dynamic tree, but is quite useful for a 'contents' tree type control. */
    829     private class JTreeChangeTask
    830     extends ChangeTask {
    831     private DictionaryTreeNode node;
    832     private JTree component;
    833     public JTreeChangeTask(JTree component, String key, String value) {
    834         super(key, value);
    835         this.component = component;
    836     }
    837     public JTreeChangeTask(JTree component, String key, DictionaryTreeNode node, String value) {
    838         super(key, value);
    839         this.component = component;
    840         this.node = node;
    841     }
    842     public void run() {
    843         if(value != null) {
    844         node.setText(value);
    845         ((DefaultTreeModel)component.getModel()).nodeChanged((TreeNode)node);
    846         }
    847                 // Set the tool tip
    848         else {
    849         if(!value.equals(key+"_Tooltip")) {
    850             component.setToolTipText(value);
    851         }
    852         else {
    853             component.setToolTipText(null);
    854         }
    855         }
    856     }
    857     }
    858     /** Update the title of this titled border. */
    859     private class TitledBorderChangeTask
    860     extends ChangeTask {
    861     private TitledBorder component;
    862     public TitledBorderChangeTask(TitledBorder component, String key, String value) {
    863         super(key, value);
    864         this.component = component;
    865     }
    866     public void run() {
    867         component.setTitle(value);
    868         component.getParent().repaint();
    869     }
     520        this.component = component;
     521        this.index = index;
     522        this.tooltip = tooltip;
     523    }
     524    public void run() {
     525        component.setTitleAt(index, value);
     526        if(!tooltip.equals(key+"_Tooltip")) {
     527        component.setToolTipTextAt(index, tooltip);
     528        }
     529        else {
     530        component.setToolTipTextAt(index, null);
     531        }
     532    }
    870533    }
    871534}
Note: See TracChangeset for help on using the changeset viewer.