Class SwingTerminal.TerminalComponent

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
org.jline.builtins.SwingTerminal.TerminalComponent
All Implemented Interfaces:
KeyListener, ImageObserver, MenuContainer, Serializable, EventListener, Sized
Enclosing class:
SwingTerminal

public static class SwingTerminal.TerminalComponent extends JComponent implements KeyListener, Sized
JComponent that renders the terminal display. This is the inner class that contains the original ScreenTerminal-based implementation.
See Also:
  • Constructor Details

    • TerminalComponent

      public TerminalComponent(int columns, int rows)
      Create a TerminalComponent for rendering and capturing input for a terminal with the specified character grid size.
      Parameters:
      columns - the number of character columns in the terminal
      rows - the number of character rows in the terminal
  • Method Details

    • setTerminal

      public void setTerminal(SwingTerminal terminal)
      Sets the terminal reference after construction to avoid this-escape issues.
      Parameters:
      terminal - the SwingTerminal instance
    • setTerminalFont

      public void setTerminalFont(Font font)
      Sets the font used for terminal display.
      Parameters:
      font - the font to use (should be monospace)
    • getTerminalFont

      public Font getTerminalFont()
      Gets the current terminal font.
      Returns:
      the current font
    • setSize

      public boolean setSize(Sized size)
      Resize the terminal to the specified columns and rows.
      Parameters:
      size - the new Size whose columns and rows will be applied
      Returns:
      true if the size was set successfully, false otherwise
    • getColumns

      public int getColumns()
      Description copied from interface: Sized
      Returns the number of columns (width) in this object.

      The number of columns represents the width in character cells.

      Specified by:
      getColumns in interface Sized
      Returns:
      The number of columns (width) in this object.
    • getRows

      public int getRows()
      Description copied from interface: Sized
      Returns the number of rows (height) in this object.

      The number of rows represents the height in character cells.

      Specified by:
      getRows in interface Sized
      Returns:
      The number of rows (height) in this object.
    • paintComponent

      protected void paintComponent(Graphics g)
      Paints this Swing component and its terminal contents.

      Prepares a Graphics2D context with high-quality text rendering and the component's terminal font, then delegates actual terminal rendering to the paintTerminalContent method.

      Overrides:
      paintComponent in class JComponent
    • pollInput

      public String pollInput()
      Gets the next input from the input queue.
      Returns:
      the next input string, or null if none available
    • takeInput

      public String takeInput() throws InterruptedException
      Gets the next input from the input queue, blocking if necessary.
      Returns:
      the next input string
      Throws:
      InterruptedException - if interrupted while waiting
    • write

      public void write(String text)
      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 fill
      x - the starting x coordinate
      y - the starting y coordinate
      height - the height to dump
      width - the width to dump
      cursor - the cursor position array to fill
    • dump

      public String dump(long timeout, boolean forceUpdate) throws InterruptedException
      Dumps the terminal screen data with scrollback.
      Parameters:
      timeout -
      forceUpdate -
      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
    • getScreenTerminal

      public ScreenTerminal getScreenTerminal()
    • keyTyped

      public void keyTyped(KeyEvent e)
      Specified by:
      keyTyped in interface KeyListener
    • keyPressed

      public void keyPressed(KeyEvent e)
      Specified by:
      keyPressed in interface KeyListener
    • keyReleased

      public void keyReleased(KeyEvent e)
      Specified by:
      keyReleased in interface KeyListener
    • dispose

      public void dispose()
      Stops the cursor timer and cleans up resources.