]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/richtext/textpanel/TextPanelEvent.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / richtext / textpanel / TextPanelEvent.java
1 /*\r
2  * (C) Copyright IBM Corp. 1998-2007.  All Rights Reserved.\r
3  *\r
4  * The program is provided "as is" without any warranty express or\r
5  * implied, including the warranty of non-infringement and the implied\r
6  * warranties of merchantibility and fitness for a particular purpose.\r
7  * IBM will not be liable for any damages suffered by you as a result\r
8  * of using the Program. In no event will IBM be liable for any\r
9  * special, indirect or consequential damages or lost profits even if\r
10  * IBM has been advised of the possibility of their occurrence. IBM\r
11  * will not be liable for any third party claims against you.\r
12  */\r
13 package com.ibm.richtext.textpanel;\r
14 \r
15 import java.util.EventObject;\r
16 \r
17 /**\r
18  * TextPanelEvent is generated by an MTextPanel to notify listeners\r
19  * of changes.  To receive TextPanelEvents from an MTextPanel, clients\r
20  * must implement TextPanelListener and add themselves to the MTextPanel's\r
21  * list of listeners.\r
22  * <p>\r
23  * Some event types are special cases of others.  This is intentional - it\r
24  * allows notifications to be sent less often in certain common cases.  For\r
25  * example, a change in the selection range generates a SELECTION_RANGE_CHANGED \r
26  * event.  This is a very common occurrance, and if many clients listen for this\r
27  * event, there may be a significant performance penalty.  By\r
28  * listening for a more specialized event (such as SELECTION_EMPTY_CHANGED), clients\r
29  * can reduce the number of notifications sent.\r
30  * \r
31  * @see MTextPanel\r
32  * @see TextPanelListener\r
33  */\r
34 public final class TextPanelEvent extends EventObject {\r
35 \r
36     /**\r
37      * For serialization\r
38      */\r
39     private static final long serialVersionUID = 6971512969738427763L;\r
40 \r
41     /**\r
42      * The lower bound of TextPanelEvent ID's.\r
43      */\r
44     public static final int TEXT_PANEL_FIRST = 11;\r
45 \r
46     /**\r
47      * Events of this type indicate a change in the selection range.\r
48      * This occurs quite often.  Most clients do not need to be \r
49      * notified every time the selection range changes.\r
50      */\r
51     public static final int SELECTION_RANGE_CHANGED = 11;\r
52     \r
53     /**\r
54      * Events of this type are sent when the selection range becomes\r
55      * 0-length after not being 0-length, or vice versa.  This event\r
56      * is a special case of SELECTION_RANGE_CHANGED.\r
57      */\r
58     public static final int SELECTION_EMPTY_CHANGED = 12;\r
59     \r
60     /**\r
61      * Events of this type indicate that the text in the TextPanel changed.\r
62      * This type of event occurs often.\r
63      */\r
64     public static final int TEXT_CHANGED = 13;\r
65     \r
66     /**\r
67      * Events of this type are sent when the styles in the current\r
68      * selection change.\r
69      */\r
70     public static final int SELECTION_STYLES_CHANGED = 14;\r
71      \r
72     /**\r
73      * Events of this type are sent when the undo/redo state changes.\r
74      */\r
75     public static final int UNDO_STATE_CHANGED = 15;\r
76     \r
77     /**\r
78      * Events of this type are sent when the clipboard state changes.\r
79      */\r
80     public static final int CLIPBOARD_CHANGED = 16;\r
81     \r
82     /**\r
83      * Events of this type are sent when \r
84      * the wrap width of the text changes.\r
85      */\r
86     public static final int FORMAT_WIDTH_CHANGED = 17;\r
87 \r
88     /**\r
89      * Events of this type are sent when the key remap changes.\r
90      */\r
91     public static final int KEYREMAP_CHANGED = 18;\r
92 \r
93     /**\r
94      * The upper bound of TextPanelEvent ID's.\r
95      */\r
96     public static final int TEXT_PANEL_LAST = 18;\r
97 \r
98     private int fId;\r
99 \r
100     /**\r
101      * Create a new TextPanelEvent.\r
102      * @param source the MTextPanel which generated the event\r
103      * @param id the ID for this event.  Must be within\r
104      * [TEXT_PANEL_FIRST, TEXT_PANEL_LAST].\r
105      */\r
106     TextPanelEvent(MTextPanel source, int id) {\r
107 \r
108         super(source);\r
109         if (id < TEXT_PANEL_FIRST || id > TEXT_PANEL_LAST) {\r
110             throw new IllegalArgumentException("id out of range");\r
111         }\r
112         fId = id;\r
113     }\r
114 \r
115     /**\r
116      * Return the event ID for this event.  Event ID's are\r
117      * one of the class constants.\r
118      * @return the event ID for this event\r
119      */\r
120     public int getID() {\r
121 \r
122         return fId;\r
123     }\r
124     \r
125     public String toString() {\r
126         \r
127         String desc = null;\r
128         \r
129         switch(fId) {\r
130             case SELECTION_RANGE_CHANGED:\r
131                 desc = "SELECTION_RANGE_CHANGED";\r
132                 break;\r
133             case SELECTION_EMPTY_CHANGED:\r
134                 desc = "SELECTION_EMPTY_CHANGED";\r
135                 break;\r
136             case TEXT_CHANGED:\r
137                 desc = "TEXT_CHANGED";\r
138                 break;\r
139             case SELECTION_STYLES_CHANGED:\r
140                 desc = "SELECTION_STYLES_CHANGED";\r
141                 break;\r
142             case UNDO_STATE_CHANGED:\r
143                 desc = "UNDO_STATE_CHANGED";\r
144                 break;\r
145             case CLIPBOARD_CHANGED:\r
146                 desc = "CLIPBOARD_CHANGED";\r
147                 break;\r
148             case FORMAT_WIDTH_CHANGED:\r
149                 desc = "FORMAT_WIDTH_CHANGED";\r
150                 break;\r
151             case KEYREMAP_CHANGED:\r
152                 desc = "KEYREMAP_CHANGED";\r
153                 break;\r
154         }\r
155         return "[TextPanelEvent:"+desc+"]";\r
156     }\r
157 }\r