Package jexer.backend
Class SwingTerminal
- java.lang.Object
-
- jexer.backend.LogicalScreen
-
- jexer.backend.SwingTerminal
-
- All Implemented Interfaces:
java.awt.event.ComponentListener,java.awt.event.KeyListener,java.awt.event.MouseListener,java.awt.event.MouseMotionListener,java.awt.event.MouseWheelListener,java.awt.event.WindowListener,java.util.EventListener,Screen,TerminalReader
public class SwingTerminal extends LogicalScreen implements TerminalReader, java.awt.event.ComponentListener, java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.awt.event.WindowListener
This Screen backend reads keystrokes and mouse events and draws to either a Java Swing JFrame (potentially triple-buffered) or a JComponent. This class is a bit of an inversion of typical GUI classes. It performs all of the drawing logic from SwingTerminal (which is not a Swing class), and uses a SwingComponent wrapper class to call the JFrame or JComponent methods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSwingTerminal.CursorStyleCursor style to draw.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringFONTFILEThe terminus font resource filename.-
Fields inherited from class jexer.backend.LogicalScreen
cursorVisible, cursorX, cursorY, height, logical, physical, reallyCleared, width
-
-
Constructor Summary
Constructors Constructor Description SwingTerminal(Backend backend, int windowWidth, int windowHeight, int fontSize, java.lang.Object listener)Public constructor creates a new JFrame to render to.SwingTerminal(Backend backend, javax.swing.JComponent component, int windowWidth, int windowHeight, int fontSize, java.lang.Object listener)Public constructor renders to an existing JComponent.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.awt.ColorattrToBackgroundColor(CellAttributes attr)Convert a CellAttributes background color to an AWT Color.static java.awt.ColorattrToForegroundColor(CellAttributes attr)Convert a CellAttributes foreground color to an AWT Color.voidcloseTerminal()Restore terminal to normal state.voidcomponentHidden(java.awt.event.ComponentEvent event)Pass component events into the event queue.voidcomponentMoved(java.awt.event.ComponentEvent event)Pass component events into the event queue.voidcomponentResized(java.awt.event.ComponentEvent event)Pass component events into the event queue.voidcomponentShown(java.awt.event.ComponentEvent event)Pass component events into the event queue.voidflushPhysical()Push the logical screen to the physical device.longgetBlinkMillis()Get the number of millis to wait before switching the blink from visible to invisible.booleangetCursorBlinkVisible()Get the current status of the blink flag.SwingTerminal.CursorStylegetCursorStyle()Get the cursor style.voidgetEvents(java.util.List<TInputEvent> queue)Return any events in the IO queue.java.awt.FontgetFont()Get the font this screen was last set to.intgetFontSize()Get the font size in points.java.lang.StringgetMouseStyle()Get the mouse cursor style.SessionInfogetSessionInfo()Getter for sessionInfo.SwingComponentgetSwingComponent()Getter for the underlying Swing component.intgetTextAdjustHeight()Get the height text adjustment.intgetTextAdjustWidth()Get the width text adjustment.intgetTextAdjustX()Get the X text adjustment.intgetTextAdjustY()Get the Y text adjustment.intgetTextHeight()Get the height of a character cell in pixels.intgetTextWidth()Get the width of a character cell in pixels.booleanhasEvents()Check if there are events in the queue.booleanisImagesOverText()Check if screen will support incomplete image fragments over text display.booleanisPixelMouse()Check if terminal is reporting pixel-based mouse position.booleanisTripleBuffer()Get triple buffering flag.voidkeyPressed(java.awt.event.KeyEvent key)Pass Swing keystrokes into the event queue.voidkeyReleased(java.awt.event.KeyEvent key)Pass Swing keystrokes into the event queue.voidkeyTyped(java.awt.event.KeyEvent key)Pass Swing keystrokes into the event queue.voidmouseClicked(java.awt.event.MouseEvent mouse)Pass mouse events into the event queue.voidmouseDragged(java.awt.event.MouseEvent mouse)Pass mouse events into the event queue.voidmouseEntered(java.awt.event.MouseEvent mouse)Pass mouse events into the event queue.voidmouseExited(java.awt.event.MouseEvent mouse)Pass mouse events into the event queue.voidmouseMoved(java.awt.event.MouseEvent mouse)Pass mouse events into the event queue.voidmousePressed(java.awt.event.MouseEvent mouse)Pass mouse events into the event queue.voidmouseReleased(java.awt.event.MouseEvent mouse)Pass mouse events into the event queue.voidmouseWheelMoved(java.awt.event.MouseWheelEvent mouse)Pass mouse events into the event queue.voidpaint(java.awt.Graphics gr)Paint redraws the whole screen.voidreloadOptions()Reload options from System properties.voidresizeToScreen()Resize the physical screen to match the logical screen dimensions.voidsetCursorStyle(java.lang.String cursorStyleString)Set the cursor style.voidsetCursorStyle(SwingTerminal.CursorStyle cursorStyle)Set the cursor style.voidsetDefaultFont()Set the font to Terminus, the best all-around font for both CP437 and ISO8859-1.voidsetFont(java.awt.Font font)Set to a new font, and resize the screen to match its dimensions.voidsetFontSize(int fontSize)Set the font size in points.voidsetListener(java.lang.Object listener)Set listener to a different Object.voidsetMouseStyle(java.lang.String mouseStyle)Set the mouse pointer (cursor) style.voidsetPixelMouse(boolean pixelMouse)Set request for terminal to report pixel-based mouse position.voidsetTextAdjustHeight(int textAdjustHeight)Set the height text adjustment.voidsetTextAdjustWidth(int textAdjustWidth)Set the width text adjustment.voidsetTextAdjustX(int textAdjustX)Set the X text adjustment.voidsetTextAdjustY(int textAdjustY)Set the Y text adjustment.voidsetTitle(java.lang.String title)Set the window title.voidsetTripleBuffer(boolean tripleBuffer)Set triple buffering.voidshutdown()Restore terminal to normal state.inttextColumn(int x)Convert pixel column position to text cell column position.inttextRow(int y)Convert pixel row position to text cell row position.voidwindowActivated(java.awt.event.WindowEvent event)Pass window events into the event queue.voidwindowClosed(java.awt.event.WindowEvent event)Pass window events into the event queue.voidwindowClosing(java.awt.event.WindowEvent event)Pass window events into the event queue.voidwindowDeactivated(java.awt.event.WindowEvent event)Pass window events into the event queue.voidwindowDeiconified(java.awt.event.WindowEvent event)Pass window events into the event queue.voidwindowIconified(java.awt.event.WindowEvent event)Pass window events into the event queue.voidwindowOpened(java.awt.event.WindowEvent event)Pass window events into the event queue.-
Methods inherited from class jexer.backend.LogicalScreen
blendRectangle, blendScreen, clear, clearPhysical, copyScreen, copyScreen, copySelection, drawBox, drawBox, drawBoxShadow, getAttrXY, getBackend, getCharXY, getCharXY, getClipBottom, getClipLeft, getClipRight, getClipTop, getCursorX, getCursorY, getHeight, getOffsetX, getOffsetY, getWidth, hideCursor, hLineXY, hLineXY, invertCell, invertCell, isCursorVisible, isDirty, putAll, putAttrXY, putAttrXY, putCharXY, putCharXY, putCharXY, putCursor, putFullwidthCharXY, putFullwidthCharXY, putFullwidthCharXY, putStringXY, putStringXY, reset, resetClipping, setBackend, setClipBottom, setClipLeft, setClipRight, setClipTop, setDimensions, setHeight, setOffsetX, setOffsetY, setSelection, setWidth, snapshot, snapshot, snapshotPhysical, unsetImageRow, vLineXY, vLineXY
-
-
-
-
Field Detail
-
FONTFILE
public static final java.lang.String FONTFILE
The terminus font resource filename.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SwingTerminal
public SwingTerminal(Backend backend, int windowWidth, int windowHeight, int fontSize, java.lang.Object listener)
Public constructor creates a new JFrame to render to.- Parameters:
backend- the backend that will read from this terminalwindowWidth- the number of text columns to start withwindowHeight- the number of text rows to start withfontSize- the size in points. Good values to pick are: 16, 20, 22, and 24.listener- the object this backend needs to wake up when new input comes in
-
SwingTerminal
public SwingTerminal(Backend backend, javax.swing.JComponent component, int windowWidth, int windowHeight, int fontSize, java.lang.Object listener)
Public constructor renders to an existing JComponent.- Parameters:
backend- the backend that will read from this terminalcomponent- the Swing component to render towindowWidth- the number of text columns to start withwindowHeight- the number of text rows to start withfontSize- the size in points. Good values to pick are: 16, 20, 22, and 24.listener- the object this backend needs to wake up when new input comes in
-
-
Method Detail
-
setTitle
public void setTitle(java.lang.String title)
Set the window title.- Specified by:
setTitlein interfaceScreen- Overrides:
setTitlein classLogicalScreen- Parameters:
title- the new title
-
flushPhysical
public void flushPhysical()
Push the logical screen to the physical device.- Specified by:
flushPhysicalin interfaceScreen- Overrides:
flushPhysicalin classLogicalScreen
-
hasEvents
public boolean hasEvents()
Check if there are events in the queue.- Specified by:
hasEventsin interfaceTerminalReader- Returns:
- if true, getEvents() has something to return to the backend
-
getEvents
public void getEvents(java.util.List<TInputEvent> queue)
Return any events in the IO queue.- Specified by:
getEventsin interfaceTerminalReader- Parameters:
queue- list to append new events to
-
closeTerminal
public void closeTerminal()
Restore terminal to normal state.- Specified by:
closeTerminalin interfaceTerminalReader
-
setListener
public void setListener(java.lang.Object listener)
Set listener to a different Object.- Specified by:
setListenerin interfaceTerminalReader- Parameters:
listener- the new listening object that run() wakes up on new input
-
reloadOptions
public void reloadOptions()
Reload options from System properties.- Specified by:
reloadOptionsin interfaceTerminalReader
-
isTripleBuffer
public boolean isTripleBuffer()
Get triple buffering flag.- Returns:
- true if triple buffering is enabled
-
setTripleBuffer
public void setTripleBuffer(boolean tripleBuffer)
Set triple buffering.- Parameters:
tripleBuffer- if true, enable triple buffering
-
setMouseStyle
public void setMouseStyle(java.lang.String mouseStyle)
Set the mouse pointer (cursor) style.- Parameters:
mouseStyle- the pointer style string, one of: "default", "none", "hand", "text", "move", or "crosshair"
-
getMouseStyle
public java.lang.String getMouseStyle()
Get the mouse cursor style.- Returns:
- the cursor style string, one of: "default", "none", "hand", "text", "move", or "crosshair"
-
getCursorStyle
public SwingTerminal.CursorStyle getCursorStyle()
Get the cursor style.- Returns:
- the cursor style
-
setCursorStyle
public void setCursorStyle(SwingTerminal.CursorStyle cursorStyle)
Set the cursor style.- Parameters:
cursorStyle- the new cursor style
-
setCursorStyle
public void setCursorStyle(java.lang.String cursorStyleString)
Set the cursor style.- Parameters:
cursorStyleString- the new cursor style
-
getTextWidth
public int getTextWidth()
Get the width of a character cell in pixels.- Specified by:
getTextWidthin interfaceScreen- Overrides:
getTextWidthin classLogicalScreen- Returns:
- the width in pixels of a character cell
-
getTextHeight
public int getTextHeight()
Get the height of a character cell in pixels.- Specified by:
getTextHeightin interfaceScreen- Overrides:
getTextHeightin classLogicalScreen- Returns:
- the height in pixels of a character cell
-
getBlinkMillis
public long getBlinkMillis()
Get the number of millis to wait before switching the blink from visible to invisible.- Returns:
- the number of milli to wait before switching the blink from visible to invisible
-
getCursorBlinkVisible
public boolean getCursorBlinkVisible()
Get the current status of the blink flag.- Returns:
- true if the cursor and blinking text should be visible
-
getFontSize
public int getFontSize()
Get the font size in points.- Returns:
- font size in points
-
setFontSize
public void setFontSize(int fontSize)
Set the font size in points.- Parameters:
fontSize- font size in points
-
setFont
public void setFont(java.awt.Font font)
Set to a new font, and resize the screen to match its dimensions.- Parameters:
font- the new font
-
getFont
public java.awt.Font getFont()
Get the font this screen was last set to.- Returns:
- the font
-
setDefaultFont
public void setDefaultFont()
Set the font to Terminus, the best all-around font for both CP437 and ISO8859-1.
-
getTextAdjustX
public int getTextAdjustX()
Get the X text adjustment.- Returns:
- X text adjustment
-
setTextAdjustX
public void setTextAdjustX(int textAdjustX)
Set the X text adjustment.- Parameters:
textAdjustX- the X text adjustment
-
getTextAdjustY
public int getTextAdjustY()
Get the Y text adjustment.- Returns:
- Y text adjustment
-
setTextAdjustY
public void setTextAdjustY(int textAdjustY)
Set the Y text adjustment.- Parameters:
textAdjustY- the Y text adjustment
-
getTextAdjustHeight
public int getTextAdjustHeight()
Get the height text adjustment.- Returns:
- height text adjustment
-
setTextAdjustHeight
public void setTextAdjustHeight(int textAdjustHeight)
Set the height text adjustment.- Parameters:
textAdjustHeight- the height text adjustment
-
getTextAdjustWidth
public int getTextAdjustWidth()
Get the width text adjustment.- Returns:
- width text adjustment
-
setTextAdjustWidth
public void setTextAdjustWidth(int textAdjustWidth)
Set the width text adjustment.- Parameters:
textAdjustWidth- the width text adjustment
-
attrToForegroundColor
public static java.awt.Color attrToForegroundColor(CellAttributes attr)
Convert a CellAttributes foreground color to an AWT Color.- Parameters:
attr- the text attributes- Returns:
- the AWT Color
-
attrToBackgroundColor
public static java.awt.Color attrToBackgroundColor(CellAttributes attr)
Convert a CellAttributes background color to an AWT Color.- Parameters:
attr- the text attributes- Returns:
- the AWT Color
-
resizeToScreen
public void resizeToScreen()
Resize the physical screen to match the logical screen dimensions.- Overrides:
resizeToScreenin classLogicalScreen
-
paint
public void paint(java.awt.Graphics gr)
Paint redraws the whole screen.- Parameters:
gr- the Swing Graphics context
-
shutdown
public void shutdown()
Restore terminal to normal state.
-
textColumn
public int textColumn(int x)
Convert pixel column position to text cell column position.- Parameters:
x- pixel column position- Returns:
- text cell column position
-
textRow
public int textRow(int y)
Convert pixel row position to text cell row position.- Parameters:
y- pixel row position- Returns:
- text cell row position
-
getSessionInfo
public SessionInfo getSessionInfo()
Getter for sessionInfo.- Returns:
- the SessionInfo
-
getSwingComponent
public SwingComponent getSwingComponent()
Getter for the underlying Swing component.- Returns:
- the SwingComponent
-
isImagesOverText
public boolean isImagesOverText()
Check if screen will support incomplete image fragments over text display.- Returns:
- true if images can partially obscure text
-
isPixelMouse
public boolean isPixelMouse()
Check if terminal is reporting pixel-based mouse position.- Returns:
- true if single-pixel mouse movements are reported
-
setPixelMouse
public void setPixelMouse(boolean pixelMouse)
Set request for terminal to report pixel-based mouse position.- Parameters:
pixelMouse- if true, single-pixel mouse movements will be reported
-
keyReleased
public void keyReleased(java.awt.event.KeyEvent key)
Pass Swing keystrokes into the event queue.- Specified by:
keyReleasedin interfacejava.awt.event.KeyListener- Parameters:
key- keystroke received
-
keyTyped
public void keyTyped(java.awt.event.KeyEvent key)
Pass Swing keystrokes into the event queue.- Specified by:
keyTypedin interfacejava.awt.event.KeyListener- Parameters:
key- keystroke received
-
keyPressed
public void keyPressed(java.awt.event.KeyEvent key)
Pass Swing keystrokes into the event queue.- Specified by:
keyPressedin interfacejava.awt.event.KeyListener- Parameters:
key- keystroke received
-
windowActivated
public void windowActivated(java.awt.event.WindowEvent event)
Pass window events into the event queue.- Specified by:
windowActivatedin interfacejava.awt.event.WindowListener- Parameters:
event- window event received
-
windowClosed
public void windowClosed(java.awt.event.WindowEvent event)
Pass window events into the event queue.- Specified by:
windowClosedin interfacejava.awt.event.WindowListener- Parameters:
event- window event received
-
windowClosing
public void windowClosing(java.awt.event.WindowEvent event)
Pass window events into the event queue.- Specified by:
windowClosingin interfacejava.awt.event.WindowListener- Parameters:
event- window event received
-
windowDeactivated
public void windowDeactivated(java.awt.event.WindowEvent event)
Pass window events into the event queue.- Specified by:
windowDeactivatedin interfacejava.awt.event.WindowListener- Parameters:
event- window event received
-
windowDeiconified
public void windowDeiconified(java.awt.event.WindowEvent event)
Pass window events into the event queue.- Specified by:
windowDeiconifiedin interfacejava.awt.event.WindowListener- Parameters:
event- window event received
-
windowIconified
public void windowIconified(java.awt.event.WindowEvent event)
Pass window events into the event queue.- Specified by:
windowIconifiedin interfacejava.awt.event.WindowListener- Parameters:
event- window event received
-
windowOpened
public void windowOpened(java.awt.event.WindowEvent event)
Pass window events into the event queue.- Specified by:
windowOpenedin interfacejava.awt.event.WindowListener- Parameters:
event- window event received
-
componentHidden
public void componentHidden(java.awt.event.ComponentEvent event)
Pass component events into the event queue.- Specified by:
componentHiddenin interfacejava.awt.event.ComponentListener- Parameters:
event- component event received
-
componentShown
public void componentShown(java.awt.event.ComponentEvent event)
Pass component events into the event queue.- Specified by:
componentShownin interfacejava.awt.event.ComponentListener- Parameters:
event- component event received
-
componentMoved
public void componentMoved(java.awt.event.ComponentEvent event)
Pass component events into the event queue.- Specified by:
componentMovedin interfacejava.awt.event.ComponentListener- Parameters:
event- component event received
-
componentResized
public void componentResized(java.awt.event.ComponentEvent event)
Pass component events into the event queue.- Specified by:
componentResizedin interfacejava.awt.event.ComponentListener- Parameters:
event- component event received
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent mouse)
Pass mouse events into the event queue.- Specified by:
mouseDraggedin interfacejava.awt.event.MouseMotionListener- Parameters:
mouse- mouse event received
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent mouse)
Pass mouse events into the event queue.- Specified by:
mouseMovedin interfacejava.awt.event.MouseMotionListener- Parameters:
mouse- mouse event received
-
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent mouse)
Pass mouse events into the event queue.- Specified by:
mouseClickedin interfacejava.awt.event.MouseListener- Parameters:
mouse- mouse event received
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent mouse)
Pass mouse events into the event queue.- Specified by:
mouseEnteredin interfacejava.awt.event.MouseListener- Parameters:
mouse- mouse event received
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent mouse)
Pass mouse events into the event queue.- Specified by:
mouseExitedin interfacejava.awt.event.MouseListener- Parameters:
mouse- mouse event received
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent mouse)
Pass mouse events into the event queue.- Specified by:
mousePressedin interfacejava.awt.event.MouseListener- Parameters:
mouse- mouse event received
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent mouse)
Pass mouse events into the event queue.- Specified by:
mouseReleasedin interfacejava.awt.event.MouseListener- Parameters:
mouse- mouse event received
-
mouseWheelMoved
public void mouseWheelMoved(java.awt.event.MouseWheelEvent mouse)
Pass mouse events into the event queue.- Specified by:
mouseWheelMovedin interfacejava.awt.event.MouseWheelListener- Parameters:
mouse- mouse event received
-
-