/*
 * @(#)RequestWebImageViewer.java    2.3.3  2 January 2005
 *
 * Copyright 2005
 * College of Computer and Information Science
 * Northeastern University
 * Boston, MA  02115
 *
 * The Java Power Tools software may be used for educational
 * purposes as long as this copyright notice is retained intact
 * at the top of all source files.
 *
 * To discuss possible commercial use of this software, 
 * contact Richard Rasala at Northeastern University, 
 * College of Computer and Information Science,
 * 617-373-2462 or rasala@ccs.neu.edu.
 *
 * The Java Power Tools software has been designed and built
 * in collaboration with Viera Proulx and Jeff Raab.
 *
 * Should this software be modified, the words "Modified from 
 * Original" must be included as a comment below this notice.
 *
 * All publication rights are retained.  This software or its 
 * documentation may not be published in any media either
 * in whole or in part without explicit permission.
 *
 * This software was created with support from Northeastern 
 * University and from NSF grant DUE-9950829.
 */

package edu.neu.ccs.gui;


/**
 * <p>Class <code>RequestWebImageViewer</code> creates a simple
 * GUI to enable a user to specify the parameters for making
 * a <code>WebImageViewer</code>;
 * this GUI also provides a button to create the viewer and
 * a button to provide help directions.</p>
 *
 * @author  Richard Rasala
 * @version 2.3.3
 * @since   2.3.3
 */
public class RequestWebImageViewer extends DisplayPanel {
    
    /** The text field for the images URL string. */
    private TextFieldView imagesURLview   = new TextFieldView("", 600);
    
    /** The text field for the filelist URL string. */
    private TextFieldView filelistURLview = new TextFieldView("", 600);
    
    /** The text field for the filelist string. */
    private TextFieldView filelistView    = new TextFieldView("imagelist.txt", 600);
    
    
    /** The frame for the help directions. */
    private JPTFrame helpFrame = null;
    
    
    /** The action to show the help directions. */
    private SimpleAction help = new SimpleAction("Show Web Image Viewer Help") {
        public void perform() {
            showHelp();
        }
    };
    
    /** The action to make the image viewer. */
    private SimpleAction action = new SimpleAction("Make Web Image Viewer") {
        public void perform() {
            makeWebImageViewer();
        }
    };
    
    /** A threaded version of the action to make the image viewer. */
    private ThreadedAction threadedaction = new ThreadedAction(action);
    
    
    /** The check box to permit the user to decide whether to autoscale. */
    private BooleanView autoscaleview =
        new BooleanView("Scale Images to Fit Screen", false);
    
    
    /** The panel for the labeled text field views in the main GUI. */
    private TablePanel panel = new TablePanel(
        new Object[][] {
                { "Images URL",     imagesURLview   },
                { "Image List URL",  filelistURLview },
                { "Image List Name", filelistView    } },
        10, 10, WEST);
    
    
    /** The panel for the help GUI. */
    private TablePanel helpPanel = new TablePanel(
        new Object[][] {
            { "Images URL:",      "The web directory with the images" },
            { null,               "     No default" },
            { "Image List URL:",  "The web directory with the list of image file names" },
            { null,               "     Default: Images URL" },
            { "Image List Name:", "The text file that contains the list of image file names" },
            { null,               "     Default: imagelist.txt" }
        }, 10, 10, WEST);
    
    
    /** The main panel for the text fields, check box, and buttons. */
    private TablePanel mainPanel = new TablePanel(
        new Object[] { help, panel, autoscaleview, threadedaction }, VERTICAL, 10, 10, CENTER);
    
    
    /** The constructor that builds the request GUI and frames it. */
    public RequestWebImageViewer() {
        add(mainPanel);
        frame("Request Web Image Viewer");
    }
    
    
    /** The action to make an image viewer from the data provided by the user. */
    private void makeWebImageViewer() {
        String imagesURL   = imagesURLview.  getViewState();
        String filelistURL = filelistURLview.getViewState();
        String filelist    = filelistView.   getViewState();
        
        boolean autoscale = autoscaleview.getBooleanValue();
        
        new WebImageViewer(imagesURL, filelistURL, filelist, autoscale);
    }
    
    
    /** The action to show the help GUI. */
    private void showHelp() {
        if (helpFrame == null)
            helpFrame = helpPanel.frame("Web Image Viewer Help", NORTH);
        else
            helpFrame.show();
    }
    
}
