+ public void showInternalDialog(JPanel mainPanel, String title,
+ int yesNoCancelOption, int questionMessage, Icon icon,
+ Object[] options, String initresponse)
+ {
+ if (!isInteractiveMode())
+ {
+ handleResponse(getMockResponse());
+ }
+
+ ourOptions = Arrays.asList(options);
+ int response;
+ if (parentComponent != this)
+ {
+ response = JOptionPane.showInternalOptionDialog(parentComponent,
+ mainPanel, title, yesNoCancelOption, questionMessage, icon,
+ options, initresponse);
+ }
+ else
+ {
+ response = JOptionPane.showOptionDialog(parentComponent, mainPanel,
+ title, yesNoCancelOption, questionMessage, icon, options,
+ initresponse);
+ }
+ if (!Platform.isJS())
+ /**
+ * Java only
+ *
+ * @j2sIgnore
+ */
+ {
+ handleResponse(response);
+ }
+ }
+
+ @Override
+ public JvOptionPane setResponseHandler(Object response, Runnable action)
+ {
+ callbacks.put(response, action);
+ return this;
+ }
+
+ /**
+ * JalviewJS signals option selection by a property change event for the
+ * option e.g. "OK". This methods responds to that by running the response
+ * action that corresponds to that option.
+ *
+ * @param evt
+ */
+ @Override
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ Object newValue = evt.getNewValue();
+ int ourOption = ourOptions.indexOf(newValue);
+ if (ourOption >= 0)
+ {
+ handleResponse(ourOption);
+ }
+ else
+ {
+ // try our luck..
+ handleResponse(newValue);
+ }
+ }
+
+ @Override
+ public void handleResponse(Object response)
+ {
+ /*
+ * this test is for NaN in Chrome
+ */
+ if (response != null && !response.equals(response))
+ {
+ return;
+ }
+ Runnable action = callbacks.get(response);
+ if (action != null)
+ {
+ action.run();
+ parentComponent.requestFocus();
+ }
+ }