2 * JIconRadioButton.java
\r
4 * Created on 31 October 2001, 17:52
\r
5 * $Header: /VisTA/CID/Components/JIconRadioButton.java 6 7/11/01 16:47 Tj $
\r
7 * $History: JIconRadioButton.java $
\r
9 * ***************** Version 6 *****************
\r
10 * User: Tj Date: 7/11/01 Time: 16:47
\r
11 * Updated in $/VisTA/CID/Components
\r
12 * Adjusted horizontalAlignment to LEADING as per JRadioButton
\r
14 * ***************** Version 5 *****************
\r
15 * User: Tj Date: 2/11/01 Time: 1:29
\r
16 * Updated in $/VisTA/CID/Components
\r
17 * Added algorithm to updateUI() to dynamically detect which UIManager
\r
18 * technique to register with - allows component to move to javax.swing
\r
19 * package without recompiliation
\r
21 * ***************** Version 4 *****************
\r
22 * User: Tj Date: 1/11/01 Time: 22:17
\r
23 * Updated in $/VisTA/CID/Components
\r
24 * Corrected signatures in Constructors
\r
26 * ***************** Version 3 *****************
\r
27 * User: Tj Date: 1/11/01 Time: 0:49
\r
28 * Updated in $/VisTA/CID/Components
\r
29 * Requires new super class between it and JIconToggleButton
\r
31 * ***************** Version 2 *****************
\r
32 * User: Tj Date: 31/10/01 Time: 18:00
\r
33 * Updated in $/VisTA/CID/Components
\r
36 * ***************** Version 1 *****************
\r
37 * User: Tj Date: 31/10/01 Time: 17:56
\r
38 * Created in $/VisTA/CID/Components
\r
42 package org.tjworld.components;
\r
44 import javax.swing.Icon;
\r
45 import javax.swing.UIManager;
\r
46 import org.tjworld.components.JIconToggleButton;
\r
49 * A JRadioButton style component that can have an icon in the same way that a JRadioButtonMenuItem can.
\r
51 * That is: [stateIcon] [[userIcon] [Text]]
\r
53 * setIcon() and setPressedIcon() access the User functionality indicator icons.
\r
54 * get/setSelectedStateIcon(), get/setDeselectedStateIcon(),
\r
55 * get/setDisabledSelectedStateIcon() and get/setDisabledDeselectedStateIcon()
\r
56 * access the button state indicator icon.
\r
58 * By default the state icons are null in a JIconToggleButton, but are used in inheriting
\r
59 * classes such as JIconRadioButton and JIconCheckBox.
\r
61 * Positioning logic (in BasicIconRadioButtonUI) places the stateIcon 'first' and closest to the
\r
62 * leading edge of the button.
\r
63 * In a LeftToRight Locale that means close to the left edge of the button.
\r
64 * The default icon is placed with the button Text (if any) and positioned according to the rules
\r
65 * governing text placement.
\r
67 * A new UI delegate <code>BasicIconRadioButtonUI</code> knows how to paint this component, and
\r
68 * is registered with the UIManager when an instance of this component is first created.
\r
70 * PropertyChange Event Properties:
\r
71 * "selectedStateIcon", "disabledSelectedStateIcon", "deselectedStateIcon","disabledDeselectedStateIcon"
\r
73 * @see JIconToggleButton
\r
77 public class JIconRadioButton extends JIconToggleButton {
\r
79 /** Defines the UI delegate of the Look & Feel responsible for painting this Button
\r
81 * @see #getUIClassID
\r
84 private static final String uiClassID = "BasicIconRadioButtonUI";
\r
86 /** Creates a new 'empty' JIconRadioButton */
\r
87 public JIconRadioButton() {
\r
88 this( null, (Icon)null, (Icon)null, (Icon)null, (Icon)null, false);
\r
91 /** Creates new JIconRadioButton with text label, Enabled and Disabled Selected and Unselected icons
\r
92 * @param text Label text
\r
93 * @param selectedState The selected-state Icon
\r
94 * @param unselectedState The unselected-state Icon
\r
95 * @param disabledSelectedState The disabled selected-state Icon
\r
96 * @param disabledUnselectedState The disabled unselected-state Icon
\r
97 * @param selected true if selected, false if unselected
\r
99 public JIconRadioButton(String text, Icon selectedState, Icon unselectedState, Icon disabledSelectedState, Icon disabledUnselectedState, boolean selected) {
\r
100 super(text, (Icon)null, (Icon)null, selected); // create & init the IconToggleButton bit
\r
101 selectedStateIcon = selectedState;
\r
102 unselectedStateIcon = unselectedState;
\r
103 disabledSelectedStateIcon = disabledSelectedState;
\r
104 disabledUnselectedStateIcon = disabledUnselectedState;
\r
105 setBorderPainted(false); // Radio's don't have a border usually
\r
106 setHorizontalAlignment(LEADING);
\r
109 /** Create new JIconRadioButton with Selected and Unselected Icons
\r
110 * @param selectedState The selected-state Icon
\r
111 * @param unselectedState The unselected-state Icon
\r
112 * @param selected true if selected, false if unselected
\r
114 public JIconRadioButton(Icon selectedState, Icon unselectedState, boolean selected) {
\r
115 this(null, selectedState, unselectedState, null, null, selected);
\r
118 /** creates new JIconRadioButton with text label, selected and unselected Icons
\r
119 * @param text Label text
\r
120 * @param selectedState The selected-state Icon
\r
121 * @param unselectedState The unselected-state Icon
\r
122 * @param selected true if selected, false if unselected
\r
124 public JIconRadioButton(String text, Icon selectedState, Icon unselectedState, boolean selected) {
\r
125 this(text, selectedState, unselectedState, null, null, selected);
\r
129 * Sets the look and feel object that renders this component.
\r
131 * @param ui the <code>BasicIconRadioButtonUI</code> L&F object
\r
132 * @see UIDefaults#getUI
\r
136 * attribute: visualUpdate true
\r
137 * description: The UI object that implements the component's LookAndFeel.
\r
139 public void setUI(BasicIconRadioButtonUI ui) {
\r
144 * Resets the UI property with a value from the current look and feel.
\r
146 * @see JComponent#updateUI
\r
148 public void updateUI() {
\r
149 // clever way of dynamically detecting if JIconRadioButton has become part of the
\r
150 // javax.swing package rather than the org.tjworld.components package
\r
151 String className = this.getClass().getName();
\r
153 if(className.startsWith("javax.swing.")) //** Use when this component IS a part of a Look & Feel
\r
154 setUI((BasicIconRadioButtonUI)UIManager.getUI(this));
\r
157 setUI(BasicIconRadioButtonUI.createUI(this));
\r
158 /* use when this component IS NOT a part of any Look & Feel
\r
159 * this makes sure the UIManager doesn't throw an error
\r
160 * when it tries to use the current Look & Feel classloader
\r
161 * to load the UI delegate, because the delegate (BasicIconRadioButtonUI)
\r
162 * isn't included in the Look & Feel package.
\r
167 * Returns a string that specifies the name of the l&f class
\r
168 * that renders this component.
\r
170 * @return String "BasicIconRadioButtonUI"
\r
171 * @see JComponent#getUIClassID
\r
172 * @see UIDefaults#getUI
\r
174 * description: A string that specifies the name of the L&F class
\r
176 public String getUIClassID() {
\r