samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/IOManager.java
changeset 312 0678c9589013
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/trycatchredo/src/org/apidesign/exceptions/trycatchredo/api/IOManager.java	Sun Feb 01 16:29:46 2009 +0100
     1.3 @@ -0,0 +1,44 @@
     1.4 +package org.apidesign.exceptions.trycatchredo.api;
     1.5 +
     1.6 +import java.net.URL;
     1.7 +import javax.swing.Action;
     1.8 +import javax.swing.JDialog;
     1.9 +import javax.swing.JOptionPane;
    1.10 +
    1.11 +/**
    1.12 + *
    1.13 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.14 + */
    1.15 +public final class IOManager {
    1.16 +    IOManager() {
    1.17 +    }
    1.18 +
    1.19 +    /** Action that can store a text to given URL.
    1.20 +     *
    1.21 +     * @param where the url to upload the text to
    1.22 +     * @param what the text to upload
    1.23 +     * @return action that can be invoked anytime to save the content
    1.24 +     */
    1.25 +    public static Action createSaveAction(URL where, CharSequence what) {
    1.26 +        if (old) {
    1.27 +            return new SaveAction(where, what);
    1.28 +        } else {
    1.29 +            return new SaveActionWithQuery(where, what);
    1.30 +        }
    1.31 +    }
    1.32 +
    1.33 +    //
    1.34 +    // Support for executing mock objects in tests
    1.35 +    //
    1.36 +
    1.37 +    static boolean old;
    1.38 +    static Object setVisibleOption;
    1.39 +    static void setVisible(JDialog d, JOptionPane p) {
    1.40 +        if (setVisibleOption == null) {
    1.41 +            d.setVisible(true);
    1.42 +        } else {
    1.43 +            // only in test mode
    1.44 +            p.setValue(setVisibleOption);
    1.45 +        }
    1.46 +    }
    1.47 +}