1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.jtella;
21
22 import javax.swing.Action;
23
24 import org.xnap.peer.Peer;
25 import org.xnap.plugin.Plugin;
26 import org.xnap.search.AbstractSearchResult;
27 import org.xnap.search.SearchResult;
28 import org.xnap.search.SearchResultContainer;
29
30 import com.kenmccrary.jtella.SearchReplyMessage;
31
32 /***
33 * This class is the default implementation for search results.
34 */
35 public class JTellaSearchResult extends AbstractSearchResult {
36
37
38
39
40
41 private SearchReplyMessage message;
42
43 /***
44 * The index of the file record in {@link #message}.
45 */
46 private int fileIndex;
47
48 private JTellaServant peer;
49 private String filename;
50
51
52
53 public JTellaSearchResult(SearchReplyMessage message, int fileIndex,
54 JTellaServant peer)
55 {
56 this.message = message;
57 this.fileIndex = fileIndex;
58 this.peer = peer;
59
60
61 this.filename = getFileRecord().getName();
62 this.filename = filename.substring(0, filename.length() - 1);
63 }
64
65
66
67 public boolean canGroup(SearchResult result)
68 {
69 if (result instanceof JTellaSearchResult) {
70 return result.getFilesize() == getFilesize();
71 }
72
73 return false;
74 }
75
76 public SearchResultContainer createContainer()
77 {
78 return new JTellaSearchResultContainer();
79 }
80
81 public Action[] getActions()
82 {
83 return new Action[] { new JTellaDownloadAction(this) };
84 }
85
86 public int getAvailability()
87 {
88 return message.getDownloadSpeed() + 1;
89 }
90
91 public String getFilename()
92 {
93 return filename;
94 }
95
96 public SearchReplyMessage.FileRecord getFileRecord()
97 {
98 return message.getFileRecord(fileIndex);
99 }
100
101 /***
102 * Returns the filesize.
103 */
104 public long getFilesize()
105 {
106 return getFileRecord().getSize();
107 }
108
109 public Object getHash()
110 {
111 return new Long(getFilesize());
112 }
113
114 /***
115 * Returns the jtella plugin.
116 */
117 public Plugin getPlugin()
118 {
119 return JTellaPlugin.getInstance();
120 }
121
122 /***
123 * Returns the peer that offer this result for download.
124 */
125 public Peer getPeer()
126 {
127 return peer;
128 }
129
130 public SearchReplyMessage getReply()
131 {
132 return message;
133 }
134
135 }