01: /*
02: * @(#)PPCLabelPeer.java 1.8 06/10/10
03: *
04: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26: package sun.awt.pocketpc;
27:
28: import java.awt.*;
29: import sun.awt.peer.*;
30:
31: class PPCLabelPeer extends PPCComponentPeer implements LabelPeer {
32:
33: private static native void initIDs();
34:
35: static {
36: initIDs();
37: }
38:
39: // ComponentPeer overrides
40:
41: public Dimension getMinimumSize() {
42: FontMetrics fm = getFontMetrics(((Label) target).getFont());
43: String label = ((Label) target).getText();
44: if (label == null) {
45: label = "";
46: }
47: return new Dimension(fm.stringWidth(label) + 14,
48: fm.getHeight() + 8);
49: }
50:
51: // LabelPeer implementation
52:
53: public native void setText(String label);
54:
55: public native void setAlignment(int alignment);
56:
57: // Toolkit & peer internals
58:
59: PPCLabelPeer(Label target) {
60: super (target);
61: }
62:
63: native void create(PPCComponentPeer parent);
64:
65: void initialize() {
66: Label l = (Label) target;
67:
68: String txt = l.getText();
69: if (txt != null) {
70: setText(txt);
71: }
72:
73: int align = l.getAlignment();
74: if (align != Label.LEFT) {
75: setAlignment(align);
76: }
77:
78: Color bg = ((Component) target).getBackground();
79: if (bg != null) {
80: setBackground(bg);
81: }
82:
83: super .initialize();
84: return;
85: }
86:
87: void clearRectBeforePaint(Graphics g, Rectangle r) {
88: // Overload to do nothing for native components
89: return;
90: }
91:
92: /**
93: * DEPRECATED
94: */
95: public Dimension minimumSize() {
96: return getMinimumSize();
97: }
98:
99: }
|