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