| author | Jaroslav Tulach <jtulach@netbeans.org> |
| Fri Aug 27 14:06:39 2010 +0200 | |
| changeset 365 | 0b7ec6ef8a72 |
| parent 312 | 0678c9589013 |
| permissions | -rw-r--r-- |
| jtulach@312 | 1 |
package org.apidesign.exceptions.trycatchredo.api; |
| jtulach@312 | 2 |
|
| jtulach@312 | 3 |
import java.awt.EventQueue; |
| jtulach@312 | 4 |
import java.awt.event.ActionEvent; |
| jtulach@312 | 5 |
import java.io.IOException; |
| jtulach@312 | 6 |
import java.io.OutputStream; |
| jtulach@312 | 7 |
import java.net.URL; |
| jtulach@312 | 8 |
import javax.swing.AbstractAction; |
| jtulach@312 | 9 |
import javax.swing.JDialog; |
| jtulach@312 | 10 |
import javax.swing.JOptionPane; |
| jtulach@312 | 11 |
|
| jtulach@312 | 12 |
/** |
| jtulach@312 | 13 |
* |
| jtulach@312 | 14 |
* @author Jaroslav Tulach |
| jtulach@312 | 15 |
*/ |
| jtulach@312 | 16 |
final class SaveActionWithQuery extends AbstractAction {
|
| jtulach@312 | 17 |
private final URL where; |
| jtulach@312 | 18 |
private final CharSequence what; |
| jtulach@312 | 19 |
|
| jtulach@312 | 20 |
SaveActionWithQuery(URL where, CharSequence what) {
|
| jtulach@312 | 21 |
this.where = where; |
| jtulach@312 | 22 |
this.what = what; |
| jtulach@312 | 23 |
} |
| jtulach@312 | 24 |
|
| jtulach@312 | 25 |
|
| jtulach@312 | 26 |
public void actionPerformed(ActionEvent ev) {
|
| jtulach@312 | 27 |
assert EventQueue.isDispatchThread(); |
| jtulach@314 | 28 |
// BEGIN: trycatchredo.SaveActionWithQuery |
| jtulach@312 | 29 |
for (;;) {
|
| jtulach@312 | 30 |
try {
|
| jtulach@312 | 31 |
OutputStream os = where.openConnection().getOutputStream(); |
| jtulach@312 | 32 |
os.write(what.toString().getBytes()); |
| jtulach@312 | 33 |
os.close(); |
| jtulach@312 | 34 |
} catch (UserQuestionException ex) {
|
| jtulach@312 | 35 |
JOptionPane p = ex.getQuestionPane(); |
| jtulach@312 | 36 |
JDialog d = p.createDialog(ex.getLocalizedMessage()); |
| jtulach@312 | 37 |
setVisible(d, p); |
| jtulach@312 | 38 |
ex.confirm(p.getValue()); |
| jtulach@312 | 39 |
if ( |
| jtulach@312 | 40 |
!p.getValue().equals(JOptionPane.CANCEL_OPTION) && |
| jtulach@312 | 41 |
!p.getValue().equals(JOptionPane.CLOSED_OPTION) |
| jtulach@312 | 42 |
) {
|
| jtulach@312 | 43 |
continue; |
| jtulach@312 | 44 |
} |
| jtulach@312 | 45 |
} catch (IOException ex) {
|
| jtulach@312 | 46 |
JOptionPane.showMessageDialog(null, ex); |
| jtulach@312 | 47 |
} |
| jtulach@312 | 48 |
break; |
| jtulach@312 | 49 |
} |
| jtulach@314 | 50 |
// END: trycatchredo.SaveActionWithQuery |
| jtulach@312 | 51 |
} |
| jtulach@312 | 52 |
|
| jtulach@312 | 53 |
private static void setVisible(JDialog d, JOptionPane p) {
|
| jtulach@312 | 54 |
IOManager.setVisible(d, p); |
| jtulach@312 | 55 |
} |
| jtulach@312 | 56 |
} |