001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: ButtonProperties.java,v 1.3 2005/02/16 11:28:15 jesper Exp $
023: package net.infonode.properties.gui.util;
024:
025: import net.infonode.gui.button.ButtonFactory;
026: import net.infonode.properties.propertymap.*;
027: import net.infonode.properties.types.ButtonFactoryProperty;
028: import net.infonode.properties.types.IconProperty;
029: import net.infonode.properties.types.StringProperty;
030:
031: import javax.swing.*;
032:
033: /**
034: * Properties and property values for a button.
035: *
036: * @author $Author: jesper $
037: * @version $Revision: 1.3 $
038: */
039: public class ButtonProperties extends PropertyMapContainer {
040: /**
041: * Property group for all button properties.
042: */
043: public static final PropertyMapGroup PROPERTIES = new PropertyMapGroup(
044: "Button Properties", "");
045:
046: /**
047: * The button icon.
048: */
049: public static final IconProperty ICON = new IconProperty(
050: PROPERTIES, "Icon", "Icon for the enabled button state.",
051: PropertyMapValueHandler.INSTANCE);
052:
053: /**
054: * The disabled button icon.
055: */
056: public static final IconProperty DISABLED_ICON = new IconProperty(
057: PROPERTIES, "Disabled Icon",
058: "Icon for the disabled button state.",
059: PropertyMapValueHandler.INSTANCE);
060:
061: /**
062: * The enabled button tool tip text.
063: */
064: public static final StringProperty TOOL_TIP_TEXT = new StringProperty(
065: PROPERTIES, "Tool Tip Text", "The button tool tip text.",
066: PropertyMapValueHandler.INSTANCE);
067:
068: /**
069: * <p>The button factory.</p>
070: *
071: * <p>The created button will be assigned the icon from
072: * {@link #ICON} or {@link #DISABLED_ICON} and the tool tip from {@link #TOOL_TIP_TEXT}. An action listener is also added to the button.
073: * </p>
074: */
075: public static final ButtonFactoryProperty FACTORY = new ButtonFactoryProperty(
076: PROPERTIES,
077: "Factory",
078: "The button factory. This factory is used to create a button. The "
079: + "created button will be assigned the icon from the '"
080: + ICON.getName()
081: + "' property or the '"
082: + DISABLED_ICON.getName()
083: + "' property and the tool tip from the '"
084: + TOOL_TIP_TEXT.getName()
085: + "' "
086: + "property. An action listener is also added to the button.",
087: PropertyMapValueHandler.INSTANCE);
088:
089: static {
090: ButtonProperties properties = new ButtonProperties(PROPERTIES
091: .getDefaultMap());
092: properties.setIcon(null).setDisabledIcon(null).setToolTipText(
093: null);
094: }
095:
096: /**
097: * Creates an empty property object.
098: */
099: public ButtonProperties() {
100: super (PROPERTIES);
101: }
102:
103: /**
104: * Creates a property map containing the map.
105: *
106: * @param map the property map
107: */
108: public ButtonProperties(PropertyMap map) {
109: super (map);
110: }
111:
112: /**
113: * Creates a property object that inherit values from another property object.
114: *
115: * @param inheritFrom the object from which to inherit property values
116: */
117: public ButtonProperties(ButtonProperties inheritFrom) {
118: super (PropertyMapFactory.create(inheritFrom.getMap()));
119: }
120:
121: /**
122: * Adds a super object from which property values are inherited.
123: *
124: * @param properties the object from which to inherit property values
125: * @return this
126: */
127: public ButtonProperties addSuperObject(ButtonProperties properties) {
128: getMap().addSuperMap(properties.getMap());
129:
130: return this ;
131: }
132:
133: /**
134: * Removes the last added super object.
135: *
136: * @return this
137: */
138: public ButtonProperties removeSuperObject() {
139: getMap().removeSuperMap();
140: return this ;
141: }
142:
143: /**
144: * Removes the given super object.
145: *
146: * @param superObject super object to remove
147: * @return this
148: */
149: public ButtonProperties removeSuperObject(
150: ButtonProperties super Object) {
151: getMap().removeSuperMap(super Object.getMap());
152: return this ;
153: }
154:
155: /**
156: * Sets the button icon.
157: *
158: * @param icon the button icon
159: * @return this
160: */
161: public ButtonProperties setIcon(Icon icon) {
162: ICON.set(getMap(), icon);
163: return this ;
164: }
165:
166: /**
167: * Returns the button icon.
168: *
169: * @return the button icon
170: */
171: public Icon getIcon() {
172: return ICON.get(getMap());
173: }
174:
175: /**
176: * Sets the disabled button icon.
177: *
178: * @param icon the disabled button icon
179: * @return this
180: */
181: public ButtonProperties setDisabledIcon(Icon icon) {
182: DISABLED_ICON.set(getMap(), icon);
183: return this ;
184: }
185:
186: /**
187: * Returns the disabled button icon.
188: *
189: * @return the disabled button icon
190: */
191: public Icon getDisabledIcon() {
192: return DISABLED_ICON.get(getMap());
193: }
194:
195: /**
196: * Returns the button tool tip text.
197: *
198: * @return the button tool tip text
199: */
200: public String getToolTipText() {
201: return TOOL_TIP_TEXT.get(getMap());
202: }
203:
204: /**
205: * Sets the button tool tip text.
206: *
207: * @param text the button tool tip text
208: * @return this
209: */
210: public ButtonProperties setToolTipText(String text) {
211: TOOL_TIP_TEXT.set(getMap(), text);
212: return this ;
213: }
214:
215: /**
216: * <p>Gets the button factory.</p>
217: *
218: * <p>The created button will be assigned the icon from
219: * {@link #ICON} or {@link #DISABLED_ICON} and the tool tip from {@link #TOOL_TIP_TEXT}.
220: * An action listener is also added to the button.
221: * </p>
222: *
223: * @return the button factory
224: */
225: public ButtonFactory getFactory() {
226: return FACTORY.get(getMap());
227: }
228:
229: /**
230: * <p>Sets the button factory.</p>
231: *
232: * <p>The created button will be assigned the icon from
233: * {@link #ICON} or {@link #DISABLED_ICON} and the tool tip from {@link #TOOL_TIP_TEXT}.
234: * An action listener is also added to the button.
235: * </p>
236: *
237: * @param factory the button factory
238: * @return this
239: */
240: public ButtonProperties setFactory(ButtonFactory factory) {
241: FACTORY.set(getMap(), factory);
242: return this ;
243: }
244:
245: /**
246: * Applies the icon, disabled icon and tool tip to the given button
247: *
248: * @param button botton
249: * @return the button
250: */
251: public AbstractButton applyTo(AbstractButton button) {
252: button.setIcon(getIcon());
253: button.setDisabledIcon(getDisabledIcon());
254: button.setToolTipText(getToolTipText());
255:
256: return button;
257: }
258: }
|