001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: JBorderlessToggleButton.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.swing;
009:
010: import javax.swing.Action;
011: import javax.swing.Icon;
012: import javax.swing.JToggleButton;
013:
014: /**
015: * A toggle button that maintains its borderless look when
016: * the look & feel changes.
017: *
018: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
019: * @version $Revision: 3634 $
020: * @since 1.0
021: */
022: public class JBorderlessToggleButton extends JToggleButton {
023: private static final long serialVersionUID = 6408368895438315474L;
024:
025: /**
026: * Creates an initially unselected toggle button
027: * without setting the text or image.
028: * @since 1.0
029: */
030: public JBorderlessToggleButton() {
031: super ();
032: setStyle();
033: }
034:
035: /**
036: * Creates an initially unselected toggle button
037: * with the specified image but no text.
038: *
039: * @param icon the image that the button should display
040: * @since 1.0
041: */
042: public JBorderlessToggleButton(Icon icon) {
043: super (icon);
044: setStyle();
045: }
046:
047: /**
048: * Creates a toggle button with the specified image
049: * and selection state, but no text.
050: *
051: * @param icon the image that the button should display
052: * @param selected if true, the button is initially selected;
053: * otherwise, the button is initially unselected
054: * @since 1.0
055: */
056: public JBorderlessToggleButton(Icon icon, boolean selected) {
057: super (icon, selected);
058: setStyle();
059: }
060:
061: /**
062: * Creates an unselected toggle button with the specified text.
063: *
064: * @param text the string displayed on the toggle button
065: * @since 1.0
066: */
067: public JBorderlessToggleButton(String text) {
068: super (text);
069: setStyle();
070: }
071:
072: /**
073: * Creates a toggle button with the specified text
074: * and selection state.
075: *
076: * @param text the string displayed on the toggle button
077: * @param selected if true, the button is initially selected;
078: * otherwise, the button is initially unselected
079: * @since 1.0
080: */
081: public JBorderlessToggleButton(String text, boolean selected) {
082: super (text, selected);
083: setStyle();
084: }
085:
086: /**
087: * Creates a toggle button where properties are taken from the
088: * Action supplied.
089: *
090: * @param a
091: * @since 1.0
092: */
093: public JBorderlessToggleButton(Action a) {
094: super (a);
095: setStyle();
096: }
097:
098: /**
099: * Creates a toggle button that has the specified text and image,
100: * and that is initially unselected.
101: *
102: * @param text the string displayed on the button
103: * @param icon the image that the button should display
104: * @since 1.0
105: */
106: public JBorderlessToggleButton(String text, Icon icon) {
107: super (text, icon);
108: setStyle();
109: }
110:
111: /**
112: * Creates a toggle button with the specified text, image, and
113: * selection state.
114: *
115: * @param text the text of the toggle button
116: * @param icon the image that the button should display
117: * @param selected if true, the button is initially selected;
118: * otherwise, the button is initially unselected
119: * @since 1.0
120: */
121: public JBorderlessToggleButton(String text, Icon icon,
122: boolean selected) {
123: super (text, icon, selected);
124: setStyle();
125: }
126:
127: /**
128: * Notification from the UIFactory that the L&F
129: * has changed. Maintains the borderless look.
130: *
131: * @see JToggleButton#updateUI()
132: * @since 1.0
133: */
134: public void updateUI() {
135: super .updateUI();
136: setStyle();
137: }
138:
139: /**
140: * Makes this toggle button borderless.
141: * @since 1.0
142: */
143: private void setStyle() {
144: setBorder(null);
145: }
146: }
|