public class CoordinatesConversion
extends java.lang.Object
The conversion is implemented with the help of conversion parameters which are injected as
CoordinatesConversionParams
instance during class instantiation.
Note that the class considers the character coordinate values as 0-based. This is contrary to the 1-based nature of ROW/COLUMN 4GL attributes.
Modifier and Type | Field and Description |
---|---|
private static CoordinatesConversion |
CHUI
The static instance suitable for ChUI environments.
|
private CoordinatesConversionParams |
params
The instance responsible for providing the conversion parameters.
|
Constructor and Description |
---|
CoordinatesConversion(CoordinatesConversionParams params)
Constructs new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
Point |
baseUnits()
Determine the base units for the current client mode.
|
static CoordinatesConversion |
chuiInstance()
Returns the singleton instance suitable for Chui environments.
|
double |
columnFromNative(int x)
Converts a native X coordinate value to a column ChUI coordinate value.
|
double |
columnFromPixels(int pixels)
Converts a value in pixel units to character columns.
|
double |
columnFromPixels(int pixels,
Coordinate.RoundingMode mode)
Converts a value in pixel units to character columns.
|
int |
columnToNative(double column)
Converts a column ChUI coordinate value to native coordinate value.
|
int |
columnToPixels(double columns)
Converts character columns to a value measured in pixel units.
|
Dimension |
dimensionFromNative(NativeDimension dimension)
Converts the passed-in instance from native to character units.
|
NativeDimension |
dimensionToNative(Dimension dimension)
Converts the passed-in instance from character to native units.
|
double |
heightFromNative(int height)
Converts a native height value to a ChUI height value.
|
double |
heightFromNative(int height,
WidgetId windowId,
int font)
Converts a native height value to a ChUI height value.
|
int |
heightToNative(double height)
Converts ChUI height value to native height value.
|
int |
heightToNative(double height,
WidgetId windowId,
int font)
Converts ChUI height value to native height value.
|
Insets |
insetsFromNative(NativeInsets insets)
Converts the passed-in instance from native to character units.
|
NativeInsets |
insetsToNative(Insets insets)
Converts the passed-in instance from character to native units.
|
Point |
pointFromNative(NativePoint point)
Converts the passed-in instance from native to character units.
|
NativePoint |
pointToNative(Point point)
Converts the passed-in instance from character to native units.
|
Rectangle |
rectangleFromNative(NativeRectangle rect)
Converts the passed-in instance from native to character units.
|
NativeRectangle |
rectangleToNative(Rectangle rect)
Converts the passed-in instance from character to native units.
|
double |
rowFromNative(int y)
Converts a native Y coordinate value to a row ChUI coordinate value.
|
double |
rowFromPixels(int pixels)
Converts a value in pixel units to character rows.
|
double |
rowFromPixels(int pixels,
Coordinate.RoundingMode mode)
Converts a value in pixel units to character rows.
|
int |
rowToNative(double row)
Converts a row ChUI coordinate value to native coordinate value.
|
int |
rowToPixels(double rows)
Converts character rows to a value measured in pixel units.
|
private double |
toChar(int pixels,
int pixelsPerChar)
Converts pixels to character units.
|
private double |
toChar(int pixels,
int pixelsPerChar,
Coordinate.RoundingMode mode)
Converts pixels to character units.
|
private int |
toPixels(double chars,
int pixelsPerChar)
Converts character units to pixels.
|
double |
widthFromNative(int width)
Converts a native width value to a ChUI width value.
|
double |
widthFromNative(int width,
WidgetId windowId,
int font)
Converts a native width value to a ChUI width value.
|
int |
widthToNative(double width)
Converts ChUI width value to native width value.
|
int |
widthToNative(double width,
WidgetId windowId,
int font)
Converts ChUI width value to native width value.
|
private static final CoordinatesConversion CHUI
private CoordinatesConversionParams params
public CoordinatesConversion(CoordinatesConversionParams params)
params
- A valid reference to CoordinatesConversionParams
instance.public static CoordinatesConversion chuiInstance()
public NativePoint pointToNative(Point point)
point
- A Point
instance.public Point baseUnits()
In ChUI, the base units is 1 character for row or column coordinates.
In GUI, the base units is computed by converting 1 character to 1 pixel, depending on the PIXELS-PER-COLUMN and PIXELS-PER-ROW values.
public Point pointFromNative(NativePoint point)
point
- A NativePoint
instance.public NativeDimension dimensionToNative(Dimension dimension)
dimension
- A Dimension
instance.public Dimension dimensionFromNative(NativeDimension dimension)
dimension
- A NativeDimension
instance.public NativeRectangle rectangleToNative(Rectangle rect)
rect
- A Rectangle
instance.public Rectangle rectangleFromNative(NativeRectangle rect)
rect
- A NativeRectangle
instance.public NativeInsets insetsToNative(Insets insets)
insets
- An Insets
instance.public Insets insetsFromNative(NativeInsets insets)
insets
- An NativeInsets
instance.public int columnToNative(double column)
column
- The value being converted.public double columnFromNative(int x)
x
- The value being converted.public int rowToNative(double row)
window
and font
parameters.row
- The value being converted.public double rowFromNative(int y)
y
- The value being converted.public int widthToNative(double width)
width
- The value being converted.public int widthToNative(double width, WidgetId windowId, int font)
window
and font
parameters.width
- The value being converted.windowId
- ID of the window representing the current UI environment.font
- The font number defined in the window represented by the window
parameter.public double widthFromNative(int width)
width
- The value being converted.public double widthFromNative(int width, WidgetId windowId, int font)
window
and font
parameters.width
- The value being converted.windowId
- ID of the window representing the current UI environment.font
- The font number defined in the window represented by the window
parameter.public int heightToNative(double height)
height
- The value being converted.public int heightToNative(double height, WidgetId windowId, int font)
window
and font
parameters.height
- The value being converted.windowId
- ID of the window representing the current UI environment.font
- The font number defined in the window represented by the window
parameter.public double heightFromNative(int height)
height
- The value being converted.public double heightFromNative(int height, WidgetId windowId, int font)
window
and font
parameters.height
- The value being converted.windowId
- ID of the window representing the current UI environment.font
- The font number defined in the window represented by the window
parameter.public int columnToPixels(double columns)
CoordinatesConversionParams.getPixelsPerColumn()
.columns
- The value being converted.public double columnFromPixels(int pixels)
CoordinatesConversionParams.getPixelsPerColumn()
.pixels
- The value in pixel units.public double columnFromPixels(int pixels, Coordinate.RoundingMode mode)
CoordinatesConversionParams.getPixelsPerColumn()
.
See toChar(int, int)
for more information about rounding modes.
pixels
- The value in pixel units.mode
- The desired rounding mode.public int rowToPixels(double rows)
CoordinatesConversionParams.getPixelsPerRow()
.rows
- The value being converted.public double rowFromPixels(int pixels)
CoordinatesConversionParams.getPixelsPerRow()
.pixels
- The value in pixel units.public double rowFromPixels(int pixels, Coordinate.RoundingMode mode)
CoordinatesConversionParams.getPixelsPerRow()
.
See toChar(int, int)
for more information about rounding modes.
pixels
- The value in pixel units.mode
- The desired rounding mode.private double toChar(int pixels, int pixelsPerChar)
pixels
- The pixel value being converted.pixelsPerChar
- Number of pixels per one character unit.private double toChar(int pixels, int pixelsPerChar, Coordinate.RoundingMode mode)
Two rounding modes are supported, Coordinate.RoundingMode.ROUND
and Coordinate.RoundingMode.TRUNCATE
.
Coordinate.RoundingMode.ROUND
performs two rounds operations. First
a half-up round with a scale of three and second a half-up round with
a scale of two.
Coordinate.RoundingMode.TRUNCATE
simply discards the decimal part and
effectively makes the method return a whole number.
pixels
- The pixel value being converted.pixelsPerChar
- Number of pixels per one character unit.mode
- The desired rounding mode.private int toPixels(double chars, int pixelsPerChar)
chars
- The value in character units being converted.pixelsPerChar
- Number of pixels per one character unit.