1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.search;
21
22 import java.io.File;
23 import java.util.Iterator;
24 import java.util.StringTokenizer;
25
26 import javax.swing.Action;
27 import javax.swing.Icon;
28
29 import org.xnap.gui.FileProvider;
30 import org.xnap.gui.action.OpenFileAction;
31 import org.xnap.gui.util.IconHelper;
32 import org.xnap.io.MetaInfoFile;
33 import org.xnap.peer.Peer;
34 import org.xnap.plugin.Plugin;
35
36 /***
37 * This class stores a local search result.
38 */
39 public class MetaInfoFileSearchResult implements SearchResult, FileProvider {
40
41
42
43 public static Icon ICON = IconHelper.getIcon("gohome.png", 16, false);
44
45
46
47 private MetaInfoFile file;
48
49
50
51 public MetaInfoFileSearchResult(MetaInfoFile file)
52 {
53 this.file = file;
54 }
55
56
57
58 public boolean canGroup(SearchResult result)
59 {
60 return false;
61 }
62
63 public SearchResultContainer createContainer()
64 {
65 return null;
66 }
67
68 public Object get(String key)
69 {
70 return file.get(key);
71 }
72
73 public Action[] getActions()
74 {
75 return new Action[] { new OpenFileAction(this) };
76 }
77
78 public int getAvailability()
79 {
80 return 0;
81 }
82
83 public File[] getFiles()
84 {
85 return new File[] { file };
86 }
87
88 public String getFilename()
89 {
90 return file.getAbsolutePath();
91 }
92
93 public long getFilesize()
94 {
95 return file.length();
96 }
97
98 public Object getHash()
99 {
100 return null;
101 }
102
103 /***
104 * Returns null;
105 */
106 public Icon getIcon()
107 {
108 return ICON;
109 }
110
111 public String[] getPath()
112 {
113 StringTokenizer t = new StringTokenizer(getFilename(), File.separator);
114 if (t.countTokens() > 1) {
115 String[] path = new String[t.countTokens() - 1];
116 for (int i = 0; i < path.length; i++) {
117 path[i] = t.nextToken();
118 }
119
120 return path;
121 }
122 else {
123 return null;
124 }
125 }
126
127 public Plugin getPlugin()
128 {
129 return null;
130 }
131
132 public int getSourcesCount()
133 {
134 return 1;
135 }
136
137 /***
138 * Returns the name of the file.
139 */
140 public String getShortFilename()
141 {
142 return file.getName();
143 }
144
145 public Peer getPeer()
146 {
147 return null;
148 }
149
150 /***
151 * Returns the keys of the file.
152 *
153 * @see MetaInfoFile#keys()
154 */
155 public Iterator keys()
156 {
157 return file.keys();
158 }
159
160 }