4 * Created on 02 November 2001, 01:32
\r
5 * $Header: /VisTA/CID/Components/JIconCheckBox.java 2 2/11/01 2:12 Tj $
\r
7 * $History: JIconCheckBox.java $
\r
9 * ***************** Version 2 *****************
\r
10 * User: Tj Date: 2/11/01 Time: 2:12
\r
11 * Updated in $/VisTA/CID/Components
\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
20 package org.tjworld.components;
\r
22 import javax.swing.Icon;
\r
23 import javax.swing.UIManager;
\r
24 import org.tjworld.components.JIconToggleButton;
\r
27 * A JCheckBox style component that can have an icon in the same way that a JCheckBoxMenuItem can.
\r
29 * That is: [stateIcon] [[userIcon] [Text]]
\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
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
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
45 * PropertyChange Event Properties:
\r
46 * "selectedStateIcon", "disabledSelectedStateIcon", "deselectedStateIcon","disabledDeselectedStateIcon"
\r
48 * @see JIconToggleButton
\r
52 public class JIconCheckBox extends JIconToggleButton {
\r
54 /** Defines the UI delegate of the Look & Feel responsible for painting this Button
\r
56 * @see #getUIClassID
\r
59 private static final String uiClassID = "BasicIconCheckBoxUI";
\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
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
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
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
89 public JIconCheckBox(Icon selectedState, Icon unselectedState, boolean selected) {
\r
90 this(null, selectedState, unselectedState, null, null, selected);
\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
99 public JIconCheckBox(String text, Icon selectedState, Icon unselectedState, boolean selected) {
\r
100 this(text, selectedState, unselectedState, null, null, selected);
\r
104 * Sets the look and feel object that renders this component.
\r
106 * @param ui the <code>BasicIconCheckBoxUI</code> L&F object
\r
107 * @see UIDefaults#getUI
\r
111 * attribute: visualUpdate true
\r
112 * description: The UI object that implements the component's LookAndFeel.
\r
114 public void setUI(BasicIconCheckBoxUI ui) {
\r
119 * Resets the UI property with a value from the current look and feel.
\r
121 * @see JComponent#updateUI
\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
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
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
142 * Returns a string that specifies the name of the l&f class
\r
143 * that renders this component.
\r
145 * @return String "BasicIconCheckBoxUI"
\r
146 * @see JComponent#getUIClassID
\r
147 * @see UIDefaults#getUI
\r
149 * description: A string that specifies the name of the L&F class
\r
151 public String getUIClassID() {
\r