+ /**
+ * Handle keystrokes.
+ *
+ * @param keypress keystroke event
+ */
+ @Override
+ public void onKeypress(final TKeypressEvent keypress) {
+
+ if (this instanceof TInputBox) {
+ super.onKeypress(keypress);
+ return;
+ }
+
+ // Some convenience for message boxes: Alt won't be needed for the
+ // buttons.
+ switch (type) {
+
+ case OK:
+ if (keypress.equals(kbO)) {
+ buttons.get(0).dispatch();
+ return;
+ }
+ break;
+
+ case OKCANCEL:
+ if (keypress.equals(kbO)) {
+ buttons.get(0).dispatch();
+ return;
+ } else if (keypress.equals(kbC)) {
+ buttons.get(1).dispatch();
+ return;
+ }
+ break;
+
+ case YESNO:
+ if (keypress.equals(kbY)) {
+ buttons.get(0).dispatch();
+ return;
+ } else if (keypress.equals(kbN)) {
+ buttons.get(1).dispatch();
+ return;
+ }
+ break;
+
+ case YESNOCANCEL:
+ if (keypress.equals(kbY)) {
+ buttons.get(0).dispatch();
+ return;
+ } else if (keypress.equals(kbN)) {
+ buttons.get(1).dispatch();
+ return;
+ } else if (keypress.equals(kbC)) {
+ buttons.get(2).dispatch();
+ return;
+ }
+ break;
+
+ default:
+ throw new IllegalArgumentException("Invalid message box type: " + type);
+ }
+
+ super.onKeypress(keypress);
+ }
+