Top Description Fields Constructors Methods
org.eclipse.swt.graphics

public abstract Class Device

extends Object
implements Drawable
Class Inheritance
All Implemented Interfaces
org.eclipse.swt.graphics.Drawable
Known Direct Subclasses
org.eclipse.swt.printing.Printer, org.eclipse.swt.widgets.Display
Imports
java.io.*, java.util.function.*, java.util.stream.*, org.eclipse.swt.*, org.eclipse.swt.internal.*, org.eclipse.swt.internal.gtk.*, org.eclipse.swt.internal.gtk3.*, org.eclipse.swt.internal.gtk4.*

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 Also
Sample code and further information

Field Summary

Modifier and TypeField and Description
protected static final int
pack-priv Color
pack-priv Color
pack-priv Color
pack-priv Color
pack-priv Color
pack-priv Color
pack-priv Color
pack-priv Color
pack-priv Color
pack-priv Color
pack-priv Color
pack-priv Color
pack-priv Color
pack-priv Color
pack-priv Color
pack-priv Color
pack-priv Color
protected static Device
public static boolean
pack-priv boolean
protected static Runnable
pack-priv static Device[]
pack-priv long
pack-priv volatile boolean
pack-priv Point
pack-priv long
pack-priv Error[]
pack-priv Callback
pack-priv long
pack-priv int[]
pack-priv boolean
pack-priv String[]
pack-priv Callback
pack-priv long
pack-priv Object[]
pack-priv long
pack-priv Font
pack-priv boolean
pack-priv Object
pack-priv int
protected long
xDisplay

the handle to the X Display (Warning: This field is platform dependent)

Important Note

This field is not part of the SWT public API.

pack-priv static Callback
pack-priv static long
pack-priv static Callback
pack-priv static long
pack-priv static long
pack-priv static long

Constructor Summary

AccessConstructor and Description
public
Device()

Constructs a new instance of this class.

public
Device(DeviceData
the DeviceData which describes the receiver
data
)

Constructs a new instance of this class.

Method Summary

Modifier and TypeMethod and Description
protected void
checkDevice()

Throws an SWTException if the receiver can not be accessed by the caller.

protected void
create(DeviceData
the DeviceData which describes the receiver
data
)

Creates the device in the operating system.

pack-priv static synchronized void
protected void
destroy()

Destroys the device in the operating system and releases the device's handle.

public void
dispose()

Disposes of the operating system resources associated with the receiver.

pack-priv void
pack-priv static synchronized Device
findDevice(long xDisplay)

public Rectangle

Returns:

the bounding rectangle
getBounds
()

Returns a rectangle describing the receiver's size and location.

private Rectangle
public Rectangle

Returns:

the client area
getClientArea
()

Returns a rectangle which describes the area of the receiver which is capable of displaying data.

public int

Returns:

the depth of the screen
getDepth
()

Returns the bit depth of the screen, which is the number of bits it takes to represent the number of unique colors that the screen is currently capable of displaying.

pack-priv static synchronized Device
public DeviceData

Returns:

a DeviceData containing the device's data and attributes
getDeviceData
()

Returns a DeviceData based on the receiver.

protected int

Returns:

zoom in percentage
getDeviceZoom
()

Gets the scaling factor from the device and calculates the zoom level.

public Point

Returns:

the horizontal and vertical DPI
getDPI
()

Returns a point whose x coordinate is the logical horizontal dots per inch of the display, and whose y coordinate is the logical vertical dots per inch of the display.

public FontData[]

Returns:

the matching font data
getFontList
(String
the name of the font to look for, or null
faceName
,
boolean
if true only scalable fonts are returned, otherwise only non-scalable fonts are returned.
scalable
)

Returns FontData objects which describe the fonts that match the given arguments.

pack-priv Point
public Color

Returns:

the matching color
getSystemColor
(int
the color constant
id
)

Returns the matching standard color for the given constant, which should be one of the color constants specified in class SWT.

public Font

Returns:

a font
getSystemFont
()

Returns a reasonable font for applications to use.

public boolean

Returns:

trueif warnings are being handled, and false otherwise
getWarnings
()

Returns true if the underlying window system prints out warning messages on the console, and setWarnings had previously been called with true.

protected void
init()

Initializes any internal resources needed by the device.

public abstract void
internal_dispose_GC(long
the platform specific GC handle
hDC
,
GCData
the platform specific GC data
data
)

