public class ChuiSimulator extends EmulatedTerminalState
All output is done in the same fixed width font family, with character attributes implemented by modifying the attributes of the common font for each output character. The output stored in a 2-dimensional buffer of of cells, which store the character to be drawn and the attributes/color of that character.
The current cursor position is remembered and can be manipulated by the application. The cursor visibility state can be externally controlled as well. When rendering output, if the cursor is visible, it is drawn by inverting the foreground/background colors of the font used to draw the character at which the cursor is located.
Input is read using key events and that is kept in a FIFO buffer as if they had been sent by the remote terminal hardware.
Other common end-user functionality is implemented including printing, selection of text, copy of selected text to the clipboard, paste of text from the clipboard into the keyboard input buffer and copying the entire terminal's visible state to the clipboard as an image.
Limitations:
Modifier and Type | Field and Description |
---|---|
private int |
baseLine
Number of pixels between each row based on font metrics.
|
private int |
c0
Selection start column number.
|
private int |
c1
Selection end column number.
|
private int |
charHeight
The height of a single character in pixels (same as the row height).
|
private int |
charWidth
The width of a single character in pixels.
|
private ColorMapper |
colorMap
Helper to map color specifications to the font needed for drawing.
|
private TerminalMenu |
menu
Popup menu.
|
private ContentPane |
pane
Content pane of the containing swing window.
|
private int |
r0
Selection start row number.
|
private int |
r1
Selection end row number.
|
private java.awt.Rectangle |
selected
Boundary of the current selected region in pixel coordinates.
|
private java.awt.Color |
selectionColor
Color used for the selection rectangle.
|
private boolean |
selectionTrack
Flag to control if it is valid to track selection events.
|
private int |
x0
Selection start X coordinate in pixels.
|
private int |
x1
Selection end X coordinate in pixels.
|
private int |
y0
Selection start Y coordinate in pixels.
|
private int |
y1
Selection end Y coordinate in pixels.
|
cfgLock, cursorX, cursorY, data, dataLock, options, selLock, showCursor
Constructor and Description |
---|
ChuiSimulator(java.awt.Window window,
ContainerOps container,
TerminalOptions options)
Create a new instance with the container and frame given.
|
Modifier and Type | Method and Description |
---|---|
private java.awt.Rectangle |
calcCharBoundary()
Based on the X and Y coordinates in pixels from a mouse button event
(during selection processing), calculate the starting and ending
coordinates of the selection rectangle in both character positions
(rows/columns) and in pixels.
|
void |
cancelSelection()
Cancel the current selection operation, reset the selection state and
force a repaint of the entire screen which will cause the selection
box to disappear.
|
boolean |
canSelectionTrack()
Report if selection tracking is active.
|
void |
configure(TerminalOptions termopt)
Initialize the instance using the given configuration.
|
java.lang.String |
copy()
Read the current terminal buffer at each character position inside the
current selection and return the text in a string.
|
private void |
drawString(java.awt.Graphics graphics,
java.lang.String text,
java.awt.Font font,
int x,
int y)
Helper method to draw the given string into the given graphics object
at the given location with the given font.
|
void |
enableSelectionTrack(boolean track)
Control whether the selection tracker is tracking mouse events.
|
void |
endSelection(int x,
int y)
End the current selection operation, update the final selection state and
force a repaint of the selection region which will cause the selection
box to be drawn in its final position and size.
|
ContentPane |
getContentPane()
Obtain the content pane for the terminal simulator.
|
private boolean |
isInsideSelectionArea(int x,
int y)
Detect if the given point is inside the current selection rectangle.
|
void |
paintComponent(java.awt.Graphics graphics)
Paint the entire component to the given graphics instance, using
previously set state.
|
void |
startSelection(int x,
int y)
Start selection processing based on the given starting coordinates and
force a repaint of the selection region which will cause the selection
box to be drawn around the character in which the point is found.
|
void |
triggerRepaint(boolean full)
Cause a partial or full repaint to occur.
|
void |
updateSelection(int x,
int y)
Update the selection state based on the latest ending coordinates and
force a repaint of the selection region which will cause the selection
box to be drawn in its new position and size.
|
append, clear, getColumns, getCursorX, getCursorY, getRows, getScreenData, getTerminalOptions, replace, setCursor, setCursorStatus
private TerminalMenu menu
private ColorMapper colorMap
private int charHeight
private int charWidth
private int baseLine
private int x0
private int x1
private int y0
private int y1
private int r0
private int r1
private int c0
private int c1
private boolean selectionTrack
private java.awt.Rectangle selected
private ContentPane pane
private java.awt.Color selectionColor
public ChuiSimulator(java.awt.Window window, ContainerOps container, TerminalOptions options)
For applications, the frame and the container are usually the same
object (of type JFrame
). For applets, these are different
instances since a JApplet
will be the container and the
frame will be a parent container of the JApplet
.
window
- The containing window. Needed for key event processing and for the processing of
modal dialog boxes.container
- The immediate container component, which can be called to
force a resizing to match a changed simulator size.options
- The terminal configuration (size and appearance).public void configure(TerminalOptions termopt)
configure
in class EmulatedTerminalState
termopt
- The configuration for the terminal simulator.public ContentPane getContentPane()
public void paintComponent(java.awt.Graphics graphics)
graphics
- The object into which to draw.public void triggerRepaint(boolean full)
full
is
true
or if there is no current selection operation occurring,
a repaint of the entire component ("screen") will occur. Otherwise,
a repaint of only the selection area will occur.triggerRepaint
in class EmulatedTerminalState
full
- Flag to force a the entire screen to repaint.public java.lang.String copy()
public void enableSelectionTrack(boolean track)
track
- true
to allow tracking, false
to
ignore all mouse events (no tracking).public boolean canSelectionTrack()
true
if selection tracking is active.public void startSelection(int x, int y)
x
- Most recent ending X coordinate.y
- Most recent ending Y coordinate.public void updateSelection(int x, int y)
x
- Most recent ending X coordinate.y
- Most recent ending Y coordinate.public void endSelection(int x, int y)
x
- Ending X coordinate.y
- Ending Y coordinate.public void cancelSelection()
private boolean isInsideSelectionArea(int x, int y)
x
- X coordinate to check.y
- Y coordinate to check.true
if the point is inside the selection area.private void drawString(java.awt.Graphics graphics, java.lang.String text, java.awt.Font font, int x, int y)
graphics
- Instance to draw into.text
- Text to draw.font
- The common font in which to draw all characters from the string.x
- X coordinate.y
- Y coordinate.private java.awt.Rectangle calcCharBoundary()