01: /*
02: * @(#)QtButtonPeer.java 1.14 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: */
27: package sun.awt.qt;
28:
29: import sun.awt.peer.*;
30: import java.awt.*;
31: import java.awt.event.*;
32:
33: /**
34: * QtButtonPeer.java
35: *
36: * @author Nicholas Allen
37: */
38:
39: class QtButtonPeer extends QtComponentPeer implements ButtonPeer {
40: private static native void initIDs();
41:
42: static {
43: initIDs();
44: }
45:
46: QtButtonPeer(QtToolkit toolkit, Button target) {
47: super (toolkit, target);
48: setLabel(target.getLabel());
49: }
50:
51: public Dimension getPreferredSize() {
52: Font font = target.getFont();
53: FontMetrics fm = toolkit.getFontMetrics(font);
54:
55: return new Dimension(fm.stringWidth(((Button) target)
56: .getLabel()) + 14, fm.getHeight() + 8);
57: }
58:
59: public boolean isFocusTraversable() {
60: return true;
61: }
62:
63: protected native void create(QtComponentPeer parentPeer);
64:
65: protected native void setLabelNative(String label);
66:
67: public void setLabel(String label) {
68: if (label != null)
69: setLabelNative(label);
70: target.invalidate();
71: }
72:
73: private void postActionEvent() {
74: QtToolkit.postEvent(new ActionEvent(target,
75: ActionEvent.ACTION_PERFORMED, ((Button) target)
76: .getActionCommand()));
77: }
78:
79: public boolean isFocusable() {
80: return true;
81: }
82: }
|