|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.fedmest.cw.keyboard.KeyboardUtils
public abstract class KeyboardUtils
The KeyboardUtils class is an abstract class that defines the interface for easily accessing the keyboard. It offers a
method (newDefaultKeyboard()) that returns the default implementation of itself. Various methods allow the programmer
to retrieve the basic data types from the input string with a simple call, while the use of the KeyboardInputValidator
framework simplifies access to more complex input requirements.
This class - and all other classes in this framework - is not thread-safe and is not meant to be used in multithreaded applications.
| Constructor Summary | |
|---|---|
KeyboardUtils()
|
|
| Method Summary | ||
|---|---|---|
protected abstract java.lang.String |
addErrTag(java.lang.String msg)
Adds the error tag to a string. |
|
protected abstract java.lang.String |
addPrompt(java.lang.String msg)
Adds the input prompt to a string. |
|
void |
error(java.lang.String msg)
Displays an error message to the user. |
|
boolean |
isCancelable()
Tells you whether the current instance of KeyboardUtils allows the user to cancel input. |
|
static KeyboardUtils |
newDefaultKeyboard()
Returns the default implementation of this abstract class. |
|
void |
prompt(java.lang.String msg)
Displays an input prompt to the user. |
|
int |
readBinaryFromKeyboard()
Reads an int value from the keyboard in binary notation without a prompt to the user. |
|
int |
readBinaryFromKeyboard(java.lang.String msg)
Reads an int value from the keyboard in binary notation. |
|
boolean |
readBoolFromKeyboard()
Reads a boolean response from the keyboard without a prompt to the user. |
|
boolean |
readBoolFromKeyboard(java.lang.String msg)
Reads a boolean response from the keyboard. |
|
char |
readCharFromKeyboard()
Reads a character from the keyboard without a prompt to the user. |
|
char |
readCharFromKeyboard(java.lang.String msg)
Reads a character from the keyboard. |
|
double |
readDoubleFromKeyboard()
Reads a double floating point value from the keyboard without a prompt to the user. |
|
double |
readDoubleFromKeyboard(java.lang.String msg)
Reads a double floating point value from the keyboard. |
|
float |
readFloatFromKeyboard()
Reads a floating point value from the keyboard without a prompt to the user. |
|
float |
readFloatFromKeyboard(java.lang.String msg)
Reads a floating point value from the keyboard. |
|
java.lang.String |
readFromKeyboard()
Reads a new line of text from the keyboard and returns it as it was typed. |
|
|
readFromKeyboard(KeyboardInputValidator<T> v)
Reads a new line of text from the keyboard without printing out any prompt to the user and uses the specified KeyboardInputValidator to verify the input and convert it to the type offered by the validator itself. |
|
java.lang.String |
readFromKeyboard(java.lang.String msg)
Prints a prompt to the user on System.out, then reads a new line of text from the keyboard and returns it as it was
typed. |
|
|
readFromKeyboard(java.lang.String msg,
KeyboardInputValidator<T> v)
Prints a prompt to the user on System.out, then reads a new line of text from the keyboard and uses the specified
KeyboardInputValidator to verify the input and convert it to the type offered by the validator itself. |
|
int |
readHexFromKeyboard()
Reads an int value from the keyboard in hexadecimal notation without a prompt to the user. |
|
int |
readHexFromKeyboard(java.lang.String msg)
Reads an int value from the keyboard in hexadecimal notation. |
|
int |
readIntFromKeyboard()
Reads an int value from the keyboard without a prompt to the user. |
|
int |
readIntFromKeyboard(java.lang.String msg)
Reads an int value from the keyboard. |
|
int |
readIntFromKeyboard(java.lang.String msg,
int radix)
Reads an int value from the keyboard in the specified number base. |
|
long |
readLongFromKeyboard()
Reads a long value from the keyboard without a prompt to the user. |
|
long |
readLongFromKeyboard(java.lang.String msg)
Reads a long value from the keyboard. |
|
long |
readLongFromKeyboard(java.lang.String msg,
int radix)
Reads an long value from the keyboard in the specified number base. |
|
int |
readOctalFromKeyboard()
Reads an int value from the keyboard in octal notation without a prompt to the user. |
|
int |
readOctalFromKeyboard(java.lang.String msg)
Reads an int value from the keyboard in octal notation. |
|
void |
setCancelable(boolean cancelable)
Specifies whether the current instance of KeyboardUtils allows the user to cancel input. |
|
protected abstract boolean |
shouldCancel(java.lang.String msg)
Checks whether a cancel sequence was typed. |
|
boolean |
wasCanceled()
Tells you whether the user canceled input. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public KeyboardUtils()
| Method Detail |
|---|
public static final KeyboardUtils newDefaultKeyboard()
KeyboardUtilsDefImplpublic java.lang.String readFromKeyboard()
public java.lang.String readFromKeyboard(java.lang.String msg)
System.out, then reads a new line of text from the keyboard and returns it as it was
typed. No validation or conversion occurs.
msg - the prompt to show the user. The prompt string will feature a set of characters to alert the user that input is
expected - the specific sequence of characters for the prompt depends on the KeyboardUtils implementation
being used.
public <T> T readFromKeyboard(KeyboardInputValidator<T> v)
KeyboardInputValidator to verify the input and convert it to the type offered by the validator itself. The method
will keep on asking for input until a valid string is typed, unless the instance is cancelable.
T - the type of data that the input string will be converted to.v - an instance of the validator object that should be used against the keyboard input
public <T> T readFromKeyboard(java.lang.String msg,
KeyboardInputValidator<T> v)
System.out, then reads a new line of text from the keyboard and uses the specified
KeyboardInputValidator to verify the input and convert it to the type offered by the validator itself. The method
will keep on asking for input until a valid string is typed, unless the instance is cancelable.
T - the type of data that the input string will be converted to.msg - the prompt to show the user. The prompt string will feature a set of characters to alert the user that input is
expected - the specific sequence of characters for the prompt depends on the KeyboardUtils implementation
being used.v - an instance of the validator object that should be used against the keyboard input
public int readIntFromKeyboard()
IntValidator.
readFromKeyboard(String, KeyboardInputValidator)public int readIntFromKeyboard(java.lang.String msg)
IntValidator.
msg - a prompt on System.out for the user.
readFromKeyboard(String, KeyboardInputValidator)public int readHexFromKeyboard()
IntValidator.
readFromKeyboard(String, KeyboardInputValidator)public int readHexFromKeyboard(java.lang.String msg)
IntValidator.
msg - a prompt on System.out for the user.
readFromKeyboard(String, KeyboardInputValidator)public int readOctalFromKeyboard()
IntValidator.
readFromKeyboard(String, KeyboardInputValidator)public int readOctalFromKeyboard(java.lang.String msg)
IntValidator.
msg - a prompt on System.out for the user.
readFromKeyboard(String, KeyboardInputValidator)public int readBinaryFromKeyboard()
IntValidator.
readFromKeyboard(String, KeyboardInputValidator)public int readBinaryFromKeyboard(java.lang.String msg)
IntValidator.
msg - a prompt on System.out for the user.
readFromKeyboard(String, KeyboardInputValidator)
public int readIntFromKeyboard(java.lang.String msg,
int radix)
IntValidator.
msg - a prompt on System.out for the user.radix - the number base of the integer to parse.
readFromKeyboard(String, KeyboardInputValidator)public long readLongFromKeyboard()
LongValidator.
readFromKeyboard(String, KeyboardInputValidator)public long readLongFromKeyboard(java.lang.String msg)
LongValidator.
msg - a prompt on System.out for the user.
readFromKeyboard(String, KeyboardInputValidator)
public long readLongFromKeyboard(java.lang.String msg,
int radix)
LongValidator.
msg - a prompt on System.out for the user.radix - the number base of the long to parse.
readFromKeyboard(String, KeyboardInputValidator)public float readFloatFromKeyboard()
FloatValidator.
readFromKeyboard(String, KeyboardInputValidator)public float readFloatFromKeyboard(java.lang.String msg)
FloatValidator.
msg - a prompt on System.out for the user.
readFromKeyboard(String, KeyboardInputValidator)public double readDoubleFromKeyboard()
double floating point value from the keyboard without a prompt to the user. This method internally uses a
DoubleValidator.
double floating point number that the user typedreadFromKeyboard(String, KeyboardInputValidator)public double readDoubleFromKeyboard(java.lang.String msg)
double floating point value from the keyboard. This method internally uses a DoubleValidator.
msg - a prompt on System.out for the user.
double floating point number that the user typedreadFromKeyboard(String, KeyboardInputValidator)public boolean readBoolFromKeyboard()
BooleanValidator. Accepted values are "yes", "true", "ok", "no" and "false". Case is irrelevant.
true if the user typed "yes", "true" or "ok",false if they typed "no" or "false".readFromKeyboard(String, KeyboardInputValidator)public boolean readBoolFromKeyboard(java.lang.String msg)
BooleanValidator. Accepted values are
"yes", "true", "ok", "no" and "false". Case is irrelevant.
msg - a prompt on System.out for the user.
true if the user typed "yes", "true" or "ok",false if they typed "no" or "false".readFromKeyboard(String, KeyboardInputValidator)public char readCharFromKeyboard()
CharValidator.
readFromKeyboard(String, KeyboardInputValidator)public char readCharFromKeyboard(java.lang.String msg)
CharValidator.
msg - a prompt on System.out for the user.
readFromKeyboard(String, KeyboardInputValidator)public boolean isCancelable()
KeyboardUtils allows the user to cancel input.
true if user can cancel input,false if user has to type a valid value before they can continuepublic void setCancelable(boolean cancelable)
KeyboardUtils allows the user to cancel input.
cancelable - specifies whether the user can cancel input (true) or has to type a valid value before continuing
(false)public boolean wasCanceled()
true, the client application must discard whatever
return value was offered by a readFromKeyboard() method. The methods will return null if possible, but for
primitive types a dummy value will be returned that must be ignored.
true if user canceled input and return value from readFromKeyboard() method is to be discarded,false if the user typed a valid value that the application can use.public void error(java.lang.String msg)
KeyboardUtils implementation being
used. The method will also add the prompt character sequence, so that input can be retried.
msg - the error message that will displayed on System.out for the user.public void prompt(java.lang.String msg)
msg - the message that will displayed on System.out for the user.protected abstract java.lang.String addPrompt(java.lang.String msg)
KeyboardUtils to specify how the
error tag combines with the error message.
msg - the message that should be combined with the input prompt character sequence.
protected abstract java.lang.String addErrTag(java.lang.String msg)
msg - the message that should be combined with the error tag character sequence.
protected abstract boolean shouldCancel(java.lang.String msg)
KeyboardUtils to specify
whether the string typed by the user is a request to cancel current input. This method will not be invoked by the framework
if the instance if not cancelable and canceling will not be possible.
msg - the message that the user type on the keyboard.
true if the string means the user intends to cancel input,false if the string is not a request to
cancel and should be validated and possibly converted before returning it.isCancelable(),
setCancelable(boolean),
wasCanceled()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||