org.eclipse.swt.graphics.Device Maven / Gradle / Ivy
Show all versions of org.eclipse.swt.win32.win32.x86 Show documentation
/******************************************************************************* * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.swt.graphics; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gdip.*; import org.eclipse.swt.internal.win32.*; import org.eclipse.swt.*; /** * This class is the abstract superclass of all device objects, * such as the Display device and the Printer device. Devices * can have a graphics context (GC) created for them, and they * can be drawn on by sending messages to the associated GC. * * @see Sample code and further information */ public abstract class Device implements Drawable { /* Debugging */ public static boolean DEBUG; boolean debug = DEBUG; boolean tracking = DEBUG; Error [] errors; Object [] objects; Object trackingLock; /** * Palette * (Warning: This field is platform dependent) *
if the receiver can not * be accessed by the caller. This may include both checks on * the state of the receiver and more generally on the entire * execution context. This method should be called by * device implementors to enforce the standard SWT invariants. ** IMPORTANT: This field is not part of the SWT * public API. It is marked public only so that it can be shared * within the packages provided by SWT. It is not available on all * platforms and should never be accessed from application code. *
* * @noreference This field is not intended to be referenced by clients. */ public int /*long*/ hPalette = 0; int [] colorRefCount; /* System Font */ Font systemFont; /* Font Enumeration */ int nFonts = 256; LOGFONT [] logFonts; TEXTMETRIC metrics; int[] pixels; /* Scripts */ int /*long*/ [] scripts; /* Advanced Graphics */ int /*long*/ [] gdipToken; int /*long*/ fontCollection; String[] loadedFonts; boolean disposed; /* * TEMPORARY CODE. When a graphics object is * created and the device parameter is null, * the current Display is used. This presents * a problem because SWT graphics does not * reference classes in SWT widgets. The correct * fix is to remove this feature. Unfortunately, * too many application programs rely on this * feature. */ protected static Device CurrentDevice; protected static Runnable DeviceFinder; static { try { Class.forName ("org.eclipse.swt.widgets.Display"); //$NON-NLS-1$ } catch (ClassNotFoundException e) {} } /* * TEMPORARY CODE. */ static synchronized Device getDevice () { if (DeviceFinder != null) DeviceFinder.run(); Device device = CurrentDevice; CurrentDevice = null; return device; } /** * Constructs a new instance of this class. ** You must dispose the device when it is no longer required. *
* * @see #create * @see #init * * @since 3.1 */ public Device() { this(null); } /** * Constructs a new instance of this class. ** You must dispose the device when it is no longer required. *
* * @param data the DeviceData which describes the receiver * * @see #create * @see #init * @see DeviceData */ public Device(DeviceData data) { synchronized (Device.class) { if (data != null) { debug = data.debug; tracking = data.tracking; } if (tracking) { errors = new Error [128]; objects = new Object [128]; trackingLock = new Object (); } create (data); init (); } } void addFont (String font) { if (loadedFonts == null) loadedFonts = new String [4]; int length = loadedFonts.length; for (int i=0; iSWTException * Currently, it is an error to invoke any method (other than *
isDisposed()
anddispose()
) on a * device that has had itsdispose()
method called. ** In future releases of SWT, there may be more or fewer error * checks and exceptions may be thrown for different reasons. *
* * @exception SWTException
-
*
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed *
* This method is called before init
.
*
* Subclasses are supposed to reimplement this method and not
* call the super
implementation.
*
* This method is called after release
.
*
* Subclasses are supposed to reimplement this method and not
* call the super
implementation.
*
true
when sent the message
* isDisposed()
.
*
* @see #release
* @see #destroy
* @see #checkDevice
*/
public void dispose () {
synchronized (Device.class) {
if (isDisposed()) return;
checkDevice ();
release ();
destroy ();
disposed = true;
if (tracking) {
synchronized (trackingLock) {
printErrors ();
objects = null;
errors = null;
trackingLock = null;
}
}
}
}
void dispose_Object (Object object) {
synchronized (trackingLock) {
for (int i=0; i-
*
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed *
DeviceData
based on the receiver.
* Modifications made to this DeviceData
will not
* affect the receiver.
*
* @return a DeviceData
containing the device's data and attributes
*
* @exception SWTException -
*
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed *
-
*
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed *
-
*
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed *
FontData
objects which describe
* the fonts that match the given arguments. If the
* faceName
is null, all fonts will be returned.
*
* @param faceName the name of the font to look for, or null
* @param scalable if true only scalable fonts are returned, otherwise only non-scalable fonts are returned.
* @return the matching font data
*
* @exception SWTException -
*
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed *
-
*
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed *
* Typically, applications which want the default look * should simply not set the font on the widgets they * create. Widgets are always created with the correct * default font for the class of user-interface component * they represent. *
* * @return a font * * @exception SWTException-
*
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed *
true
if the underlying window system prints out
* warning messages on the console, and setWarnings
* had previously been called with true
.
*
* @return true
if warnings are being handled, and false
otherwise
*
* @exception SWTException -
*
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed *
* This method is called after create
.
*
* If subclasses reimplement this method, they must
* call the super
implementation.
*
* IMPORTANT: This method is not part of the public
* API for Device
. It is marked public only so that it
* can be shared within the packages provided by SWT. It is not
* available on all platforms, and should never be called from
* application code.
*
* IMPORTANT: This method is not part of the public
* API for Device
. It is marked public only so that it
* can be shared within the packages provided by SWT. It is not
* available on all platforms, and should never be called from
* application code.
*
true
if the device has been disposed,
* and false
otherwise.
*
* This method gets the dispose state for the device.
* When a device has been disposed, it is an error to
* invoke any other method using the device.
*
* @return true
when the device is disposed and false
otherwise
*/
public boolean isDisposed () {
synchronized (Device.class) {
return disposed;
}
}
/**
* Loads the font specified by a file. The font will be
* present in the list of fonts available to the application.
*
* @param path the font file path
* @return whether the font was successfully loaded
*
* @exception SWTException
-
*
- ERROR_NULL_ARGUMENT - if path is null *
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed *
release
. Also,to assist the garbage
* collector and minimize the amount of memory that is not
* reclaimed when the programmer keeps a reference to a
* disposed device, all fields except the handle are zero'd.
* The handle is needed by destroy
.
*
* This method is called before destroy
.
*
* If subclasses reimplement this method, they must
* call the super
implementation.
*
false
prevents these
* messages from being printed. If the argument is true
then
* message printing is not blocked.
*
* @param warnings true
if warnings should be printed, and false
otherwise
*
* @exception SWTException -
*
- ERROR_DEVICE_DISPOSED - if the receiver has been disposed *