001: /*
002: * @(#)ButtonEvent.java
003: *
004: * Copyright 2002 - 2003 JIDE Software Inc. All rights reserved.
005: */
006: package com.jidesoft.dialog;
007:
008: import java.awt.*;
009: import java.util.EventObject;
010:
011: /**
012: * An EventObject used to change the state of any button.
013: */
014: public class ButtonEvent extends EventObject {
015:
016: /**
017: * The first number in the range of IDs used for <code>ButtonEvent</code>.
018: */
019: public static final int BUTTON_EVENT_FIRST = AWTEvent.RESERVED_ID_MAX + 5000;
020:
021: /**
022: * The last number in the range of IDs used for <code>DockableFrame</code> events.
023: */
024: public static final int BUTTON_EVENT_LAST = BUTTON_EVENT_FIRST + 8;
025:
026: /**
027: * This event is fired when you want to show the button.
028: */
029: public static final int SHOW_BUTTON = BUTTON_EVENT_FIRST;
030:
031: /**
032: * This event is fired when you want to hide the button.
033: */
034: public static final int HIDE_BUTTON = 1 + BUTTON_EVENT_FIRST;
035:
036: /**
037: * This event is fired when you want to enable the button.
038: */
039: public static final int ENABLE_BUTTON = 2 + BUTTON_EVENT_FIRST;
040:
041: /**
042: * This event is fired when you want to disable the button.
043: */
044: public static final int DISABLE_BUTTON = 3 + BUTTON_EVENT_FIRST;
045:
046: /**
047: * This event is fired when you want to change the text of the button.
048: */
049: public static final int CHANGE_BUTTON_TEXT = 4 + BUTTON_EVENT_FIRST;
050:
051: /**
052: * This event is fired when you want to change the mnemonic of the button.
053: */
054: public static final int CHANGE_BUTTON_MNEMONIC = 5 + BUTTON_EVENT_FIRST;
055:
056: /**
057: * This event is fired when you want to change the tooltip of the button.
058: */
059: public static final int CHANGE_BUTTON_TOOLTIP = 6 + BUTTON_EVENT_FIRST;
060:
061: /**
062: * This event is fired when you want to set focus to the button.
063: */
064: public static final int CHANGE_BUTTON_FOCUS = 7 + BUTTON_EVENT_FIRST;
065:
066: /**
067: * This event is fired when you want to set focus to the button.
068: */
069: public static final int SET_DEFAULT_BUTTON = 8 + BUTTON_EVENT_FIRST;
070:
071: private int _id;
072:
073: private String _buttonName;
074:
075: private String _userObject;
076:
077: /**
078: * Creates a ButtonEvent with source, id and the button name.
079: *
080: * @param source
081: * @param id
082: * @param buttonName
083: */
084: public ButtonEvent(Object source, int id, String buttonName) {
085: super (source);
086: _id = id;
087: _buttonName = buttonName;
088: checkParam();
089: }
090:
091: /**
092: * Creates a ButtonEvent with source, id, the button name and a user
093: * object. User object is required for CHANGE_BUTTON_TEXT and
094: * CHANGE_BUTTON_TOOLTIP event.
095: *
096: * @param source
097: * @param id
098: * @param buttonName
099: * @param userObject
100: */
101: public ButtonEvent(Object source, int id, String buttonName,
102: String userObject) {
103: super (source);
104: _id = id;
105: _buttonName = buttonName;
106: _userObject = userObject;
107: checkParam();
108: }
109:
110: private void checkParam() {
111: if (getID() < BUTTON_EVENT_FIRST && getID() > BUTTON_EVENT_LAST) {
112: throw new IllegalArgumentException(getID()
113: + " is an invalid event id for ButtonEvent");
114: }
115: if (_buttonName == null || _buttonName.trim().length() == 0) {
116: throw new IllegalArgumentException(
117: "buttonName cannot be null or empty");
118: }
119: if ((_userObject == null || _userObject.trim().length() == 0)
120: && (getID() == CHANGE_BUTTON_TEXT
121: || getID() == CHANGE_BUTTON_MNEMONIC || getID() == CHANGE_BUTTON_TOOLTIP)) {
122: throw new IllegalArgumentException(
123: "userObject cannot be null or empty for "
124: + paramString());
125: }
126: }
127:
128: /**
129: * Returns the event id.
130: *
131: * @return event id.
132: */
133: public int getID() {
134: return _id;
135: }
136:
137: /**
138: * Sets the event id.
139: *
140: * @param id
141: */
142: public void setID(int id) {
143: _id = id;
144: }
145:
146: /**
147: * Gets the button name of this event object.
148: *
149: * @return the button name.
150: */
151: public String getButtonName() {
152: return _buttonName;
153: }
154:
155: /**
156: * Sets the button name.
157: *
158: * @param buttonName
159: */
160: public void setButtonName(String buttonName) {
161: _buttonName = buttonName;
162: }
163:
164: /**
165: * Gets the user object of this event object.
166: *
167: * @return the user object.
168: */
169: public String getUserObject() {
170: return _userObject;
171: }
172:
173: /**
174: * Sets the user object.
175: *
176: * @param userObject
177: */
178: public void setUserObject(String userObject) {
179: _userObject = userObject;
180: }
181:
182: /**
183: * Returns a parameter string identifying this event.
184: * This method is useful for event logging and for debugging.
185: *
186: * @return a string identifying the event and its attributes
187: */
188: public String paramString() {
189: String typeStr;
190: switch (getID()) {
191: case SHOW_BUTTON:
192: typeStr = "SHOW_BUTTON";
193: break;
194: case HIDE_BUTTON:
195: typeStr = "HIDE_BUTTON";
196: break;
197: case ENABLE_BUTTON:
198: typeStr = "ENABLE_BUTTON";
199: break;
200: case DISABLE_BUTTON:
201: typeStr = "DISABLE_BUTTON";
202: break;
203: case CHANGE_BUTTON_TEXT:
204: typeStr = "CHANGE_BUTTON_TEXT";
205: break;
206: case CHANGE_BUTTON_MNEMONIC:
207: typeStr = "CHANGE_BUTTON_MNEMONIC";
208: break;
209: case CHANGE_BUTTON_TOOLTIP:
210: typeStr = "CHANGE_BUTTON_TOOLTIP";
211: break;
212: case CHANGE_BUTTON_FOCUS:
213: typeStr = "CHANGE_BUTTON_FOCUS";
214: break;
215: case SET_DEFAULT_BUTTON:
216: typeStr = "SET_DEFAULT_BUTTON";
217: break;
218: default:
219: typeStr = "BUTTON_EVENT_UNKNOWN";
220: }
221: return typeStr;
222: }
223: }
|