KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search > ui > text > MatchEvent


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.search.ui.text;
12 import org.eclipse.search.ui.ISearchResult;
13 import org.eclipse.search.ui.SearchResultEvent;
14 /**
15  * An event object describing addition and removal of matches. Events of this
16  * class are sent when <code>Match</code>es are added or removed from an
17  * <code>AbstractTextSearchResult</code>.
18  * <p>
19  * Clients may instantiate or subclass this class.
20  * </p>
21  * @since 3.0
22  */

23 public class MatchEvent extends SearchResultEvent {
24     private static final long serialVersionUID = 6009335074727417445L;
25     private int fKind;
26     private Match[] fMatches;
27     private Match[] fMatchContainer = new Match[1];
28     /**
29      * Constant for a matches being added.
30      *
31      * @see MatchEvent#getKind()
32      */

33     public static final int ADDED = 1;
34     /**
35      * Constant for a matches being removed.
36      *
37      * @see MatchEvent#getKind()
38      */

39     public static final int REMOVED = 2;
40     
41     private static final Match[] fgEmtpyMatches = new Match[0];
42     
43     /**
44      * Constructs a new <code>MatchEvent</code>.
45      *
46      * @param searchResult the search result concerned
47      */

48     public MatchEvent(ISearchResult searchResult) {
49         super(searchResult);
50     }
51     
52     /**
53      * Tells whether this is a remove or an add.
54      *
55      * @return one of <code>ADDED</code> or <code>REMOVED</code>
56      */

57     public int getKind() {
58         return fKind;
59     }
60     /**
61      * Returns the concerned matches.
62      *
63      * @return the matches this event is about
64      */

65     public Match[] getMatches() {
66         if (fMatches != null)
67             return fMatches;
68         else if (fMatchContainer[0] != null)
69             return fMatchContainer;
70         else
71             return fgEmtpyMatches;
72     }
73     
74     /**
75      * Sets the kind of event this is.
76      *
77      * @param kind the kind to set; either <code>ADDED</code> or <code>REMOVED</code>
78      */

79     protected void setKind(int kind) {
80         fKind = kind;
81     }
82     /**
83      * Sets the match for the change this event reports.
84      *
85      * @param match the match to set
86      */

87     protected void setMatch(Match match) {
88         fMatchContainer[0] = match;
89         fMatches = null;
90     }
91     
92     /**
93      * Sets the matches for the change this event reports.
94      *
95      * @param matches the matches to set
96      */

97     protected void setMatches(Match[] matches) {
98         fMatchContainer[0] = null;
99         fMatches = matches;
100     }
101 }
102
Popular Tags