Class Device

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

public abstract class Device extends Object implements Drawable
This class is the abstract superclass of all device objects, such as Display.

This class is not intended to be directly used by clients.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final SerializableLock
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Throws an SWTException if the receiver can not be accessed by the caller.
    protected void
    Destroys the device .
    void
    Disposes of the operating system resources associated with the receiver.
    Returns a rectangle describing the receiver's size and location.
    Returns a rectangle which describes the area of the receiver which is capable of displaying data.
    int
    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.
    Returns a point whose x coordinate is the horizontal dots per inch of the display, and whose y coordinate is the vertical dots per inch of the display.
    getFontList(String faceName, boolean scalable)
    Returns FontData objects which describe the fonts that match the given arguments.
    Returns the matching standard color for the given constant, which should be one of the color constants specified in class SWT.
    Returns a reasonable font for applications to use.
    boolean
    Returns true if the device has been disposed, and false otherwise.
    protected void
    Releases any internal resources .

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • deviceLock

      protected final SerializableLock deviceLock
  • Constructor Details

    • Device

      public Device()
  • Method Details

    • 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 free'd because it was allocated by the system, not the application.
      Parameters:
      id - the color constant
      Returns:
      the matching color
      Throws:
      SWTException -
      • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • 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 free'd 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_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
      • 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
      Since:
      1.3
    • 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
      Since:
      1.2
      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
      Since:
      1.3
    • getDPI

      public Point getDPI()
      Returns a point whose x coordinate is the horizontal dots per inch of the display, and whose y coordinate is the vertical dots per inch of the display.
      Returns:
      the horizontal and vertical DPI
      Throws:
      SWTException -
      • ERROR_DEVICE_DISPOSED - if the receiver has been disposed
      Since:
      1.3
    • 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
      Since:
      1.2
    • 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:
    • 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
    • release

      protected void release()
      Releases any internal resources .

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

      protected void destroy()
      Destroys the device . 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:
    • 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