01: /*
02: * @(#)PPCButtonPeer.java 1.3 02/12/09
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:
27: package sun.awt.pocketpc;
28:
29: import sun.awt.peer.*;
30: import java.awt.*;
31: import java.awt.event.*;
32:
33: /**
34: * PPCButtonPeer.java
35: *
36: * @author Nicholas Allen
37: */
38:
39: class PPCButtonPeer extends PPCComponentPeer implements ButtonPeer {
40:
41: static {
42: initIDs();
43: }
44:
45: PPCButtonPeer(Button target) {
46: super (target);
47: //Perhaps not necessary?
48: //setLabel(target.getLabel());
49: }
50:
51: public boolean isFocusTraversable() {
52: return true;
53: }
54:
55: native void create(PPCComponentPeer peer);
56:
57: private native void setLabelNative(String label);
58:
59: private static native void initIDs();
60:
61: public void setLabel(String label) {
62: setLabelNative(label);
63: // may not be necessary?
64: //((Component)target).invalidate();
65: }
66:
67: public Dimension getMinimumSize() {
68: FontMetrics fm = getFontMetrics(((Button) target).getFont());
69: return new Dimension(fm.stringWidth(((Button) target)
70: .getLabel()) + 14, fm.getHeight() + 8);
71: }
72:
73: public Dimension minimumSize() {
74: return getMinimumSize();
75: }
76:
77: public void handleAction() {
78: PPCToolkit.postEvent(new ActionEvent(target,
79: ActionEvent.ACTION_PERFORMED, ((Button) target)
80: .getActionCommand()));
81: }
82:
83: void clearRectBeforePaint(Graphics g, Rectangle r) {
84: // Overload to do nothing for native components
85: }
86: }
|