001: /*
002: * @(#)SearchableEvent.java
003: *
004: * Copyright 2002 - 2004 JIDE Software Inc. All rights reserved.
005: */
006: package com.jidesoft.swing.event;
007:
008: import com.jidesoft.swing.Searchable;
009:
010: import java.awt.*;
011:
012: /**
013: * An <code>AWTEvent</code> that adds support for
014: * <code>SearchableEvent</code> objects as the event source.
015: *
016: * @see com.jidesoft.swing.Searchable
017: * @see SearchableListener
018: */
019: public class SearchableEvent extends AWTEvent {
020:
021: private String _searchingText;
022: private String _oldSearchingText;
023: private String _matchingText;
024: private Object _matchingObject;
025:
026: /**
027: * Creates a <code>SearchableEvent</code>.
028: *
029: * @param source
030: * @param id
031: */
032: public SearchableEvent(Searchable source, int id) {
033: super (source, id);
034: }
035:
036: /**
037: * Creates a <code>SearchableEvent</code>. The searching text is the text that is being searched for.
038: *
039: * @param source
040: * @param id
041: * @param searchingText
042: */
043: public SearchableEvent(Object source, int id, String searchingText) {
044: super (source, id);
045: _searchingText = searchingText;
046: }
047:
048: public SearchableEvent(Object source, int id, String searchingText,
049: String oldSearchingText) {
050: super (source, id);
051: _searchingText = searchingText;
052: _oldSearchingText = oldSearchingText;
053: }
054:
055: public SearchableEvent(Object source, int id, String searchingText,
056: Object matchingObject, String matchingText) {
057: super (source, id);
058: _searchingText = searchingText;
059: _matchingObject = matchingObject;
060: _matchingText = matchingText;
061: }
062:
063: /**
064: * The first number in the range of IDs used for <code>SearchableEvent</code>.
065: */
066: public static final int SEARCHABLE_FIRST = AWTEvent.RESERVED_ID_MAX + 1000;
067:
068: /**
069: * The last number in the range of IDs used for <code>SearchableEvent</code>.
070: */
071: public static final int SEARCHABLE_LAST = SEARCHABLE_FIRST + 6;
072:
073: /**
074: * To indicate the searching process started. It is fired when the search popup shows up.
075: */
076: public static final int SEARCHABLE_START = SEARCHABLE_FIRST;
077:
078: /**
079: * To indicate the searching process stopped. It is fired when the search popup is gone.
080: */
081: public static final int SEARCHABLE_END = SEARCHABLE_FIRST + 1;
082:
083: /**
084: * To indicate the searching process finds a matching element. In this case, <code>getSearchingText()</code> will return
085: * the text that is being searched for. <code>getMatchingObject()</code> will return the element that matches the searching text.
086: * <code>getMatchingText()</code> is the text converting from the the matching object.
087: */
088: public static final int SEARCHABLE_MATCH = SEARCHABLE_FIRST + 3;
089:
090: /**
091: * To indicate the searching process doesn't find a matching element. In this case, <code>getSearchingText()</code> will return
092: * the text that is being searched for. <code>getMatchingObject()</code> and <code>getMatchingText()</code> will be null.
093: */
094: public static final int SEARCHABLE_NOMATCH = SEARCHABLE_FIRST + 4;
095:
096: /**
097: * To indicate the searching text changes. In this case, <code>getSearchingText()</code> will return
098: * the text that is being searched for. <code>getOldSearchingText()</code> will return the previous searching text.
099: */
100: public static final int SEARCHABLE_CHANGE = SEARCHABLE_FIRST + 5;
101:
102: /**
103: * To indicate the search component model is changed. The model could be ListModel in the case of JList, TableModel in the case
104: * of JTable, etc.
105: */
106: public static final int SEARCHABLE_MODEL_CHANGE = SEARCHABLE_FIRST + 6;
107:
108: /**
109: * Returns a parameter string identifying this event.
110: * This method is useful for event logging and for debugging.
111: *
112: * @return a string identifying the event and its attributes
113: */
114: @Override
115: public String paramString() {
116: String typeStr;
117: switch (id) {
118: case SEARCHABLE_START:
119: typeStr = "SEARCHABLE_START: searchingText = \""
120: + _searchingText + "\"";
121: break;
122: case SEARCHABLE_END:
123: typeStr = "SEARCHABLE_END";
124: break;
125: case SEARCHABLE_MATCH:
126: typeStr = "SEARCHABLE_MATCH: searchingText = \""
127: + _searchingText + "\" matchingText = \""
128: + _matchingText + "\"";
129: break;
130: case SEARCHABLE_NOMATCH:
131: typeStr = "SEARCHABLE_NOMATCH: searchingText = \""
132: + _searchingText + "\"";
133: break;
134: case SEARCHABLE_CHANGE:
135: typeStr = "SEARCHABLE_CHANGE: searchingText = \""
136: + _searchingText + "\" oldSearchingText = \""
137: + _oldSearchingText + "\"";
138: break;
139: case SEARCHABLE_MODEL_CHANGE:
140: typeStr = "SEARCHABLE_MODEL";
141: break;
142: default:
143: typeStr = "SEARCHABLE_UNKNOWN";
144: }
145: return typeStr;
146: }
147:
148: /**
149: * Returns the originator of the event.
150: *
151: * @return the <code>Searchable</code> object that originated the event
152: */
153:
154: public Searchable getSearchable() {
155: return (source instanceof Searchable) ? (Searchable) source
156: : null;
157: }
158:
159: /**
160: * Gets the text that is being searched for. The returned value is valid for events SEARCHABLE_START,
161: * SEARCHABLE_MATCH, SEARCHABLE_NOMATCH, and SEARCHABLE_CHANGE.
162: *
163: * @return the text that is being searched for.
164: */
165: public String getSearchingText() {
166: return _searchingText;
167: }
168:
169: /**
170: * Gets the text that was searched for.
171: * The returned value is only valid for event SEARCHABLE_CHANGE.
172: *
173: * @return the text that was searched for.
174: */
175: public String getOldSearchingText() {
176: return _oldSearchingText;
177: }
178:
179: /**
180: * Gets the text that is converted from the object matching the searching text.
181: * The returned value is only valid for events SEARCHABLE_MATCH.
182: *
183: * @return the text that is converted from the object matching the searching text.
184: */
185: public String getMatchingText() {
186: return _matchingText;
187: }
188:
189: /**
190: * Gets the object that matches the searching text.
191: * The returned value is only valid for events SEARCHABLE_MATCH.
192: *
193: * @return Gets the object that matches the searching text.
194: */
195: public Object getMatchingObject() {
196: return _matchingObject;
197: }
198: }
|