home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 14 / IOPROG_14.ISO / soft / sdkjava / sdkjava.exe / SDKJava.cab / Samples / AFC / JNotepad / src / JNoteToolbar.java < prev    next >
Encoding:
Java Source  |  1998-03-05  |  18.2 KB  |  793 lines

  1. //
  2. // (c) 1998 Microsoft Corporation.  All rights reserved.
  3. //
  4. /**
  5. *    JNoteToolbar
  6. *
  7. *    Toolbar class. Operates on objects that implement the IFileOperationTarget
  8. *    interface, which contains common file operations. Also implements changing
  9. *    application settings.
  10. *
  11. *    The IFileOperationTarget will have certain methods called when the user
  12. *    clicks file-related buttons on the toolbar.
  13. *
  14. *    @version    1.0, 7/10/97
  15. *    @see        IFileOperationTarget
  16. *    @see        SettingsObject
  17. */
  18.  
  19. import com.ms.ui.*;
  20. import java.awt.*;
  21. import com.ms.fx.*;
  22. import java.io.File;
  23. import java.io.*;
  24. import java.util.*;
  25. import java.awt.image.*;
  26. import java.net.URL;
  27. import com.ms.ui.resource.*;
  28. import com.ms.util.*;
  29. import com.ms.awt.image.StreamedImageSource;
  30.  
  31. public class JNoteToolbar extends UIBand implements ICommandFeedback
  32. {
  33.     /**
  34.     *    The hashtable that holds the buttons in the toolbar
  35.     */
  36.     protected Hashtable buttonTable;
  37.     
  38.     /**
  39.     *    Foreground color chooser control.    
  40.     */
  41.     JNoteColorChoice colorChoiceFg;
  42.     
  43.     /**
  44.     *    The applet that we're running from. If we're in standalone mode, this
  45.     *    is null.
  46.     */
  47.     UIApplet theApplet;
  48.     
  49.     /**
  50.     *    Background color chooser control.
  51.     */
  52.     JNoteColorChoice colorChoiceBg;
  53.     
  54.     /**
  55.     *    Creates a JNoteToolbar.        
  56.     */
  57.     
  58.     /**
  59.     *    Creates a JNoteToolbar.        
  60.     *
  61.     *    @param applet The applet which this is running from. This is null if we're running standalone
  62.     */
  63.     public JNoteToolbar(UIApplet applet)
  64.     {
  65.         //super(IFxGraphicsConstants.EDGE_RAISED);
  66.         super("", BREAK);
  67.         colorChoiceFg=null;
  68.         colorChoiceBg=null;
  69.         
  70.         init(applet);
  71.     }
  72.     
  73.     /**
  74.     *    Private init function. Initializes the button hash table and other
  75.     *    variables.
  76.     *
  77.     *    @param applet The applet which this is running from. This is null if we're running standalone.
  78.     */
  79.     private void init(UIApplet applet)
  80.     {            
  81.         theApplet = applet;
  82.         buttonTable = new Hashtable(11);
  83.     }
  84.                 
  85.     
  86.     /**
  87.     *    Loads buttons and their from the settings object
  88.     *    and places the button objects into the button table. Also adds JNoteColorChoice
  89.     *    controls to the toolbar.
  90.     *
  91.     *    @param     settings    Object which holds application settings information
  92.     */
  93.     public void loadButtons(Win32ResourceDecoder res)
  94.     {
  95.         int i = 0;
  96.         boolean bLoadedOK = true;
  97.         
  98.         MediaTracker mt = new MediaTracker(FxToolkit.getHelperFrame());
  99.         MediaTracker grayMT = new MediaTracker(FxToolkit.getHelperFrame());
  100.         
  101.         JNoteSettings settings = JNoteAppSettings.getSettingsObj();
  102.         
  103.         String cmdSection=null;
  104.         while ((cmdSection = settings.get("Toolbar", String.valueOf(i), null)) != null)
  105.         {                    
  106.             if (cmdSection.length() == 0)
  107.             {
  108.                 // toolbar load error
  109.                 UIMessageBox _box_ = new UIMessageBox(new UIFrame(), 
  110.                     JNotePad.loadString(ResourceIDs.IDS_MSGTITLE),
  111.                     JNotePad.loadString(ResourceIDs.IDS_MSGINITOOLBARERR),
  112.                     UIMessageBox.STOP, UIButtonBar.OK);
  113.                 _box_.doModal();
  114.                 
  115.                 cmdSection = "Default";
  116.             }
  117.  
  118.             //
  119.             // get the filename for the image
  120.             // Get the resource ID for the tooltip
  121.             // get the CMD id for the button.
  122.             //
  123.             String imageName = settings.get(cmdSection, "Image", "");
  124.             String nameID = settings.get(cmdSection, "Tip", "");
  125.             String name=null;
  126.  
  127.             try
  128.             {
  129.                 name = res.getString( Integer.parseInt(nameID));
  130.             }
  131.             catch (Exception e)
  132.             {
  133.                 name="";
  134.             }
  135.             String cmd = settings.get(cmdSection,"CMD","");
  136.             int cmdID= Integer.parseInt(cmd);
  137.             
  138.             JNotePushButton button = null;
  139.             Image im = null;
  140.             UIGraphic grayGraphic = null;
  141.             
  142.             if (imageName != null)
  143.             {
  144.                 im = loadImage(imageName);                            
  145.             }
  146.  
  147.             if ((imageName == null) || (im == null))
  148.             {
  149.                 // if button image doesn't exist, pop up an error
  150.                 // box at the end of the button loading.
  151.                 button = new JNotePushButton(name);
  152.  
  153.                 bLoadedOK = false;
  154.             }
  155.             else
  156.             {
  157.                 //
  158.                 //
  159.                 //
  160.                 int iIndex = imageName.indexOf('.');
  161.                 if (iIndex > -1)
  162.                 {
  163.                     // the grayed out bitmap has a _ appended to the end of the normal bitmap's name
  164.                     String grayImageName = imageName.substring(0, iIndex)+"_"+imageName.substring(iIndex);
  165.                     
  166.                     File grayFile = new File(grayImageName);
  167.                     if (grayFile.exists())
  168.                     {
  169.                         Image grayIm;
  170.                         
  171.                         grayIm = loadImage(grayImageName);
  172.                         grayGraphic = new UIGraphic(grayIm);
  173.                         grayMT.addImage(grayIm, i);
  174.                     }
  175.                 }
  176.                 
  177.                 button = new JNotePushButton(new UIGraphic(im), grayGraphic, 0);
  178.                 button.setName(name);
  179.                 
  180.                 mt.addImage(im, i);
  181.             }
  182.             
  183.             button.setID(cmdID);
  184.             add(button);
  185.             buttonTable.put(name, button);
  186.  
  187.             i++;
  188.         }
  189.         
  190.         try
  191.         {
  192.             mt.waitForAll();
  193.             grayMT.waitForAll();
  194.         }
  195.         catch (InterruptedException e)
  196.         {
  197.         }
  198.  
  199.         // add a color choice dropdown for selecting the text color
  200.         UIPanel panel = new UIPanel();
  201.         colorChoiceFg = new JNoteColorChoice(JNoteColorChoice.TEXTCOLOR);
  202.         panel.add(colorChoiceFg);
  203.         add(panel);
  204.  
  205.         // add a color choice dropdown for selecting the background color
  206.         panel = new UIPanel();
  207.         colorChoiceBg = new JNoteColorChoice(JNoteColorChoice.BACKCOLOR);
  208.         panel.add(colorChoiceBg);
  209.         add(panel);
  210.             
  211.         if (!bLoadedOK)
  212.         {
  213.             // ini graphic load error
  214.             UIMessageBox _box_ = new UIMessageBox(new UIFrame(), 
  215.                 JNotePad.loadString(ResourceIDs.IDS_MSGTITLE),
  216.                 JNotePad.loadString(ResourceIDs.IDS_MSGINITIMGERR),
  217.                 UIMessageBox.STOP, UIButtonBar.OK);
  218.             _box_.doModal();
  219.             
  220.         }
  221.         
  222.         repaint();
  223.     }
  224.     
  225.     
  226.     // ICommandFeedback methods
  227.     
  228.     /**
  229.     *    Part of ICommandFeedback. Called when a command button needs to be enabled or disabled.
  230.     *    Disables the button and grays it out.
  231.     *    
  232.     *    @see    ICommandFeedback
  233.     *    @param    command    Name of button to enable or disable
  234.     *    @param    on    true if button is to be enabled, false if it is to be disabled.
  235.     */
  236.     public void enableCommand(String command, boolean on)
  237.     {
  238.         JNotePushButton button = (JNotePushButton)buttonTable.get(command);
  239.         
  240.         if (button != null)
  241.         {
  242.             button.setEnabled(on);
  243.             button.repaint();
  244.         }
  245.     }
  246.     
  247.     /**
  248.     *    Part of ICommandFeedback. Checks the enabled state of a button.
  249.     *
  250.     *    @param    command    Name of button to check
  251.     *    @returns    true if button is enabled, false if it is not.
  252.     */
  253.     public boolean isEnabled(String command)
  254.     {
  255.         JNotePushButton button = (JNotePushButton)buttonTable.get(command);
  256.         
  257.         if (button != null)
  258.         {
  259.             return button.isEnabled();                    
  260.         }
  261.         else
  262.         {
  263.             return true;
  264.         }
  265.     }
  266.     
  267.     
  268.     
  269.     /**
  270.     *    Part of ICommandFeedback. Called when a command button needs to be checked or unchecked.
  271.     *    Sets the checkmark accordingly. This works only on UICheckButtons -- it has no effect
  272.     *    on other buttons.
  273.     *    
  274.     *    @see    ICommandFeedback
  275.     *    @param    command    Name of button to set the check on
  276.     *    @param    on    true if button is to be checked, false if it is to be unchecked.
  277.     */
  278.     public void setChecked(String command, boolean on)
  279.     {
  280.         Object obj = buttonTable.get(command);
  281.         
  282.         if ((obj != null) && (obj instanceof UICheckButton))
  283.         {
  284.             UICheckButton button = (UICheckButton)obj;
  285.             
  286.             button.setChecked(on);
  287.             button.repaint();
  288.         }
  289.     }
  290.     
  291.     
  292.     /**
  293.     *    Called when a file is loaded. Adds filename to Most Recently Used (MRU) list.
  294.     *    Part of ICommandFeedback. Does nothing in this class cause there's no 
  295.     *    MRU list to add to.
  296.     *
  297.     *    @param    command    Name of file to add to MRU list
  298.     *    @see    ICommandFeedback
  299.     */
  300.     public void addToMRUList(String filename)
  301.     {
  302.     }
  303.     
  304.     /**
  305.     *    Called when a control in the system changes color. Changes the colors
  306.     *    in the JNoteColorChoice controls to reflect this change if the component
  307.     *    being changed is the edit control.
  308.     *
  309.     *    @param    comp    Component who had a color change
  310.     *    @param    color    Color that the component was changed to
  311.     *    @param    whichPart    Which part of the component had a color change. This can
  312.     *                        be either FOREGROUND or BACKGROUND.
  313.     */        
  314.     public void    notifyColorChange(Object comp, FxColor color, int whichPart)
  315.     {            
  316.  
  317.         if (!(comp instanceof ITextOperationTargetExt))
  318.         {
  319.             return;
  320.         }
  321.         
  322.         JNoteColorChoice colorChooser = null;
  323.         if (whichPart == COLORCHANGE_FOREGROUND)
  324.         {
  325.             colorChooser = colorChoiceFg;
  326.         }
  327.         else
  328.         {
  329.             colorChooser = colorChoiceBg;
  330.         }
  331.         
  332.         colorChooser.setSelectedColor(color);            
  333.     }
  334.     
  335.     /**
  336.     *    Loads an image file. Loads from the Toolkit if we're standalone or over
  337.     *    the net if we're an applet.
  338.     *    
  339.     *    @param    imageName    Name of image to load
  340.     */
  341.     protected Image loadImage(String imageName)
  342.     {
  343.         if (!JNoteAppletObject.isApplet())
  344.         {
  345.             // standalone
  346.             ClassLoader cl=this.getClass().getClassLoader();
  347.  
  348.             InputStream is;
  349.             if(cl!=null)
  350.                 is=cl.getResourceAsStream(imageName);
  351.             else
  352.                 is=ClassLoader.getSystemResourceAsStream(imageName);
  353.             if(is!=null)
  354.                 return Toolkit.getDefaultToolkit().createImage(new StreamedImageSource(is));
  355.             return null;
  356.         }
  357.         else
  358.         {
  359.             // applet
  360.             URL url = theApplet.getCodeBase();
  361.             return theApplet.getImage(url, imageName);
  362.         }
  363.     }
  364.     
  365.     
  366. }
  367.  
  368.  
  369. /**
  370. *    JNotePushButton
  371. *
  372. *  JNoteToolbar private class. This implements Tooltips in a standard UIPushButton.
  373. *  The Tooltip displayed is the name of the control.
  374. *
  375. *    @version    1.0, 7/31/97
  376. *    @see        JNoteToolbar
  377. */
  378.  
  379. class JNotePushButton extends UIPushButton
  380. {
  381.     private UIGraphic grayedImage = null;
  382.     private UIGraphic normalImage = null;
  383.     
  384.     /**
  385.     *    Creates a JNotePushButton with a text field.
  386.     *
  387.     *    @param text Text to display on button.
  388.     */
  389.     public JNotePushButton(String text)
  390.     {
  391.         super(text);
  392.         normalImage = null;
  393.         grayedImage = null;        
  394.     }
  395.     /**
  396.     *    Creates a JNotePushButton with a particular style and text.
  397.     *
  398.     *    @param text Text to display on button
  399.     *    @param style Button style -- constants in <a href="com.ms.ui.UIPushButton">UIPushButton</a>.
  400.     */
  401.     public JNotePushButton(String text, int style)
  402.     {
  403.         super(text, style);
  404.         normalImage = null;
  405.         grayedImage = null;
  406.     }
  407.     
  408.     
  409.     /**
  410.     *    Creates a JNotePushButton which displays a IUIComponent, such as UIGraphic
  411.     *    or UIStatic.
  412.     *
  413.     *    @param comp IUIComponent to display on button
  414.     */
  415.     public JNotePushButton(IUIComponent comp)
  416.     {
  417.         super(comp);
  418.         init(comp, null);
  419.     }
  420.     
  421.     
  422.     /**
  423.     *    Creates JNotePushButton with a particular style and displaying a given IUIComponent.
  424.     *
  425.     *    @param comp IUIComponent to display
  426.     *    @param style Style of button - constants in <a href="com.ms.ui.UIPushButton">UIPushButton</a>.
  427.     */
  428.     public JNotePushButton(IUIComponent comp, int style)
  429.     {
  430.         super(comp, style);
  431.         init(comp, null);
  432.     }
  433.     
  434.     
  435.     /**
  436.     *    Creates JNotePushButton with a particular style and displaying a given IUIComponent.
  437.     *    When disabled, the button displays the given image.
  438.     *
  439.     *    @param comp IUIComponent to display
  440.     *    @param grayComp    IUIComponent to display when grayed out (disabled)
  441.     *    @param style Style of button - constants in <a href="com.ms.ui.UIPushButton">UIPushButton</a>.
  442.     */
  443.     public JNotePushButton(IUIComponent comp, IUIComponent grayComp, int style)
  444.     {
  445.         super(comp, style);
  446.         init(comp, grayComp);
  447.     }
  448.     
  449.     
  450.     
  451.     /**
  452.     *    Private init method. Initializes the button with the given
  453.     *    component and style. Also constructs a grayed out image for display
  454.     *    when the button is disabled.
  455.     *    
  456.     *    @param    comp    Component to display on button
  457.     *    @param    style    Style of button - constants constants in <a href="com.ms.ui.UIPushButton">UIPushButton</a>
  458.     */
  459.     private void init(IUIComponent comp, IUIComponent grayComp)
  460.     {
  461.         if (comp instanceof UIGraphic)
  462.         {
  463.             normalImage = (UIGraphic)comp;
  464.             
  465.             if ((grayComp != null) && (grayComp instanceof UIGraphic))
  466.             {
  467.                 grayedImage = (UIGraphic)grayComp;
  468.             }
  469.             else
  470.             {
  471.                 makeGrayedImage(normalImage);
  472.             }
  473.         }
  474.     }            
  475.     
  476.     /**
  477.     *    Implements the getHelp() method for Tooltips. The text displayed
  478.     *    by a Tooltip is whatever is returned from the getHelp() method.
  479.     *    JNotePushButtons return the name of the button (getName()).
  480.     */
  481.     public String getHelp()
  482.     {
  483.         return getName();
  484.     }
  485.     
  486.     /**
  487.     *    enables or disables the button. If there's an image, changes it to
  488.     *    a grayed out version.
  489.     *
  490.     *    @param    on    true if the button is to be enabled, false if it is to be disabled.
  491.     *    @returns    true
  492.     */
  493.     public void setEnabled(boolean on)
  494.     {
  495.         if (isEnabled() == on)
  496.         {
  497.             return;
  498.         }
  499.         
  500.         super.setEnabled(on);
  501.         
  502.         if (normalImage != null)
  503.         {                    
  504.             UIGraphic image = null;
  505.             
  506.             if (on == false)
  507.             {
  508.                 // set the current image to a grayed out image.
  509.                 image = grayedImage;
  510.             }
  511.             else
  512.             {
  513.                 // reset the original image
  514.                 image = normalImage;                        
  515.             }
  516.             
  517.             replace(image, 0);
  518.             
  519.             repaint();
  520.         }
  521.     } 
  522.     
  523.     
  524.     /**
  525.     *    Private method to create a grayed version of the component and store
  526.     *    it in grayedImage. Currently works only with UIGraphic objects. 
  527.     *    Text strings gray automatically when disabled.
  528.     *
  529.     *    @param    comp    Component to gray out
  530.     */     
  531.     private void makeGrayedImage(UIGraphic image)
  532.     {
  533.         // use a gray filter to gray out the image
  534.         grayedImage = new UIGraphic( createImage(new FilteredImageSource(image.getImage().getSource(),
  535.             new GrayImageFilter())) );
  536.         
  537.         
  538.     }
  539.     
  540. }
  541.  
  542.  
  543. /**
  544. *    JNoteColorChoice
  545. *
  546. *    This is a private class to JNoteToolbar. It creates a dropdown color choice
  547. *    list.
  548. *
  549. *    @version    1.0, 8/12/97
  550. *
  551. *    @see    JNoteToolbar
  552. */
  553.  
  554. class JNoteColorChoice extends UIChoice
  555. {        
  556. /**
  557. *    Maps colors to items in the list
  558.     */
  559.     private Hashtable colorTable;                
  560.     
  561.     /**
  562.     *    whether this control displays foreground or background colors        
  563.     */
  564.     private int iStyle;                
  565.     
  566.     /**
  567.     *    foreground color style
  568.     */
  569.     public static final int TEXTCOLOR = 1;
  570.     
  571.     /**
  572.     *    background color style    
  573.     */
  574.     public static final int BACKCOLOR = 2;
  575.     
  576.     /**
  577.     *    Creates a new JNoteColorChoice.
  578.     *
  579.     *    @param    style    Style of the control. TEXTCOLOR indicates the control will
  580.     *                    display foreground colors, and BACKCOLOR indicates it will 
  581.     *                    display background colors.
  582.     */
  583.     public JNoteColorChoice(int style)
  584.     {
  585.         colorTable = new Hashtable(10);
  586.         init(style);
  587.     }
  588.     
  589.     /**
  590.     *    Private init method. Creates the UIChoice control and adds color bars to it.
  591.     *
  592.     *    @param    style    Style of the control. See <a href="JNoteColorChoice">JNoteColorChoice</a> 
  593.     *                    for details.
  594.     */
  595.     private void init(int style)
  596.     {
  597.         iStyle = style;
  598.         
  599.         // grab settings object
  600.         JNoteSettings settings = JNoteAppSettings.getSettingsObj();
  601.         
  602.         // fill vector with the color names
  603.         Vector svector = new Vector(10);
  604.         Enumeration e = settings.getKeys("Colors");
  605.         
  606.         while (e.hasMoreElements())
  607.         {
  608.             svector.addElement(e.nextElement());
  609.         }
  610.                 
  611.         // sort the vector so we get the colors in alpha order
  612.         VectorSort.sort(svector, new StringComparison());
  613.  
  614.         e = svector.elements();
  615.         
  616.         while (e.hasMoreElements())
  617.         {
  618.             String colorName = (String)e.nextElement();
  619.             FxColor color = settings.getColor(colorName, null);
  620.             
  621.             if (color == null)
  622.             {
  623.                 // ini color load error
  624.                 UIMessageBox _box_ = new UIMessageBox(new UIFrame(), 
  625.                     JNotePad.loadString(ResourceIDs.IDS_MSGTITLE),
  626.                     JNotePad.loadString(ResourceIDs.IDS_MSGINICOLORERR),
  627.                     UIMessageBox.STOP, UIButtonBar.OK);
  628.                 _box_.doModal();
  629.                 
  630.                 return;
  631.             }
  632.             
  633.             addColorBar(colorName, color);                        
  634.         }
  635.         
  636.         
  637.         // add a box for custom color. This usually launches a color dialog.
  638.         
  639.         UIStatic custom;
  640.         
  641.         if (iStyle == TEXTCOLOR)
  642.         {
  643.             custom = new UIText("Custom...", UIText.LEFT);
  644.             custom.setForeground(FxColor.getExtendedColor(Color.black));
  645.         }
  646.         else
  647.         {
  648.             custom = new UIText("Custom...", UIText.LEFT);
  649.             custom.setBackground(FxColor.getExtendedColor(Color.lightGray));
  650.         }
  651.         
  652.         //choiceControl.add(custom);
  653.         add(custom);
  654.         
  655.         //add(choiceControl);
  656.         
  657.         //choiceControl.repaint();
  658.         repaint();
  659.     }
  660.     
  661.     /**
  662.     *    Adds a component to the end of the list. Also adds its color value
  663.     *    to the hashtable so you can do a lookup of components by color.
  664.     *
  665.     *    @param    comp    Component to be added
  666.     */
  667.     public IUIComponent add(IUIComponent comp)
  668.     {
  669.         super.add(comp);
  670.         FxColor color = null;
  671.         
  672.         if (iStyle == TEXTCOLOR)
  673.         {
  674.             color = FxColor.getExtendedColor(comp.getForeground());
  675.         }
  676.         else
  677.         {
  678.             color = FxColor.getExtendedColor(comp.getBackground());
  679.         }                
  680.         
  681.         // if the item we're adding is the Custom... item (which isn't
  682.         // really a color - it launches a color menu), add its name
  683.         // as the key instead of its color. We use this later.
  684.         if (!(comp.getName().equals("Custom...")))
  685.         {
  686.             colorTable.put(color, comp);                        
  687.         }
  688.         else
  689.         {
  690.             colorTable.put(comp.getName(), comp);
  691.         }
  692.         
  693.         return comp;
  694.     }
  695.     
  696.     /**
  697.     *    adds a color bar. 
  698.     *
  699.     *    @param    colorname    Name of the color
  700.     *    @param    color    Color object
  701.     */
  702.     public void addColorBar(String colorname, FxColor color)
  703.     {    
  704.         UIStatic s = new UIText(colorname, UIText.LEFT);
  705.         
  706.         // create an inverse color
  707.         int red = color.getRed() - 255;
  708.         int green = color.getGreen() - 255;
  709.         int blue = color.getBlue() - 255;
  710.         
  711.         if (red < 0) red = -red;
  712.         if (green < 0) green = -green;
  713.         if (blue < 0) blue = -blue;    
  714.         
  715.         FxColor inverse = new FxColor((red << 16) | (green << 8) | (blue));
  716.         
  717.         if (iStyle == TEXTCOLOR)
  718.         {
  719.             s.setForeground(color);                            
  720.             //s.setForeground(color.getShadow());
  721.         }
  722.         else
  723.         {
  724.             s.setBackground(color);
  725.             //s.setForeground(color.getDarkShadow());
  726.             s.setForeground(inverse);
  727.         }
  728.         
  729.         //choiceControl.add(s);
  730.         add(s);
  731.     }    
  732.     
  733.     /**
  734.     *    Sets the selection to an element in the list which is of the
  735.     *    given color.
  736.     *
  737.     *    @param    color    Color to set the UIChoice to
  738.     */
  739.     public void setSelectedColor(FxColor color)
  740.     {                
  741.         IUIComponent comp = (IUIComponent)colorTable.get(color);
  742.         
  743.         if (comp != null)
  744.         {
  745.             setSelectedItem(comp);
  746.         }
  747.         else
  748.         {
  749.             comp = (IUIComponent)colorTable.get("Custom...");
  750.             if (comp != null)
  751.             {
  752.                 setSelectedItem(comp);
  753.             }
  754.         }
  755.     }
  756.     
  757.     public String getHelp()
  758.     {
  759.         if (iStyle == TEXTCOLOR)
  760.         {
  761.             return "Change Text Color";
  762.         }
  763.         else
  764.         {
  765.             return "Change Background Color";
  766.         }
  767.         
  768.     }
  769. }
  770.  
  771. /**
  772. *    Private class to be used with SortedVectors. Compares two colors
  773. *    
  774. *    @version    1.0, 7/28/97
  775. */
  776. class StringComparison implements Comparison
  777. {
  778.     /**
  779.     *    Compares two objects.    
  780.     *
  781.     *    @returns    negative if a < b, 0 if a == b, positive if a > b
  782.     */
  783.     public int compare(Object p, Object q)
  784.     {
  785.         if ((p instanceof String) || (q instanceof String))
  786.         {
  787.             return ((String)p).compareTo((String)q);
  788.         }
  789.         return 0;
  790.     }
  791. }
  792.  
  793.