Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / javax / swing / plaf / basic / BasicRadioButtonUI.java
blob66e53803722101eecf9f888f4e740791db9a368a
1 /* BasicRadioButtonUI.java
2 Copyright (C) 2002, 2004 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)
9 any later version.
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., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
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
24 combination.
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;
41 import java.awt.Color;
42 import java.awt.Dimension;
43 import java.awt.Font;
44 import java.awt.Graphics;
45 import java.awt.Rectangle;
47 import javax.swing.AbstractButton;
48 import javax.swing.Icon;
49 import javax.swing.JComponent;
50 import javax.swing.SwingUtilities;
51 import javax.swing.UIManager;
52 import javax.swing.plaf.ComponentUI;
54 /**
55 * The BasicLookAndFeel UI implementation for
56 * {@link javax.swing.JRadioButton}s.
58 public class BasicRadioButtonUI extends BasicToggleButtonUI
60 /**
61 * The default icon for JRadioButtons. The default icon displays the usual
62 * RadioButton and is sensible to the selection state of the button,
63 * and can be used both as normal icon as well as selectedIcon.
65 protected Icon icon;
67 /**
68 * Creates and returns a new instance of <code>BasicRadioButtonUI</code>.
70 * @return a new instance of <code>BasicRadioButtonUI</code>
72 public static ComponentUI createUI(final JComponent c) {
73 return new BasicRadioButtonUI();
76 /**
77 * Creates a new instance of <code>BasicButtonUI</code>.
79 public BasicRadioButtonUI()
81 icon = getDefaultIcon();
84 /**
85 * Installs defaults from the Look &amp; Feel table on the specified
86 * button.
88 * @param b the button on which to install the defaults
90 protected void installDefaults(AbstractButton b)
92 super.installDefaults(b);
93 if (b.getIcon() == null)
94 b.setIcon(icon);
95 if (b.getSelectedIcon() == null)
96 b.setSelectedIcon(icon);
97 if (b.getDisabledIcon() == null)
98 b.setDisabledIcon(icon);
99 if (b.getDisabledSelectedIcon() == null)
100 b.setDisabledSelectedIcon(icon);
104 * Returns the prefix used for UIDefaults properties. This is
105 * <code>RadioButton</code> in this case.
107 * @return the prefix used for UIDefaults properties
109 protected String getPropertyPrefix()
111 return "RadioButton.";
115 * Returns the default icon for JRadioButtons.
116 * The default icon displays the usual
117 * RadioButton and is sensible to the selection state of the button,
118 * and can be used both as normal icon as well as selectedIcon.
120 * @return the default icon for JRadioButtons
122 public Icon getDefaultIcon()
124 return UIManager.getIcon(getPropertyPrefix() + "icon");
128 * Paints the RadioButton.
130 * @param g the Graphics context to paint with
131 * @param c the button to paint
133 public void paint(Graphics g, JComponent c)
135 AbstractButton b = (AbstractButton) c;
137 Rectangle tr = new Rectangle();
138 Rectangle ir = new Rectangle();
139 Rectangle vr = new Rectangle();
141 Font f = c.getFont();
143 g.setFont(f);
145 Icon currentIcon = null;
146 if (b.isSelected() && b.isEnabled())
147 currentIcon = b.getSelectedIcon();
148 else if (!b.isSelected() && b.isEnabled())
149 currentIcon = b.getIcon();
150 else if (b.isSelected() && !b.isEnabled())
151 currentIcon = b.getDisabledSelectedIcon();
152 else // (!b.isSelected() && !b.isEnabled())
153 currentIcon = b.getDisabledIcon();
155 SwingUtilities.calculateInnerArea(b, vr);
156 String text = SwingUtilities.layoutCompoundLabel
157 (c, g.getFontMetrics(f), b.getText(), currentIcon,
158 b.getVerticalAlignment(), b.getHorizontalAlignment(),
159 b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
160 vr, ir, tr, b.getIconTextGap() + defaultTextShiftOffset);
162 if (currentIcon != null)
164 currentIcon.paintIcon(c, g, ir.x, ir.y);
166 if (text != null)
167 paintText(g, b, tr, text);
168 // TODO: Figure out what is the size parameter?
169 if (b.hasFocus() && b.isFocusPainted() && b.isEnabled())
170 paintFocus(g, tr, null);
174 * Paints the focus indicator for JRadioButtons.
176 * @param g the graphics context
177 * @param tr the rectangle for the text label
178 * @param size the size (??)
180 // TODO: Figure out what for is the size parameter.
181 protected void paintFocus(Graphics g, Rectangle tr, Dimension size)
183 Color focusColor = UIManager.getColor(getPropertyPrefix() + ".focus");
184 Color saved = g.getColor();
185 g.setColor(focusColor);
186 g.drawRect(tr.x, tr.y, tr.width, tr.height);
187 g.setColor(saved);