samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/IOManager.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sun, 01 Feb 2009 16:29:46 +0100
changeset 312 0678c9589013
permissions -rw-r--r--
Renaming the project to 'Try Catch Redo'
     1 package org.apidesign.exceptions.trycatchredo.api;
     2 
     3 import java.net.URL;
     4 import javax.swing.Action;
     5 import javax.swing.JDialog;
     6 import javax.swing.JOptionPane;
     7 
     8 /**
     9  *
    10  * @author Jaroslav Tulach <jtulach@netbeans.org>
    11  */
    12 public final class IOManager {
    13     IOManager() {
    14     }
    15 
    16     /** Action that can store a text to given URL.
    17      *
    18      * @param where the url to upload the text to
    19      * @param what the text to upload
    20      * @return action that can be invoked anytime to save the content
    21      */
    22     public static Action createSaveAction(URL where, CharSequence what) {
    23         if (old) {
    24             return new SaveAction(where, what);
    25         } else {
    26             return new SaveActionWithQuery(where, what);
    27         }
    28     }
    29 
    30     //
    31     // Support for executing mock objects in tests
    32     //
    33 
    34     static boolean old;
    35     static Object setVisibleOption;
    36     static void setVisible(JDialog d, JOptionPane p) {
    37         if (setVisibleOption == null) {
    38             d.setVisible(true);
    39         } else {
    40             // only in test mode
    41             p.setValue(setVisibleOption);
    42         }
    43     }
    44 }