Package org.jline.builtins
Class SwingTerminal
java.lang.Object
org.jline.terminal.impl.AbstractTerminal
org.jline.terminal.impl.LineDisciplineTerminal
org.jline.builtins.SwingTerminal
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,Sized,TerminalExt,Terminal
A Swing-based terminal implementation that extends LineDisciplineTerminal.
This class provides a proper JLine Terminal implementation that can be embedded in Swing applications to display a terminal interface. It renders terminal content using Java 2D graphics and handles keyboard and mouse input with proper terminal capabilities.
Features:
- Full JLine Terminal interface implementation
- Custom painting for terminal characters and attributes
- ANSI color support with configurable color palette
- Font configuration with monospace font support
- Keyboard input handling with proper terminal capabilities
- Mouse support for cursor positioning
- Scrollback buffer support
- Cursor blinking
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classJComponent that renders the terminal display.Nested classes/interfaces inherited from interface org.jline.terminal.Terminal
Terminal.MouseTracking, Terminal.Signal, Terminal.SignalHandler -
Field Summary
Fields inherited from class org.jline.terminal.impl.LineDisciplineTerminal
attributes, masterOutput, size, skipNextLf, slaveInput, slaveInputPipe, slaveOutput, slaveReader, slaveWriterFields inherited from class org.jline.terminal.impl.AbstractTerminal
bools, closed, currentMouseTracking, encoding, handlers, inputEncoding, ints, name, onClose, outputEncoding, palette, status, strings, typeFields inherited from interface org.jline.terminal.Terminal
TYPE_DUMB, TYPE_DUMB_COLOR -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new SwingTerminal with default dimensions (80x24).SwingTerminal(int columns, int rows) Creates a new SwingTerminal with the specified dimensions.SwingTerminal(String name, int columns, int rows) Creates a new SwingTerminal with the specified name and dimensions. -
Method Summary
Modifier and TypeMethodDescriptioncreateFrame(String title) Creates a JFrame containing the terminal component.voiddispose()Deprecated.protected voiddoClose()voiddump(long[] screen, int x, int y, int height, int width, int[] cursor) Dumps the terminal screen data.dump(long timeout, boolean forceUpdate) Dumps the terminal screen data with scrollback.Gets the Swing component that renders the terminal.booleanisDirty()Checks if the terminal is dirty (needs repainting).Gets input from the terminal component (non-blocking).voidprocessInputBytes(byte[] input) Processes input bytes through the terminal's line discipline.voidRequests that the terminal adopt the specified window dimensions.Gets input from the terminal component (blocking).voidWrites text to the terminal component.Methods inherited from class org.jline.terminal.impl.LineDisciplineTerminal
doProcessInputByte, getAttributes, getProvider, getSize, getSystemStream, input, output, processInputByte, processInputBytes, processIOException, processOutputByte, raise, reader, setAttributes, writerMethods inherited from class org.jline.terminal.impl.AbstractTerminal
canPauseResume, checkClosed, checkInterrupted, close, detectTrueColorSupport, echo, echo, echoSignal, encoding, enterRawMode, flush, getBooleanCapability, getCurrentMouseTracking, getCursorPosition, getDefaultBackgroundColor, getDefaultForegroundColor, getGraphemeClusterMode, getKind, getName, getNumericCapability, getPalette, getStatus, getStatus, getStringCapability, getType, handle, hasFocusSupport, hasMouseSupport, inputEncoding, isClusterGrouped, outputEncoding, parseInfoCmp, pause, pause, paused, puts, readMouseEvent, readMouseEvent, readMouseEvent, readMouseEvent, resume, setGraphemeClusterMode, setOnClose, supportsGraphemeClusterMode, toString, trackFocus, trackMouseMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jline.terminal.Terminal
getBufferSize, getColumns, getHeight, getRows, getWidth, setSize
-
Constructor Details
-
SwingTerminal
Creates a new SwingTerminal with the specified dimensions.- Parameters:
columns- the number of columnsrows- the number of rows- Throws:
IOException- if an I/O error occurs during initialization
-
SwingTerminal
Creates a new SwingTerminal with default dimensions (80x24).- Throws:
IOException- if an I/O error occurs during initialization
-
SwingTerminal
Creates a new SwingTerminal with the specified name and dimensions.- Parameters:
name- the terminal namecolumns- the number of columnsrows- the number of rows- Throws:
IOException- if an I/O error occurs during initialization
-
-
Method Details
-
getComponent
Gets the Swing component that renders the terminal.- Returns:
- the terminal component
-
createFrame
-
pollInput
Gets input from the terminal component (non-blocking).- Returns:
- the next input string, or null if none available
-
takeInput
Gets input from the terminal component (blocking).- Returns:
- the next input string
- Throws:
InterruptedException- if interrupted while waiting
-
processInputBytes
Processes input bytes through the terminal's line discipline.- Overrides:
processInputBytesin classLineDisciplineTerminal- Parameters:
input- the input bytes to process- Throws:
IOException- if an I/O error occurs
-
write
Writes text to the terminal component.- Parameters:
text- the text to write
-
dump
public void dump(long[] screen, int x, int y, int height, int width, int[] cursor) Dumps the terminal screen data.- Parameters:
screen- the screen data array to fillx- the starting x coordinatey- the starting y coordinateheight- the height to dumpwidth- the width to dumpcursor- the cursor position array to fill
-
dump
Dumps the terminal screen data with scrollback.- Parameters:
timeout- the number of scrollback linesforceUpdate- whether to include scrollback- Returns:
- the screen data
- Throws:
InterruptedException- if interrupted while waiting
-
isDirty
public boolean isDirty()Checks if the terminal is dirty (needs repainting).- Returns:
- true if dirty
-
doClose
- Overrides:
doClosein classLineDisciplineTerminal- Throws:
IOException
-
dispose
Deprecated.UseAbstractTerminal.close()instead, which properly handles all cleanup including disposing of resources. This method will be made package-private or removed in a future major release.Disposes of the terminal resources. -
setSize
Description copied from interface:TerminalRequests that the terminal adopt the specified window dimensions. Implementations may apply constraints or ignore the request if resizing is unsupported; callers should useTerminal.getSize()to observe the effective size after calling this method.- Specified by:
setSizein interfaceTerminal- Overrides:
setSizein classLineDisciplineTerminal- Parameters:
sz- the desired terminal size (columns and rows)- See Also:
-
AbstractTerminal.close()instead, which properly handles all cleanup including disposing of resources.