root/dwt/graphics/Resource.d

Revision 246:fd9c62a2998e, 3.1 kB (checked in by Frank Benoit <benoit@tionex.de>, 6 months ago)

Updater SWT 3.4M7 to 3.4

Line 
1 /*******************************************************************************
2  * Copyright (c) 2000, 2008 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  * Port to the D programming language:
11  *     Frank Benoit <benoit@tionex.de>
12  *******************************************************************************/
13 module dwt.graphics.Resource;
14
15 import dwt.DWT;
16 import dwt.graphics.Device;
17
18 /**
19  * This class is the abstract superclass of all graphics resource objects.
20  * Resources created by the application must be disposed.
21  * <p>
22  * IMPORTANT: This class is intended to be subclassed <em>only</em>
23  * within the DWT implementation. However, it has not been marked
24  * final to allow those outside of the DWT development team to implement
25  * patched versions of the class in order to get around specific
26  * limitations in advance of when those limitations can be addressed
27  * by the team.  Any class built using subclassing to access the internals
28  * of this class will likely fail to compile or run between releases and
29  * may be strongly platform specific. Subclassing should not be attempted
30  * without an intimate and detailed understanding of the workings of the
31  * hierarchy. No support is provided for user-written classes which are
32  * implemented as subclasses of this class.
33  * </p>
34  *
35  * @see #dispose
36  * @see #isDisposed
37  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
38  *
39  * @since 3.1
40  */
41 public abstract class Resource {
42
43     /**
44      * the device where this resource was created
45      */
46     Device device;
47
48 public this() {
49 }
50
51 this(Device device) {
52     if (device is null) device = Device.getDevice();
53     if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
54     this.device = device;
55 }
56
57 void destroy() {
58 }
59
60 /**
61  * Disposes of the operating system resources associated with
62  * this resource. Applications must dispose of all resources
63  * which they allocate.
64  */
65 public void dispose() {
66     if (device is null) return;
67     if (device.isDisposed()) return;
68     destroy();
69     if (device.tracking) device.dispose_Object(this);
70     device = null;
71 }
72
73 /**
74  * Returns the <code>Device</code> where this resource was
75  * created.
76  *
77  * @return <code>Device</code> the device of the receiver
78  *
79  * @since 3.2
80  */
81 public Device getDevice() {
82     Device device = this.device;
83     if (device is null || isDisposed ()) DWT.error (DWT.ERROR_GRAPHIC_DISPOSED);
84     return device;
85 }
86
87 void init_() {
88     if (device.tracking) device.new_Object(this);
89 }
90
91 /**
92  * Returns <code>true</code> if the resource has been disposed,
93  * and <code>false</code> otherwise.
94  * <p>
95  * This method gets the dispose state for the resource.
96  * When a resource has been disposed, it is an error to
97  * invoke any other method using the resource.
98  *
99  * @return <code>true</code> when the resource is disposed and <code>false</code> otherwise
100  */
101 public abstract bool isDisposed();
102
103 }
Note: See TracBrowser for help on using the browser.