View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.plugin.gift.net;
21  
22  import org.xnap.XNap;
23  import org.xnap.plugin.gift.net.event.SearchControlEvent;
24  import org.xnap.plugin.gift.net.event.SearchItemEvent;
25  import org.xnap.plugin.gift.net.event.listener.SearchEventListener;
26  import org.xnap.search.AbstractSearch;
27  import org.xnap.search.SearchFilter;
28  import org.xnap.search.SearchHandler;
29  
30  
31  /***
32   * GiFTSearch
33   *
34   * @author <a href="mailto:tvanlessen@taval.de">Tammo van Lessen</a>
35   * @version CVS $Id: GiFTSearch.java,v 1.4 2004/07/20 18:02:28 leist Exp $
36   */
37  public class GiFTSearch extends AbstractSearch implements SearchEventListener {
38      //~ Constructors -----------------------------------------------------------
39  
40      private String gid;
41  
42  	private boolean started;
43  
44  	private boolean finished;
45  	private SearchHandler handler;
46  	private GiFTDaemon daemon;
47  
48  	/***
49       * Constructor for GiFTSearch.
50       *
51       * @param filter
52       * @param priority
53       * @param maxResults
54       */
55      public GiFTSearch(SearchFilter filter, GiFTDaemon daemon) {
56          super(filter);
57  
58  		this.daemon = daemon;
59      }
60  
61      //~ Methods ----------------------------------------------------------------
62  
63  
64  	/***
65  	 * @see xnap.plugin.gift.net.event.listener.SearchEventListener#searchFinished(xnap.plugin.gift.net.event.SearchControlEvent)
66  	 */
67  	public void searchFinished(SearchControlEvent evt) {
68  		finished = true;
69  	}
70  
71  	/***
72  	 * @see xnap.plugin.gift.net.event.listener.SearchEventListener#searchItemReceived(xnap.plugin.gift.net.event.SearchItemEvent)
73  	 */
74  	public void searchItemReceived(SearchItemEvent evt) {
75  		handler.resultReceived(evt.getSearchResult());
76  	}
77  
78  	/***
79  	 * @see xnap.plugin.gift.net.event.listener.SearchEventListener#searchStarted(xnap.plugin.gift.net.event.SearchControlEvent)
80  	 */
81  	public void searchStarted(SearchControlEvent evt) {
82  		started = true;	
83  	}
84  
85  
86  	/***
87  	 * @see xnap.search.Search#getStatus()
88  	 */
89  	public String getStatus() {
90  		return (started
91  			? XNap.tr("Running")
92  			: finished
93  			? XNap.tr("Finished")
94  			: XNap.tr("Pending"));
95  	}
96  
97  	/***
98  	 * @see xnap.search.Search#isDone()
99  	 */
100 	public boolean isDone() {
101 		return finished;
102 	}
103 
104 	/***
105 	 * @see xnap.search.Search#start(xnap.search.SearchHandler)
106 	 */
107 	public void start(SearchHandler handler) {
108 		this.handler = handler;
109 		daemon.search(this);
110 	}
111 
112 	/***
113 	 * @see xnap.search.Search#stop()
114 	 */
115 	public void stop() {
116 		daemon.changeSearch(this, "cancel");
117 	}
118 
119 	public String getGID() {
120 		return gid;
121 	}
122 
123 	/***
124 	 * @param string
125 	 */
126 	public void setGID(String string) {
127 		gid = string;
128 	}
129 
130 }