}
}
// Master processor used for the editor.
// Allows us to do things like append brace matcher text.
EditorProcessor proc = new EditorProcessor();
proc.setCodeEditor(true); // assume it is a code editor for now
proc.setPasswordField(text instanceof JPasswordField);
String message = null;
boolean addAnnotation = false;
boolean addMatcherText = false;
char code = getUberEvent().key.getKeyChar();
int keyCode = getUberEvent().key.getKeyCode();
//save whether the shift key is held
boolean isShiftDown = getUberEvent().key.isShiftDown();
//save whether the alt key is held
boolean isAltDown = getUberEvent().key.isAltDown();
//save whether the meta/altGr key is held
boolean isMetaDown = getUberEvent().key.isMetaDown();
//save whether the control key is held
boolean isControlDown = getUberEvent().key.isControlDown();
//get operating system
String os = System.getProperty("os.name");
//get type of textbox
String editorType = text.getClass().getName();
boolean process = false;
//variable for whether the line information should be spoken
boolean lineInfo = false;
// Determine whether or not editing is allowed.
proc.setEditable(text.isEditable());
proc.setMultiLine(text instanceof JEditorPane);
switch (keyCode) {
//right key is pressed
case KeyEvent.VK_RIGHT:
//While the alt key is held on Mac OS - jumps over next word
if (isAltDown && !getUberEvent().preprocess && os.startsWith("Mac")) {
//after event, read previous word
proc.setText(getPreviousWord());
process = true;
}
//while the control key is held on Windows - jumps over next word
else if (isControlDown && !getUberEvent().preprocess && os.startsWith("Win")){
//after event, read previous word
proc.setText(getPreviousWord());
process = true;
}
//while the meta key is held on Mac OS - jumps to end of line
else if (isMetaDown && !getUberEvent().preprocess && os.startsWith("Mac")) {
//after event, read previous word - last word on line
proc.setText(getPreviousWord());
process = true;
}
//otherwise read character that was stepped over
else {
// Don't read newlines here.
String c = getCurrentCharacterAsString();
if (!c.equals("\n") && !c.equals("\r")) {
proc.setText(getCurrentCharacterAsString());
proc.setRequestType(RequestType.CHARACTER);
process = true;
}
//if you are not using any special keys and you are in the editor, also do auditory brace matching
/*if (!isControlDown && !isShiftDown && !isAltDown && !isMetaDown && editorType.equals("org.openide.text.QuietEditorPane")) {
addMatcherText = true;
}*/
process = true;
}
break;
//delete key is pressed
case KeyEvent.VK_DELETE:
if (getUberEvent().preprocess) {
String word;
word = Character.toString(getNextCharacter());
//followed by "deleted"
proc.setText(word);
proc.setRequestType(RequestType.CHARACTER);
proc.setDeletedChar(true);
process = true;
}
break;
//backspace key is pressed
case KeyEvent.VK_BACK_SPACE:
if (getUberEvent().preprocess) {
String word;
// say character was deleted.
proc.setText(Character.toString(getPreviousCharacter()));
proc.setRequestType(RequestType.CHARACTER);
proc.setDeletedChar(true);
process = true;
}
break;
//left key is pressed
case KeyEvent.VK_LEFT:
//While the alt key is held on Mac OS - jumps over previous word
if (isAltDown && !getUberEvent().preprocess && os.startsWith("Mac")) {
//after event, read next word
proc.setText(getNextWord());
process = true;
}
//while the control key is held on Windows - jumps over pevious word
else if (isControlDown && !getUberEvent().preprocess && os.startsWith("Win")){
//after event, read next word
proc.setText(getNextWord());
process = true;
}
//while the meta key is held on Mac OS - jumps to beginning of line
else if (isMetaDown && !getUberEvent().preprocess && os.startsWith("Mac")) {
//after event, read next word - first word on line
proc.setText(getNextWord());
process = true;
}
//otherwise read character that was stepped over
else {
// Don't read newlines here.
String c = getCurrentCharacterAsString();
if (!c.equals("\n") && !c.equals("\r")) {
proc.setText(getCurrentCharacterAsString());
proc.setRequestType(RequestType.CHARACTER);
process = true;
}
//if you are not using any special keys and you are in the editor, also do auditory brace matching
/*if (!isControlDown && !isShiftDown && !isAltDown && !isMetaDown && editorType.equals("org.openide.text.QuietEditorPane")) {
// TODO: Modify handling of matcher text
addMatcherText = true;
}*/
process = true;
}
break;
//up or down arrow key is pressed
case KeyEvent.VK_UP:
case KeyEvent.VK_DOWN:
//read current line
proc.setText(getCurrentLineOfText());
process = true;
lineInfo = true;
//if you are not using any special keys and you are in the editor, also do auditory brace matching and add annotations
if (!isControlDown && !isShiftDown && !isAltDown && !isMetaDown && editorType.equals("org.openide.text.QuietEditorPane")) {
addMatcherText = true;
addAnnotation = true;
}
break;
//end button is pressed
case KeyEvent.VK_END:
//read previous word - last word on line
proc.setText(getPreviousWord());
process = true;
break;
//home button is pressed
case KeyEvent.VK_HOME:
//read next word - first word on line
proc.setText(getNextWord());
process = true;
break;
//0 is pressed
case KeyEvent.VK_0:
// If control is down, don't speak "0".
if (isControlDown || isMetaDown)
{
// Fix to focus bug on Windows
proc.setText("");
process = false;
}
else
{
if (Character.isDefined(code) && keyCode != 0) {
proc.setText(Character.toString(code));
process = true;
}
//}
proc.setRequestType(RequestType.CHARACTER);
}
break;
//1 is pressed
case KeyEvent.VK_1:
//if shift is pressed - exclamation mark is written - read "exclamation"
/*if (isShiftDown && !getUberEvent().preprocess) {
//read "exclamation"
proc.setText("!");
process = true;
}
//otherwise read normal character
else {*/
if (Character.isDefined(code) && keyCode != 0) {
proc.setText(Character.toString(code));
process = true;
}
//}
proc.setRequestType(RequestType.CHARACTER);
break;
//C is pressed
case KeyEvent.VK_C:
//if control is pressed on Windows, read "copy"
if (os.startsWith("Win") && isControlDown && !getUberEvent().preprocess) {
//read line number
proc.setText("copy");
process = true;
}
//if command (meta-key) is pressed on Mac, read "copy"
if (os.startsWith("Mac") && isMetaDown && !getUberEvent().preprocess) {
//read line number
proc.setText("copy");
process = true;
}
//otherwise read normal character
else {
if (Character.isDefined(code) && keyCode != 0) {
proc.setText(Character.toString(code));
proc.setRequestType(RequestType.CHARACTER);
process = true;
}
}
break;
//L is pressed
case KeyEvent.VK_L:
//if control is pressed
if (isControlDown && !getUberEvent().preprocess) {
//read line number
int line = getCurrentLineNumber();
proc.setLineNumber(line);
process = true;
}
//otherwise read normal character
else {
if (Character.isDefined(code) && keyCode != 0) {
proc.setText(Character.toString(code));
proc.setRequestType(RequestType.CHARACTER);
process = true;
}
}
break;
//V is pressed
case KeyEvent.VK_V:
//if control is pressed on Windows, read "copy"
if (os.startsWith("Win") && isControlDown && !getUberEvent().preprocess) {
//read line number
proc.setText("paste");
process = true;
}
//if command (meta-key) is pressed on Mac, read "copy"
if (os.startsWith("Mac") && isMetaDown && !getUberEvent().preprocess) {
//read line number
proc.setText("paste");
process = true;
}
//otherwise read normal character
else {
if (Character.isDefined(code) && keyCode != 0) {
proc.setText(Character.toString(code));
proc.setRequestType(RequestType.CHARACTER);
process = true;
}
}
break;
//X is pressed
case KeyEvent.VK_X:
//if control is pressed on Windows, read "copy"
if (os.startsWith("Win") && isControlDown && !getUberEvent().preprocess) {
//read line number
proc.setText("cut");
process = true;
}
//if command (meta-key) is pressed on Mac, read "copy"
if (os.startsWith("Mac") && isMetaDown && !getUberEvent().preprocess) {
//read line number
proc.setText("cut");
process = true;
}
//otherwise read normal character
else {
if (Character.isDefined(code) && keyCode != 0) {
proc.setText(Character.toString(code));
proc.setRequestType(RequestType.CHARACTER);
process = true;
}
}
break;
//Y is pressed
case KeyEvent.VK_Y:
//if control is pressed on Windows, read "copy"
if (os.startsWith("Win") && isControlDown && !getUberEvent().preprocess) {
//read line number
proc.setText("redo");
process = true;
}
//if command (meta-key) is pressed on Mac, read "copy"
if (os.startsWith("Mac") && isMetaDown && !getUberEvent().preprocess) {
//read line number
proc.setText("redo");
process = true;
}
//otherwise read normal character
else {
if (Character.isDefined(code) && keyCode != 0) {
proc.setText(Character.toString(code));
proc.setRequestType(RequestType.CHARACTER);
process = true;
}
}
break;
//Z is pressed
case KeyEvent.VK_Z:
//if control is pressed on Windows, read "copy"
if (os.startsWith("Win") && isControlDown && !getUberEvent().preprocess) {
//read line number
proc.setText("undo");
process = true;
}
//if command (meta-key) is pressed on Mac, read "copy"
if (os.startsWith("Mac") && isMetaDown && !getUberEvent().preprocess) {
//read line number
proc.setText("undo");
process = true;
}
//otherwise read normal character
else {
if (Character.isDefined(code) && keyCode != 0) {
proc.setText(Character.toString(code));
proc.setRequestType(RequestType.CHARACTER);
process = true;
}
}
break;
default:
if (Character.isDefined(code) && keyCode != 0) {
proc.setText(Character.toString(code));
proc.setRequestType(RequestType.CHARACTER);
process = true;
}
}
if (process) {
String processed = textProcessor.process("");
if (lineInfo && proc.isMultiLine()) {
proc.setLineNumber(getCurrentLineNumber());
if (getCurrentLineNumber() == 1)
proc.setStartOfDocument(true);
else if(getLastLineNumber() == getCurrentLineNumber())
proc.setEndOfDocument(true);
}
//add the end matcher text to the end of the processed line message
if (addMatcherText) {
proc.setBraceMatcherText(getMatchingMessage());
}
//ad the line annotation descriptions to the end of the processed line message
if (addAnnotation) {
proc.setAnnotations(getAnnotation());
}
}
return proc;
}