/*
 * StateView.java  
 *
 * Copyright 2001
 * College of Computer Science
 * Northeastern University
 * Boston, MA  02115
 *
 * This software may be used for educational purposes as long as
 * this copyright notice is retained intact at the top of all files.
 *
 * 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.
 *
 * Contact information:
 *   Richard Rasala    rasala@ccs.neu.edu
 *   Viera Proulx      vkp@ccs.neu.edu
 *   Jeff Raab         jmr@ccs.neu.edu
 *   Jennifer McDonald jenimac@ccs.neu.edu
 * 
 * Telephone:          617-373-2462
 *
 * This software was created with support from Northeastern 
 * University and from NSF grant DUE-9950829.
 */

import edu.neu.ccs.*;
import edu.neu.ccs.util.JPTConstants;
import edu.neu.ccs.gui.*;
import java.awt.*;
import javax.swing.*;

//View for input of a state

public class StateView extends DisplayCollection
					   implements TypedView {
    
     // The labels for the final/non-final option buttons
    protected static final String[] finalityStrings
        = new String[] { "Final", "Non-final" };
    
    // The final/non-final radio button panel in the user interface. 
    protected OptionsView stateOptions
        = new OptionsView
            (finalityStrings, 0, new GridLayout(0,1));
    	
     // State radius
    private TextFieldView radiusTFV = 
    	new TextFieldView("75", "Please enter a radius:",
    					  "State Radius");	

    // color input for States
    private ColorView stateColor =
    	new ColorView(Color.yellow);
    
   	// Collection of controls
    private DisplayCollection controls = 
    	new DisplayCollection(SwingConstants.VERTICAL);
    	
    // Property list for StateView
    private InputProperties properties = 
    	new InputProperties();
  
   	//constructor
	public StateView() {
		
		// add control objects to the controls DisplayCollection		
		controls.add( new ComponentWrapper(
					  new Display(stateOptions)));
		
		controls.add( new ComponentWrapper(
      		 		  new Display(radiusTFV, 
      		 		  			  "Radius: ", null)));
      		 		  			  
      	controls.add( new ComponentWrapper(
      		 			new Display(stateColor, 
      		 						"Color:   ", null)));
      		 						
      	add( new Display(controls, null, "State Options"));	
    }
	
	public Stringable demandObject() {
		return null;
	}
	
	public Stringable requestObject() 
		throws CancelledException{
		return null;
	}
	
	public Stringable requestObject(Automata automata, 
									Point lastClicked) 
		throws CancelledException{
	
		StateImage image = new StateImage(lastClicked, 
										  radiusTFV.requestInt(), 
										  stateColor.getColor());
		
		String name = new SimpleDialog().requestString("State name: ",
													   "Enter a Name");
	
		State s = new State(name, 
							(stateOptions.getSelectedIndex() == 0), 
							image);
	
		while (!(automata.addState(s))) {
			name = new SimpleDialog().requestString(
				"Please enter a unique name for " +
			    "the state you wish to add.", 
				"Enter a Unique Name");
				
		    s = new State(name, 
							(stateOptions.getSelectedIndex() == 0), 
							image);
		}
		
		return s;
	}
		
	public void setInputProperties(InputProperties p){
		properties = p;	
	}

	public InputProperties getInputProperties(){
		return properties;	
	}
	
	public Class getDataType(){
		return State.class;
	}	
}


