01: /*
02: * Javu WingS - Lightweight Java Component Set
03: * Copyright (c) 2005-2007 Krzysztof A. Sadlocha
04: * e-mail: ksadlocha@programics.com
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20:
21: package com.javujavu.javux.wings.extra;
22:
23: import java.awt.Dimension;
24: import java.awt.Graphics;
25: import java.awt.Image;
26: import java.awt.Insets;
27: import java.awt.Rectangle;
28: import com.javujavu.javux.wings.Style;
29: import com.javujavu.javux.wings.WingComponent;
30: import com.javujavu.javux.wings.WingFont;
31: import com.javujavu.javux.wings.WingToolkit;
32: import com.javujavu.javux.wings.item.ItemRenderer;
33:
34: /**
35: * This class is a self-rendering label implementing <code>ItemRederer</code>,
36: * that can display multiline text using specified font.<br>
37: * Object of this class can be used instead of String labels
38: * in labels, buttons, checkboxes, menus and so on, and as an item
39: * in lists, combo boxes, tables and so on.
40: * <br>
41: * <b>This in an extra class, NOT a part of base WingS component set.</b>
42: * <br>
43: * <br>
44: * <b>This class is thread safe.</b>
45: **/
46: public class FontItem implements ItemRenderer {
47: public final WingFont font;
48: public final String text;
49:
50: public FontItem(String text, WingFont font) {
51: this .text = text;
52: this .font = font;
53: }
54:
55: public String toString() {
56: return text;
57: }
58:
59: public Dimension getItemSize(Object item, WingComponent owner,
60: Style style, Object context) {
61: return WingToolkit.calcLabelSize(style.icon, text, font,
62: style.margin, style.gap, owner);
63: }
64:
65: public void drawItem(Graphics g, int x, int y, int width,
66: int height, Object item, WingComponent owner, Style style,
67: Insets margin, int alignment, int textPosition,
68: Object context) {
69: WingToolkit
70: .drawBackground(g, x, y, width, height, style, owner);
71: WingToolkit.drawLabel(g, x, y, width, height, style.icon, text,
72: font, style.foreground, null, margin, style.gap,
73: alignment, textPosition, owner);
74: }
75:
76: public boolean imageUpdate(Image img, int infoflags, int x, int y,
77: int width, int height, Object item, WingComponent owner,
78: Style style, Rectangle itemBounds) {
79: return false;
80: }
81: }
|