Class Device

java.lang.Object
org.eclipse.swt.graphics.Device
All Implemented Interfaces:
Drawable
Direct Known Subclasses:
Display, Printer

public abstract class Device extends Object implements Drawable
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:
  • Field Details

    • CHANGE_SCALEFACTOR

      protected static final int CHANGE_SCALEFACTOR
      Since:
      3.105
      See Also:
    • gsettingsProc

      long gsettingsProc
    • gsettingsCallback

      Callback gsettingsCallback
    • isConnected

      boolean isConnected
    • displaySettings

      long displaySettings
    • xDisplay

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

      IMPORTANT: 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.

    • shellHandle

      long shellHandle
    • DEBUG

      public static boolean DEBUG
    • debug

      boolean debug
    • tracking

      boolean tracking
    • errors

      Error[] errors
    • objects

      Object[] objects
    • trackingLock

      Object trackingLock
    • disposed

      volatile boolean disposed
    • logProc

      long logProc
    • logCallback

      Callback logCallback
    • log_domains

      String[] log_domains
    • handler_ids

      int[] handler_ids
    • warningLevel

      int warningLevel
    • XErrorCallback

      static Callback XErrorCallback
    • XIOErrorCallback

      static Callback XIOErrorCallback
    • XErrorProc

      static long XErrorProc
    • XIOErrorProc

      static long XIOErrorProc
    • XNullErrorProc

      static long XNullErrorProc
    • XNullIOErrorProc

      static long XNullIOErrorProc
    • Devices

      static Device[] Devices
    • COLOR_BLACK

      static final Color COLOR_BLACK
    • COLOR_DARK_RED

      static final Color COLOR_DARK_RED
    • COLOR_DARK_GREEN

      static final Color COLOR_DARK_GREEN
    • COLOR_DARK_YELLOW

      static final Color COLOR_DARK_YELLOW
    • COLOR_DARK_BLUE

      static final Color COLOR_DARK_BLUE
    • COLOR_DARK_MAGENTA

      static final Color COLOR_DARK_MAGENTA
    • COLOR_DARK_CYAN

      static final Color COLOR_DARK_CYAN
    • COLOR_GRAY

      static final Color COLOR_GRAY
    • COLOR_DARK_GRAY

      static final Color COLOR_DARK_GRAY
    • COLOR_RED

      static final Color COLOR_RED
    • COLOR_TRANSPARENT

      static final Color COLOR_TRANSPARENT
    • COLOR_GREEN

      static final Color COLOR_GREEN
    • COLOR_YELLOW

      static final Color COLOR_YELLOW
    • COLOR_BLUE

      static final Color COLOR_BLUE
    • COLOR_MAGENTA

      static final Color COLOR_MAGENTA
    • COLOR_CYAN

      static final Color COLOR_CYAN
    • COLOR_WHITE

      static final Color COLOR_WHITE
    • systemFont

      Font systemFont
    • dpi

      Point dpi
    • emptyTab

      long emptyTab
    • CurrentDevice

      protected static Device CurrentDevice
    • DeviceFinder

      protected static Runnable DeviceFinder
  • Constructor Details

    • Device

      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:
    • Device

      public Device(DeviceData data)
      Constructs a new instance of this class.

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

      Parameters:
      data - the DeviceData which describes the receiver
      See Also:
  • Method Details

    • getDevice

      static Device getDevice()
    • isTracking

      public boolean isTracking()
      Throws:
      SWTException -
      • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
      Since:
      3.115
    • setTracking

      public void setTracking(boolean tracking)
      Throws:
      SWTException -
      • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
      Since:
      3.115
    • startTracking

      private void startTracking()
    • stopTracking

      private void stopTracking()
    • checkDevice

      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.

      Throws:
      SWTException -
      • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
    • create

      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 - the DeviceData which describes the receiver
      See Also:
    • dispose

      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:
    • dispose_Object

      void dispose_Object(Object object)
    • findDevice

      static Device findDevice(long xDisplay)
    • deregister

      static void deregister(Device device)
    • destroy

      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:
    • getBounds

      public Rectangle getBounds()
      Returns a rectangle describing the receiver's size and location.
      Returns:
      the bounding rectangle
      Throws:
      SWTException -
      • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • getDeviceData

      public DeviceData getDeviceData()
      Returns a DeviceData based on the receiver. Modifications made to this DeviceData will not affect the receiver.
      Returns:
      a DeviceData containing the device's data and attributes
      Throws:
      SWTException -
      • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
      See Also:
    • getClientArea

      public Rectangle getClientArea()
      Returns a rectangle which describes the area of the receiver which is capable of displaying data.
      Returns:
      the client area
      Throws:
      SWTException -
      • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
      See Also:
    • getDepth

      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:
      the depth of the screen
      Throws:
      SWTException -
      • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • getDPI

      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:
      the horizontal and vertical DPI
      Throws:
      SWTException -
      • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • getFontList

      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 - the name of the font to look for, or null
      scalable - if true only scalable fonts are returned, otherwise only non-scalable fonts are returned.
      Returns:
      the matching font data
      Throws:
      SWTException -
      • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • getScreenDPI

      Point getScreenDPI()
    • getSystemColor

      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 - the color constant
      Returns:
      the matching color
      Throws:
      SWTException -
      • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
      See Also:
    • getSystemFont

      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:
      a font
      Throws:
      SWTException -
      • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • getWarnings

      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:
      trueif warnings are being handled, and false otherwise
      Throws:
      SWTException -
      • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • init

      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:
    • overrideThemeValues

      private void overrideThemeValues()
      For functionality invalid input: '&' 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.
    • internal_new_GC

      public abstract long internal_new_GC(GCData data)
      Invokes platform specific functionality to allocate a new GC handle.

      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.

      Specified by:
      internal_new_GC in interface Drawable
      Parameters:
      data - the platform specific GC data
      Returns:
      the platform specific GC handle
    • internal_dispose_GC

      public abstract void internal_dispose_GC(long hDC, GCData data)
      Invokes platform specific functionality to dispose a GC handle.

      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.

      Specified by:
      internal_dispose_GC in interface Drawable
      Parameters:
      hDC - the platform specific GC handle
      data - the platform specific GC data
    • isDisposed

      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:
      true when the device is disposed and false otherwise
    • loadFont

      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 - the font file path
      Returns:
      whether the font was successfully loaded
      Throws:
      SWTException -
      • ERROR_NULL_ARGUMENT - if path is null
      • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
      Since:
      3.3
      See Also:
    • logProc

      long logProc(long log_domain, long log_level, long message, long user_data)
    • new_Object

      void new_Object(Object object)
    • register

      static void register(Device device)
    • release

      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:
    • setWarnings

      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 - trueif warnings should be printed, and false otherwise
      Throws:
      SWTException -
      • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
    • XErrorProc

      static long XErrorProc(long xDisplay, long xErrorEvent)
    • XIOErrorProc

      static long XIOErrorProc(long xDisplay)
    • getDeviceZoom

      protected int getDeviceZoom()
      Gets the scaling factor from the device and calculates the zoom level.
      Returns:
      zoom in percentage
      Since:
      3.105