Package mars.venus

Class ConsoleTextArea

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

public class ConsoleTextArea extends JTextArea
Special text area used by MessagesPane to imitate console input/output. Output written using writeOutput(String) is buffered to reduce the load on the GUI and prevent rapid-fire writes from clogging the event queue, which would be the case if JTextArea.append(String) was used instead. User input is not entirely accurate to the behavior of a real console, as it prevents the user from entering any input while no system calls are requesting it, and limits the user from exceeding character limits while typing. These differences should be beneficial in the majority of cases, though.

The user input code was originally written by Ricardo Fernández Pascual (rfernandez@ditec.um.es) in December 2009.

See Also:
  • Field Details

    • MAXIMUM_LINE_COUNT

      public static final int MAXIMUM_LINE_COUNT
      See Also:
    • TRIM_LINES_EXTRA_COUNT

      public static final int TRIM_LINES_EXTRA_COUNT
      See Also:
    • MAXIMUM_CHARACTER_COUNT

      public static final int MAXIMUM_CHARACTER_COUNT
      See Also:
    • TRIM_CHARACTERS_EXTRA_COUNT

      public static final int TRIM_CHARACTERS_EXTRA_COUNT
      See Also:
  • Constructor Details

    • ConsoleTextArea

      public ConsoleTextArea()
      Create a new ConsoleTextArea.
  • Method Details

    • clear

      public void clear()
      Clear all text from the text area, and clear any buffered output.

      This method must be called from the GUI thread.

    • writeMessage

      public void writeMessage(LogMessage message)
      Write output text to the console. Console output is buffered so as to lighten the load on the GUI when calls to this method are made in rapid succession.

      This method may be called from any thread.

      Parameters:
      message - String to append to the console output.
    • writeOutput

      public void writeOutput(String text)
      Write output text to the console. Console output is buffered so as to lighten the load on the GUI when calls to this method are made in rapid succession.

      This method may be called from any thread.

      Parameters:
      text - String to append to the console output.
    • flushOutput

      public void flushOutput()
      Flush the output buffer to the GUI text area, trimming the content to have at most MAXIMUM_LINE_COUNT lines if necessary.

      This method must be called from the GUI thread.

    • clickMessage

      public void clickMessage(LogMessage message)
    • awaitUserInput

      public String awaitUserInput(int maxLength) throws InterruptedException
      Allow the user to input text into the console, waiting until the input is submitted.

      This blocks the current thread. Always call this method from the simulator thread!

      Parameters:
      maxLength - Maximum length allowed for user input, or -1 if no maximum length should be enforced. If set to a non-negative value, the user will be prevented from exceeding the limit while typing.
      Returns:
      The input submitted by the user, not including the newline.
      Throws:
      InterruptedException
    • updateUI

      public void updateUI()
      Update the appearance of this text area, overriding the background color and font according to current settings.
      Overrides:
      updateUI in class JTextComponent