Redeclares org.eclipse.swt.graphics.Drawable.internal_dispose_GC.

Invokes platform specific functionality to dispose a GC handle.
public abstract long

Returns:

the platform specific GC handle
internal_new_GC
(GCData
the platform specific GC data
data
)

Redeclares org.eclipse.swt.graphics.Drawable.internal_new_GC.

Invokes platform specific functionality to allocate a new GC handle.
public boolean

Returns:

true when the device is disposed and false otherwise
isDisposed
()

Returns true if the device has been disposed, and false otherwise.

public boolean
public boolean

Returns:

whether the font was successfully loaded
loadFont
(String
the font file path
path
)

Loads the font specified by a file.

pack-priv long
logProc(long log_domain, long log_level, long message, long user_data)

pack-priv void
private void
overrideThemeValues()

For functionality & improved looks, we override some CSS theme values with custom values.

pack-priv static synchronized void
register(Device device)

protected void
release()

Releases any internal resources back to the operating system and clears all fields except the device handle.

public void
setTracking(boolean tracking)

public void
setWarnings(boolean
trueif warnings should be printed, and false otherwise
warnings
)

If the underlying window system supports printing warning messages to the console, setting warnings to false prevents these messages from being printed.

private void
private void
pack-priv static long
XErrorProc(long xDisplay, long xErrorEvent)

pack-priv static long
XIOErrorProc(long xDisplay)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CHANGE_SCALEFACTORback to summary
protected static final int CHANGE_SCALEFACTOR
Since
3.105
COLOR_BLACKback to summary
pack-priv Color COLOR_BLACK
COLOR_BLUEback to summary
pack-priv Color COLOR_BLUE
COLOR_CYANback to summary
pack-priv Color COLOR_CYAN
COLOR_DARK_BLUEback to summary
pack-priv Color COLOR_DARK_BLUE
COLOR_DARK_CYANback to summary
pack-priv Color COLOR_DARK_CYAN
COLOR_DARK_GRAYback to summary
pack-priv Color COLOR_DARK_GRAY
COLOR_DARK_GREENback to summary
pack-priv Color COLOR_DARK_GREEN
COLOR_DARK_MAGENTAback to summary
pack-priv Color COLOR_DARK_MAGENTA
COLOR_DARK_REDback to summary
pack-priv Color COLOR_DARK_RED
COLOR_DARK_YELLOWback to summary
pack-priv Color COLOR_DARK_YELLOW
COLOR_GRAYback to summary
pack-priv Color COLOR_GRAY
COLOR_GREENback to summary
pack-priv Color COLOR_GREEN
COLOR_MAGENTAback to summary
pack-priv Color COLOR_MAGENTA
COLOR_REDback to summary
pack-priv Color COLOR_RED
COLOR_TRANSPARENTback to summary
pack-priv Color COLOR_TRANSPARENT
COLOR_WHITEback to summary
pack-priv Color COLOR_WHITE
COLOR_YELLOWback to summary
pack-priv Color COLOR_YELLOW
CurrentDeviceback to summary
protected static Device CurrentDevice
DEBUGback to summary
public static boolean DEBUG
debugback to summary
pack-priv boolean debug
DeviceFinderback to summary
protected static Runnable DeviceFinder
Devicesback to summary
pack-priv static Device[] Devices
displaySettingsback to summary
pack-priv long displaySettings
disposedback to summary
pack-priv volatile boolean disposed
dpiback to summary
pack-priv Point dpi
emptyTabback to summary
pack-priv long emptyTab
errorsback to summary
pack-priv Error[] errors
gsettingsCallbackback to summary
pack-priv Callback gsettingsCallback
gsettingsProcback to summary
pack-priv long gsettingsProc
handler_idsback to summary
pack-priv int[] handler_ids
isConnectedback to summary
pack-priv boolean isConnected
log_domainsback to summary
pack-priv String[] log_domains
logCallbackback to summary
pack-priv Callback logCallback
logProcback to summary
pack-priv long logProc
objectsback to summary
pack-priv Object[] objects
shellHandleback to summary
pack-priv long shellHandle
systemFontback to summary
pack-priv Font systemFont
trackingback to summary
pack-priv boolean tracking
trackingLockback to summary
pack-priv Object trackingLock
warningLevelback to summary
pack-priv int warningLevel
xDisplayback to summary
protected long xDisplay

the handle to the X Display (Warning: This field is platform dependent)

Important Note

