Class GWTConsoleAdapter

java.lang.Object
com.singularsys.client.GWTConsoleAdapter
All Implemented Interfaces:
Scheduler.ScheduledCommand, KeyPressHandler, EventHandler, Command

public class GWTConsoleAdapter extends Object implements KeyPressHandler, Command
Class handling most of the I/O interaction of of Console apps so that they can use an HTML TextArea for I/O.

To use first create subclass of the standard Jep Console you want to implement. Then add a GWTConsoleAdapter member variable and create delegate methods for testSpecialCommands(String command), print(Object o), println(Object o) as below.

public class GWTConsole extends CPConsole implements EntryPoint  {
        GWTConsoleAdapter adapt;

    @Override
        public void onModuleLoad() {
                initialise();
                adapt = new GWTConsoleAdapter(this);
            printIntroText();
            print(getPrompt());
        }

    @Override
    public SPEC_ACTION testSpecialCommands(String command) {
        SPEC_ACTION sa = adapt.testSpecialCommands(command);
        if(sa != SPEC_ACTION.CONTINUE)
            return sa;
                return super.testSpecialCommands(command);
    }

    @Override
    public void print(Object o)
    {
                adapt.print(o);
    }
        
    @Override
    public void println(Object o)
    {
                adapt.println(o);
    }
 }
 

The adapter will handle KeyPress events and call the processCommand(String) when a newline is entered.

  • Constructor Details

    • GWTConsoleAdapter

      public GWTConsoleAdapter(Console c)
      Constructor
      Parameters:
      c - any subclass of the Console.
  • Method Details

    • onKeyPress

      public void onKeyPress(KeyPressEvent event)
      Handle KeyPress events. When enter pressed, extract the command from the text area and schedule an event calling execute()
      Specified by:
      onKeyPress in interface KeyPressHandler
    • execute

      public void execute()
      Calls the Console.processCommand(String) method using line read from TextArea.
      Specified by:
      execute in interface Command
      Specified by:
      execute in interface Scheduler.ScheduledCommand
    • format

      public String format(double val)
      Format a number.
    • print

      public void print(Object o)
      Prints the object to the Bottom of the TextArea
      Parameters:
      o - object to print
    • consoleLog

      public static void consoleLog(String msg)
      Prints a message to the console
      Parameters:
      msg -
    • println

      public void println(Object o)
      Prints a line of text with a newline. Subclasses should call this method rather than System.out.print to allow for output to different places.
    • testSpecialCommands

      public Console.SPEC_ACTION testSpecialCommands(String command)
      Tests for format command and gets a GWT NumberFormat object.
    • getGwtTa

      public TextArea getGwtTa()
      Gets the TextArea component
      Returns: