1 18 19 package org.objectweb.jac.aspects.gui; 20 21 import java.applet.Applet ; 22 import java.applet.AppletContext ; 23 import java.applet.AppletStub ; 24 import java.applet.AudioClip ; 25 import java.awt.Image ; 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.net.URL ; 29 import java.util.Arrays ; 30 import java.util.Enumeration ; 31 import java.util.Iterator ; 32 import java.util.Vector ; 33 import javax.swing.JApplet ; 34 import org.objectweb.jac.aspects.gui.Border; 35 import org.objectweb.jac.aspects.gui.View; 36 import org.objectweb.jac.core.rtti.FieldItem; 37 import org.objectweb.jac.core.rtti.MethodItem; 38 39 50 51 public class AppletView extends JApplet 52 implements View 53 { 54 protected String label; 55 protected DisplayContext context; 56 protected ViewFactory factory; 57 protected Object [] parameters; 58 protected String type; 59 protected Object substance; 60 61 67 68 public AppletView(ViewFactory factory, DisplayContext context, Object substance) { 69 this.substance = substance; 70 this.factory = factory; 71 this.context = context; 72 init(); 73 start(); 74 } 75 76 Border viewBorder; 77 78 82 public Border getViewBorder() { 83 return viewBorder; 84 } 85 86 90 public void setViewBorder(Border v) { 91 this.viewBorder = v; 92 } 93 94 View parentView; 95 96 100 public View getParentView() { 101 return parentView; 102 } 103 104 108 public void setParentView(View v) { 109 this.parentView = v; 110 } 111 112 public View getRootView() { 113 if (parentView==null) 114 return this; 115 return parentView.getRootView(); 116 } 117 118 public boolean isDescendantOf(View ancestor) { 119 if (this==ancestor) 120 return true; 121 else if (parentView==null) 122 return false; 123 else 124 return parentView.isDescendantOf(ancestor); 125 } 126 127 String style; 129 130 public void setStyle(String style) { 131 this.style = style; 132 } 133 134 public String getStyle() { 135 return style; 136 } 137 138 139 141 Border border; 142 143 147 public Border getBorder() { 148 return border; 149 } 150 151 155 public void setBorder(Border v) { 156 this.border = v; 157 } 158 159 String description; 160 161 165 public String getDescription() { 166 return description; 167 } 168 169 173 public void setDescription(String v) { 174 this.description = v; 175 } 176 177 178 public void setLabel(String label) { 179 this.label = label; 180 } 181 182 public String getLabel() { 183 return label; 184 } 185 186 MethodItem message; 187 188 192 public MethodItem getMessage() { 193 return message; 194 } 195 196 200 public void setMessage(MethodItem v) { 201 this.message = v; 202 } 203 204 public void setContext(DisplayContext context) { 205 this.context = context; 206 } 207 208 public DisplayContext getContext() { 209 return context; 210 } 211 212 public void setFactory(ViewFactory factory) { 213 this.factory = factory; 214 } 215 216 public ViewFactory getFactory() { 217 return factory; 218 } 219 220 public void setWidth(int width) { 221 } 222 223 public void setHeight(int heigth) { 224 } 225 226 public void setParameters(Object [] parameters) { 227 this.parameters = parameters; 228 } 229 230 public Object [] getParameters() { 231 return parameters; 232 } 233 234 public void setType(String type) { 235 this.type = type; 236 } 237 238 public String getType() { 239 return type; 240 } 241 242 public boolean equalsView(ViewIdentity view) { 243 return 244 ( ( type!=null && 245 type.equals(view.getType()) ) 246 || (type==null && view.getType()==null ) ) 247 && ( ( parameters!=null && 248 Arrays.equals(parameters,view.getParameters()) ) 249 || (parameters==null && view.getParameters()==null) ); 250 } 251 252 public boolean equalsView(String type, Object [] parameters) { 253 return this.type.equals(type) 254 && Arrays.equals(this.parameters,parameters); 255 } 256 257 public void close(boolean validate) { 258 closed = true; 259 } 260 261 boolean closed = false; 262 263 public boolean isClosed() { 264 return closed; 265 } 266 267 public Object getSubstance() { 268 return substance; 269 } 270 271 public void setSubstance(Object substance) { 272 this.substance = substance; 273 } 274 275 public void setFocus(FieldItem field, Object option) { 276 } 277 278 284 285 public void init() { 286 setStub(new InternalStub(new InternalContext(),this)); 287 } 288 289 292 static class InternalStub implements AppletStub { 293 InternalContext context; 294 public InternalStub(InternalContext context,Applet applet) { 295 this.context = context; 296 context.setApplet(applet); 297 } 298 public void appletResize(int width, int height) { 299 } 302 public AppletContext getAppletContext() { 303 return context; 304 } 305 public URL getCodeBase() { 306 URL ret = null; 307 try { 308 ret = new URL ("file:/"); 309 } catch(Exception e) { 310 e.printStackTrace(); 311 } 312 return ret; 313 } 314 public URL getDocumentBase() { 315 URL ret = null; 316 try { 317 ret = new URL ("file:/"); 318 } catch(Exception e) { 319 e.printStackTrace(); 320 } 321 return ret; 322 } 323 public String getParameter(String name) { 324 return null; 325 } 326 public boolean isActive() { 327 return true; 328 } 329 } 330 331 static class InternalContext implements AppletContext { 332 public void setApplet(Applet a) { 333 v.add(a); 334 } 335 Vector v=new Vector (); 336 public Applet getApplet(String name) { 337 return (Applet )v.get(0); 338 } 339 public Enumeration getApplets() { 340 return v.elements(); 341 } 342 public AudioClip getAudioClip(URL url) { 343 return null; 344 } 345 public Image getImage(URL url) { 346 return null; 347 } 348 public void showDocument(URL url) {} 349 public void showDocument(URL url, String target) {} 350 public void showStatus(String status) {} 351 Vector streamKeys=new Vector (); 353 public void setStream(String key, 354 InputStream stream) 355 throws IOException {} 356 public InputStream getStream(String key) { 357 return null; 358 } 359 public Iterator getStreamKeys() { 360 return streamKeys.iterator(); 361 } 362 } 363 364 } 365 | Popular Tags |