2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath 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 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax
.swing
.plaf
.basic
;
42 import javax
.swing
.plaf
.*;
46 public class BasicButtonUI
extends ButtonUI
49 // int y_text_space = 2, x_text_space + 5;
51 Color textColor
, disabledTextColor
;
52 Color pressedBackgroundColor
;
53 Color normalBackgroundColor
;
56 public static ComponentUI
createUI(final JComponent c
)
58 return new BasicButtonUI();
62 public void installUI(final JComponent c
)
66 textColor
= new Color(0,0,0);
67 disabledTextColor
= new Color(130, 130, 130);
68 pressedBackgroundColor
= new Color(150,150,150);
69 pressedBackgroundColor
= new Color(150,150,150);
70 normalBackgroundColor
= new Color(192,192,192);
74 public Dimension
getPreferredSize(JComponent c
)
76 AbstractButton b
= (AbstractButton
)c
;
77 Dimension d
= BasicGraphicsUtils
.getPreferredButtonSize(b
, gap
);
78 // System.out.println("^^^^^^^^^^^^^^^^^^^^^^ BASIC-PREF="+d + ",T="+b.text);
83 public void paint(Graphics g
, JComponent c
)
85 AbstractButton b
= (AbstractButton
) c
;
87 Rectangle tr
= new Rectangle();
88 Rectangle ir
= new Rectangle();
89 Rectangle vr
= new Rectangle();
95 FontMetrics fm
= g
.getFontMetrics(f
);
97 Insets i
= c
.getInsets();
101 vr
.width
= b
.getWidth() - (i
.right
+ vr
.x
);
102 vr
.height
= b
.getHeight() - (i
.bottom
+ vr
.y
);
104 //System.out.println(" VIEW-RECT-BUTTON="+vr+", insets="+i+", FONTM="+fm);
106 String text
= SwingUtilities
.layoutCompoundLabel(c
,
110 b
.getVerticalAlignment(),
111 b
.getHorizontalAlignment(),
112 b
.getVerticalTextPosition(),
113 b
.getHorizontalTextPosition(),
119 if (b
.getModel().isPressed() ||
120 b
.getModel().isSelected())
122 //System.out.println("paint pressed");
123 paintButtonPressed(g
, c
);
127 //System.out.println("paint normal");
128 paintButtonNormal(g
, c
);
132 paintText(g
, c
, tr
, b
.getText());
133 paintFocus(g
, c
, vr
, tr
, ir
);
137 protected void paintFocus(Graphics g
,
145 protected void paintIcon(Graphics g
,
149 AbstractButton b
= (AbstractButton
) c
;
150 if (b
.getIcon() != null)
155 System
.out
.println("WE HAVE AN ICON: " + b
.getIcon());
157 b
.getIcon().paintIcon(c
, g
, x
, y
);
161 //System.out.println("NO ICON FOR BUTTON:" + b.text);
165 protected void paintButtonPressed(Graphics g
,
168 Dimension size
= b
.getSize();
170 g
.setColor(pressedBackgroundColor
);
171 g
.fillRect(1,1,size
.width
-2, size
.height
-2);
175 protected void paintButtonNormal(Graphics g
,
178 Dimension size
= b
.getSize();
180 g
.setColor(normalBackgroundColor
);
181 g
.fillRect(1,1,size
.width
-2, size
.height
-2);
185 protected void paintText(Graphics g
,
190 Font f
= c
.getFont();
194 FontMetrics fm
= g
.getFontMetrics(f
);
196 g
.setColor(c
.isEnabled() ? textColor
: disabledTextColor
);
198 BasicGraphicsUtils
.drawString(g
,
202 textRect
.y
+ fm
.getAscent()/2);