1 19 package org.lucane.client; 20 21 import org.lucane.common.*; 22 import org.lucane.common.net.ObjectConnection; 23 24 import java.io.*; 25 import java.lang.reflect.InvocationTargetException ; 26 import java.lang.reflect.Method ; 27 import java.net.*; 28 import java.util.*; 29 30 import javax.swing.ImageIcon ; 31 32 33 38 public abstract class Plugin 39 implements Runnable 40 { 41 private boolean starter; 43 protected ResourceBundle bundle; 44 private ResourceBundle defaultBundle; 45 private LocalConfig config; 46 private String name = null; 47 48 53 public String getName() 54 { 55 if(name != null) 56 return this.name; 57 58 return this.getClass().getPackage().getName(); 59 } 60 61 66 protected void setName(String name) 67 { 68 this.name = name; 69 } 70 71 76 public String getVersion() 77 { 78 return tr("version"); 79 } 80 81 86 public String getAuthor() 87 { 88 return tr("author"); 89 } 90 91 96 public String getEmail() 97 { 98 return tr("email"); 99 } 100 101 106 public String getToolTip() 107 { 108 return tr("tooltip"); 109 } 110 111 116 public String getIcon() 117 { 118 return tr("icon"); 119 } 120 121 126 public String getIcon16() 127 { 128 return tr("icon16"); 129 } 130 131 136 public String getCategory() 137 { 138 return tr("category"); 139 } 140 141 146 public String getTitle() 147 { 148 return tr("title"); 149 } 150 151 157 protected void setStarter(boolean starter) 158 { 159 this.starter = starter; 160 } 161 162 166 public boolean isStandalone() 167 { 168 return false; 169 } 170 171 178 public abstract Plugin newInstance(ConnectInfo[] friends); 179 180 188 public void load(ObjectConnection oc, ConnectInfo who, String data) 189 { 190 } 191 192 197 public void start() 198 { 199 exit(); 200 } 201 202 205 public void follow() 206 { 207 exit(); 208 } 209 210 218 public Object invoke(String method, Class [] types, Object [] params) 219 throws SecurityException , NoSuchMethodException , IllegalArgumentException , IllegalAccessException , InvocationTargetException 220 { 221 Method m = this.getClass().getDeclaredMethod(method, types); 222 return m.invoke(this, params); 223 } 224 225 226 229 public void exit() 230 { 231 Logging.getLogger().fine("Plugin exited"); 232 try { 233 this.config.save(); 234 } catch(IOException ioe) { 235 Logging.getLogger().warning("Unable to save localconfig"); 236 ioe.printStackTrace(); 237 } 238 PluginManager.getInstance().removeRunningPlugin(this); 239 } 240 241 244 public void run() 245 { 246 PluginManager.getInstance().addRunningPlugin(this); 247 Logging.getLogger().fine("attempt to start a plugin thread"); 248 Logging.getLogger().fine("starter = " + this.starter); 249 this.config = new LocalConfig(this.getName()); 250 251 if(this.starter) 252 start(); 253 else 254 follow(); 255 } 256 257 262 public void setLocale(String lang) 263 { 264 try { 265 InputStream is = new URL(getDirectory() + "messages/messages.properties").openStream(); 266 this.bundle = new PropertyResourceBundle(is); 267 this.defaultBundle = this.bundle; 268 } catch(Exception e2) { 269 this.bundle = null; 270 this.defaultBundle = null; 271 } 272 273 try { 274 InputStream is = new URL(getDirectory() + "messages/messages_" + lang + ".properties").openStream(); 275 this.bundle = new PropertyResourceBundle(is); 276 } catch(Exception e1) { 277 } 279 } 280 281 287 public String tr(String origin) 288 { 289 try { 290 return bundle.getString(origin); 291 } catch(Exception e) { 292 try { 293 return defaultBundle.getString(origin); 294 } catch(Exception e2) { 295 return origin; 296 } 297 } 298 } 299 304 public String getDirectory() 305 { 306 String pack = this.getClass().getPackage().getName(); 307 308 String url = "jar:file:///" + System.getProperty("user.dir") + "/" + 309 Client.APPLICATIONS_DIRECTORY + getName() + ".jar!/"; 310 311 return url.replace('\\', '/'); 312 } 313 314 319 public ImageIcon getImageIcon(String file) 320 { 321 try { 322 return new ImageIcon (new URL(getDirectory() + "images/" + file)); 323 } catch(Exception e) { 324 return new ImageIcon (); 325 } 326 } 327 328 333 public LocalConfig getLocalConfig() 334 { 335 return this.config; 336 } 337 338 public String toString() 339 { 340 return getTitle(); 341 } 342 } 343 | Popular Tags |