1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.xnap.plugin.freeway;
20
21 import java.beans.PropertyChangeListener;
22 import java.io.File;
23 import java.security.Security;
24 import java.util.logging.Level;
25
26 import javax.swing.Icon;
27
28 import org.apache.log4j.Logger;
29 import org.bouncycastle.jce.provider.BouncyCastleProvider;
30 import org.gnu.freeway.Application;
31 import org.gnu.freeway.DaemonSocket;
32 import org.gnu.freeway.Prefs;
33 import org.gnu.freeway.protocol.afs.esed2.NNode;
34 import org.gnu.freeway.protocol.afs.esed2.Policy;
35 import org.gnu.freeway.protocol.afs.swing.SController;
36 import org.gnu.freeway.util.ConfigurationService;
37 import org.gnu.freeway.util.LoggingService;
38 import org.gnu.freeway.util.Service;
39 import org.gnu.freeway.util.ServiceManager;
40 import org.gnu.freeway.util.StarFormatter;
41 import org.gnu.freeway.util.ui.UIResources;
42 import org.xnap.XNap;
43 import org.xnap.gui.Dialogs;
44 import org.xnap.gui.XNapFrame;
45 import org.xnap.gui.util.IconHelper;
46 import org.xnap.plugin.AbstractPlugin;
47 import org.xnap.search.MediaType;
48 import org.xnap.search.Search;
49 import org.xnap.search.SearchFilter;
50 import org.xnap.search.SearchManager;
51 import org.xnap.search.SearchProvider;
52
53
54 /***
55 *
56 *
57 */
58 public class FreewayPlugin extends AbstractPlugin
59 implements SController, SearchProvider
60 {
61 private static FreewayPlugin instance = null;
62 private ConfigurationService config;
63 private UIResources resources;
64 private ServiceManager services;
65 private Prefs preferences;
66 private Policy policy;
67
68 private static Logger logger = Logger.getLogger(FreewayPlugin.class);
69
70 public static final String ICON_FILENAME = "emacs.png";
71
72 public static final Icon ICON_16 = IconHelper.getIcon(ICON_FILENAME, 16, false);
73 private FreewayPanel freewayPanel;
74
75 public static FreewayPlugin getInstance()
76 {
77 return instance;
78 }
79
80
81
82
83 public Application getApplication()
84 {
85
86 return null;
87 }
88
89
90
91
92 public File getCache()
93 {
94 return preferences.getSystemCache();
95 }
96
97 public String getName()
98 {
99 return getInfo().getName();
100 }
101
102
103
104
105 public Policy getPolicy()
106 {
107 return policy;
108 }
109
110
111
112
113 public Prefs getPreferences()
114 {
115 return preferences;
116 }
117
118
119
120
121 public UIResources getResources()
122 {
123 return resources;
124 }
125
126
127
128
129 public MediaType[] getSupportedMediaTypes()
130 {
131 return new MediaType[] { SearchManager.MEDIA_ANYTHING };
132 }
133
134
135
136
137 public void addPropertyChangeListener(PropertyChangeListener arg0)
138 {
139
140 }
141
142
143
144
145 public void addPropertyChangeListener(String arg0,
146 PropertyChangeListener arg1)
147 {
148
149 }
150
151
152
153
154 public DaemonSocket connect()
155 {
156
157 return null;
158 }
159
160
161
162
163 public void displayDirectory(String arg0, NNode arg1)
164 {
165
166 }
167
168
169
170
171 public void download(NNode arg0)
172 {
173
174 }
175
176
177
178
179 public void enterCritical()
180 {
181
182 }
183
184
185
186
187 public void err(String arg0, Throwable arg1)
188 {
189 logger.error(arg0, arg1);
190 }
191
192
193
194
195 public void guiMessage(String arg0)
196 {
197 Dialogs.showNotification(XNapFrame.getInstance(), "freewayNotification",
198 XNap.tr("XNap GNUnet notification"), arg0);
199 }
200
201
202
203
204 public void infoMessage(boolean arg0, String arg1)
205 {
206
207 }
208
209
210
211
212 public void leaveCritical()
213 {
214
215 }
216
217
218
219
220 public void log(Level arg0, String arg1) {}
221
222
223
224
225 public void refreshMenus()
226 {
227
228 }
229
230
231
232
233 public void removePropertyChangeListener(PropertyChangeListener arg0)
234 {
235
236 }
237
238
239
240
241 public void removePropertyChangeListener(String arg0,
242 PropertyChangeListener arg1)
243 {
244
245 }
246
247
248
249
250 public Search search(SearchFilter filter)
251 {
252 return new FreewaySearch(filter, this);
253 }
254
255
256
257
258 public Service service(Class c)
259 {
260 return services.service(c);
261 }
262
263
264
265
266 public void showStats()
267 {
268
269 }
270
271
272
273
274 public void start() throws Exception
275 {
276 instance = this;
277
278 try {
279 Security.insertProviderAt(new BouncyCastleProvider(), 0);
280 }
281 catch (SecurityException se) {
282 logger.error("Could not add Provider");
283 }
284
285 LoggingService.configureLoggingToConsole(new StarFormatter());
286 Prefs.ensureInitialized();
287 services = ServiceManager.getInstance();
288 services.start();
289 preferences = new Prefs();
290 config = (ConfigurationService)service(ConfigurationService.class);
291 config.readConfiguration(preferences);
292 resources = new UIResources("main.xml", getCache());
293 resources.setGlobalTarget(this);
294 policy = new Policy(config, preferences);
295 policy.initAnonymityPolicy(null);
296 SearchManager.getInstance().add(this);
297 }
298
299
300
301
302 public void startGUI()
303 {
304 freewayPanel = new FreewayPanel(this);
305 XNapFrame.getInstance().insertTab
306 (getInfo().getName(), IconHelper.getListIcon(ICON_FILENAME),
307 freewayPanel);
308 }
309
310
311
312
313 public void stop()
314 {
315 policy.doneAnonymityPolicy();
316 services.stop();
317 SearchManager.getInstance().remove(this);
318 }
319
320
321
322
323 public void stopGUI()
324 {
325 XNapFrame.getInstance().removeTab(freewayPanel);
326 freewayPanel = null;
327 }
328 }