comparison org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/graphics/Resource.d @ 0:6dd524f61e62

add dwt win and basic java stuff
author Frank Benoit <benoit@tionex.de>
date Mon, 02 Mar 2009 14:44:16 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:6dd524f61e62
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 org.eclipse.swt.graphics.Resource;
14
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.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 SWT implementation. However, it has not been marked
24 * final to allow those outside of the SWT 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 /// SWT extension for D: do no dispose check
44 public bool disposeChecking = true;
45 /// SWT extension for D: do no dispose check
46 public static bool globalDisposeChecking = true;
47
48 /**
49 * the device where this resource was created
50 */
51 Device device;
52
53 public this() {
54 }
55
56 this(Device device) {
57 if (device is null) device = Device.getDevice();
58 if (device is null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
59 this.device = device;
60 }
61
62 ~this(){
63 if( globalDisposeChecking && disposeChecking && !isDisposed() ){
64 SWT.error( 0, null, " Resource deleted, but is not yet disposed. "
65 "This check can be disabled with "
66 "\"import org.eclipse.swt.graphics.Resource; "
67 "Resource.globalDisposeChecking = false; \". "
68 "This problem occured with type " ~ this.classinfo.name ~
69 " this.toString()=" ~ this.toString() );
70 }
71 }
72
73 void destroy() {
74 }
75
76 /**
77 * Disposes of the operating system resources associated with
78 * this resource. Applications must dispose of all resources
79 * which they allocate.
80 */
81 public void dispose() {
82 if (device is null) return;
83 if (device.isDisposed()) return;
84 destroy();
85 if (device.tracking) device.dispose_Object(this);
86 device = null;
87 }
88
89 /**
90 * Returns the <code>Device</code> where this resource was
91 * created.
92 *
93 * @return <code>Device</code> the device of the receiver
94 *
95 * @since 3.2
96 */
97 public Device getDevice() {
98 Device device = this.device;
99 if (device is null || isDisposed ()) SWT.error (SWT.ERROR_GRAPHIC_DISPOSED);
100 return device;
101 }
102
103 void init_() {
104 if (device.tracking) device.new_Object(this);
105 }
106
107 /**
108 * Returns <code>true</code> if the resource has been disposed,
109 * and <code>false</code> otherwise.
110 * <p>
111 * This method gets the dispose state for the resource.
112 * When a resource has been disposed, it is an error to
113 * invoke any other method using the resource.
114 *
115 * @return <code>true</code> when the resource is disposed and <code>false</code> otherwise
116 */
117 public abstract bool isDisposed();
118
119 }