001: package com.jidesoft.dialog;
002:
003: import javax.swing.*;
004:
005: /**
006: * AbstractDialogPage is an abstract base class extends AbstractPage.
007: * In addition to AbstractPage, this class has some new properties so
008: * that it can be used in dialog.
009: * <BR>
010: * For example, it can support ButtonEvent which is used by ButtonPanel.
011: * In addition, it has title, icon, description and parent attribute.
012: */
013: public abstract class AbstractDialogPage extends AbstractPage {
014:
015: protected transient ButtonEvent _buttonEvent = null;
016:
017: protected String _title;
018: protected String _description;
019: protected Icon _icon;
020: protected boolean _pageEnabled = true;
021: protected AbstractDialogPage _parentPage;
022:
023: public static final String TITLE_PROPERTY = "title";
024: public static final String DESCRIPTION_PROPERTY = "description";
025: public static final String ICON_PROPERTY = "icon";
026: public static final String PROPERTY_PAGE_ENABLED = "enabled";
027:
028: /**
029: * Creates an AbstractDialogPage.
030: */
031: protected AbstractDialogPage() {
032: }
033:
034: /**
035: * Creates an AbstractDialogPage with title.
036: *
037: * @param title the title of the page
038: */
039: public AbstractDialogPage(String title) {
040: _title = title;
041: }
042:
043: /**
044: * Creates an AbstractDialogPage with title and icon.
045: *
046: * @param title the title of the page
047: * @param description the description for the page
048: */
049: public AbstractDialogPage(String title, String description) {
050: _title = title;
051: _description = description;
052: }
053:
054: /**
055: * Creates an AbstractDialogPage with title and icon.
056: *
057: * @param title the title of the page
058: * @param icon the icon of the page
059: */
060: public AbstractDialogPage(String title, Icon icon) {
061: _title = title;
062: _icon = icon;
063: }
064:
065: /**
066: * Creates an AbstractDialogPage with title, icon and description.
067: *
068: * @param title the title of the page
069: * @param icon the icon of the page
070: * @param description the description for the page
071: */
072: public AbstractDialogPage(String title, String description,
073: Icon icon) {
074: _title = title;
075: _icon = icon;
076: _description = description;
077: }
078:
079: /**
080: * /**
081: * Creates an AbstractDialogPage with title, icon, description and its parent.
082: *
083: * @param title the title of the page
084: * @param icon the icon of the page
085: * @param description the description for the page
086: * @param parentPage the parent of the page
087: */
088: public AbstractDialogPage(String title, String description,
089: Icon icon, AbstractDialogPage parentPage) {
090: _title = title;
091: _icon = icon;
092: _description = description;
093: _parentPage = parentPage;
094: }
095:
096: /**
097: * Adds a <code>ButtonListener</code> to the page.
098: *
099: * @param l the <code>ButtonListener</code> to be added
100: */
101: public void addButtonListener(ButtonListener l) {
102: listenerList.add(ButtonListener.class, l);
103: }
104:
105: /**
106: * Removes a <code>ButtonListener</code> from the page.
107: *
108: * @param l the <code>ButtonListener</code> to be removed
109: */
110: public void removeButtonListener(ButtonListener l) {
111: listenerList.remove(ButtonListener.class, l);
112: }
113:
114: /**
115: * Returns an array of all the <code>ButtonListener</code>s added
116: * to this <code>Page</code> with
117: * <code>ButtonListener</code>.
118: *
119: * @return all of the <code>ButtonListener</code>s added, or an empty
120: * array if no listeners have been added
121: * @since 1.4
122: */
123: public ButtonListener[] getButtonListeners() {
124: return (ButtonListener[]) listenerList
125: .getListeners(ButtonListener.class);
126: }
127:
128: /**
129: * Fire button event with id and button name.
130: *
131: * @param id
132: * @param buttonName
133: */
134: public void fireButtonEvent(int id, String buttonName) {
135: fireButtonEvent(id, buttonName, null);
136: }
137:
138: /**
139: * Fire button event with id, button name and user object if needed.
140: *
141: * @param id
142: * @param buttonName
143: * @param userObject
144: */
145: public void fireButtonEvent(int id, String buttonName,
146: String userObject) {
147: Object[] listeners = listenerList.getListenerList();
148: for (int i = listeners.length - 2; i >= 0; i -= 2) {
149: if (listeners[i] == ButtonListener.class) {
150: if (_buttonEvent == null) {
151: _buttonEvent = new ButtonEvent(this , id,
152: buttonName, userObject);
153: } else {
154: _buttonEvent.setID(id);
155: _buttonEvent.setButtonName(buttonName);
156: _buttonEvent.setUserObject(userObject);
157: }
158: ((ButtonListener) listeners[i + 1])
159: .buttonEventFired(_buttonEvent);
160: }
161: }
162: }
163:
164: /**
165: * Gets the title of the page.
166: *
167: * @return the title
168: */
169: public String getTitle() {
170: return _title;
171: }
172:
173: /**
174: * Sets the title of the page.
175: *
176: * @param title the new title
177: */
178: public void setTitle(String title) {
179: String old = _title;
180: _title = title;
181: firePropertyChange(TITLE_PROPERTY, old, _title);
182: }
183:
184: /**
185: * Gets the icon of the page.
186: *
187: * @return the icon of the page.
188: */
189: public Icon getIcon() {
190: return _icon;
191: }
192:
193: /**
194: * Sets the icon of the page.
195: *
196: * @param icon the new icon
197: */
198: public void setIcon(Icon icon) {
199: Icon old = _icon;
200: _icon = icon;
201: firePropertyChange(ICON_PROPERTY, old, _icon);
202: }
203:
204: /**
205: * Checks if the page is enabled.
206: *
207: * @return true if the page is enabled. Otherwise false.
208: */
209: public boolean isPageEnabled() {
210: return _pageEnabled;
211: }
212:
213: /**
214: * Sets page enabled or disabled. The only place this flag is used
215: * right now is in MultiplePageDialog ICON_STYLE and TAB_STYLE. Disabled page
216: * will have a disabled icon or tab as indicator.
217: *
218: * @param pageEnabled
219: */
220: public void setPageEnabled(boolean pageEnabled) {
221: if (_pageEnabled != pageEnabled) {
222: Boolean oldValue = _pageEnabled ? Boolean.TRUE
223: : Boolean.FALSE;
224: Boolean newValue = pageEnabled ? Boolean.TRUE
225: : Boolean.FALSE;
226: _pageEnabled = pageEnabled;
227: firePropertyChange(PROPERTY_PAGE_ENABLED, oldValue,
228: newValue);
229: }
230: }
231:
232: /**
233: * Gets the description of the page.
234: *
235: * @return the description
236: */
237: public String getDescription() {
238: return _description;
239: }
240:
241: /**
242: * Sets the description of the page.
243: *
244: * @param description the new description
245: */
246: public void setDescription(String description) {
247: String old = _description;
248: _description = description;
249: firePropertyChange(DESCRIPTION_PROPERTY, old, _description);
250: }
251:
252: /**
253: * Gets the parent page.
254: *
255: * @return the parent page
256: */
257: public AbstractDialogPage getParentPage() {
258: return _parentPage;
259: }
260:
261: /**
262: * Sets the parent page.
263: *
264: * @param parentPage the parent page
265: */
266: public void setParentPage(AbstractDialogPage parentPage) {
267: _parentPage = parentPage;
268: }
269:
270: /**
271: * Gets the full title. It is basically a concat of the titles
272: * of all its parent with "." in between.
273: *
274: * @return the full qualified title
275: */
276: public String getFullTitle() {
277: StringBuffer buffer = new StringBuffer(getTitle());
278: AbstractDialogPage page = this ;
279: while (page.getParentPage() != null) {
280: AbstractDialogPage parent = page.getParentPage();
281: buffer.insert(0, ".");
282: buffer.insert(0, parent.getTitle());
283: page = parent;
284: }
285: return new String(buffer);
286: }
287: }
|