This field is not part of the SWT public API. It is marked protected 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.

XErrorCallbackback to summary
pack-priv static Callback XErrorCallback
XErrorProcback to summary
pack-priv static long XErrorProc
XIOErrorCallbackback to summary
pack-priv static Callback XIOErrorCallback
XIOErrorProcback to summary
pack-priv static long XIOErrorProc
XNullErrorProcback to summary
pack-priv static long XNullErrorProc
XNullIOErrorProcback to summary
pack-priv static long XNullIOErrorProc

Constructor Detail

Deviceback to summary
public Device()

Constructs a new instance of this class.

You must dispose the device when it is no longer required.

Since
3.1
See Also
create, init
Deviceback to summary
public Device(DeviceData data)

Constructs a new instance of this class.

You must dispose the device when it is no longer required.

Parameters
data:DeviceData

the DeviceData which describes the receiver

See Also
create, init, DeviceData

Method Detail

checkDeviceback to summary
protected void checkDevice()

Throws an SWTException 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.

Currently, it is an error to invoke any method (other than isDisposed() and dispose()) on a device that has had its dispose() method called.

In future releases of SWT, there may be more or fewer error checks and exceptions may be thrown for different reasons.

Exceptions
SWTException:
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
createback to summary
protected void create(DeviceData data)

Creates the device in the operating system. If the device does not have a handle, this method may do nothing depending on the device.

This method is called before init.

Subclasses are supposed to reimplement this method and not call the super implementation.

Parameters
data:DeviceData

the DeviceData which describes the receiver

See Also
init
deregisterback to summary
pack-priv static synchronized void deregister(Device device)
destroyback to summary
protected void destroy()

Destroys the device in the operating system and releases the device's handle. If the device does not have a handle, this method may do nothing depending on the device.

This method is called after release.

Subclasses are supposed to reimplement this method and not call the super implementation.

See Also
dispose, release
disposeback to summary
public void dispose()

Disposes of the operating system resources associated with the receiver. After this method has been invoked, the receiver will answer true when sent the message isDisposed().

See Also
release, destroy, checkDevice
dispose_Objectback to summary
pack-priv void dispose_Object(Object object)
findDeviceback to summary
pack-priv static synchronized Device findDevice(long xDisplay)
getBoundsback to summary
public Rectangle getBounds()

Returns a rectangle describing the receiver's size and location.

Returns:Rectangle

the bounding rectangle

Exceptions
SWTException:
  • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
getBoundsInPixelsback to summary
private Rectangle getBoundsInPixels()
getClientAreaback to summary
public Rectangle getClientArea()

Returns a rectangle which describes the area of the receiver which is capable of displaying data.

Returns:Rectangle

the client area

Exceptions
SWTException:
  • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
See Also
getBounds
getDepthback to summary
public int getDepth()

Returns the bit depth of the screen, which is the number of bits it takes to represent the number of unique colors that the screen is currently capable of displaying. This number will typically be one of 1, 8, 15, 16, 24 or 32.

Returns:int

the depth of the screen

Exceptions
SWTException:
  • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
getDeviceback to summary
pack-priv static synchronized Device getDevice()
getDeviceDataback to summary
public DeviceData getDeviceData()

Returns a DeviceData based on the receiver. Modifications made to this DeviceData will not affect the receiver.

Returns:DeviceData

a DeviceData containing the device's data and attributes

Exceptions
SWTException:
  • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
See Also
DeviceData
getDeviceZoomback to summary
protected int getDeviceZoom()

Gets the scaling factor from the device and calculates the zoom level.

Returns:int

zoom in percentage

Since
3.105
getDPIback to summary
public Point getDPI()

Returns a point whose x coordinate is the logical horizontal dots per inch of the display, and whose y coordinate is the logical vertical dots per inch of the display.

Returns:Point

the horizontal and vertical DPI

Exceptions
SWTException:
  • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
getFontListback to summary
public FontData[] getFontList(String faceName, boolean scalable)

Returns FontData objects which describe the fonts that match the given arguments. If the faceName is null, all fonts will be returned.

Parameters
faceName:String

the name of the font to look for, or null

scalable:boolean

if true only scalable fonts are returned, otherwise only non-scalable fonts are returned.

Returns:FontData[]

the matching font data

Exceptions
SWTException:
  • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
getScreenDPIback to summary
pack-priv Point getScreenDPI()
getSystemColorback to summary
public Color getSystemColor(int id)

