home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 15
/
BUGCD1998_06.ISO
/
aplic
/
jbuilder
/
jsamples.z
/
ResourceableLineItemDetailPainter.java
< prev
next >
Wrap
Text File
|
1997-07-24
|
2KB
|
64 lines
package borland.samples.intl.application;
import java.awt.*;
import java.util.*;
import borland.jbcl.view.*;
import borland.jbcl.model.*;
import borland.jbcl.util.*;
/**
* Custom model-view item painter for painting localized values for
* the orderLineItemDataSet's details column. Uses the
* non-localized value in the details column as the lookup key
* into its resource bundle, then paints the localized value.
*/
public class ResourceableLineItemDetailPainter implements ItemPainter {
TextItemPainter textItemPainter;
ResourceBundle resourceBundle;
public ResourceableLineItemDetailPainter(Insets margins, int alignment) {
textItemPainter = new SelectableTextItemPainter(alignment, margins);
}
public ResourceableLineItemDetailPainter() {
textItemPainter = new SelectableTextItemPainter();
}
public void setResourceBundle(ResourceBundle resourceBundle) {
this.resourceBundle = resourceBundle;
}
public ResourceBundle getResourceBundle() {
return resourceBundle;
}
public Dimension getPreferredSize(Object object, Graphics g, int state, ItemPaintSite site) {
if (object.toString().length() != 0 && resourceBundle != null) {
StringTokenizer tokenizer = new StringTokenizer(object.toString(), ",", false);
String text = "";
while (tokenizer.hasMoreTokens()) {
text += resourceBundle.getString(tokenizer.nextToken());
}
return textItemPainter.getPreferredSize(text, g, state, site);
} else {
return textItemPainter.getPreferredSize(object, g, state, site);
}
}
public void paint(Object object, Graphics g, Rectangle r, int state, ItemPaintSite site) {
if (object.toString().length() != 0 && resourceBundle != null) {
StringTokenizer tokenizer = new StringTokenizer(object.toString(), ",", false);
String text = "";
while (tokenizer.hasMoreTokens()) {
text += resourceBundle.getString(tokenizer.nextToken()) + " ";
}
textItemPainter.paint(text, g, r, state, site);
} else {
textItemPainter.paint(object, g, r, state, site);
}
}
}