Class ScreenDistance

java.lang.Object
com.luciad.input.ScreenDistance
All Implemented Interfaces:
AutoCloseable

public final class ScreenDistance extends Object implements AutoCloseable
This class is used to represent distances between screen locations.

It consists of a unit (expressed as a ScreenDistanceUnit) and the distance value.

This class contains utility methods for converting distance values from millimeters to pixels or vice-versa, by taking DPI and display scale into account (see ScreenDistance#asPixels and ScreenDistance#asMillimeters).

Related article: Support high-resolution (HiDPI) displays.

  • Constructor Details Link icon

  • Method Details Link icon

    • finalize Link icon

      protected void finalize()
      Overrides:
      finalize in class Object
    • close Link icon

      public void close()
      Specified by:
      close in interface AutoCloseable
    • pixels Link icon

      @NotNull public static ScreenDistance pixels(double pixels)
      Utility factory method for constructing a ScreenDistance expressed in device independent pixels.
      Parameters:
      pixels - the distance in device independent pixels.
      Returns:
      a ScreenDistance instance taking the passed value and expressed in device independent pixels.
    • millimeters Link icon

      @NotNull public static ScreenDistance millimeters(double millimeters)
      Utility factory method for constructing a ScreenDistance expressed in millimeters.
      Parameters:
      millimeters - the distance in millimeters.
      Returns:
      a ScreenDistance instance taking the passed value and expressed in millimeters.
    • getValue Link icon

      public double getValue()
      Returns the screen distance value, as a double.
      Returns:
      the screen distance value, as a double.
    • getUnit Link icon

      @NotNull public ScreenDistanceUnit getUnit()
      Returns the screen distance unit.
      Returns:
      the screen distance unit.
    • asPixels Link icon

      public double asPixels(double dpi, double displayScale)
      Converting value method which returns the distance value as a double, expressed in device independent pixels.

      In order to make any possible conversion from millimeters to pixels, the display DPI and display scale must be provided. If the stored unit is ScreenDistanceUnit#Pixels, the currently stored value is returned.

      Parameters:
      dpi - the display density in dots per inch
      displayScale - the display scale
      Returns:
      the screen distance in device independent pixels, as a double.
    • asMillimeters Link icon

      public double asMillimeters(double dpi, double displayScale)
      Converting value method which returns the distance value as a double, expressed in millimeters.

      In order to make any possible conversion from device independent pixels to millimeters, the display DPI and display scale must be provided. If the stored unit is ScreenDistanceUnit#Millimeters, the currently stored value is returned.

      Parameters:
      dpi - the display density in dots per inch
      displayScale - the display scale
      Returns:
      the screen distance in millimeters, as a double.