# HG changeset patch # User Jaroslav Tulach # Date 1233491888 -3600 # Node ID 1687adb2b7f0946af3d66e2dbc92ba0dc690cbbd # Parent 7f38f014244cc34404e2bfff98123090a35f082a Test passes with query diff -r 7f38f014244c -r 1687adb2b7f0 samples/exceptions/src/org/apidesign/exceptions/trycatchredo/IOManager.java --- a/samples/exceptions/src/org/apidesign/exceptions/trycatchredo/IOManager.java Sun Feb 01 13:27:04 2009 +0100 +++ b/samples/exceptions/src/org/apidesign/exceptions/trycatchredo/IOManager.java Sun Feb 01 13:38:08 2009 +0100 @@ -12,6 +12,6 @@ } public static Action createSaveAction(URL where, CharSequence what) { - return new SaveAction(where, what); + return new SaveActionWithQuery(where, what); } } diff -r 7f38f014244c -r 1687adb2b7f0 samples/exceptions/src/org/apidesign/exceptions/trycatchredo/SaveActionWithQuery.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/exceptions/src/org/apidesign/exceptions/trycatchredo/SaveActionWithQuery.java Sun Feb 01 13:38:08 2009 +0100 @@ -0,0 +1,45 @@ +package org.apidesign.exceptions.trycatchredo; + +import java.awt.EventQueue; +import java.awt.event.ActionEvent; +import java.io.IOException; +import java.io.OutputStream; +import java.net.URL; +import javax.swing.AbstractAction; +import javax.swing.JDialog; +import javax.swing.JOptionPane; + +/** + * + * @author Jaroslav Tulach + */ +final class SaveActionWithQuery extends AbstractAction { + private final URL where; + private final CharSequence what; + + SaveActionWithQuery(URL where, CharSequence what) { + this.where = where; + this.what = what; + } + + + public void actionPerformed(ActionEvent ev) { + assert EventQueue.isDispatchThread(); + for (;;) { + try { + OutputStream os = where.openConnection().getOutputStream(); + os.write(what.toString().getBytes()); + os.close(); + } catch (UserQuestionException ex) { + JOptionPane p = ex.getQuestionPane(); + JDialog d = p.createDialog(ex.getLocalizedMessage()); + d.setVisible(true); + ex.confirm(p.getValue()); + continue; + } catch (IOException ex) { + JOptionPane.showMessageDialog(null, ex); + } + break; + } + } +} diff -r 7f38f014244c -r 1687adb2b7f0 samples/exceptions/src/org/apidesign/exceptions/trycatchredo/UserQuestionException.java --- a/samples/exceptions/src/org/apidesign/exceptions/trycatchredo/UserQuestionException.java Sun Feb 01 13:27:04 2009 +0100 +++ b/samples/exceptions/src/org/apidesign/exceptions/trycatchredo/UserQuestionException.java Sun Feb 01 13:38:08 2009 +0100 @@ -1,13 +1,13 @@ package org.apidesign.exceptions.trycatchredo; import java.io.IOException; -import javax.swing.JComponent; +import javax.swing.JOptionPane; /** * * @author Jaroslav Tulach */ public abstract class UserQuestionException extends IOException { - public abstract JComponent getQuestionPane(); - public abstract void confirm(); + public abstract JOptionPane getQuestionPane(); + public abstract void confirm(Object option); }