home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-07-30 | 2.6 KB | 91 lines |
- package borland.samples.intl.util;
-
- import java.awt.*;
- import java.util.*;
-
- import borland.jbcl.view.*;
- import borland.jbcl.model.*;
- import borland.jbcl.util.*;
-
- /**
- * AnnotatedEmptyItemPainter -- displays a string when the item is blank, i.e. toString().length() == 0.
- * Used to display a 'value required' message in blank columns which must be filled in.
- */
- public class AnnotatedEmptyItemPainter implements ItemPainter {
- ItemPainter itemPainter;
- String displayString;
-
- /**
- * By default, use TextItemPainter is used to paint text.
- */
- public AnnotatedEmptyItemPainter() {
- itemPainter = new TextItemPainter();
- }
-
- /**
- * By default, use the specified ItemPainter to paint text.
- *
- * @param itemPainter ItemPainter to use to paint.
- */
- public AnnotatedEmptyItemPainter(ItemPainter itemPainter) {
- this.itemPainter = itemPainter;
- }
-
- /**
- * Sets the string to display when the data is empty.
- *
- * @param displayString string to display
- */
- public void setDisplayString(String displayString) {
- this.displayString = displayString;
- }
-
- /**
- * Returns the string to display when the data is empty.
- *
- * @return string to display
- */
- public String getDisplayString() {
- return displayString;
- }
-
- /**
- * Sets the item painter used to paint text
- *
- * @param itemPainter item painter to use
- */
- public void setItemPainter(ItemPainter itemPainter) {
- this.itemPainter = itemPainter;
- }
-
- /**
- * Returns the item painter used to paint text
- *
- * @return item painter to use
- */
- public ItemPainter getItemPainter() {
- return itemPainter;
- }
-
- // required for implementation of ItemPainter interface
- public Dimension getPreferredSize(Object object, Graphics g, int state, ItemPaintSite site) {
- // if the object is an empty string, use the specified display string
- if ((object != null) && (object.toString().length() == 0) && displayString != null) {
- return itemPainter.getPreferredSize(displayString, g, state, site);
- } else {
- return itemPainter.getPreferredSize(object, g, state, site);
- }
- }
-
- // required for implementation of ItemPainter interface
- public void paint(Object object, Graphics g, Rectangle r, int state, ItemPaintSite site) {
- // if the object is an empty string, paint the specified display string
- if ((object != null) && (object.toString().length() == 0) && displayString != null) {
- itemPainter.paint(displayString, g, r, state, site);
- } else {
- itemPainter.paint(object, g, r, state, site);
- }
- }
-
- }
-