samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/SaveActionWithQuery.java
Updating to NBMs from NetBeans 8.0.1 as some of them are required to run on JDK8
1 package org.apidesign.exceptions.trycatchredo.api;
3 import java.awt.EventQueue;
4 import java.awt.event.ActionEvent;
5 import java.io.IOException;
6 import java.io.OutputStream;
8 import javax.swing.AbstractAction;
9 import javax.swing.JDialog;
10 import javax.swing.JOptionPane;
14 * @author Jaroslav Tulach
16 final class SaveActionWithQuery extends AbstractAction {
17 private final URL where;
18 private final CharSequence what;
20 SaveActionWithQuery(URL where, CharSequence what) {
26 public void actionPerformed(ActionEvent ev) {
27 assert EventQueue.isDispatchThread();
28 // BEGIN: trycatchredo.SaveActionWithQuery
31 OutputStream os = where.openConnection().getOutputStream();
32 os.write(what.toString().getBytes());
34 } catch (UserQuestionException ex) {
35 JOptionPane p = ex.getQuestionPane();
36 JDialog d = p.createDialog(ex.getLocalizedMessage());
38 ex.confirm(p.getValue());
40 !p.getValue().equals(JOptionPane.CANCEL_OPTION) &&
41 !p.getValue().equals(JOptionPane.CLOSED_OPTION)
45 } catch (IOException ex) {
46 JOptionPane.showMessageDialog(null, ex);
50 // END: trycatchredo.SaveActionWithQuery
53 private static void setVisible(JDialog d, JOptionPane p) {
54 IOManager.setVisible(d, p);