home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / AnnotatedEmptyItemPainter.java < prev    next >
Encoding:
Java Source  |  1997-07-30  |  2.6 KB  |  91 lines

  1. package borland.samples.intl.util;
  2.  
  3. import java.awt.*;
  4. import java.util.*;
  5.  
  6. import borland.jbcl.view.*;
  7. import borland.jbcl.model.*;
  8. import borland.jbcl.util.*;
  9.  
  10. /**
  11.  * AnnotatedEmptyItemPainter -- displays a string when the item is blank, i.e. toString().length() == 0.
  12.  * Used to display a 'value required' message in blank columns which must be filled in.
  13.  */
  14. public class AnnotatedEmptyItemPainter implements ItemPainter {
  15.   ItemPainter itemPainter;
  16.   String displayString;
  17.  
  18.   /**
  19.    * By default, use TextItemPainter is used to paint text.
  20.    */
  21.   public AnnotatedEmptyItemPainter() {
  22.     itemPainter = new TextItemPainter();
  23.   }
  24.  
  25.   /**
  26.    * By default, use the specified ItemPainter to paint text.
  27.    *
  28.    * @param itemPainter ItemPainter to use to paint.
  29.    */
  30.   public AnnotatedEmptyItemPainter(ItemPainter itemPainter) {
  31.     this.itemPainter = itemPainter;
  32.   }
  33.  
  34.   /**
  35.    * Sets the string to display when the data is empty.
  36.    *
  37.    * @param displayString string to display
  38.    */
  39.   public void setDisplayString(String displayString) {
  40.     this.displayString = displayString;
  41.   }
  42.  
  43.   /**
  44.    * Returns the string to display when the data is empty.
  45.    *
  46.    * @return string to display
  47.    */
  48.   public String getDisplayString() {
  49.     return displayString;
  50.   }
  51.  
  52.   /**
  53.    * Sets the item painter used to paint text
  54.    *
  55.    * @param itemPainter item painter to use
  56.    */
  57.   public void setItemPainter(ItemPainter itemPainter) {
  58.     this.itemPainter = itemPainter;
  59.   }
  60.  
  61.   /**
  62.    * Returns the item painter used to paint text
  63.    *
  64.    * @return item painter to use
  65.    */
  66.   public ItemPainter getItemPainter() {
  67.     return itemPainter;
  68.   }
  69.  
  70.   // required for implementation of ItemPainter interface
  71.   public Dimension getPreferredSize(Object object, Graphics g, int state, ItemPaintSite site) {
  72.   // if the object is an empty string, use the specified display string
  73.     if ((object != null) && (object.toString().length() == 0) && displayString != null) {
  74.       return itemPainter.getPreferredSize(displayString, g, state, site);
  75.     } else {
  76.       return itemPainter.getPreferredSize(object, g, state, site);
  77.     }
  78.   }
  79.  
  80.   // required for implementation of ItemPainter interface
  81.   public void paint(Object object, Graphics g, Rectangle r, int state, ItemPaintSite site) {
  82.   // if the object is an empty string, paint the specified display string
  83.     if ((object != null) && (object.toString().length() == 0) && displayString != null) {
  84.       itemPainter.paint(displayString, g, r, state, site);
  85.     } else {
  86.       itemPainter.paint(object, g, r, state, site);
  87.     }
  88.   }
  89.  
  90. }
  91.