/** * Show the specified message in a modal dialog. If the user clicks on the "Cancel" button, then * throw an exception. This gives the user the option of not continuing the execution, something * that is particularly useful if continuing execution will result in repeated warnings. NOTE: If * this is called outside the swing event thread, then no cancel button is presented and no * CancelException will be thrown. This is because the displaying of the message must be deferred * to the swing event thread, according to the swing architecture, or we could get deadlock or * rendering problems. * * @param info The message. * @exception ptolemy.util.CancelException If the user clicks on the "Cancel" button. */ protected void _warning(final String info) throws CancelException { // In swing, updates to showing graphics must be done in the // event thread. If we are in the event thread, then proceed. // Otherwise, defer. if (EventQueue.isDispatchThread()) { super._warning(info); } else { Runnable doWarning = new Runnable() { public void run() { Object[] options = {"OK"}; Object[] message = new Object[1]; // If the message lines are longer than 80 characters, we split it // into shorter new line separated strings. // Running vergil on a HSIF .xml file will create a line longer // than 80 characters message[0] = StringUtilities.ellipsis(info, StringUtilities.ELLIPSIS_LENGTH_LONG); // Show the MODAL dialog /*int selected =*/ JOptionPane.showOptionDialog( getContext(), message, "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); } }; Top.deferIfNecessary(doWarning); } }
/** * Show the specified message and throwable information in a modal dialog. If the user clicks on * the "Cancel" button, then throw an exception. This gives the user the option of not continuing * the execution, something that is particularly useful if continuing execution will result in * repeated warnings. By default, only the message of the throwable is shown. The stack trace * information is only shown if the user clicks on the "Display Stack Trace" button. NOTE: If this * is called outside the swing event thread, then no cancel button is presented and no * CancelException will be thrown. This is because the displaying of the message must be deferred * to the swing event thread, according to the swing architecture, or we could get deadlock or * rendering problems. * * @param info The message. * @param throwable The throwable. * @exception ptolemy.util.CancelException If the user clicks on the "Cancel" button. */ protected void _warning(final String info, final Throwable throwable) throws CancelException { // In swing, updates to showing graphics must be done in the // event thread. If we are in the event thread, then proceed. // Otherwise, defer. if (EventQueue.isDispatchThread()) { super._warning(info, throwable); } else { Runnable doWarning = new Runnable() { public void run() { Object[] message = new Object[1]; message[0] = StringUtilities.ellipsis(info, StringUtilities.ELLIPSIS_LENGTH_LONG); Object[] options = {"OK", "Display Stack Trace"}; // Show the MODAL dialog int selected = JOptionPane.showOptionDialog( getContext(), message, "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); if (selected == 1) { _showStackTrace(throwable, info); } } }; Top.deferIfNecessary(doWarning); } }