public class SwingEmulatedWindow extends EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
Modifier and Type | Field and Description |
---|---|
private java.util.Deque<java.awt.Shape> |
clippings
A stack of clipping rectangles.
|
private int |
clips
Tracks clipping operations.
|
private boolean |
DEBUG_LIST_PRIMITIVES
Debugging conditional.
|
private java.awt.Stroke |
dotLargeStroke
Large dotted line pattern.
|
private java.awt.Stroke |
dotSmallStroke
Small dotted line pattern.
|
private java.awt.Stroke |
dotSmallThinStroke
Small and thin dotted line pattern.
|
private java.awt.Stroke |
dotStroke
Dotted line pattern.
|
private BufferedImageDrawHelper |
drawHelper
Helper to generate image wrappers.
|
private java.awt.image.BufferedImage |
highlightRestoreBuffer
Screen buffer for clearing an active highlight
|
private int |
highlightX
The left location of the last highlighted widget.
|
private int |
highlightY
The top location of the last highlighted widget.
|
private int |
openBatches
Tracks open batch brackets.
|
private ContentPane |
pane
Content pane for the window.
|
private boolean |
prevEnabled
The original window enabled state when enableEvents(false) is called.
|
private java.awt.image.BufferedImage |
readyScreen
The off-screen image ready to be bitblt to to screen.
|
private java.util.Map<java.lang.Class<? extends java.util.EventListener>,java.util.List<java.util.EventListener>> |
savedListeners
Map of saved event listeners, which can be restored at a later time.
|
private int |
trans
Tracks translate operations.
|
private int |
translateX
The X translated location of the drawing area, on the physical canvas.
|
private int |
translateY
The Y translated location of the drawing area, on the physical canvas.
|
private java.awt.Window |
window
Containing window (may be an applet or application frame/dialog).
|
private java.awt.Graphics2D |
workingGraphics
The current off-screen graphic context for the working screen.
|
private java.awt.image.BufferedImage |
workingScreen
The working off-screen image.
|
LOG, mouseHandler, windowId
Constructor and Description |
---|
SwingEmulatedWindow(java.awt.Window window,
SwingKeyboardReader keyReader)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private void |
clearHighlightWorker(java.awt.Graphics2D g2)
This is the worker method for restoring the screen area previously highlighted by
drawHighlightWorker(int, int, int, int, ColorRgb, Graphics2D) . |
private int |
convertFontStyle(FontStyle style)
Convert the generic font style to a Swing font style.
|
void |
draw(PaintStructure<java.awt.Font,java.awt.image.BufferedImage> ps)
Draw using a paint operation.
|
private void |
drawHighlightWorker(int x,
int y,
int width,
int height,
ColorRgb color,
java.awt.Graphics2D g2)
This is the worker method for drawing a highlighted rectangular area of the specified
color and bounds.
|
private void |
drawString(PaintStructure<java.awt.Font,java.awt.image.BufferedImage> ps,
java.awt.Graphics2D g2)
Draw a string using the current font.
|
private void |
drawStringScaled(PaintStructure<java.awt.Font,java.awt.image.BufferedImage> ps,
java.awt.Graphics2D g2)
Draw a string using the current font, which will be scaled so that the final string will
have the specified legacy width and height.
|
void |
enableEvents(boolean capture)
Enable or Disable OS-level events for the specified windows.
|
private void |
enableEventsImpl(boolean capture)
Enable or Disable OS-level events for the specified windows.
|
void |
flush()
Render the given paint operation.
|
BufferedImageDrawHelper |
getBufferedImageDrawHelper()
Gets the instanve of the helper to work with buffered images.
|
(package private) java.awt.Window |
getContainingWindow()
Obtain the containing window for the terminal simulator.
|
(package private) ContentPane |
getContentPane()
Obtain the content pane for the terminal simulator.
|
NativeRectangle |
getDisplayBounds()
Returns bounds of a physical screen the top-level window this instance
represents is positioned on.
|
NativeRectangle |
getDisplayWorkArea()
Returns an application-usable display area.
|
FontMetricsHelper |
getFontMetrics(FontDetails<java.awt.Font> f)
Get the metrics of the given font.
|
int |
getHeight()
Get the window height.
|
private java.awt.FontMetrics |
getNativeFontMetrics(java.awt.Font font)
Get the metrics of the given font.
|
int |
getParagraphHeight(java.lang.String text,
FontDetails<java.awt.Font> font,
int maxWidth)
The method performs a layout operation on the supplied text and
returns the resulting paragraph height while maintaining the
supplied maximum width.
|
int |
getTextHeight(java.lang.String text,
FontDetails<java.awt.Font> f)
Get the height of the specified text, using the given font.
|
int |
getWidth()
Get the window width.
|
NativePoint |
getWindowLocation()
Get the window location on screen.
|
private java.awt.Graphics2D |
getWorkingGraphics()
Obtain the current graphic context for working off screen image.
|
boolean |
isWindowVisible()
Check if the simulated window is visible.
|
private int |
layoutParagraphWorker(java.awt.Graphics2D g2,
java.lang.String text,
FontDetails<java.awt.Font> font,
int maxWidth,
boolean draw,
int x,
int y)
The method performs a layout operation on the supplied text and
returns the resulting paragraph height while maintaining the
supplied maximum width.
|
protected java.lang.Object |
lock()
Obtain the lock object that can be used to synchronize drawing operations.
|
(package private) void |
moveToBottom()
Move this window to the bottom of the z-order, at the OS level.
|
(package private) void |
moveToTop(boolean focus)
Move this window to top of the z-order, at the OS level.
|
void |
offer(PaintStructure ps)
Add a new
PaintStructure to be drawn. |
void |
quit()
Cause the outer frame to be disposed, as the window is being terminated.
|
void |
repaint()
Cause repaint processing to occur.
|
private void |
resizeScreenBuffers(int width,
int height)
Resize the screen buffers so that they will have the new width/height.
|
void |
resizeWindow(int width,
int height)
Resize window.
Because of swing constraints, the effective command is executed on Swing dispatch thread. |
private static void |
safeInvokeAndWait(java.lang.Runnable code)
The method invokes the supplied runnable on the Swing event dispatch
thread (EDT) by calling
SwingUtilities.invokeAndWait(Runnable) . |
void |
setCursor(java.awt.Cursor c)
Set the mouse cursor to the given one.
|
void |
setCursor(CursorType type)
Set the mouse cursor to the given type.
|
void |
setIconificationState(boolean iconify)
Manage any window state related to iconification.
|
void |
setWindowBounds(int left,
int top,
int width,
int height)
Set new bounds for this window.
Because of swing constraints, the effective command is executed on Swing dispatch thread. |
void |
setWindowEnabled(boolean enable)
Set the window' sensitive state, depending on the
enable flag. |
void |
setWindowLocation(int left,
int top)
Set window location.
|
void |
setWindowVisible(boolean visible)
Hide or show the window, depending on the
visible flag. |
deiconifyWindow, drawOnScreenBitmap, endBatch, getMouseHandler, getScreenBitmap, getWindowId, iconifyWindow, isIconified, screenHeight, screenWidth, setScreenBitmap, setWindowId
private java.util.Map<java.lang.Class<? extends java.util.EventListener>,java.util.List<java.util.EventListener>> savedListeners
private ContentPane pane
private java.awt.image.BufferedImage readyScreen
private java.awt.image.BufferedImage workingScreen
BATCH
is in progress, the stack of
PaintStructure
s is drawn as the primitives are issued. The image is not flushed to
readyScreen
until the batch is over.private java.awt.Graphics2D workingGraphics
private int openBatches
readyScreen
image because some widgets my be incorrectly
(incompletely) drawn.private int clips
private int trans
private java.util.Deque<java.awt.Shape> clippings
private int translateX
private int translateY
private java.awt.image.BufferedImage highlightRestoreBuffer
private int highlightX
private int highlightY
private java.awt.Window window
private java.awt.Stroke dotStroke
private java.awt.Stroke dotSmallStroke
private java.awt.Stroke dotSmallThinStroke
private java.awt.Stroke dotLargeStroke
private final BufferedImageDrawHelper drawHelper
private boolean prevEnabled
private boolean DEBUG_LIST_PRIMITIVES
true
all draw primitives are listed to console.public SwingEmulatedWindow(java.awt.Window window, SwingKeyboardReader keyReader)
window
- Application window.keyReader
- The key reader
which listens for incoming keys.public void quit()
quit
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
public void repaint()
repaint
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
public void offer(PaintStructure ps)
PaintStructure
to be drawn.offer
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
ps
- A new PaintStructure instance.public void setWindowVisible(boolean visible)
visible
flag.setWindowVisible
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
visible
- The window visibility state.public void setWindowLocation(int left, int top)
setWindowLocation
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
left
- left coordinatetop
- top coordinatepublic void resizeWindow(int width, int height)
resizeWindow
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
width
- New width.height
- New heightpublic void setWindowBounds(int left, int top, int width, int height)
setWindowBounds
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
width
- New width.height
- New heightpublic void setWindowEnabled(boolean enable)
enable
flag.setWindowEnabled
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
enable
- The window sensitive state.public boolean isWindowVisible()
isWindowVisible
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
public NativePoint getWindowLocation()
getWindowLocation
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
public int getHeight()
getHeight
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
public int getWidth()
getWidth
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
public void setIconificationState(boolean iconify)
setIconificationState
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
iconify
- true
if this window is being iconified, false
for
de-iconified.public void setCursor(CursorType type)
type
- The cursor type.public void setCursor(java.awt.Cursor c)
c
- The custom cursor.public void enableEvents(boolean capture)
enableEvents
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
capture
- Flag indicating OS level events are captured (when true
).private void enableEventsImpl(boolean capture)
capture
- Flag indicating OS level events are captured (when true
).public FontMetricsHelper getFontMetrics(FontDetails<java.awt.Font> f)
getFontMetrics
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
f
- The font for which the font metrics are to be obtained.public int getTextHeight(java.lang.String text, FontDetails<java.awt.Font> f)
getTextHeight
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
text
- The text.f
- The font used to draw and measure the text.public int getParagraphHeight(java.lang.String text, FontDetails<java.awt.Font> font, int maxWidth)
Note that the algorithm for text layout is compatible with
PaintPrimitives.DRAW_PARAGRAPH
and so
can be used in conjunction with this method.
getParagraphHeight
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
text
- The text to measure.font
- The font to use during layout.maxWidth
- The maximum paragraph width.public void draw(PaintStructure<java.awt.Font,java.awt.image.BufferedImage> ps)
draw
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
ps
- Paint operation parameters.public NativeRectangle getDisplayBounds()
TopLevelWindow
.
For single-display setups the top-left corner of the returned rectangle is always 0,0. For multiple-display setups it can be 0,0 or positive.
getDisplayBounds
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
public NativeRectangle getDisplayWorkArea()
getDisplayWorkArea
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
public void flush()
flush
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
public BufferedImageDrawHelper getBufferedImageDrawHelper()
getBufferedImageDrawHelper
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
protected java.lang.Object lock()
lock
in class EmulatedWindowState<java.awt.Font,java.awt.image.BufferedImage>
java.awt.Window getContainingWindow()
ContentPane getContentPane()
void moveToTop(boolean focus)
focus
- true
to force the window to request the focus.void moveToBottom()
private java.awt.FontMetrics getNativeFontMetrics(java.awt.Font font)
workingGraphics
have been obtained, call
the getFontMetrics(com.goldencode.p2j.ui.client.FontDetails<java.awt.Font>)
and the graphics object. Otherwise, use the simulator's
graphics.font
- The font for which the font metrics are to be obtained.private void resizeScreenBuffers(int width, int height)
This will be a no-op if either the width or the height is not a positive number.
width
- The new width.height
- The new height.private int convertFontStyle(FontStyle style)
style
- The font style to convert.private void drawStringScaled(PaintStructure<java.awt.Font,java.awt.image.BufferedImage> ps, java.awt.Graphics2D g2)
Once this API is finished, the graphic's font is restored to its state as before the call.
ps
- The structure with the drawing details.g2
- graphic context for operationprivate void drawString(PaintStructure<java.awt.Font,java.awt.image.BufferedImage> ps, java.awt.Graphics2D g2)
ps
- The structure with the drawing details.g2
- Graphic context for operationprivate int layoutParagraphWorker(java.awt.Graphics2D g2, java.lang.String text, FontDetails<java.awt.Font> font, int maxWidth, boolean draw, int x, int y)
Note that the algorithm for text layout is compatible with
PaintPrimitives.DRAW_PARAGRAPH
and so
can be used in conjunction with this method.
g2
- Graphics2D reference.text
- The text to measure.font
- The font to use during layout.maxWidth
- The maximum paragraph width.draw
- When false
the method performs
only the layout part and does not render
the text on the output device.x
- The drawing x position, ignored when draw set to
false
.y
- The drawing y position, ignored when draw set to
false
.private void drawHighlightWorker(int x, int y, int width, int height, ColorRgb color, java.awt.Graphics2D g2)
x
- left positiony
- top positionwidth
- area widthheight
- area heightcolor
- highlight colorg2
- graphic context for operationprivate void clearHighlightWorker(java.awt.Graphics2D g2)
drawHighlightWorker(int, int, int, int, ColorRgb, Graphics2D)
.g2
- graphic context for operationprivate static void safeInvokeAndWait(java.lang.Runnable code)
SwingUtilities.invokeAndWait(Runnable)
.
If the method is already being executed on the Swing EDT, then
the supplied runnable is directly invoked.code
- A valid Runnable
reference.private java.awt.Graphics2D getWorkingGraphics()
pane
's component context is returned.