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  package org.xnap.plugin.freeway;
20  
21  import java.awt.event.ActionEvent;
22  
23  import javax.swing.Action;
24  import javax.swing.Icon;
25  
26  import org.gnu.freeway.protocol.afs.esed2.RootNode;
27  import org.xnap.XNap;
28  import org.xnap.gui.action.AbstractDownloadAction;
29  import org.xnap.gui.util.FocusManager;
30  import org.xnap.peer.Peer;
31  import org.xnap.plugin.Plugin;
32  import org.xnap.search.AbstractSearchResult;
33  import org.xnap.search.SearchResult;
34  import org.xnap.search.SearchResultContainer;
35  import org.xnap.transfer.DownloadManager;
36  import org.xnap.util.Formatter;
37  
38  /***
39   * 
40   */
41  public class FreewaySearchResult extends AbstractSearchResult 
42  {
43  
44  	RootNode node;
45  
46  	/***
47  	 * 
48  	 */
49  	public FreewaySearchResult(RootNode node) 
50  	{
51  		this.node = node;
52  		
53  		put(XNap.tr("Filesize"), Formatter.formatSize(getFilesize()));
54  		put(XNap.tr("CRC"), new Integer(node.getFileIdentifier().getFileCRC()));
55  		put(XNap.tr("Description"), node.getDescription());
56  		put(XNap.tr("Mimetype"), node.getMimeType());
57  		put(XNap.tr("URI"), node.getFileIdentifier().toURI());
58  		put(XNap.tr("Query Hash"), node.getFileIdentifier().chk.query.toHex());
59  		put(XNap.tr("Key Hash"), node.getFileIdentifier().chk.key.toHex());
60  	}
61  
62  	/*
63  	 * @see org.xnap.search.SearchResult#canGroup(org.xnap.search.SearchResult)
64  	 */
65  	public boolean canGroup(SearchResult result) 
66  	{
67  		return false;
68  	}
69  
70  	/*
71  	 * @see org.xnap.search.SearchResult#createContainer()
72  	 */
73  	public SearchResultContainer createContainer() 
74  	{
75  		return null;
76  	}
77  	
78  	public Icon getIcon()
79  	{
80  		return FreewayPlugin.ICON_16;
81  	}
82  
83  	/*
84  	 * @see org.xnap.search.SearchResult#getActions()
85  	 */
86  	public Action[] getActions() 
87  	{
88  		return new Action[] { new FreewayDownloadAction() };
89  	}
90  
91  	/*
92  	 * @see org.xnap.search.SearchResult#getAvailability()
93  	 */
94  	public int getAvailability() 
95  	{
96  		return 0;
97  	}
98  
99  	/*
100 	 * @see org.xnap.search.SearchResult#getFilename()
101 	 */
102 	public String getFilename() 
103 	{
104 		return node.getFileName(); 
105 	}
106 
107 	/*
108 	 * @see org.xnap.search.SearchResult#getFilesize()
109 	 */
110 	public long getFilesize()
111 	{
112 		return node.getFileIdentifier().getFileLength();
113 	}
114 
115 	/*
116 	 * @see org.xnap.search.SearchResult#getHash()
117 	 */
118 	public Object getHash() 
119 	{
120 		return new Integer(node.getFileIdentifier().getFileCRC());
121 	}
122 
123 	/*
124 	 * @see org.xnap.search.SearchResult#getPlugin()
125 	 */
126 	public Plugin getPlugin() 
127 	{
128 		return null;
129 	}
130 
131 	/*
132 	 * @see org.xnap.search.SearchResult#getPeer()
133 	 */
134 	public Peer getPeer() 
135 	{
136 		return null;
137 	}
138 
139 	private class FreewayDownloadAction extends AbstractDownloadAction
140 	{
141 		public void actionPerformed(ActionEvent e) 
142 		{
143 			DownloadManager.getInstance().add(new FreewayDownload(node));
144 			FocusManager.setFocusTo("transfer",e);
145 		}
146 	}
147 }