Mercurial > projects > dwt-win
annotate dwt/graphics/Resource.d @ 333:684eed7589a0
Generate error if a resource is deleted without disposal. Without that, is is very hard to find accidental deleted/scoped Color/Font/..
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 10 Feb 2009 17:14:24 +0100 |
parents | fd9c62a2998e |
children | c49e17d48b76 |
rev | line source |
---|---|
174
f906dbcacee5
Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents:
14
diff
changeset
|
1 /******************************************************************************* |
246 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
14 | 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 | |
174
f906dbcacee5
Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents:
14
diff
changeset
|
10 * Port to the D programming language: |
f906dbcacee5
Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents:
14
diff
changeset
|
11 * Frank Benoit <benoit@tionex.de> |
14 | 12 *******************************************************************************/ |
13 module dwt.graphics.Resource; | |
14 | |
15 import dwt.DWT; | |
16 import dwt.graphics.Device; | |
333
684eed7589a0
Generate error if a resource is deleted without disposal. Without that, is is very hard to find accidental deleted/scoped Color/Font/..
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
17 //import tango.util.log.Trace; |
14 | 18 |
19 /** | |
174
f906dbcacee5
Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents:
14
diff
changeset
|
20 * This class is the abstract superclass of all graphics resource objects. |
14 | 21 * Resources created by the application must be disposed. |
22 * <p> | |
23 * IMPORTANT: This class is intended to be subclassed <em>only</em> | |
24 * within the DWT implementation. However, it has not been marked | |
25 * final to allow those outside of the DWT development team to implement | |
26 * patched versions of the class in order to get around specific | |
27 * limitations in advance of when those limitations can be addressed | |
28 * by the team. Any class built using subclassing to access the internals | |
29 * of this class will likely fail to compile or run between releases and | |
30 * may be strongly platform specific. Subclassing should not be attempted | |
31 * without an intimate and detailed understanding of the workings of the | |
32 * hierarchy. No support is provided for user-written classes which are | |
33 * implemented as subclasses of this class. | |
34 * </p> | |
35 * | |
36 * @see #dispose | |
37 * @see #isDisposed | |
246 | 38 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
174
f906dbcacee5
Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents:
14
diff
changeset
|
39 * |
14 | 40 * @since 3.1 |
41 */ | |
42 public abstract class Resource { | |
174
f906dbcacee5
Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents:
14
diff
changeset
|
43 |
14 | 44 /** |
45 * the device where this resource was created | |
46 */ | |
47 Device device; | |
48 | |
246 | 49 public this() { |
213 | 50 } |
51 | |
52 this(Device device) { | |
53 if (device is null) device = Device.getDevice(); | |
54 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
55 this.device = device; | |
56 } | |
57 | |
333
684eed7589a0
Generate error if a resource is deleted without disposal. Without that, is is very hard to find accidental deleted/scoped Color/Font/..
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
58 ~this(){ |
684eed7589a0
Generate error if a resource is deleted without disposal. Without that, is is very hard to find accidental deleted/scoped Color/Font/..
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
59 if( !isDisposed ){ |
684eed7589a0
Generate error if a resource is deleted without disposal. Without that, is is very hard to find accidental deleted/scoped Color/Font/..
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
60 //Trace.formatln("{} {} {} Resource deleted, but is not yet disposed", __FILE__, __LINE__, this.classinfo.name ); |
684eed7589a0
Generate error if a resource is deleted without disposal. Without that, is is very hard to find accidental deleted/scoped Color/Font/..
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
61 DWT.error( 0, null, " Resource deleted, but is not yet disposed: (" ~ this.classinfo.name ~ ")" ); |
684eed7589a0
Generate error if a resource is deleted without disposal. Without that, is is very hard to find accidental deleted/scoped Color/Font/..
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
62 } |
684eed7589a0
Generate error if a resource is deleted without disposal. Without that, is is very hard to find accidental deleted/scoped Color/Font/..
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
63 } |
684eed7589a0
Generate error if a resource is deleted without disposal. Without that, is is very hard to find accidental deleted/scoped Color/Font/..
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
64 |
213 | 65 void destroy() { |
66 } | |
67 | |
14 | 68 /** |
69 * Disposes of the operating system resources associated with | |
70 * this resource. Applications must dispose of all resources | |
71 * which they allocate. | |
72 */ | |
213 | 73 public void dispose() { |
74 if (device is null) return; | |
75 if (device.isDisposed()) return; | |
76 destroy(); | |
77 if (device.tracking) device.dispose_Object(this); | |
78 device = null; | |
79 } | |
14 | 80 |
81 /** | |
82 * Returns the <code>Device</code> where this resource was | |
83 * created. | |
84 * | |
85 * @return <code>Device</code> the device of the receiver | |
174
f906dbcacee5
Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents:
14
diff
changeset
|
86 * |
14 | 87 * @since 3.2 |
88 */ | |
89 public Device getDevice() { | |
90 Device device = this.device; | |
91 if (device is null || isDisposed ()) DWT.error (DWT.ERROR_GRAPHIC_DISPOSED); | |
92 return device; | |
93 } | |
94 | |
213 | 95 void init_() { |
96 if (device.tracking) device.new_Object(this); | |
97 } | |
98 | |
14 | 99 /** |
100 * Returns <code>true</code> if the resource has been disposed, | |
101 * and <code>false</code> otherwise. | |
102 * <p> | |
103 * This method gets the dispose state for the resource. | |
104 * When a resource has been disposed, it is an error to | |
105 * invoke any other method using the resource. | |
106 * | |
107 * @return <code>true</code> when the resource is disposed and <code>false</code> otherwise | |
108 */ | |
109 public abstract bool isDisposed(); | |
110 | |
111 } |