Package com.singularsys.client
Class GWTConsoleAdapter
java.lang.Object
com.singularsys.client.GWTConsoleAdapter
- All Implemented Interfaces:
Scheduler.ScheduledCommand
,KeyPressHandler
,EventHandler
,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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
consoleLog
(String msg) Prints a message to the consolevoid
execute()
Calls theConsole.processCommand(String)
method using line read from TextArea.format
(double val) Format a number.getGwtTa()
Gets the TextArea componentvoid
onKeyPress
(KeyPressEvent event) Handle KeyPress events.void
Prints the object to the Bottom of the TextAreavoid
Prints a line of text with a newline.testSpecialCommands
(String command) Tests forformat
command and gets a GWTNumberFormat
object.
-
Constructor Details
-
GWTConsoleAdapter
Constructor- Parameters:
c
- any subclass of the Console.
-
-
Method Details
-
onKeyPress
Handle KeyPress events. When enter pressed, extract the command from the text area and schedule an event callingexecute()
- Specified by:
onKeyPress
in interfaceKeyPressHandler
-
execute
public void execute()Calls theConsole.processCommand(String)
method using line read from TextArea.- Specified by:
execute
in interfaceCommand
- Specified by:
execute
in interfaceScheduler.ScheduledCommand
-
format
Format a number. -
print
Prints the object to the Bottom of the TextArea- Parameters:
o
- object to print
-
consoleLog
Prints a message to the console- Parameters:
msg
-
-
println
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
Tests forformat
command and gets a GWTNumberFormat
object. -
getGwtTa
Gets the TextArea component- Returns:
-