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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidconsoleLog(String msg) Prints a message to the consolevoidexecute()Calls theConsole.processCommand(String)method using line read from TextArea.format(double val) Format a number.getGwtTa()Gets the TextArea componentvoidonKeyPress(KeyPressEvent event) Handle KeyPress events.voidPrints the object to the Bottom of the TextAreavoidPrints a line of text with a newline.testSpecialCommands(String command) Tests forformatcommand and gets a GWTNumberFormatobject.
-
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:
onKeyPressin interfaceKeyPressHandler
-
execute
public void execute()Calls theConsole.processCommand(String)method using line read from TextArea.- Specified by:
executein interfaceCommand- Specified by:
executein 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 forformatcommand and gets a GWTNumberFormatobject. -
getGwtTa
Gets the TextArea component- Returns:
-