1 /* |
|
2 * Copyright 1995-2001 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 package sun.awt.motif; |
|
26 |
|
27 import java.awt.*; |
|
28 import java.awt.peer.*; |
|
29 import java.awt.event.ActionEvent; |
|
30 |
|
31 class MButtonPeer extends MComponentPeer implements ButtonPeer { |
|
32 native void create(MComponentPeer peer); |
|
33 public native void setLabel(String label); |
|
34 |
|
35 MButtonPeer(Button target) { |
|
36 super(target); |
|
37 } |
|
38 |
|
39 public Dimension getMinimumSize() { |
|
40 FontMetrics fm = getFontMetrics(target.getFont()); |
|
41 String label = ((Button)target).getLabel(); |
|
42 if ( label == null ) { |
|
43 label = ""; |
|
44 } |
|
45 return new Dimension(fm.stringWidth(label) + 14, |
|
46 fm.getHeight() + 8); |
|
47 } |
|
48 |
|
49 public boolean isFocusable() { |
|
50 return true; |
|
51 } |
|
52 |
|
53 // NOTE: This method is called by privileged threads. |
|
54 // DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
55 public void action(final long when, final int modifiers) { |
|
56 MToolkit.executeOnEventHandlerThread(target, new Runnable() { |
|
57 public void run() { |
|
58 postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED, |
|
59 ((Button)target).getActionCommand(), |
|
60 when, modifiers)); |
|
61 } |
|
62 }); |
|
63 } |
|
64 |
|
65 /* |
|
66 * Print the native component by rendering the Motif look ourselves. |
|
67 * ToDo(aim): needs to query native motif for more accurate size and |
|
68 * color information. |
|
69 */ |
|
70 public void print(Graphics g) { |
|
71 Button b = (Button)target; |
|
72 Dimension d = b.size(); |
|
73 Color bg = b.getBackground(); |
|
74 Color fg = b.getForeground(); |
|
75 |
|
76 g.setColor(bg); |
|
77 g.fillRect(2, 2, d.width - 3, d.height - 3); |
|
78 draw3DRect(g, bg, 1, 1, d.width - 2, d.height - 2, true); |
|
79 |
|
80 g.setColor(fg); |
|
81 g.setFont(b.getFont()); |
|
82 FontMetrics fm = g.getFontMetrics(); |
|
83 String lbl = b.getLabel(); |
|
84 g.drawString(lbl, (d.width - fm.stringWidth(lbl)) / 2, |
|
85 (d.height + fm.getMaxAscent() - fm.getMaxDescent()) / 2); |
|
86 |
|
87 target.print(g); |
|
88 } |
|
89 |
|
90 /** |
|
91 * DEPRECATED |
|
92 */ |
|
93 public Dimension minimumSize() { |
|
94 return getMinimumSize(); |
|
95 } |
|
96 |
|
97 } |
|