Mercurial > projects > dwt-mac
comparison dwt/graphics/Resource.d @ 0:380af2bdd8e5
Upload of whole dwt tree
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sat, 09 Aug 2008 17:00:02 +0200 |
parents | |
children | 1a8b3cb347e0 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:380af2bdd8e5 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2005 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 *******************************************************************************/ | |
11 module dwt.graphics.Resource; | |
12 | |
13 import dwt.dwthelper.utils; | |
14 | |
15 import dwt.DWT; | |
16 | |
17 /** | |
18 * This class is the abstract superclass of all graphics resource objects. | |
19 * Resources created by the application must be disposed. | |
20 * <p> | |
21 * IMPORTANT: This class is intended to be subclassed <em>only</em> | |
22 * within the DWT implementation. However, it has not been marked | |
23 * final to allow those outside of the DWT development team to implement | |
24 * patched versions of the class in order to get around specific | |
25 * limitations in advance of when those limitations can be addressed | |
26 * by the team. Any class built using subclassing to access the internals | |
27 * of this class will likely fail to compile or run between releases and | |
28 * may be strongly platform specific. Subclassing should not be attempted | |
29 * without an intimate and detailed understanding of the workings of the | |
30 * hierarchy. No support is provided for user-written classes which are | |
31 * implemented as subclasses of this class. | |
32 * </p> | |
33 * | |
34 * @see #dispose | |
35 * @see #isDisposed | |
36 * | |
37 * @since 3.1 | |
38 */ | |
39 public abstract class Resource { | |
40 | |
41 /** | |
42 * the device where this resource was created | |
43 */ | |
44 Device device; | |
45 | |
46 Resource() { | |
47 } | |
48 | |
49 Resource(Device device) { | |
50 if (device is null) device = Device.getDevice(); | |
51 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
52 this.device = device; | |
53 } | |
54 | |
55 void destroy() { | |
56 } | |
57 | |
58 /** | |
59 * Disposes of the operating system resources associated with | |
60 * this resource. Applications must dispose of all resources | |
61 * which they allocate. | |
62 */ | |
63 public void dispose() { | |
64 if (device is null) return; | |
65 if (device.isDisposed()) return; | |
66 destroy(); | |
67 if (device.tracking) device.dispose_Object(this); | |
68 device = null; | |
69 } | |
70 | |
71 /** | |
72 * Returns the <code>Device</code> where this resource was | |
73 * created. | |
74 * | |
75 * @return <code>Device</code> the device of the receiver | |
76 * | |
77 * @since 3.2 | |
78 */ | |
79 public Device getDevice() { | |
80 Device device = this.device; | |
81 if (device is null || isDisposed ()) DWT.error (DWT.ERROR_GRAPHIC_DISPOSED); | |
82 return device; | |
83 } | |
84 | |
85 void init() { | |
86 if (device.tracking) device.new_Object(this); | |
87 } | |
88 | |
89 /** | |
90 * Returns <code>true</code> if the resource has been disposed, | |
91 * and <code>false</code> otherwise. | |
92 * <p> | |
93 * This method gets the dispose state for the resource. | |
94 * When a resource has been disposed, it is an error to | |
95 * invoke any other method using the resource. | |
96 * | |
97 * @return <code>true</code> when the resource is disposed and <code>false</code> otherwise | |
98 */ | |
99 public abstract bool isDisposed(); | |
100 | |
101 } |