home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
AnnotatedEmptyItemPainter.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
4KB
|
111 lines
/*
* Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
*
* This SOURCE CODE FILE, which has been provided by Borland as part
* of a Borland product for use ONLY by licensed users of the product,
* includes CONFIDENTIAL and PROPRIETARY information of Borland.
*
* USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
* OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
* THE PRODUCT.
*
* IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
* COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
* OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
* OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
* OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
* OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
* CODE FILE.
*/
package borland.samples.intl.beans;
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.
* Uses a TextItemPainter if an ItemPainter is not explicitly specified.
*/
public class AnnotatedEmptyItemPainter implements ItemPainter {
ItemPainter itemPainter;
String displayString;
/**
* By default, use a Focusable, Selectable, TextItemPainter to paint text.
*/
public AnnotatedEmptyItemPainter() {
itemPainter = new FocusableItemPainter(new SelectableItemPainter(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);
}
}
}