import edu.neu.ccs.gui.*;

/**
 * Class <code>StringViewer</code> provides static
 * tools for viewing a <code>String</code> in a GUI.
 */
public class StringViewer {
    
    public static final int WIDTH  = 800;
    public static final int HEIGHT = 600;
    
    
    /**
     * <p>Wraps the given <code>String</code> in a JPT
     * <code>Annotation</code> object; then wraps
     * the annotation in a <code>JPTScrollPane</code>
     * object whose viewport is bounded by the given
     * width and height; this scrollpane is returned.</p>
     * 
     * <p>If the given string is <code>null</code>, the
     * scrollpane will show an error message.</p>
     * 
     * <p>No error checks are done on the given width
     * and height.</p>
     * 
     * @param string the string to view
     * @param width  the viewport width  bound
     * @param height the viewport height bound
     */
    public static JPTScrollPane makeScrollView
        (String string, int width, int height)
    {
        if (string == null)
            string = "Null String passed to StringViewer.makeScrollView";
        
        Annotation annotation =
            new Annotation(string);
        
        JPTScrollPane scrollpane =
            new JPTScrollPane(annotation);
        
        scrollpane.boundViewportPreferredSize(width, height);
        
        return scrollpane;
    }
    
    
    /**
     * <p>Wraps the given <code>String</code> in a JPT
     * <code>Annotation</code> object; then wraps
     * the annotation in a <code>JPTScrollPane</code>
     * object whose viewport is bounded by 800-by-600;
     * this scrollpane is returned.</p>
     * 
     * <p>If the given string is <code>null</code>, the
     * scrollpane will show an error message.</p>
     * 
     * @param string the string to view
     */
    public static JPTScrollPane makeScrollView(String string) {
        return makeScrollView(string, WIDTH, HEIGHT);
    }
    
    
    /**
     * Shows the given string in a frame that contains
     * a scroll pane bounded by the given width and
     * height.
     * 
     * @param string the string to view
     * @param width  the viewport width  bound
     * @param height the viewport height bound
     */
    public static void showStringInFrame
        (String string, int width, int height)
    {
        JPTScrollPane scrollpane =
            makeScrollView(string, width, height);
        
        DisplayPanel panel = new DisplayPanel();
        
        panel.add(scrollpane);
        
        panel.frame();
    }
    
    
    /**
     * Shows the given string in a frame that contains
     * a scroll pane bounded by 800-by-600.
     * 
     * @param string the string to view
     */
    public static void showStringInFrame(String string) {
        showStringInFrame(string, WIDTH, HEIGHT);
    }
    
    
    /**
     * Shows the given string in an OK dialog that contains
     * a scroll pane bounded by the given width and height.
     * 
     * @param string the string to view
     * @param width  the viewport width  bound
     * @param height the viewport height bound
     */
    public static void showStringInDialog
        (String string, int width, int height)
    {
        JPTScrollPane scrollpane =
            makeScrollView(string, width, height);
        
        GeneralDialog.showOKDialog(scrollpane, "");
    }
    
    
    /**
     * Shows the given string in an OK dialog that contains
     * a scroll pane bounded by 800-by-600.
     * 
     * @param string the string to view
     */
    public static void showStringInDialog(String string) {
        showStringInDialog(string, WIDTH, HEIGHT);
    }
    
}

