/**
  *
  * See the end of the file for the log of changes.
  *
  * $Author: mtsezgin $
  * $Date: 2000/06/03 01:52:31 $
  * $Revision: 1.3 $
  * $Headers$
  * $Id: ControlModule.java,v 1.3 2000/06/03 01:52:31 mtsezgin Exp $
  * $Name:  $
  * $Locker:  $
  * $Source: /mit/mtsezgin/CVS/Repository/REC/ControlModule.java,v $
  *
  **/


import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.Image;
import java.awt.TextField;
import java.awt.Toolkit;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

/**
  *
  * This class is used for controlling and changing the parameters
  * in the main application.
  *
  **/

class      ControlModule
extends    Frame
implements ActionListener
{    
    private Tablet    tablet;
    
    private Menu      file;
    private MenuBar   menubar;
    private MenuItem  quit_menu;

    private TextField scale;
    private TextField window_width;
    private TextField step_angle;
    private TextField orientation_angle;
    
    /**
    *
    * The constructor.
    *
    **/
    public ControlModule( Tablet tablet )
    {
        super( "Controls" );
        this.tablet = tablet;

        menubar     = new MenuBar();
        file        = new Menu( "File" );
        quit_menu   = new MenuItem( "Quit" );
        
        setLayout( new GridLayout( 4, 2 ) );
        
        scale             = 
            new TextField( "" + 
                tablet.scale );
        step_angle        = 
            new TextField( "" + 
                GeometryUtil.radian2degree( tablet.step_angle ) );
        window_width      = 
            new TextField( "" + 
                GeometryUtil.radian2degree( tablet.window_width ) );
        orientation_angle = 
            new TextField( "" + 
                GeometryUtil.radian2degree( tablet.orientation_angle ) );
        
        add( new Label("Threshold Scale  ") );
        add( scale                          );
        add( new Label("Step Angle       ") );
        add( step_angle                     );
        add( new Label("Window Width     ") );
        add( window_width                   );
        add( new Label("Orientation Angle") );
        add( orientation_angle              );
        
        
        file.add( quit_menu );
        menubar.add( file );
        setMenuBar( menubar );
        file.add( quit_menu );
		
        quit_menu.addActionListener( this );
        scale.addActionListener( this );
        step_angle.addActionListener( this );
        window_width.addActionListener( this );
        orientation_angle.addActionListener( this );
		
        pack();
        validate();
    }
    
    /**
    *
    * Handle key stroke events
    *
    **/
    public void
    keyPressed( KeyEvent k )
    {
    }
     
    /**
    *
    * Handle key stroke events
    *
    **/
    public void
    keyReleased( KeyEvent k )
    {    
    }
     
    /**
    *
    * Handle key stroke events
    *
    **/
    public void
    keyTyped( KeyEvent k )
    {
        char key = k.getKeyChar();
        
        if ( key == 'q' ) {
            System.exit( 0 );
            return;
        }
    }
     
    /**
    *
    * Handle action events
    *
    **/
    public void
    actionPerformed( ActionEvent e ) 
    {
        String command = e.getActionCommand();
        Object source  = e.getSource();
        
        if ( ( source == scale             ) || 
             ( source == step_angle        ) || 
             ( source == window_width      ) ||
             ( source == orientation_angle ) ) {

            double angle = GeometryUtil.degree2radian( 
                    Double.valueOf( command ).doubleValue() );

            double value = Double.valueOf( command ).doubleValue();

            if ( source == scale ) {
                tablet.scale = value;
            }
            
            if ( source == step_angle ) {
                tablet.step_angle = angle;
            }

            if ( source == window_width ) {
                tablet.window_width = angle;
            }
            
            if ( source == orientation_angle ) {
                tablet.orientation_angle = angle;
            }             
        }

        System.out.println( command );

        if ( command == "Quit" ) {
            System.exit( 0 );
        }
    }
}

/**
  *
  * $Log: ControlModule.java,v $
  * Revision 1.3  2000/06/03 01:52:31  mtsezgin
  * *** empty log message ***
  *
  * Revision 1.2  2000/06/02 21:11:14  mtsezgin
  * *** empty log message ***
  *
  * Revision 1.1  2000/05/26 20:39:25  mtsezgin
  *
  * This GUI lets the user play with the paramaters used by the
  * recognition algorithms.
  *
  * Revision 1.2  2000/05/24 01:53:22  mtsezgin
  *
  * The polygon angle normalization works reliably.
  *
  * Revision 1.1  2000/05/21 23:13:15  mtsezgin
  *
  * This module is used for plotting and investigating certain statistical
  * features.
  *
  *
  *
  **/
