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.opennap.net;
21  
22  import javax.swing.Action;
23  
24  import java.awt.event.ActionEvent;
25  import java.util.Iterator;
26  
27  import org.xnap.gui.action.AbstractDownloadAction;
28  import org.xnap.plugin.opennap.OpenNapPlugin;
29  import org.xnap.search.AbstractSearchResultContainer;
30  import org.xnap.search.SearchResult;
31  
32  /***
33   * 
34   */
35  public class OpenNapSearchResultContainer extends AbstractSearchResultContainer {
36  
37      // --- Constants(s) ---
38  
39      //--- Data Field(s) ---
40  
41      //--- Constructor(s) ---
42  
43      public OpenNapSearchResultContainer()
44      {
45      }
46  
47      // --- Method(s) ---
48  
49  	public synchronized boolean add(SearchResult result) 
50  	{
51  		for (Iterator i = iterator(); i.hasNext();) {
52  			if (i.next().equals(result)) {
53  				// FIX: maybe we should add result as a fallback
54  				return false;
55  			}
56  		}
57  		return super.add(result);
58  	}
59  
60      public Action[] getActions()
61      {
62  		return new Action[] { new DownloadAction(), };
63      }
64  
65  	public OpenNapSearchResult[] getResults()
66  	{
67  		return (OpenNapSearchResult[])results.toArray(new OpenNapSearchResult[0]);
68  	}
69  
70  
71  	//--- Inner Class(es) ---
72  	
73  	private class DownloadAction extends AbstractDownloadAction {
74  
75  		/***
76  		 *
77  		 */
78  		public void actionPerformed(ActionEvent e) 
79  		{
80  			if (isNotInLibrary(getShortFilename())) {
81  				OpenNapPlugin.getTransferManager().download(getResults());
82  			}
83  		}
84  
85  	}
86  
87  }