public abstract class OutputManager<P extends OutputPrimitives>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private boolean |
batchModeOverride
Batch mode client override flag.
|
static java.lang.String |
CHUI_DRIVER_BATCH
CHUI batch mode driver name.
|
static java.lang.String |
CHUI_DRIVER_CONSOLE
CHUI native driver name.
|
static java.lang.String |
CHUI_DRIVER_SWING
CHUI swing driver name.
|
static java.lang.String |
CHUI_DRIVER_WEB
CHUI web driver name.
|
private CoordinatesConversion |
coordinates
The output manager's coordinate logic implementation
|
protected boolean |
debug
Flag to enable debug messages.
|
protected P |
defaultOutput
Default (direct) drawing routines.
|
protected static ContextLocal<OutputManager<?>> |
defaultTerminal
Context local instance of the default terminal manager.
|
protected boolean |
drawing
Reflects drawing in progress to avoid recursion.
|
protected ScreenDriver<?> |
driver
Active screen driver.
|
static java.lang.String |
GUI_DRIVER_SWING
GUI swing driver name.
|
static java.lang.String |
GUI_DRIVER_WEB
GUI web driver name.
|
protected int |
invalidate
The state of invalidation.
|
protected P |
output
Current drawing routines.
|
Modifier | Constructor and Description |
---|---|
protected |
OutputManager(ScreenDriver<? extends OutputManager<?>> driver)
Create a new output manager instance, with the specified driver.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
activateBatch(boolean on)
Changes the status of the active flag in batch mode if screen drives is in batch mode.
|
void |
activateWindow(TopLevelWindow<?> window)
Activates the provided window instance, depending on the output manager type.
|
void |
beep()
Generate beep signal.
|
void |
clear(int windowId,
NativePoint origin,
NativeDimension size,
Color color)
Clear specified area of the screen.
|
void |
clear(int windowId,
Point origin,
Dimension size,
Color color)
Clear specified area of the screen.
|
abstract void |
clear(Widget<?> widget)
Clear area occupied by specified widget.
|
OutputManager<?> |
clipWith(int windowId,
Rectangle rect)
Add a new clipping rectangle to the bitmap.
|
CoordinatesConversion |
coordinates()
Returns the output manager's coordinates conversion logic implementation.
|
boolean |
drawNeeded(int windowId,
Rectangle rect)
Check if the given location can draw data.
|
protected NativeRectangle |
fixCoordinates(int windowId,
NativeRectangle rect)
Fix the coordinates for the given rectangle.
|
ScreenBitmap |
getAndResetBitmap(int windowId)
Get a copy of the current screen bitmap and reset clipping entirely.
|
ScreenBitmap |
getAndSetBitmap(int windowId,
Rectangle rect)
Get a copy of the current screen bitmap and clip output further so it is
guaranteed not to go outside of the provided rectangle.
|
ScreenBitmap |
getBitmapCopy(int windowId)
Get a copy of the current screen bitmap.
|
java.util.List<NativeRectangle> |
getClippings(int windowId,
NativeRectangle nbounds)
Get the list of clipping rectangles intersecting the specified boundary.
|
java.util.List<Rectangle> |
getClippings(int windowId,
Rectangle bounds)
Get the list of clipping rectangles intersecting the specified boundary.
|
static ScreenDriver<?> |
getDriver()
Access the current UI driver instance.
|
abstract WidgetFactory |
getFactory()
Access driver-specific widget factory.
|
ScreenDriver<?> |
getInstanceDriver()
Access the instance UI driver.
|
P |
getInteractiveOutput()
Obtain the interactive output worker.
|
int |
getInvalidChars(int windowId)
Get the total number of available clipped characters, from the search
bitmap screen.
|
abstract WidgetRegistry<? extends OutputManager<?>> |
getRegistry()
Get the widget registry for this output manager.
|
static boolean |
inBatchMode()
Checks if the client is running in batch mode.
|
void |
init()
Initialize this output manager.
|
static void |
init(BootstrapConfig cfg,
ScreenDriver driver)
Initialize driver.
|
static void |
initErrorWriter()
Initializes the proper error writer handler.
|
static void |
initErrorWriter(Session session)
Initializes the proper error writer handler.
|
static OutputManager<? extends OutputPrimitives> |
instance()
Get the context-specific instance, if it exists.
|
static boolean |
isBatchInBackground()
Checks batch mode background flag.
|
private static boolean |
isBatchModeForced(BootstrapConfig cfg)
Check if the batch mode is overridden via bootstrap config.
|
boolean |
isBatchModeOverride()
Checks batch mode overridding flag.
|
boolean |
isChui()
Get screen interface type.
|
boolean |
isInvalidate()
Queries the invalidation mode.
|
boolean |
isRedirected()
Reports if the terminal is currently redirected to a stream.
|
boolean |
markArea(int windowId,
Rectangle rect)
Mark a certain area as searched and decrement the total number of
clipped characters.
|
static OutputManager<? extends OutputPrimitives> |
newInstance(BootstrapConfig cfg,
ScreenDriver<?> driver)
Force construction of a new instance.
|
protected abstract TitledWindow<?> |
overrideWindow(TopLevelWindow<?> window)
Check if the window being drawn needs to be overridden.
|
protected abstract boolean |
raiseStopCondition(int key)
Check if the given key can raise the STOP condition.
|
int |
readKey()
Read single keystroke from driver.
|
void |
realizeWindow(int windowId)
Realize new window, depending on the output manager type.
|
void |
refresh(int windowId,
Rectangle rect)
Mark a rectangle as needing repainting.
|
void |
releaseWindow()
On a device which allows multiple windows to be created, this allows releasing the window to
allow drawing from other threads.
|
void |
resetBitmap(int windowId)
Reset the screen bitmap.
|
void |
resetInvalidate(Widget<?> widget)
Resets the invalidation mode.
|
void |
resetMode()
Reset current screen mode.
|
static Widget<? extends OutputManager<?>> |
resolveWidget(int wid)
Resolve the widget with the specified ID.
|
void |
restoreInvalidate(int savedLevel)
Restores the invalidation mode.
|
void |
resume()
Resume normal driver operation.
|
int |
saveInvalidate(Widget<?> widget)
Returns and resets the invalidation mode.
|
protected ScreenBitmap |
screenBitmap(int windowId)
Determine the screen bitmap associated with the given window.
|
Dimension |
screenDimension(int windowId)
Get screen dimensions.
|
double |
screenHeight(int windowId)
Gets the number of rows on the screen.
|
double |
screenWidth(int windowId)
Gets the number of columns on the screen.
|
void |
selectWindow(int windowId)
On a device which allows multiple windows to be created, this allows selecting an explicit
window before using the primitives or before drawing a widget.
|
OutputManager<?> |
setBitmap(int windowId,
ScreenBitmap bitmap)
Restore the bitmap to a previous state.
|
boolean |
setCursorStatus(boolean on)
Set cursor status (ON/OFF).
|
void |
setDrawingArea(Rectangle bounds)
Limit available the drawing area to the specified boundaries.
|
void |
setInvalidate(boolean mode)
Sets the invalidation mode.
|
void |
setInvalidate(Widget<?> widget,
boolean mode)
Sets the invalidation mode.
|
void |
setInvalidate(Widget<?> widget,
boolean mode,
boolean flush)
Sets the invalidation mode.
|
void |
setTerminalType(java.lang.String name)
Change terminal type to specified one.
|
void |
startScreenSearch(int windowId)
Create a copy of this screen bitmap and count the invalid chars.
|
void |
suspend()
Suspend output.
|
P |
switchOutput(P newOps)
Redirect terminal output to the drawing worker represented by
newOps (or back to the interactive terminal if
newOps is null ) and return the instance
representing the current output destination. |
OutputManager<?> |
sync(int windowId)
Synchronize output with physical terminal.
|
java.lang.String |
terminalType()
Get terminal type.
|
public static final java.lang.String CHUI_DRIVER_CONSOLE
public static final java.lang.String CHUI_DRIVER_SWING
public static final java.lang.String CHUI_DRIVER_WEB
public static final java.lang.String CHUI_DRIVER_BATCH
public static final java.lang.String GUI_DRIVER_SWING
public static final java.lang.String GUI_DRIVER_WEB
protected static final ContextLocal<OutputManager<?>> defaultTerminal
protected boolean debug
protected P extends OutputPrimitives defaultOutput
protected P extends OutputPrimitives output
protected int invalidate
protected boolean drawing
protected ScreenDriver<?> driver
private boolean batchModeOverride
private CoordinatesConversion coordinates
protected OutputManager(ScreenDriver<? extends OutputManager<?>> driver)
driver
- Implements low level input/output primitives. Must NOT be null
.public static void init(BootstrapConfig cfg, ScreenDriver driver) throws java.lang.InterruptedException, java.lang.reflect.InvocationTargetException
cfg
- The bootstrap configuration file.driver
- Implements low level input/output primitives. This MAY be
null
on the first invocation BUT it MUST NOT
be null
on re-initializations.java.lang.InterruptedException
java.lang.reflect.InvocationTargetException
public static OutputManager<? extends OutputPrimitives> newInstance(BootstrapConfig cfg, ScreenDriver<?> driver) throws java.lang.InterruptedException, java.lang.reflect.InvocationTargetException
cfg
- The bootstrap configuration file.driver
- Implements low level input/output primitives. This MAY be
null
on the first invocation BUT it MUST NOT
be null
on re-initializations.java.lang.InterruptedException
java.lang.reflect.InvocationTargetException
public static Widget<? extends OutputManager<?>> resolveWidget(int wid)
wid
- The widget ID.public static OutputManager<? extends OutputPrimitives> instance()
null
if none exists.public static ScreenDriver<?> getDriver()
null
if the output manager
is not initialized.public ScreenDriver<?> getInstanceDriver()
null
if the output manager
is not initialized.public static void initErrorWriter()
public static void initErrorWriter(Session session)
session
- The server session to get the properties.public boolean isBatchModeOverride()
true
batch mode is overridden, false
otherwise.public static boolean isBatchInBackground()
true
batch mode is running in background, false
otherwise.public static boolean activateBatch(boolean on)
on
- The new value of the active flag in batch mode.true
if operation was successful, false
otherwise.public static boolean inBatchMode()
true
for batch mode, false
otherwise.private static boolean isBatchModeForced(BootstrapConfig cfg)
cfg
- The bootstrap configuration file.true
if batch mode overridden, false
otherwise.public abstract void clear(Widget<?> widget)
widget
- Reference widget.public abstract WidgetFactory getFactory()
public abstract WidgetRegistry<? extends OutputManager<?>> getRegistry()
protected abstract boolean raiseStopCondition(int key)
key
- The key code to be checked.true
if the key can raise a STOP condition.protected abstract TitledWindow<?> overrideWindow(TopLevelWindow<?> window)
window
- The currently active window.public void activateWindow(TopLevelWindow<?> window)
window
- A window.public void realizeWindow(int windowId)
windowId
- A window ID to be realized.public void init()
public OutputManager<?> setBitmap(int windowId, ScreenBitmap bitmap)
windowId
- The window ID.bitmap
- The bitmap instance to set as the output primitive's bitmap.public boolean setCursorStatus(boolean on) throws java.lang.IllegalStateException
on
- New cursor state.true
if operation was successful.java.lang.IllegalStateException
public void clear(int windowId, Point origin, Dimension size, Color color)
windowId
- The window ID.origin
- Upper left corner of the area to clear.size
- Dimensions of the area.color
- Color.public void clear(int windowId, NativePoint origin, NativeDimension size, Color color)
windowId
- The window ID.origin
- Upper left corner of the area to clear.size
- Dimensions of the area.color
- Color.public void beep()
public int readKey()
public void resetMode()
public void suspend()
public void resume()
public void setTerminalType(java.lang.String name)
name
- New terminal type name.public java.lang.String terminalType()
public P switchOutput(P newOps)
newOps
(or back to the interactive terminal if
newOps
is null
) and return the instance
representing the current output destination. This may be another
null
if the interactive terminal is in use.newOps
- The drawing worker or null
to remove redirections
and activate the interactive terminal.public boolean isRedirected()
true
if the terminal is redirected to a stream,
false
if the terminal is interactive.public P getInteractiveOutput()
public double screenWidth(int windowId)
windowId
- The window ID.public double screenHeight(int windowId)
windowId
- The window ID.public Dimension screenDimension(int windowId)
windowId
- The window ID.public void resetBitmap(int windowId)
windowId
- The window ID.public ScreenBitmap getAndResetBitmap(int windowId)
windowId
- The window ID.public ScreenBitmap getAndSetBitmap(int windowId, Rectangle rect)
windowId
- The window ID.rect
- The extra clipping rectangle. null
has no effect
on clipping.public ScreenBitmap getBitmapCopy(int windowId)
windowId
- The window ID.public void refresh(int windowId, Rectangle rect)
windowId
- The window ID.rect
- rectangle to mark for repaintingpublic OutputManager<?> sync(int windowId)
windowId
- The window ID.this
to enable chaining.public OutputManager<?> clipWith(int windowId, Rectangle rect)
true
values. Else, if the
bitmap was just reset, fill it with false
values and set
the clipping region to true.windowId
- The window ID.rect
- The clipping rectangle to be added.this
to enable chaining.public void startScreenSearch(int windowId)
windowId
- The window ID.public int getInvalidChars(int windowId)
windowId
- The window ID.public java.util.List<Rectangle> getClippings(int windowId, Rectangle bounds)
windowId
- The window ID.bounds
- The boundary.public java.util.List<NativeRectangle> getClippings(int windowId, NativeRectangle nbounds)
windowId
- The window ID.nbounds
- The boundary.public boolean markArea(int windowId, Rectangle rect)
windowId
- The window ID.rect
- Area to mark as searched.true
if this area contains a clipped character,
which was not part of an upper widget.public boolean drawNeeded(int windowId, Rectangle rect)
windowId
- The window ID.rect
- The area of the widget which is checked for drawing.true
if screen is reset or any of the bitmap
locations within the given rectangle are true
false
if nothing can be drawn.public void setInvalidate(boolean mode)
When invalidation mode is set to true
, all
PaintEvent
s are processed differently. Instead of causing
immediate drawing, they contribute their respective rectangles to the
invalidation rectangle. The moment the invalidation mode is being set to
false
, the cumulative invalidation rectangle triggers
selective redrawing of the affected area.
mode
- true
is an opening bracket for the invalidation
mode false
is a closing bracket which
conditionally flushes the accumulated paint requestspublic void setInvalidate(Widget<?> widget, boolean mode)
When invalidation mode is set to true
, all
PaintEvent
s are processed differently. Instead of causing
immediate drawing, they contribute their respective rectangles to the
invalidation rectangle. The moment the invalidation mode is being set to
false
, the cumulative invalidation rectangle triggers
selective redrawing of the affected area.
widget
- The widget which triggered this painting.mode
- true
is an opening bracket for the invalidation
mode false
is a closing bracket which
conditionally flushes the accumulated paint requestsjava.lang.NullPointerException
- If mode
is false and the widget
is null
.public void setInvalidate(Widget<?> widget, boolean mode, boolean flush)
When invalidation mode is set to true
, all
PaintEvent
s are processed differently. Instead of causing
immediate drawing, they contribute their respective rectangles to the
invalidation rectangle. The moment the invalidation mode is being set to
false
, the cumulative invalidation rectangle triggers
selective redrawing of the affected area.
widget
- The widget which triggered this drawing. If is null
, the window
as returned by WindowManager.findWindow(int)
will be used; otherwise, the
widget's window will be used.mode
- true
is an opening bracket for the invalidation
mode false
is a closing bracket which
conditionally flushes the accumulated paint requestsflush
- only meaningful for mode false
. requests
unconditional flushing of all accumulated paint requestspublic void resetInvalidate(Widget<?> widget)
widget
- The widget which triggered this painting.public int saveInvalidate(Widget<?> widget)
widget
- The widget which triggered this painting.public void restoreInvalidate(int savedLevel)
savedLevel
- saved current invalidation levelpublic boolean isInvalidate()
true
if invalidation is onpublic boolean isChui()
true
is ChUI false
is GUIpublic void setDrawingArea(Rectangle bounds)
By default this is a no-op.
bounds
- The bounds for the drawing area.public CoordinatesConversion coordinates()
CoordinatesConversion
instance.protected NativeRectangle fixCoordinates(int windowId, NativeRectangle rect)
null
; this means the rectangle
should not be fixed, as it refers to an area outside the screen.windowId
- The window ID.rect
- The rectangle which needs its coordinates fixed.null
if the rectangle is referring to an area
outside the screen.protected ScreenBitmap screenBitmap(int windowId)
After this call, the output
will have selected the specified window.
WARNING! If the ScreenBitmap
reference is saved and a code is called which in turn
ends up changing the ScreenBitmap
reference (via the setBitmap(int, com.goldencode.p2j.ui.client.ScreenBitmap)
API), then
ensure the proper reference is used!
windowId
- The window ID.ScreenBitmap
associated with this window.public void selectWindow(int windowId)
windowId
- Window ID.public void releaseWindow()