home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-05-08 | 3.6 KB | 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.*;
-
- /**
- * ResourceableItemPainter - a resourceable item painter.
- * Assumes the item to paint is actually a lookup key into a specified
- * resource bundle. The object retrieved from the resource bundle
- * (usually, but not necessarily a string) becomes the item to be painted.
- */
- public class ResourceableItemPainter implements ItemPainter {
- ItemPainter itemPainter;
- ResourceBundle resourceBundle;
-
- /**
- * By default, use a Focusable, Selectable, TextItemPainter to paint items.
- */
- public ResourceableItemPainter() {
- itemPainter = new FocusableItemPainter(new SelectableItemPainter(new TextItemPainter()));
- }
-
- /**
- * By default, use the specified ItemPainter to paint items.
- *
- * @param itemPainter ItemPainter to use to paint items
- */
- public ResourceableItemPainter(ItemPainter itemPainter) {
- this.itemPainter = itemPainter;
- }
-
- /**
- * Sets the resource bundle in which to look up items to display.
- *
- * @param resourceBundle resourceBundle to use for key lookups
- */
- public void setResourceBundle(ResourceBundle resourceBundle) {
- this.resourceBundle = resourceBundle;
- }
-
- /**
- * Returns the resource bundle used to look up resource keys.
- *
- * @return resource bundle for key lookups.
- */
- public ResourceBundle getResourceBundle() {
- return resourceBundle;
- }
-
- /**
- * Sets the ItemPainter used to display items.
- *
- * @param itemPainter ItemPainter to use.
- */
- public void setItemPainter(ItemPainter itemPainter) {
- this.itemPainter = itemPainter;
- }
-
- /**
- * Returns ItemPainter used to display text.
- *
- * @return ItemPainter in use.
- */
- public ItemPainter getItemPainter() {
- return itemPainter;
- }
-
- // required for implementation of ItemPainter interface
- public Dimension getPreferredSize(Object object, Graphics g, int state, ItemPaintSite site) {
- if (!(object.toString().length() == 0) && resourceBundle != null) {
- return itemPainter.getPreferredSize(resourceBundle.getString(object.toString()), 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) {
- String s = object.toString();
- if (!(object.toString().length() == 0) && resourceBundle != null) {
- itemPainter.paint(resourceBundle.getString(object.toString()), g, r, state, site);
- } else {
- itemPainter.paint(object, g, r, state, site);
- }
- }
-
- }
-