01: /*
02: * @(#)HollowButton.java 7/12/2005
03: *
04: * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
05: */
06: package com.jidesoft.swing;
07:
08: import com.jidesoft.plaf.XPUtils;
09:
10: import javax.swing.*;
11:
12: /**
13: * This is part of the null-components. A null component doesn't have
14: * foreground, background or font value set. In the other words, the
15: * foreground, background and font value of null-component are null.
16: * But this doesn't mean getBackground(), getForeground() or getFont()
17: * will return null. According to {@link java.awt.Component#getBackground()},
18: * {@link java.awt.Component#getForeground()} and {@link java.awt.Component#getFont()},
19: * if the value is null, it will get the value from its parent.
20: * In the other words, if you add a null-component to JPanel, you can use
21: * JPanel to control the background, foreground and font of this null-component.
22: * The feature is very helpful if you want to make sure all components in a JPanel
23: * has the same background, foreground or font.
24: * <p/>
25: * We creates a few null-components. It doesn't cover all components. You can always
26: * create your own. All you need to do is this
27: * <pre><code>
28: * public class NullXxxComponent extends XxxComponent {
29: * // all the constructors
30: * <p/>
31: * public void updateUI() {
32: * super.updateUI();
33: * clearAttribute();
34: * }
35: * <p/>
36: * private void clearAttribute() {
37: * setFont(null);
38: * setBackground(null);
39: * // do not do this for JButton since JButton always paints button
40: * // content background. So it'd better to leave the foreground alone
41: * setForeground(null);
42: * }
43: * }
44: * </code></pre>
45: *
46: * @see NullPanel
47: * @see NullCheckBox
48: * @see NullJideButton
49: * @see NullLabel
50: * @see NullRadioButton
51: */
52: public class NullButton extends JButton {
53: public NullButton() {
54: }
55:
56: public NullButton(Icon icon) {
57: super (icon);
58: }
59:
60: public NullButton(String text) {
61: super (text);
62: }
63:
64: public NullButton(Action a) {
65: super (a);
66: }
67:
68: public NullButton(String text, Icon icon) {
69: super (text, icon);
70: }
71:
72: @Override
73: public void updateUI() {
74: super .updateUI();
75: clearAttribute();
76: }
77:
78: private void clearAttribute() {
79: setFont(null);
80: if (XPUtils.isXPStyleOn()) {
81: setBackground(null);
82: }
83: }
84: }
|