Lines 10-15
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.swt.graphics; |
11 |
package org.eclipse.swt.graphics; |
12 |
|
12 |
|
|
|
13 |
import org.eclipse.swt.SWT; |
14 |
|
13 |
/** |
15 |
/** |
14 |
* This class is the abstract superclass of all graphics resource objects. |
16 |
* This class is the abstract superclass of all graphics resource objects. |
15 |
* Resources created by the application must be disposed. |
17 |
* Resources created by the application must be disposed. |
Lines 38-45
Link Here
|
38 |
* the device where this resource was created |
40 |
* the device where this resource was created |
39 |
*/ |
41 |
*/ |
40 |
Device device; |
42 |
Device device; |
|
|
43 |
|
44 |
int locks = 0; |
45 |
|
46 |
/** |
47 |
* Locks this resource, preventing its dispose method from being used. |
48 |
* This does not necessarily prevent the resource from being disposed |
49 |
* by the OS, but it will cause an exception to be thrown if an |
50 |
* attempt is made to explicitly call dispose. |
51 |
* |
52 |
* <p> |
53 |
* Locking the resource permits it to safely be exposed as public API |
54 |
* without creating a risk that other objects will dispose the resource |
55 |
* prematurely. |
56 |
* </p> |
57 |
* |
58 |
* <p> |
59 |
* Each call to lock must have a matching call to unlock with an identical |
60 |
* key before the Resource may be disposed. |
61 |
* </p> |
62 |
* |
63 |
* @param key an integer chosen by the caller that will later be used |
64 |
* to unlock the resource. |
65 |
*/ |
66 |
public void lock(int key) { |
67 |
locks += key; |
68 |
} |
41 |
|
69 |
|
42 |
/** |
70 |
/** |
|
|
71 |
* Unlocks a resource previously locked by a call to lock(...). A locked resource |
72 |
* must be unlocked with the same keys before it can be disposed. Resources |
73 |
* cannot be unlocked more than once unless they were locked the same number of |
74 |
* times. |
75 |
* |
76 |
* @param key a key that had previously been used as an argument to lock(...). |
77 |
*/ |
78 |
public void unlock(int key) { |
79 |
locks -= key; |
80 |
} |
81 |
|
82 |
/** |
83 |
* Throws an exception if this resource is currently locked. |
84 |
*/ |
85 |
protected void checkLocks() { |
86 |
if (locks != 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED_EARLY); |
87 |
} |
88 |
|
89 |
/** |
43 |
* Disposes of the operating system resources associated with |
90 |
* Disposes of the operating system resources associated with |
44 |
* this resource. Applications must dispose of all resources |
91 |
* this resource. Applications must dispose of all resources |
45 |
* which they allocate. |
92 |
* which they allocate. |