+ // ------------------------------------------------------------------------
+ // TWindow ----------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * 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);
+ }
+
+ // ------------------------------------------------------------------------
+ // TMessageBox ------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get the result.
+ *
+ * @return the result: OK, CANCEL, YES, or NO.
+ */
+ public final Result getResult() {
+ return result;
+ }
+
+ /**
+ * See if the user clicked YES.
+ *
+ * @return true if the user clicked YES
+ */
+ public final boolean isYes() {
+ return (result == Result.YES);
+ }
+
+ /**
+ * See if the user clicked NO.
+ *
+ * @return true if the user clicked NO
+ */
+ public final boolean isNo() {
+ return (result == Result.NO);
+ }
+
+ /**
+ * See if the user clicked OK.
+ *
+ * @return true if the user clicked OK
+ */
+ public final boolean isOk() {
+ return (result == Result.OK);
+ }
+
+ /**
+ * See if the user clicked CANCEL.
+ *
+ * @return true if the user clicked CANCEL
+ */
+ public final boolean isCancel() {
+ return (result == Result.CANCEL);
+ }
+