import edu.neu.ccs.*;
import edu.neu.ccs.gui.*;
import edu.neu.ccs.codec.*;
import edu.neu.ccs.console.*;
import edu.neu.ccs.filter.*;
import edu.neu.ccs.jpf.*;
import edu.neu.ccs.parser.*;
import edu.neu.ccs.pedagogy.*;
import edu.neu.ccs.quick.*;
import edu.neu.ccs.util.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.font.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
import java.util.*;
import java.math.*;
import java.beans.*;
import java.lang.reflect.*;
import java.net.URL;
import java.util.regex.*;
import java.text.ParseException;

public class KeyPressReleaseListener
    implements KeyListener
{
    private BooleanStateArray bsa = null;
    
    
    /**
     * Initializes the internal structure with all
     * key codes from the KeyEvent class.
     */
    public KeyPressReleaseListener() {
        this(StaticFields.getPublicStaticIntFieldList(KeyEvent.class));
    }
    
    
    /**
     * Initializes the internal structure with the
     * given list of key codes.
     */
    public KeyPressReleaseListener(int ... list) {
        bsa = new BooleanStateArray(list);
    }
    
    
    /** Stores the event key code state as true. */
    public void keyPressed(KeyEvent e) {
        bsa.setState(e.getKeyCode(), true);
    }
    
    
    /** Stores the event key code state as false. */
    public void keyReleased(KeyEvent e) {
        bsa.setState(e.getKeyCode(), false);
    }
    
    
    /** Does nothing. */
    public void keyTyped(KeyEvent e) {}
    
    
    /**
     * Returns the boolean state of the given key
     * where true = pressed and false = released.
     * 
     * Returns false if the key was not given in
     * the list provided to the constructor
     * since that key is not being tracked.
     */
    public boolean getState(int key) {
        return bsa.getState(key);
    }
    
}
