Debian Codegraph @

src/com/jidesoft/swing/event/SearchableEvent.java

raw
1 /*
2 * @(#)SearchableEvent.java
3 *
4 * Copyright 2002 - 2004 JIDE Software Inc. All rights reserved.
5 */
6 package com.jidesoft.swing.event;
7
8 import com.jidesoft.swing.Searchable;
9
10 import java.awt.*;
11
12 /**
13 * An <code>AWTEvent</code> that adds support for
14 * <code>SearchableEvent</code> objects as the event source.
15 *
16 * @see com.jidesoft.swing.Searchable
17 * @see SearchableListener
18 */
19 public class SearchableEvent extends AWTEvent {
20
21 private String _searchingText;
22 private String _oldSearchingText;
23 private String _matchingText;
24 private Object _matchingObject;
25
26 /**
27 * Creates a <code>SearchableEvent</code>.
28 *
29 * @param source
30 * @param id
31 */
32 public SearchableEvent(Searchable source, int id) {
33 super(source, id);
34 }
35
36 /**
37 * Creates a <code>SearchableEvent</code>. The searching text is the text that is being searched for.
38 *
39 * @param source
40 * @param id
41 * @param searchingText
42 */
43 public SearchableEvent(Object source, int id, String searchingText) {
44 super(source, id);
45 _searchingText = searchingText;
46 }
47
48 public SearchableEvent(Object source, int id, String searchingText, String oldSearchingText) {
49 super(source, id);
50 _searchingText = searchingText;
51 _oldSearchingText = oldSearchingText;
52 }
53
54 public SearchableEvent(Object source, int id, String searchingText, Object matchingObject, String matchingText) {
55 super(source, id);
56 _searchingText = searchingText;
57 _matchingObject = matchingObject;
58 _matchingText = matchingText;
59 }
60
61 /**
62 * The first number in the range of IDs used for <code>SearchableEvent</code>.
63 */
64 public static final int SEARCHABLE_FIRST = AWTEvent.RESERVED_ID_MAX + 1000;
65
66 /**
67 * The last number in the range of IDs used for <code>SearchableEvent</code>.
68 */
69 public static final int SEARCHABLE_LAST = SEARCHABLE_FIRST + 6;
70
71 /**
72 * To indicate the searching process started. It is fired when the search popup shows up.
73 */
74 public static final int SEARCHABLE_START = SEARCHABLE_FIRST;
75
76 /**
77 * To indicate the searching process stopped. It is fired when the search popup is gone.
78 */
79 public static final int SEARCHABLE_END = SEARCHABLE_FIRST + 1;
80
81 /**
82 * To indicate the searching process finds a matching element. In this case, <code>getSearchingText()</code> will return
83 * the text that is being searched for. <code>getMatchingObject()</code> will return the element that matches the searching text.
84 * <code>getMatchingText()</code> is the text converting from the the matching object.
85 */
86 public static final int SEARCHABLE_MATCH = SEARCHABLE_FIRST + 3;
87
88 /**
89 * To indicate the searching process doesn't find a matching element. In this case, <code>getSearchingText()</code> will return
90 * the text that is being searched for. <code>getMatchingObject()</code> and <code>getMatchingText()</code> will be null.
91 */
92 public static final int SEARCHABLE_NOMATCH = SEARCHABLE_FIRST + 4;
93
94 /**
95 * To indicate the searching text changes. In this case, <code>getSearchingText()</code> will return
96 * the text that is being searched for. <code>getOldSearchingText()</code> will return the previous searching text.
97 */
98 public static final int SEARCHABLE_CHANGE = SEARCHABLE_FIRST + 5;
99
100 /**
101 * To indicate the search component model is changed. The model could be ListModel in the case of JList, TableModel in the case
102 * of JTable, etc.
103 */
104 public static final int SEARCHABLE_MODEL_CHANGE = SEARCHABLE_FIRST + 6;
105
106 /**
107 * Returns a parameter string identifying this event.
108 * This method is useful for event logging and for debugging.
109 *
110 * @return a string identifying the event and its attributes
111 */
112 @Override
113 public String paramString() {
114 String typeStr;
115 switch (id) {
116 case SEARCHABLE_START:
117 typeStr = "SEARCHABLE_START: searchingText = \"" + _searchingText + "\"";
118 break;
119 case SEARCHABLE_END:
120 typeStr = "SEARCHABLE_END";
121 break;
122 case SEARCHABLE_MATCH:
123 typeStr = "SEARCHABLE_MATCH: searchingText = \"" + _searchingText + "\" matchingText = \"" + _matchingText + "\"";
124 break;
125 case SEARCHABLE_NOMATCH:
126 typeStr = "SEARCHABLE_NOMATCH: searchingText = \"" + _searchingText + "\"";
127 break;
128 case SEARCHABLE_CHANGE:
129 typeStr = "SEARCHABLE_CHANGE: searchingText = \"" + _searchingText + "\" oldSearchingText = \"" + _oldSearchingText + "\"";
130 break;
131 case SEARCHABLE_MODEL_CHANGE:
132 typeStr = "SEARCHABLE_MODEL";
133 break;
134 default:
135 typeStr = "SEARCHABLE_UNKNOWN";
136 }
137 return typeStr;
138 }
139
140
141 /**
142 * Returns the originator of the event.
143 *
144 * @return the <code>Searchable</code> object that originated the event
145 */
146
147 public Searchable getSearchable() {
148 return (source instanceof Searchable) ? (Searchable) source : null;
149 }
150
151 /**
152 * Gets the text that is being searched for. The returned value is valid for events SEARCHABLE_START,
153 * SEARCHABLE_MATCH, SEARCHABLE_NOMATCH, and SEARCHABLE_CHANGE.
154 *
155 * @return the text that is being searched for.
156 */
157 public String getSearchingText() {
158 return _searchingText;
159 }
160
161 /**
162 * Gets the text that was searched for.
163 * The returned value is only valid for event SEARCHABLE_CHANGE.
164 *
165 * @return the text that was searched for.
166 */
167 public String getOldSearchingText() {
168 return _oldSearchingText;
169 }
170
171 /**
172 * Gets the text that is converted from the object matching the searching text.
173 * The returned value is only valid for events SEARCHABLE_MATCH.
174 *
175 * @return the text that is converted from the object matching the searching text.
176 */
177 public String getMatchingText() {
178 return _matchingText;
179 }
180
181 /**
182 * Gets the object that matches the searching text.
183 * The returned value is only valid for events SEARCHABLE_MATCH.
184 *
185 * @return Gets the object that matches the searching text.
186 */
187 public Object getMatchingObject() {
188 return _matchingObject;
189 }
190 }