001: /*
002: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
003: *
004: * The program is provided "as is" without any warranty express or
005: * implied, including the warranty of non-infringement and the implied
006: * warranties of merchantibility and fitness for a particular purpose.
007: * IBM will not be liable for any damages suffered by you as a result
008: * of using the Program. In no event will IBM be liable for any
009: * special, indirect or consequential damages or lost profits even if
010: * IBM has been advised of the possibility of their occurrence. IBM
011: * will not be liable for any third party claims against you.
012: */
013: package com.ibm.richtext.textpanel;
014:
015: import java.util.EventObject;
016:
017: /**
018: * TextPanelEvent is generated by an MTextPanel to notify listeners
019: * of changes. To receive TextPanelEvents from an MTextPanel, clients
020: * must implement TextPanelListener and add themselves to the MTextPanel's
021: * list of listeners.
022: * <p>
023: * Some event types are special cases of others. This is intentional - it
024: * allows notifications to be sent less often in certain common cases. For
025: * example, a change in the selection range generates a SELECTION_RANGE_CHANGED
026: * event. This is a very common occurrance, and if many clients listen for this
027: * event, there may be a significant performance penalty. By
028: * listening for a more specialized event (such as SELECTION_EMPTY_CHANGED), clients
029: * can reduce the number of notifications sent.
030: *
031: * @see MTextPanel
032: * @see TextPanelListener
033: */
034: public final class TextPanelEvent extends EventObject {
035:
036: static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
037:
038: /**
039: * The lower bound of TextPanelEvent ID's.
040: */
041: public static final int TEXT_PANEL_FIRST = 11;
042:
043: /**
044: * Events of this type indicate a change in the selection range.
045: * This occurs quite often. Most clients do not need to be
046: * notified every time the selection range changes.
047: */
048: public static final int SELECTION_RANGE_CHANGED = 11;
049:
050: /**
051: * Events of this type are sent when the selection range becomes
052: * 0-length after not being 0-length, or vice versa. This event
053: * is a special case of SELECTION_RANGE_CHANGED.
054: */
055: public static final int SELECTION_EMPTY_CHANGED = 12;
056:
057: /**
058: * Events of this type indicate that the text in the TextPanel changed.
059: * This type of event occurs often.
060: */
061: public static final int TEXT_CHANGED = 13;
062:
063: /**
064: * Events of this type are sent when the styles in the current
065: * selection change.
066: */
067: public static final int SELECTION_STYLES_CHANGED = 14;
068:
069: /**
070: * Events of this type are sent when the undo/redo state changes.
071: */
072: public static final int UNDO_STATE_CHANGED = 15;
073:
074: /**
075: * Events of this type are sent when the clipboard state changes.
076: */
077: public static final int CLIPBOARD_CHANGED = 16;
078:
079: /**
080: * Events of this type are sent when
081: * the wrap width of the text changes.
082: */
083: public static final int FORMAT_WIDTH_CHANGED = 17;
084:
085: /**
086: * Events of this type are sent when the key remap changes.
087: */
088: public static final int KEYREMAP_CHANGED = 18;
089:
090: /**
091: * The upper bound of TextPanelEvent ID's.
092: */
093: public static final int TEXT_PANEL_LAST = 18;
094:
095: private int fId;
096:
097: /**
098: * Create a new TextPanelEvent.
099: * @param source the MTextPanel which generated the event
100: * @param id the ID for this event. Must be within
101: * [TEXT_PANEL_FIRST, TEXT_PANEL_LAST].
102: */
103: TextPanelEvent(MTextPanel source, int id) {
104:
105: super (source);
106: if (id < TEXT_PANEL_FIRST || id > TEXT_PANEL_LAST) {
107: throw new IllegalArgumentException("id out of range");
108: }
109: fId = id;
110: }
111:
112: /**
113: * Return the event ID for this event. Event ID's are
114: * one of the class constants.
115: * @return the event ID for this event
116: */
117: public int getID() {
118:
119: return fId;
120: }
121:
122: public String toString() {
123:
124: String desc = null;
125:
126: switch (fId) {
127: case SELECTION_RANGE_CHANGED:
128: desc = "SELECTION_RANGE_CHANGED";
129: break;
130: case SELECTION_EMPTY_CHANGED:
131: desc = "SELECTION_EMPTY_CHANGED";
132: break;
133: case TEXT_CHANGED:
134: desc = "TEXT_CHANGED";
135: break;
136: case SELECTION_STYLES_CHANGED:
137: desc = "SELECTION_STYLES_CHANGED";
138: break;
139: case UNDO_STATE_CHANGED:
140: desc = "UNDO_STATE_CHANGED";
141: break;
142: case CLIPBOARD_CHANGED:
143: desc = "CLIPBOARD_CHANGED";
144: break;
145: case FORMAT_WIDTH_CHANGED:
146: desc = "FORMAT_WIDTH_CHANGED";
147: break;
148: case KEYREMAP_CHANGED:
149: desc = "KEYREMAP_CHANGED";
150: break;
151: }
152: return "[TextPanelEvent:" + desc + "]";
153: }
154: }
|