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