comparison dwtx/jface/resource/ResourceManager.d @ 104:04b47443bb01

Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections. These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author Frank Benoit <benoit@tionex.de>
date Thu, 07 Aug 2008 15:01:33 +0200
parents 6c14e54dfc11
children
comparison
equal deleted inserted replaced
103:2d6540440fe6 104:04b47443bb01
18 import dwtx.jface.resource.FontDescriptor; 18 import dwtx.jface.resource.FontDescriptor;
19 import dwtx.jface.resource.DeviceResourceException; 19 import dwtx.jface.resource.DeviceResourceException;
20 import dwtx.jface.resource.RGBColorDescriptor; 20 import dwtx.jface.resource.RGBColorDescriptor;
21 21
22 // import java.util.ArrayList; 22 // import java.util.ArrayList;
23 import tango.util.collection.model.Seq;
24 import tango.util.collection.ArraySeq;
25 23
26 import dwt.DWTException; 24 import dwt.DWTException;
27 import dwt.graphics.Color; 25 import dwt.graphics.Color;
28 import dwt.graphics.Device; 26 import dwt.graphics.Device;
29 import dwt.graphics.Font; 27 import dwt.graphics.Font;
33 import dwtx.core.runtime.IStatus; 31 import dwtx.core.runtime.IStatus;
34 import dwtx.core.runtime.Status; 32 import dwtx.core.runtime.Status;
35 import dwtx.jface.util.Policy; 33 import dwtx.jface.util.Policy;
36 34
37 import dwt.dwthelper.utils; 35 import dwt.dwthelper.utils;
36 import dwtx.dwtxhelper.Collection;
38 import dwt.dwthelper.Runnable; 37 import dwt.dwthelper.Runnable;
39 38
40 /** 39 /**
41 * This class manages DWT resources. It manages reference-counted instances of resources 40 * This class manages DWT resources. It manages reference-counted instances of resources
42 * such as Fonts, Images, and Colors, and allows them to be accessed using descriptors. 41 * such as Fonts, Images, and Colors, and allows them to be accessed using descriptors.
56 55
57 /** 56 /**
58 * List of Runnables scheduled to run when the ResourceManager is disposed. 57 * List of Runnables scheduled to run when the ResourceManager is disposed.
59 * null if empty. 58 * null if empty.
60 */ 59 */
61 private Seq!(Runnable) disposeExecs = null; 60 private List disposeExecs = null;
62 61
63 /** 62 /**
64 * Returns the Device for which this ResourceManager will create resources 63 * Returns the Device for which this ResourceManager will create resources
65 * 64 *
66 * @since 3.1 65 * @since 3.1
337 // However, this should not prevent the remaining runnables from being 336 // However, this should not prevent the remaining runnables from being
338 // notified. If any runnables throw an exception, we remember one of them 337 // notified. If any runnables throw an exception, we remember one of them
339 // here and throw it at the end of the method. 338 // here and throw it at the end of the method.
340 RuntimeException foundException = null; 339 RuntimeException foundException = null;
341 340
342 Runnable[] execs = disposeExecs.toArray(); 341 Runnable[] execs = arraycast!(Runnable)(disposeExecs.toArray());
343 for (int i = 0; i < execs.length; i++) { 342 for (int i = 0; i < execs.length; i++) {
344 Runnable exec = execs[i]; 343 Runnable exec = execs[i];
345 344
346 try { 345 try {
347 exec.run(); 346 exec.run();
378 */ 377 */
379 public void disposeExec(Runnable r) { 378 public void disposeExec(Runnable r) {
380 Assert.isNotNull(cast(Object)r); 379 Assert.isNotNull(cast(Object)r);
381 380
382 if (disposeExecs is null) { 381 if (disposeExecs is null) {
383 disposeExecs = new ArraySeq!(Runnable); 382 disposeExecs = new ArrayList();
384 } 383 }
385 384
386 disposeExecs.append(r); 385 disposeExecs.add(cast(Object)r);
387 } 386 }
388 387
389 /** 388 /**
390 * Cancels a runnable that was previously scheduled with <code>disposeExec</code>. 389 * Cancels a runnable that was previously scheduled with <code>disposeExec</code>.
391 * Has no effect if the given runnable was not previously registered with 390 * Has no effect if the given runnable was not previously registered with
398 397
399 if (disposeExecs is null) { 398 if (disposeExecs is null) {
400 return; 399 return;
401 } 400 }
402 401
403 disposeExecs.remove(r); 402 disposeExecs.remove(cast(Object)r);
404 403
405 if (disposeExecs.drained()) { 404 if (disposeExecs.isEmpty()) {
406 disposeExecs = null; 405 disposeExecs = null;
407 } 406 }
408 } 407 }
409 } 408 }