public class ScreenBuffer
extends java.lang.Object
implements java.io.Externalizable
The reviewed implementation adds more control over the contents of the buffer. The total number of widgets is stored as well as the frame ID. This information allows for calculating widget index into a byte array that keeps widget state: uninitialized or changed.
Only those widgets marked as changed are present in the buffer to minimize data exchange.
Modifier and Type | Field and Description |
---|---|
private int |
baseId
Frame ID where this screen buffer belongs
|
private java.util.Map<java.lang.Integer,java.lang.Object> |
buffer
The map to store (widget ID, current value) pairs
|
static byte |
CHANGED
State flag
|
private int |
column
Value of dynamically calculated frame column.
|
private UIStatement |
currentStatement
The frame's UI statement being executed.
|
private int |
down
Rows in a dynamic down frame or -1 if no runtime override exists.
|
private WidgetConfig[] |
downConfigs
The widget configs for the current iteration in a down frame.
|
static byte |
ENTERED
State flag
|
private java.lang.String |
frameValue
Value of the last active widget.
|
private java.util.Map<java.lang.Integer,java.lang.Object> |
headers
The map to store header widget values.
|
private int |
keyCode
Key code which will be transferred in key related events.
|
private int |
line
Current frame line or -1 if it is undefined.
|
private int |
row
Value of dynamically calculated frame row.
|
private int |
size
Maximum number of entries
|
private java.util.Map<java.lang.Integer,java.lang.Byte> |
state
Per widget state map.
|
static byte |
STATE_MAX
State flag
|
static byte |
STATE_MIN
State flag
|
private java.lang.String |
title
Dynamic title text or
null for no dynamic support. |
static byte |
UNCHANGED
State flag
|
static byte |
UNINITIALIZED
State flag
|
private java.util.Map<java.lang.Integer,java.lang.Object> |
values
The map for some screen values.
|
private int |
widgetId
ID of the last active widget.
|
Constructor and Description |
---|
ScreenBuffer()
The default constructor creates a rudimentary ScreenBuffer which remains
empty.
|
ScreenBuffer(int frameId,
int numWidgets)
Constructor.
|
ScreenBuffer(int frameId,
int[] ids)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addWidget(int widgetID)
Adding new widget into screen buffer for the given widget ID.
|
private void |
bitwiseAndState(int id,
byte mask)
Makes bitwise AND operation with the given widget ID state according to mask provided.
|
void |
clearHeaders()
Removes all header values from the buffer.
|
private void |
copyState(ScreenBuffer target)
Copies the state info map from the current state to target screen buffer.
|
int |
getBaseId()
Gets the frame ID from this screen buffer.
|
ScreenBuffer |
getChanged()
Gets a new
ScreenBuffer where only widgets with the
changed values are present. |
int |
getColumn()
Get current value for dynamically calculated frame column.
|
UIStatement |
getCurrentStatement()
Get the frame's current statement.
|
int |
getDown()
Extracts the caller-specified number of rows for the associated down
frame.
|
WidgetConfig[] |
getDownConfigs()
Get the widget configs for the current frame row, in case this is a DOWN frame.
|
java.lang.String |
getFrameValue()
Get the value of the last active widget in the frame.
|
java.util.Iterator<java.lang.Integer> |
getHeaderIDIterator()
Requests the iterator to walk through the content of the header widgets.
|
java.lang.Object |
getHeaderValue(int widgetID)
Getting the header value in the Object form for the given widget ID.
|
int |
getKeyCode()
Extracts the key code for the current event.
|
int |
getLine()
Extracts the current
FRAME-LINE for the given frame. |
int |
getRow()
Get current value for dynamically calculated frame row.
|
java.lang.Object |
getScreenValue(int id)
Get current screen value.
|
byte |
getState(int widgetID)
Gets the current state for the given widget ID.
|
private byte |
getStateInt(int id)
Gets the current state for the given widget ID.
|
java.lang.String |
getTitle()
Extracts the caller-specified dynamic title for the associated frame.
|
int |
getValueWidgetId()
Get ID of the last active widget.
|
java.util.Iterator<java.lang.Integer> |
getWidgetIDIterator()
Requests the iterator to walk through the content of the screen buffer.
|
java.lang.Object |
getWidgetValue(int widgetID)
Getting the value in the Object form for the given widget ID.
|
boolean |
isEntered(int widgetID)
Checks the ENTERED state of a widget.
|
boolean |
isIdValid(int id)
Checks the ID to be used inside this screen buffer.
|
boolean |
isUninitialized(int widgetID)
Checks the UNINITIALIZED state of a widget.
|
void |
mergeChanged(ScreenBuffer diff)
Merges this ScreenBuffer with the changed widgets from the specified
one.
|
void |
putColumn(int column)
Store new value for dynamically calculated frame column.
|
void |
putDown(int down)
Stores the caller-specified number of rows for the associated down
frame for client-server transfer.
|
void |
putHeaderValue(int widgetID,
java.lang.Object value)
Storing the new header value for the given widget ID.
|
void |
putKeyCode(int keyCode)
Stores the key code for a client-server transfer.
|
void |
putLine(int line)
Stores the current
FRAME-LINE for the given frame. |
void |
putRow(int row)
Store new value for dynamically calculated frame row.
|
void |
putScreenValue(int id,
java.lang.Object screenValue)
Set screen value for specified widget.
|
void |
putTitle(java.lang.String title)
Sets the caller-specified dynamic title for the associated frame.
|
void |
putWidgetValue(int widgetID,
java.lang.Object value)
Storing the new value for the given widget ID.
|
void |
putWidgetValue(int widgetID,
java.lang.Object value,
boolean preserveState)
Storing the new value for the given widget ID.
|
void |
readExternal(java.io.ObjectInput in)
Replacement for the default object reading method.
|
void |
removeWidget(int widgetID)
Removing existed widget from screen buffer for the given widget ID.
|
void |
reset()
Resets all widgets to the UNINITIALIZED state.
|
void |
resetChanged()
Resets all widgets having CHANGED state.
|
void |
resetEntered(int[] ids)
Resets all widgets having ENTERED state.
|
void |
setCurrentStatement(UIStatement stmt)
Set the frame's current statement, to transport it to the client-side.
|
void |
setDownConfigs(WidgetConfig[] wcfgs)
Used by client-side to set the widget configs for the current frame row.
|
void |
setFrameValue(java.lang.String frameValue)
Save the value of the last active widget in the frame.
|
void |
setState(int widgetID,
byte state)
Stores the new state for the widget with the given widget ID.
|
private void |
setStateInt(int id,
byte stateNew)
Stores the new state for the widget with the given widget ID.
|
void |
setValueWidgetId(int widgetID)
Save the ID of last active widget.
|
int |
size()
Gets the maximum size of this screen buffer.
|
java.lang.String[] |
view()
Debugging Aid.
|
void |
writeExternal(java.io.ObjectOutput out)
Replacement for the default object writing method.
|
public static final byte STATE_MIN
public static final byte UNCHANGED
public static final byte UNINITIALIZED
public static final byte CHANGED
public static final byte ENTERED
public static final byte STATE_MAX
private int baseId
private int size
private java.util.Map<java.lang.Integer,java.lang.Byte> state
private java.util.Map<java.lang.Integer,java.lang.Object> buffer
private java.util.Map<java.lang.Integer,java.lang.Object> headers
private java.util.Map<java.lang.Integer,java.lang.Object> values
private int keyCode
private int down
private int line
private int column
private int row
private java.lang.String title
null
for no dynamic support.private java.lang.String frameValue
private int widgetId
private WidgetConfig[] downConfigs
private UIStatement currentStatement
public ScreenBuffer()
public ScreenBuffer(int frameId, int numWidgets)
frameId
- the ID of the frame where this ScreenBuffer belongsnumWidgets
- the total number of widgets in the framepublic ScreenBuffer(int frameId, int[] ids)
frameId
- the ID of the frame where this ScreenBuffer belongsids
- the array of the widget IDs to put inside the bufferpublic int size()
public int getBaseId()
public void addWidget(int widgetID)
widgetID
- The ID of the widget to be added.public void removeWidget(int widgetID)
widgetID
- The ID of the widget to be added.public void putWidgetValue(int widgetID, java.lang.Object value)
widgetID
- The ID of the widget to which the data is related.value
- New value as an Object instance.public void putWidgetValue(int widgetID, java.lang.Object value, boolean preserveState)
widgetID
- The ID of the widget to which the data is related.value
- New value as an Object instance.preserveState
- Flag indicating if the widget's state is preserved.
When false
, the widget state is set to CHANGED
. Otherwise
it remains unchanged.public void putHeaderValue(int widgetID, java.lang.Object value)
widgetID
- The ID of the widget to which the data is related.value
- New value as an Object instance.public byte getState(int widgetID)
widgetID
- The ID of the widget to which the data is related.-1
if such ID does not
exist.public void setState(int widgetID, byte state)
widgetID
- The ID of the widget to which the data is related.state
- new statepublic java.util.Iterator<java.lang.Integer> getWidgetIDIterator()
public java.util.Iterator<java.lang.Integer> getHeaderIDIterator()
public java.lang.Object getWidgetValue(int widgetID)
widgetID
- The numeric ID of a widget whose value must be returned.public java.lang.Object getHeaderValue(int widgetID)
widgetID
- The numeric ID of a widget whose value must be returned.public void putScreenValue(int id, java.lang.Object screenValue)
id
- Widget id.screenValue
- Widget screen value.public java.lang.Object getScreenValue(int id)
id
- Widget id.public void putKeyCode(int keyCode)
keyCode
- The P2J key code for the current event.public int getKeyCode()
public void putDown(int down)
down
- The number of rows in the frame or 0 for forcing a calculated
value or -1 for no dynamic override of the down size.public int getDown()
public void putLine(int line)
FRAME-LINE
for the given frame.line
- The frame line or -1 for undefined.public int getLine()
FRAME-LINE
for the given frame.public void putRow(int row)
row
- The new value for the frame row or -1 for no explicit value.public int getRow()
public void putColumn(int column)
column
- The new value for the frame column or -1 for no explicitly
set value.public int getColumn()
public void putTitle(java.lang.String title)
title
- The current value of the dynamic title text or
null
if no dynamic title support exists for this
frame.public java.lang.String getTitle()
null
if no dynamic title support exists for this
frame.public ScreenBuffer getChanged()
ScreenBuffer
where only widgets with the
changed values are present. As a side effect the current instance's
CHANGED
flags are reset.ScreenBuffer
public void mergeChanged(ScreenBuffer diff)
diff
- a differential ScreenBuffer
to copy widget values
from.public void resetEntered(int[] ids)
ids
- Array of IDs of entered widgets.public void resetChanged()
public void reset()
public boolean isEntered(int widgetID)
widgetID
- The ID of the widget to which the data is related.true
if the widget has been modified during the
last input operation.public boolean isUninitialized(int widgetID)
widgetID
- The ID of the widget to which the data is related.true
if the widget is in the uninitialized state.public java.lang.String getFrameValue()
public void setFrameValue(java.lang.String frameValue)
frameValue
- The frame value to set.public int getValueWidgetId()
-1
if no such widget was
detected.public void setValueWidgetId(int widgetID)
widgetID
- The widgetId to set.public void setCurrentStatement(UIStatement stmt)
stmt
- The UIStatement
.public UIStatement getCurrentStatement()
currentStatement
.public void clearHeaders()
public java.lang.String[] view()
public void setDownConfigs(WidgetConfig[] wcfgs)
wcfgs
- The widget configs.public WidgetConfig[] getDownConfigs()
null
if no configs are transferred by the client-side.public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
in
- The input source from which fields will be restored.java.io.IOException
- In case of I/O errors.java.lang.ClassNotFoundException
- If payload can't be instantiated.public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
out
- The output destination to which fields will be saved.java.io.IOException
- In case of I/O errors.public boolean isIdValid(int id)
id
- The ID of the widget to verify.true
if the widget ID can be used inside this screen buffer
false
otherwise.private void bitwiseAndState(int id, byte mask)
id
- The ID of the widget to reset status.mask
- The mask to perform bitwise and operation with the current one.private byte getStateInt(int id)
id
- The ID of the widget to which the state byte to be returned.UNINITIALIZED
if such ID does not exist in
current state map.private void setStateInt(int id, byte stateNew)
id
- The ID of the widget to which the state byte is to be stored.stateNew
- new stateprivate void copyState(ScreenBuffer target)
target
- a ScreenBuffer
to copy state map info to.