Visual Color Imbalance Detector: Reconstructed project directories and files
[VistaCID.git] / org / tjworld / components / JIconCheckBox.java
1 /*\r
2         * JIconCheckBox.java\r
3  *\r
4         * Created on 02 November 2001, 01:32\r
5         * $Header: /VisTA/CID/Components/JIconCheckBox.java 2     2/11/01 2:12 Tj $\r
6         *\r
7         * $History: JIconCheckBox.java $\r
8  * \r
9  * *****************  Version 2  *****************\r
10  * User: Tj           Date: 2/11/01    Time: 2:12\r
11  * Updated in $/VisTA/CID/Components\r
12  * Tested OK\r
13  * \r
14  * *****************  Version 1  *****************\r
15  * User: Tj           Date: 2/11/01    Time: 1:41\r
16  * Created in $/VisTA/CID/Components\r
17  * Created from JIconRadioButton Template\r
18  */\r
19 \r
20 package org.tjworld.components;\r
21 \r
22 import javax.swing.Icon;\r
23 import javax.swing.UIManager;\r
24 import org.tjworld.components.JIconToggleButton;\r
25 \r
26 /**\r
27         * A JCheckBox style component that can have an icon in the same way that a JCheckBoxMenuItem can.\r
28  *\r
29         * That is: [stateIcon]   [[userIcon] [Text]]\r
30  *\r
31         * setIcon() and setPressedIcon() access the User functionality indicator icons.\r
32         * get/setSelectedStateIcon(), get/setDeselectedStateIcon(), \r
33         * get/setDisabledSelectedStateIcon() and get/setDisabledDeselectedStateIcon()\r
34         * access the button state indicator icon.\r
35         *\r
36         * Positioning logic (in BasicIconCheckBoxUI) places the stateIcon 'first' and closest to the\r
37         * leading edge of the button.\r
38         * In a LeftToRight Locale that means close to the left edge of the button.\r
39         * The default icon is placed with the button Text (if any) and positioned according to the rules\r
40         * governing text placement.\r
41         * \r
42         * A new UI delegate <code>BasicIconCheckBoxUI</code> knows how to paint this component, and\r
43         * is registered with the UIManager when an instance of this component is first created.\r
44         * \r
45         * PropertyChange Event Properties:\r
46         * "selectedStateIcon", "disabledSelectedStateIcon", "deselectedStateIcon","disabledDeselectedStateIcon"\r
47         * \r
48         * @see JIconToggleButton\r
49         * @author  TJ\r
50  * @version 1.0\r
51  */\r
52 public class JIconCheckBox extends JIconToggleButton {\r
53 \r
54  /** Defines the UI delegate of the Look & Feel responsible for painting this Button\r
55         * \r
56   * @see #getUIClassID\r
57   * @see #readObject\r
58   */\r
59  private static final String uiClassID = "BasicIconCheckBoxUI";\r
60         \r
61  /** Creates a new 'empty' JIconCheckBox */\r
62         public JIconCheckBox() {\r
63                 this((String)null, (Icon)null, (Icon)null, (Icon)null, (Icon)null, false);\r
64         }\r
65         \r
66         /** Creates new JIconCheckBox with text label, Enabled and Disabled Selected and Unselected icons\r
67                 * @param text Label text\r
68                 * @param selectedState The selected-state Icon\r
69                 * @param unselectedState The unselected-state Icon\r
70                 * @param disabledSelectedState The disabled selected-state Icon\r
71                 * @param disabledUnselectedState The disabled unselected-state Icon\r
72                 * @param selected true if selected, false if unselected\r
73                 */\r
74  public JIconCheckBox(String text, Icon selectedState, Icon unselectedState, Icon disabledSelectedState, Icon disabledUnselectedState, boolean selected) {\r
75                 super(text, (Icon)null, (Icon)null, selected); // create & init the IconToggleButton bit\r
76                 selectedStateIcon = selectedState;\r
77                 unselectedStateIcon = unselectedState;\r
78                 disabledSelectedStateIcon = disabledSelectedState;\r
79                 disabledUnselectedStateIcon = disabledUnselectedState;\r
80                 setBorderPainted(false); // Radio's don't have a border usually\r
81   setHorizontalAlignment(LEADING);\r
82 }\r
83         \r
84         /** Create new JIconCheckBox with Selected and Unselected Icons\r
85                 * @param selectedState The selected-state Icon\r
86                 * @param unselectedState The unselected-state Icon\r
87                 * @param selected true if selected, false if unselected\r
88                 */\r
89         public JIconCheckBox(Icon selectedState, Icon unselectedState, boolean selected) {\r
90   this(null, selectedState, unselectedState, null, null, selected);\r
91         }\r
92         \r
93         /** creates new JIconCheckBox with text label, selected and unselected Icons\r
94                 * @param text Label text\r
95                 * @param selectedState The selected-state Icon\r
96                 * @param unselectedState The unselected-state Icon\r
97                 * @param selected true if selected, false if unselected\r
98                 */\r
99         public JIconCheckBox(String text, Icon selectedState, Icon unselectedState, boolean selected) {\r
100                 this(text, selectedState, unselectedState, null, null, selected);\r
101         }\r
102 \r
103  /**\r
104   * Sets the look and feel object that renders this component.\r
105   *\r
106   * @param ui  the <code>BasicIconCheckBoxUI</code> L&F object\r
107   * @see UIDefaults#getUI\r
108   * @beaninfo\r
109   *        bound: true\r
110   *       hidden: true\r
111   *    attribute: visualUpdate true\r
112   *  description: The UI object that implements the component's LookAndFeel. \r
113   */\r
114  public void setUI(BasicIconCheckBoxUI ui) {\r
115   super.setUI(ui);\r
116  }\r
117     \r
118  /**\r
119   * Resets the UI property with a value from the current look and feel.\r
120   *\r
121   * @see JComponent#updateUI\r
122   */\r
123  public void updateUI() {\r
124                 // clever way of dynamically detecting if JIconCheckBox has become part of the\r
125                 // javax.swing package rather than the org.tjworld.components package\r
126   String className = this.getClass().getName();\r
127                 \r
128                 if(className.startsWith("javax.swing.")) //** Use when this component IS a part of a Look & Feel \r
129                  setUI((BasicIconCheckBoxUI)UIManager.getUI(this));\r
130                 \r
131                 else\r
132                 setUI(BasicIconCheckBoxUI.createUI(this));\r
133    /* use when this component IS NOT a part of any Look & Feel\r
134                  * this makes sure the UIManager doesn't throw an error \r
135                         * when it tries to use the current Look & Feel classloader\r
136                         * to load the UI delegate, because the delegate (BasicIconCheckBoxUI)\r
137                         * isn't included in the Look & Feel package.\r
138                         */\r
139  }\r
140 \r
141  /**\r
142   * Returns a string that specifies the name of the l&f class\r
143   * that renders this component.\r
144   *\r
145   * @return String "BasicIconCheckBoxUI"\r
146   * @see JComponent#getUIClassID\r
147   * @see UIDefaults#getUI\r
148   * @beaninfo\r
149   *  description: A string that specifies the name of the L&F class\r
150   */\r
151  public String getUIClassID() {\r
152   return uiClassID;\r
153  }\r
154 }