1 7 8 package java.awt.event; 9 10 import java.awt.ActiveEvent ; 11 import java.awt.AWTEvent ; 12 13 36 public class InvocationEvent extends AWTEvent implements ActiveEvent { 37 38 41 public static final int INVOCATION_FIRST = 1200; 42 43 46 public static final int INVOCATION_DEFAULT = INVOCATION_FIRST; 47 48 51 public static final int INVOCATION_LAST = INVOCATION_DEFAULT; 52 53 56 protected Runnable runnable; 57 58 62 protected Object notifier; 63 64 69 protected boolean catchExceptions; 70 71 76 private Exception exception = null; 77 78 83 private Throwable throwable = null; 84 85 91 private long when; 92 93 96 private static final long serialVersionUID = 436056344909459450L; 97 98 116 public InvocationEvent(Object source, Runnable runnable) { 117 this(source, runnable, null, false); 118 } 119 120 151 public InvocationEvent(Object source, Runnable runnable, Object notifier, 152 boolean catchThrowables) { 153 this(source, INVOCATION_DEFAULT, runnable, notifier, catchThrowables); 154 } 155 156 183 protected InvocationEvent(Object source, int id, Runnable runnable, 184 Object notifier, boolean catchThrowables) { 185 super(source, id); 186 this.runnable = runnable; 187 this.notifier = notifier; 188 this.catchExceptions = catchThrowables; 189 this.when = System.currentTimeMillis(); 190 } 191 192 196 public void dispatch() { 197 if (catchExceptions) { 198 try { 199 runnable.run(); 200 } 201 catch (Throwable t) { 202 if (t instanceof Exception ) { 203 exception = (Exception ) t; 204 } 205 throwable = t; 206 } 207 } 208 else { 209 runnable.run(); 210 } 211 212 if (notifier != null) { 213 synchronized (notifier) { 214 notifier.notifyAll(); 215 } 216 } 217 } 218 219 227 public Exception getException() { 228 return (catchExceptions) ? exception : null; 229 } 230 231 239 public Throwable getThrowable() { 240 return (catchExceptions) ? throwable : null; 241 } 242 243 249 public long getWhen() { 250 return when; 251 } 252 253 259 public String paramString() { 260 String typeStr; 261 switch(id) { 262 case INVOCATION_DEFAULT: 263 typeStr = "INVOCATION_DEFAULT"; 264 break; 265 default: 266 typeStr = "unknown type"; 267 } 268 return typeStr + ",runnable=" + runnable + ",notifier=" + notifier + 269 ",catchExceptions=" + catchExceptions + ",when=" + when; 270 } 271 } 272 | Popular Tags |