/*
 * @(#)RequestImageViewer.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>RequestImageViewer</code> creates a simple
 * GUI to enable a user to specify the parameters for making
 * an <code>ImageViewer</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 RequestImageViewer extends DisplayPanel {
    
    /** The text field for the directory string. */
    private TextFieldView directoryView = 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 Image Viewer Help") {
        public void perform() {
            showHelp();
        }
    };
    
    /** The action to make the image viewer. */
    private SimpleAction action = new SimpleAction("Make Image Viewer") {
        public void perform() {
            makeImageViewer();
        }
    };
    
    /** 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 Directory", directoryView },
                { "Image List Name",  filelistView  }
        }, 10, 10, CENTER);
    
    
    /** The panel for the help GUI. */
    private TablePanel helpPanel = new TablePanel(
        new Object[][] {
            { "Images Directory:",
              "The local directory with the images" },
            
            { null,
              "     No default" },
            
            { "Image List Name:",
              "The text file that contains the list of image file names" },
            
            { null,
              "     If blank, then reads all images in the directory" } },
            
        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 RequestImageViewer() {
        add(mainPanel);
        frame("Request Image Viewer");
    }
    
    
    /** The action to make an image viewer from the data provided by the user. */
    private void makeImageViewer() {
        String directory = directoryView.getViewState();
        String filelist  = filelistView.getViewState();
        
        boolean autoscale = autoscaleview.getBooleanValue();
        
        new ImageViewer(directory, filelist, autoscale);
    }
    
    
    /** The action to show the help GUI. */
    private void showHelp() {
        if (helpFrame == null)
            helpFrame = helpPanel.frame("Image Viewer Help", NORTH);
        else
            helpFrame.show();
    }
    
}
