Marking code snippets for the trycatchredo example
authorJaroslav Tulach <jtulach@netbeans.org>
Sun, 01 Feb 2009 17:41:32 +0100
changeset 31403a451fc2256
parent 313 d8bb07520edd
child 315 08dd52950883
Marking code snippets for the trycatchredo example
samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/SaveAction.java
samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/SaveActionWithQuery.java
samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/UserQuestionException.java
samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/usage/QueryStream.java
     1.1 --- a/samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/SaveAction.java	Sun Feb 01 16:30:09 2009 +0100
     1.2 +++ b/samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/SaveAction.java	Sun Feb 01 17:41:32 2009 +0100
     1.3 @@ -24,6 +24,7 @@
     1.4      
     1.5      public void actionPerformed(ActionEvent ev) {
     1.6          assert EventQueue.isDispatchThread();
     1.7 +        // BEGIN: trycatchredo.SaveAction
     1.8          try {
     1.9              OutputStream os = where.openConnection().getOutputStream();
    1.10              os.write(what.toString().getBytes());
    1.11 @@ -31,5 +32,6 @@
    1.12          } catch (IOException ex) {
    1.13              JOptionPane.showMessageDialog(null, ex);
    1.14          }
    1.15 +        // END: trycatchredo.SaveAction
    1.16      }
    1.17  }
     2.1 --- a/samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/SaveActionWithQuery.java	Sun Feb 01 16:30:09 2009 +0100
     2.2 +++ b/samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/SaveActionWithQuery.java	Sun Feb 01 17:41:32 2009 +0100
     2.3 @@ -25,6 +25,7 @@
     2.4      
     2.5      public void actionPerformed(ActionEvent ev) {
     2.6          assert EventQueue.isDispatchThread();
     2.7 +        // BEGIN: trycatchredo.SaveActionWithQuery
     2.8          for (;;) {
     2.9              try {
    2.10                  OutputStream os = where.openConnection().getOutputStream();
    2.11 @@ -46,6 +47,7 @@
    2.12              }
    2.13              break;
    2.14          }
    2.15 +        // END: trycatchredo.SaveActionWithQuery
    2.16      }
    2.17  
    2.18      private static void setVisible(JDialog d, JOptionPane p) {
     3.1 --- a/samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/UserQuestionException.java	Sun Feb 01 16:30:09 2009 +0100
     3.2 +++ b/samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/UserQuestionException.java	Sun Feb 01 17:41:32 2009 +0100
     3.3 @@ -3,6 +3,7 @@
     3.4  import java.io.IOException;
     3.5  import javax.swing.JOptionPane;
     3.6  
     3.7 +// BEGIN: trycatchredo.UserQuestionException
     3.8  /** Specialized I/O exception to request some kind of user confirmation.
     3.9   * A code that needs to ask user shall not attempt to open a dialog itself,
    3.10   * rather it shall emit this exception and let its callers show the dialog
    3.11 @@ -13,7 +14,9 @@
    3.12   */
    3.13  public abstract class UserQuestionException extends IOException {
    3.14      /** Description of the dialog to show to the user. Whoever catches
    3.15 -     * this exception shall use {@link #getQuestionPane()}.{@link JOptionPane#createDialog(java.lang.String)}
    3.16 +     * this exception shall use 
    3.17 +     * {@link #getQuestionPane()}.
    3.18 +     * {@link JOptionPane#createDialog(java.lang.String)}
    3.19       * to construct and display the dialog.
    3.20       * 
    3.21       * @return the pane to display to user
    3.22 @@ -27,3 +30,4 @@
    3.23       */
    3.24      public abstract void confirm(Object option);
    3.25  }
    3.26 +// END: trycatchredo.UserQuestionException
    3.27 \ No newline at end of file
     4.1 --- a/samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/usage/QueryStream.java	Sun Feb 01 16:30:09 2009 +0100
     4.2 +++ b/samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/usage/QueryStream.java	Sun Feb 01 17:41:32 2009 +0100
     4.3 @@ -6,13 +6,15 @@
     4.4  import java.io.OutputStream;
     4.5  import javax.swing.JOptionPane;
     4.6  
     4.7 +// BEGIN: trycatchredo.stream
     4.8  public final class QueryStream extends OutputStream {
     4.9      private ByteArrayOutputStream arr = new ByteArrayOutputStream();
    4.10      /** this field can be manipulated by the QueryException */
    4.11      Boolean reverse;
    4.12  
    4.13      @Override
    4.14 -    public synchronized void write(byte[] b, int off, int len) throws IOException {
    4.15 +    public synchronized void write(byte[] b, int off, int len)
    4.16 +    throws IOException {
    4.17          if (reverse == null) {
    4.18              throw new QueryException();
    4.19          }
    4.20 @@ -63,3 +65,4 @@
    4.21          }
    4.22      }
    4.23  }
    4.24 +// END: trycatchredo.stream