public class GralPos
extends java.lang.Object
implements java.lang.Cloneable
org.vishia.gral.area9.GuiCallingArgs#sSize
) respectively the parameter size of GralGridProperties#GralGridProperties(char size)
.
samesize
, size
, same
, next
and refer
, the position values are stored
as absolute positions anyway. That are the elements x
, and y
with its values in
GralPos.Coordinate
.
The GralPos.Coordinate.p1
is the lesser value, left and top,
and GralPos.Coordinate.p2
,the end position is the greater value, right or bottom.
ratio
or useNatSize
.
A negative value, counts from the given spread in the parent
from bottom or right side.
GralPos.Coordinate.p1
is used for left or top and GralPos.Coordinate.p2
is used for right and bottom.
The pixel values (calculated with #calcWidgetPosAndSize(GralGridProperties, int, int, int, int)
)
uses the known height and width from the parent if the implementation graphic is active. It depends from resizing actions.
If then the left or top pixel value is greater then the right or bottom pixel value because left or top is given as positive value
and the other is given negative (from bottom or right) and the size is too less, it is calculated in this kind,
and the widget may be invisible or an position error may occur. This is a result of a bad given positioning.
useNatSize
means, the position is given as pixel units.
This is only usable for images which should not be scaled.
ratio
means, the position value in range 0..1000 is related to the spread of the parent
as ratio. This feature is still TODO. It is important for resize.
ratio
and 786432 can be immediately used too for setting the positions.
Additional some more designations are possible, which calculates the position to store from other given stored positions:
parent
panel or comprehensive widget.
Whereas negative numbers counts from bottom or right side. The 0 for end position is the bottom or right of the #parent.
same
(without additional value!) means, using the same position value as the reference position
(given as 'refPos' in the setPosition...(...) operations. If the refPos is null, it means don't change this value.
next
(without additional value!) for the left and top position means,
calculate this positions from the refPos with the given direction and border in GralPos.Coordinate.pb
.
If the direction in GralPos.Coordinate.dirNext
is 'l' or 'r' for the x position or 'u' or 'd' for the y position,
then this position is incremented.
The other position is not incremented, because the same value for dirNext is stored there.
Hence 'd' increments the y
. GralPos.Coordinate.p1
but not the x
.
refer
(0x80000) means, the position is related to the given refPos,
or the yet given own position if refPos = null. Of course the additional calculated position should not exceed
the range of 0x8000 ... 0x7fff respectively should be inside the viewable spread. It means the additional value
is usual in a small range + or - 1..100.0f or 1..1000 for integer presentation.
size
for the right and bottom coordinate means, the value is added to the value of left or top.
It is given as size. Whereby a negative size means, the position as first argument is the bottom or right position,
the top or left position is calculated with the size.
For example calling setPosition(null, 10.0f, -3.5f + GralPos.size, 20, 12 + GralPos.size)
means,
the absolute postion is 6.5..10 in y direction and 20..32 in x direction.
samesize
(without additional value!) means, the end values are calculated using the size of the refPos
or the given size before of the own positions if refPos = null.
For example For example calling setPosition(null, 4 + GralPos.refer, GralPos.samesize, 20, 12 + GralPos.size)
means,
that on given position in y 6.5..10 the new position is 10.5..14.
areaNr
is only usable for the GralArea9Panel
as selection for the sub panel.
GralCfgZbnf
.
The writing style of positions in the script regards a stinting short style to give positions,
because a hand written script should not cause a lot of calculations for positions by the writer.
It should be simple. The syntax of a position in the gral script is given in the variable syntaxZbnf
.
The method setPosition(CharSequence, GralPos)
uses that syntax.
Modifier and Type | Class and Description |
---|---|
static class |
GralPos.Coordinate
Class holds values for either x or y.
|
Modifier and Type | Field and Description |
---|---|
static int |
areaNr
Values 0ex001..0xe003 as number of a
GralArea9Panel A..C for columns, 1..3 for rows |
boolean |
dbg |
static int |
invalidPos
0xdffff Marker for invalid, to check
|
private static int |
kSpecialType
|
private static int |
kTypAdd_
Bits in an integer position value for the type.
|
private static int |
mSpecialType
|
private static int |
mType_
Bits in an integer position value for the type.
|
private static int |
mValueNegative
Bits in an integer position value for range and size.
|
private static int |
mValueRange_
Bits in an integer position value for range and size.
|
static int |
next
Use the next value for the coordinate in relation to the last one for the given direction
but the same value for the other coordinate.
|
static int |
nextBlock
Use the next value for the coordinate in relation to the last one.
|
GralWidgetBase_ifc |
parent
Relation of x and y left and top to any separation line. 0 - relation to left and top border.
|
static int |
ratio
This mask 0xa... at all coordinates means, that the value is given as ratio from the size.
|
static int |
refer
This mask 0x8... applied at any coordinate parameter of any setPosition- method means, that the value is
referred to the position of the previous or given position.
|
static int |
same
This value applied at any coordinate parameter of any setPosition- method means, that the value is
the same as the previous or given position.
|
static int |
samesize
Use the same size.
|
static int |
size
This adding value at xEnd or yEnd or the float presentations of the calling argument of any
setPosition- method means, that the value is the size, not the position.
|
static java.lang.String |
syntaxZbnf
Syntax of a position.
|
static int |
useNatSize
This value 0x0c000 at xEnd or yEnd means, that the native size of a widget should be used.
|
static java.lang.String |
version
Version, history and license.
|
GralPos.Coordinate |
x
The values for x and y positions.
|
private static int |
XXXmCheckRatio_
Mask to check ratio.
|
private static int |
XXXmNatSize_
Mask for value of natural size.
|
GralPos.Coordinate |
y
The values for x and y positions.
|
Constructor and Description |
---|
GralPos(GralMng gralMng)
Creates an position with all values 0 related to the whole screen.
|
GralPos(GralMng mng,
java.lang.String pos) |
GralPos(GralPos src)
Creates a reference position from a given one.
|
GralPos(GralPos src,
char direction)
Creates a reference position from a given one but modifies the next direction
before applying a position string.
|
GralPos(GralWidget_ifc panel,
java.lang.String pos) |
GralPos(GralWidgetBase_ifc parent)
Set a initial GralPos with the given widget as parent.
|
Modifier and Type | Method and Description |
---|---|
static void |
appendPos(java.lang.Appendable b,
int p) |
void |
assertCorrectness() |
GralPos |
calcNextPos(java.lang.String posString)
Deprecated.
|
GralRectangle |
calcWidgetPosAndSize(GralGridProperties propertiesGui,
GralRectangle parentPix,
int widthWidgetNat,
int heightWidgetNat)
Calculates the position and size of a widget from this given Pos.
|
void |
checkSetNext()
This operation should be called before usage the position.
|
GralPos |
clone()
Creates a new position instance with the same values.
|
float |
height()
Returns the height in grid position + fine position as one digit after dot.
|
java.lang.String |
posString()
Returns the position in a syntax which is able to parse
Useful to write back to a configuration file.
|
private void |
scanPosition(StringPartScan spPos,
GralPos.Coordinate co)
Scans one coordinate.
|
GralPos |
screenPos(int line,
int col,
int dy,
int dx)
Returns the position on the screen relative to the given pos
Note: the from positions should be only >0 TODO
|
void |
set(GralPos pos)
Sets all values of this with the values of pos (copy values)
|
void |
set10Position(int yPos,
int ye,
int xPos,
int xe,
char direction,
int border,
GralPos refPos)
Sets the position for the next widget to add in the container.
|
GralPos |
setAsFrame()
Mark the position as frame position for some other derived positions.
|
void |
setFinePosition(int line,
int yPosf,
int lineEndOrSize,
int yef,
int column,
int xPosf,
int columnEndOrSize,
int xef,
char direction,
int border,
int borderFrac,
GralPos refPos)
Deprecated.
use
set10Position(int, int, int, int, char, int, GralPos) for immediately replacement with 10*line + yPosf etc.
or use setPosition(GralPos, float, float, float, float, char, float) |
void |
setFullPanel(GralPanelContent panel)
Sets the position to the given full panel.
|
GralPos |
setParent(GralWidgetBase_ifc parent)
Sets a panel, maybe the
GralMng.screen as parent for the widget, where this GralPos is used. |
GralPos |
setPosition(java.lang.CharSequence sPos)
Set a new position in the same panel as given maybe relative to the own position.
|
void |
setPosition(java.lang.CharSequence sPos,
GralPos refPos)
Sets the position with the given string representation.
|
void |
setPosition(float line,
float column) |
void |
setPosition(GralPos framePos,
float line,
float lineEndOrSize,
float column,
float columnEndOrSize)
Sets the position
|
void |
setPosition(GralPos refPos,
float line,
float lineEndOrSize,
float column,
float columnEndOrSize,
char direction,
float border)
Sets the position with given grid coordinates in float.
|
void |
setPositionSize(int line,
int column,
int height,
int width,
char direction,
GralPos posFrame)
Sets a position in full grid coordinates and the size in full grid values.
|
void |
setSize(float height,
float width,
GralPos frame)
Sets the position, direction as frame, but the size as given.
|
void |
setUsed()
Marks the position as used.
|
(package private) void |
stop() |
boolean |
toResize()
Returns true if this position is from right or bottom, so that a resize of the parent needs new positions for this widget.
|
java.lang.String |
toString()
Use especially for debug.
|
java.lang.StringBuilder |
toString(java.lang.StringBuilder b,
java.lang.String... appendPanel)
Append position to given Appendable, for toString of using widgets.
|
float |
width()
Returns the width in grid position + fine position as one digit after dot.
|
float |
xGrid() |
public static final java.lang.String version
GralPos(GralPos, char)
calcWidgetPosAndSize(GralGridProperties, GralRectangle, int, int)
now uses GralRectangle
for the parent.
It is supported that the parent is any pixel region on the environment panel, not the whole panel.
This is necessary for real GralWidgComposite
without an own panel.
set10Position(int, int, int, int, char, int, GralPos)
now instead setFinePositon(...),
this is a explicitly different name to the old concept with two values for grid and fine grid position.
Designation of some operations as deprecated, comment some stuff.
screenPos(int, int, int, int)
to get a pos relative to given widget but for another window.
parent
can now be also a comprehensive widget, using GralWidgetBase_ifc
.
setAsFrame()
ToStringBuilder
for improved ToStringBuilder#toString(Appendable, String...)
GralWindow.mainPanel
#calcWidgetPosAndSize(GralGridProperties)
without more arguments.
If necessary this operation gets sizes from the parent pos. But it needs more time.
setPosition(CharSequence, GralPos)
is used.
It means, should support all features. It is refactored and yet in test. Some bugfixes including, and more features.
#setPosition(GralPos, float, float, float, float, int, char)
etc
are moved from the GralGridMngBase to this. It are methods of this class functionally. The GralGridMngBase wrappes it
because that methods should be able to call there.
same
etc. as adding values for setPosition-methods.
It prevents the necessity of a lot of special set methods. The parameter for positions may be relative, referred etc.
to the previous position or to a frame.
toString()
to see values of instance in debug
public static final int refer
public static final int same
public static final int next
public static final int nextBlock
public static final int invalidPos
public static final int useNatSize
public static final int ratio
useNatSize
have to be 0. The ratio is stored as a value from 0 to 999
in the bits 9..0. The other bits should be 0.public static final int size
public static final int samesize
public static final int areaNr
GralArea9Panel
A..C for columns, 1..3 for rowsprivate static final int mValueRange_
private static final int mValueNegative
private static final int mType_
private static final int kTypAdd_
private static final int mSpecialType
private static final int kSpecialType
private static final int XXXmCheckRatio_
private static final int XXXmNatSize_
public static final java.lang.String syntaxZbnf
position::= @ [<$?panel> ,] [ &+] [<#?yPos>[\\.<#?yPosFrac>]] [ [+] <#-?ySizeDown>[\\.<#?ySizeFrac>]| +* |] [ , [ &+] [<#?xPos>[\\.<#?xPosFrac>]] [ [+] <#-?xWidth>[\\.<#?xSizeFrac>]| +* |] [ ++] ].The semantic identifier match to the elements in
GralCfgPosition
.public GralWidgetBase_ifc parent
public final GralPos.Coordinate x
public final GralPos.Coordinate y
public boolean dbg
public GralPos(GralMng gralMng)
setPosition(float, float)
etc.public GralPos(GralWidgetBase_ifc parent)
GralPanelContent
but also a GralWidgetBase
- derived class
which is a comprehensive widget (contains a few widgets).
The initial position describes the whole area of the parent.
This initial position can be used as reference position (refPos).
setAsFrame()
for the child widgets.panel
- The given parent, a panel or comprehensive widget.public GralPos(GralPos src)
src
- the src position to copy all values.public GralPos(GralPos src, char direction)
src
- the src position to copy all values.public GralPos(GralMng mng, java.lang.String pos) throws java.text.ParseException
java.text.ParseException
public GralPos(GralWidget_ifc panel, java.lang.String pos) throws java.text.ParseException
java.text.ParseException
public void set(GralPos pos)
pos
- The src pospublic GralPos setParent(GralWidgetBase_ifc parent)
GralMng.screen
as parent for the widget, where this GralPos is used.
Note: If this is done after the position is determined by relative coordinates, the coordinates are already calculated
using the parent before, if a refPos was not given.parent
- panel for the widget where the GralPos is used.public void setFullPanel(GralPanelContent panel)
panel
- public void setPosition(float line, float column)
public void setPositionSize(int line, int column, int height, int width, char direction, GralPos posFrame)
line
- column
- height
- width
- direction
- posFrame
- public GralPos setPosition(java.lang.CharSequence sPos) throws java.text.ParseException
sPos
- See setPosition(CharSequence, GralPos)
java.text.ParseException
public void setPosition(java.lang.CharSequence sPos, GralPos refPos) throws java.text.ParseException
position::= [@] [<$?panel> ,] [ &+] [<#?yPos>[\.<#?yPosFrac>]] [ [+] <#-?ySizeDown>[\.<#?ySizeFrac>]| +* |] ##| - <#?ySizeUp>|] [ ++] [ , [ &+] [<#?xPos>[\.<#?xPosFrac>]] [ [+] <#-?xWidth>[\.<#?xSizeFrac>]| +* |] [ ++] ] : ]
sPos
- The syntax of the string see description of this class, starting with "@panel, ..." etc.
for example "@windowA, 3..5, 16+20" for absolute line 3 and 4 (exclusive 5) and from absolute column 16, size-x=20.
The position can be given without panel designation or relative, then the posParent argument is necessary.refPos
- necessary to build the absolute position from relative given sPos,
maybe null then this is used itself as reference.java.text.ParseException
- on errors of sPos or missing posParent if necessary.private void scanPosition(StringPartScan spPos, GralPos.Coordinate co) throws java.text.ParseException
[[+|%]<#?p1>[.<#p2Frac>] [..|]] <#?p2>[.<#p2Frac>]If only the right number is given, p1 is
refer
spPos
- co
- java.text.ParseException
public void setPosition(GralPos refPos, float line, float lineEndOrSize, float column, float columnEndOrSize, char direction, float border)
refPos
- The frame or last pos for relative positions.line
- The line. If the parameter lineEndOrSize is designated with size
with a negative value,
it is the bottom line for the position.
If it is designated with same
without offset and the lineEndOrSize is designated with size
with a negative value, the framePos GralPos#y.p2
is used. If it is designated
with same
but with any offset, the y
is used as refer position, it is the top line position.
Elsewhere it is the top position.lineEndOrSize
- Maybe designated with size
or samesize
column
- columnEndOrSize
- direction
- public void setPosition(GralPos framePos, float line, float lineEndOrSize, float column, float columnEndOrSize)
framePos
- The frame or last pos for relative positions.line
- The line. If the parameter lineEndOrSize is designated with size
with a negative value,
it is the bottom line for the position.
If it is designated with same
without offset and the lineEndOrSize is designated with size
with a negative value, the framePos GralPos#y.p2
is used. If it is designated
with same
but with any offset, the y
is used as refer position, it is the top line position.
Elsewhere it is the top position.lineEndOrSize
- Maybe designated with size
or samesize
column
- columnEndOrSize
- direction
- public boolean toResize()
@Deprecated public void setFinePosition(int line, int yPosf, int lineEndOrSize, int yef, int column, int xPosf, int columnEndOrSize, int xef, char direction, int border, int borderFrac, GralPos refPos)
set10Position(int, int, int, int, char, int, GralPos)
for immediately replacement with 10*line + yPosf etc.
or use setPosition(GralPos, float, float, float, float, char, float)
#setPosition(GralPos, float, float, float, float, int, char, float)
This operation is not recommended, should use the float version.
It is the old form till 2022, where the grid positions and fine positions were stored in two different variables.
The nwer variant set10Position(int, int, int, int, char, int, GralPos)
use only one value for grid and fine position
but with factor 10.public void set10Position(int yPos, int ye, int xPos, int xe, char direction, int border, GralPos refPos)
Coordinate#set(int, int, String, Coordinate)
for both coordinates.
parent
widget
or it counts from negative till ... 0 from bottom or right. For the end positions: 0 is bottom or right.
same
, next
.
It is related to the refPos or this.
samesize
,
then the end position is calculated from the start position and the size of the parent (or the given size)
refer
, ratio
, useNatSize
,
size
size
,
yPos
- start position of the spread (top)xPos
- start position of the spread (left)ye:
- end position of the spread (bottom) or the size with + size
xe
- end position of the spread (right) or the size with + size
direction:
- direction for a next widget, use 'r', 'l', 'u', 'd' for right, left, up, downborder
- border for a next position calculation.refPos
- If given, it is the base for calculation. If null, this itself is the base.public void setSize(float height, float width, GralPos frame)
height
- grid units + .fine unitswidth
- frame
- if null, it does not change the own values.public GralPos setAsFrame()
GralWidgetBase.pos()
value.
next
cannot be used.
GralPos framePos = super.pos().setAsFrame(); // from a comprehensive widget. this.mySubWdg1 = new TextField(framePos, "@2+2, 10..-10=text"); //position is related to framePos
If for that example the framePos contains "@10..20, 6..-20" inside a panel, the resulting position for the text widget is "@12+2, 16..-30" related to the panel.
This property is regarded especially in#setFinePosition(int, int, int, int, int, int, int, int, int, char, int, int, GralPos)
and also in all positioning operations.
public GralPos screenPos(int line, int col, int dy, int dx)
line
- col
- dy
- dx
- public void checkSetNext()
#setNextPosition()
is called.
This is the state where no setPosition was called after last usage.
The Position#dirNext of the x coord is set to upper case after them
to mark it for the next call of checkSetNext()
.public void setUsed()
GralPos.Coordinate.dirNext
is set to upper case.
This operation should be called (is called in GralWidgetBase.GralWidgetBase(GralPos, String, GralMng)
)
if the position is used as reference by any widget.
If it is used for a next widget without given position string,
then the called checkSetNext()
calculates the next position in the given direction.public void assertCorrectness()
public float xGrid()
public float height()
public float width()
public GralPos clone()
clone
in class java.lang.Object
@Deprecated public GralPos calcNextPos(java.lang.String posString) throws java.text.ParseException
setPosition(CharSequence)
posString
- "@parent,line, col:" syntax see description on class level.java.text.ParseException
public GralRectangle calcWidgetPosAndSize(GralGridProperties propertiesGui, GralRectangle parentPix, int widthWidgetNat, int heightWidgetNat)
GralMng#calcWidgetPosAndSize(GralPos, int, int, int, int)
,
The GralMng instance knows the propertiesGuipropertiesGui
- The properties for presentation.widthParentPixel
- width of the container. This value will be used if the position is given
from right with negative numbers.heightParentPixel
- height of the container. This value will be used if the position is given
from bottom with negative numbers.widthWidgetNat
- natural width of the component which will be positioning.
This value is used only if the pos parameter contains useNatSize
for the xe-valueheightWidgetNat
- natural height of the component which will be positioning.
This value is used only if the pos parameter contains useNatSize
for the ye-valuepublic static void appendPos(java.lang.Appendable b, int p) throws java.io.IOException
java.io.IOException
public java.lang.String posString()
public java.lang.StringBuilder toString(java.lang.StringBuilder b, java.lang.String... appendPanel)
b
- append herejava.io.IOException
- can be force RuntimeException if a StringBuilder is given as Appendablepublic java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
void stop()