Visual Color Imbalance Detector: Reconstructed project directories and files
[VistaCID.git] / org / tjworld / components / JIconRadioButton.java
1 /*\r
2         * JIconRadioButton.java\r
3  *\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
6         *\r
7         * $History: JIconRadioButton.java $\r
8  * \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
13  * \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
20  * \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
25  * \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
30  * \r
31  * *****************  Version 2  *****************\r
32  * User: Tj           Date: 31/10/01   Time: 18:00\r
33  * Updated in $/VisTA/CID/Components\r
34  * Adjusted package\r
35  * \r
36  * *****************  Version 1  *****************\r
37  * User: Tj           Date: 31/10/01   Time: 17:56\r
38  * Created in $/VisTA/CID/Components\r
39  * New Component\r
40  */\r
41 \r
42 package org.tjworld.components;\r
43 \r
44 import javax.swing.Icon;\r
45 import javax.swing.UIManager;\r
46 import org.tjworld.components.JIconToggleButton;\r
47 \r
48 /**\r
49         * A JRadioButton style component that can have an icon in the same way that a JRadioButtonMenuItem can.\r
50  *\r
51         * That is: [stateIcon]   [[userIcon] [Text]]\r
52  *\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
57         *\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
60         *\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
66         * \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
69         * \r
70         * PropertyChange Event Properties:\r
71         * "selectedStateIcon", "disabledSelectedStateIcon", "deselectedStateIcon","disabledDeselectedStateIcon"\r
72         * \r
73         * @see JIconToggleButton\r
74         * @author  TJ\r
75  * @version 1.0\r
76  */\r
77 public class JIconRadioButton extends JIconToggleButton {\r
78 \r
79  /** Defines the UI delegate of the Look & Feel responsible for painting this Button\r
80         * \r
81   * @see #getUIClassID\r
82   * @see #readObject\r
83   */\r
84  private static final String uiClassID = "BasicIconRadioButtonUI";\r
85         \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
89         }\r
90         \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
98                 */\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
107  }\r
108         \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
113                 */\r
114         public JIconRadioButton(Icon selectedState, Icon unselectedState, boolean selected) {\r
115   this(null, selectedState, unselectedState, null, null, selected);\r
116         }\r
117         \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
123                 */\r
124         public JIconRadioButton(String text, Icon selectedState, Icon unselectedState, boolean selected) {\r
125                 this(text, selectedState, unselectedState, null, null, selected);\r
126         }\r
127 \r
128  /**\r
129   * Sets the look and feel object that renders this component.\r
130   *\r
131   * @param ui  the <code>BasicIconRadioButtonUI</code> L&F object\r
132   * @see UIDefaults#getUI\r
133   * @beaninfo\r
134   *        bound: true\r
135   *       hidden: true\r
136   *    attribute: visualUpdate true\r
137   *  description: The UI object that implements the component's LookAndFeel. \r
138   */\r
139  public void setUI(BasicIconRadioButtonUI ui) {\r
140   super.setUI(ui);\r
141  }\r
142     \r
143  /**\r
144   * Resets the UI property with a value from the current look and feel.\r
145   *\r
146   * @see JComponent#updateUI\r
147   */\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
152                 \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
155                 \r
156                 else\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
163                         */\r
164  }\r
165 \r
166  /**\r
167   * Returns a string that specifies the name of the l&f class\r
168   * that renders this component.\r
169   *\r
170   * @return String "BasicIconRadioButtonUI"\r
171   * @see JComponent#getUIClassID\r
172   * @see UIDefaults#getUI\r
173   * @beaninfo\r
174   *  description: A string that specifies the name of the L&F class\r
175   */\r
176  public String getUIClassID() {\r
177   return uiClassID;\r
178  }\r
179 }\r