Returns the matching standard color for the given constant, which should be one of the color constants specified in class SWT. Any value other than one of the SWT color constants which is passed in will result in the color black. This color should not be freed because it was allocated by the system, not the application.

Parameters
id:int

the color constant

Returns:Color

the matching color

Exceptions
SWTException:
  • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
See Also
SWT
getSystemFontback to summary
public Font getSystemFont()

Returns a reasonable font for applications to use. On some platforms, this will match the "default font" or "system font" if such can be found. This font should not be freed because it was allocated by the system, not the application.

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.

Returns:Font

a font

Exceptions
SWTException:
  • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
getWarningsback to summary
public boolean getWarnings()

Returns true if the underlying window system prints out warning messages on the console, and setWarnings had previously been called with true.

Returns:boolean

trueif warnings are being handled, and false otherwise

Exceptions
SWTException:
  • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
initback to summary
protected void init()

Initializes any internal resources needed by the device.

This method is called after create.

If subclasses reimplement this method, they must call the super implementation.

See Also
create
internal_dispose_GCback to summary
public abstract void internal_dispose_GC(long hDC, GCData data)

Redeclares org.eclipse.swt.graphics.Drawable.internal_dispose_GC.

Invokes platform specific functionality to dispose a GC handle.

Important Note

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.

Parameters
hDC:long

the platform specific GC handle

data:GCData

the platform specific GC data

Annotations
@Override
internal_new_GCback to summary
public abstract long internal_new_GC(GCData data)

Redeclares org.eclipse.swt.graphics.Drawable.internal_new_GC.

Invokes platform specific functionality to allocate a new GC handle.

Important Note

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.

Parameters
data:GCData

the platform specific GC data

Returns:long

the platform specific GC handle

Annotations
@Override
isDisposedback to summary
public boolean isDisposed()

Returns 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.

Returns:boolean

true when the device is disposed and false otherwise

isTrackingback to summary
public boolean isTracking()
Exceptions
SWTException:
  • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
Since
3.115
loadFontback to summary
public boolean loadFont(String path)

Loads the font specified by a file. The font will be present in the list of fonts available to the application.

Parameters
path:String

the font file path

Returns:boolean

whether the font was successfully loaded

Exceptions
SWTException:
  • ERROR_NULL_ARGUMENT - if path is null
  • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
Since
3.3
See Also
Font
logProcback to summary
pack-priv long logProc(long log_domain, long log_level, long message, long user_data)
new_Objectback to summary
pack-priv void new_Object(Object object)
overrideThemeValuesback to summary
private void overrideThemeValues()

For functionality & improved looks, we override some CSS theme values with custom values. Note about theme load mechanism: - This method is reached early at start of SWT initialization. Later, platform.ui will call OS.setDarkThemePreferred(true), which tells Gtk to use dark theme. This has the implication that the system theme can be 'Adwaita' (light), but later be 'darkened' by platform.ui. This means that there should not be any color-specific overrides in Adwaita theming because 'Adwaita' is used for both light and dark theme. Note about light/dark system theme: - If the System theme is Adwaita (light), eclipse can be forced to be dark with setDarkThemePreferred(true). But if the System theme is Adwaita-dark, eclipse cannot be made 'light'. Note that much of eclipse 'dark theme' is done by platform.ui's CSS engine, not by SWT.

registerback to summary
pack-priv static synchronized void register(Device device)
releaseback to summary
protected void release()

Releases any internal resources back to the operating system and clears all fields except the device handle.

When a device is destroyed, resources that were acquired on behalf of the programmer need to be returned to the operating system. For example, if the device allocated a font to be used as the system font, this font would be freed in 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.

See Also
dispose, destroy
setTrackingback to summary
public void setTracking(boolean tracking)
Exceptions
SWTException:
  • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
Since
3.115
setWarningsback to summary
public void setWarnings(boolean warnings)

If the underlying window system supports printing warning messages to the console, setting warnings to false prevents these messages from being printed. If the argument is true then message printing is not blocked.

Parameters
warnings:boolean

trueif warnings should be printed, and false otherwise

Exceptions
SWTException:
  • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
startTrackingback to summary
private void startTracking()
stopTrackingback to summary
private void stopTracking()
XErrorProcback to summary
pack-priv static long XErrorProc(long xDisplay, long xErrorEvent)
XIOErrorProcback to summary
pack-priv static long XIOErrorProc(long xDisplay)