/*
 * @(#)MalformedDataEvent.java    1.0  16 February 2001
 *
 * Copyright 2004
 * 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;

import java.awt.AWTEvent;
import java.text.ParseException;

/**
 * <P>Class of <CODE>{@link AWTEvent AWTEvent}</CODE>s 
 * encapsulating the designation that a graphical input object 
 * has just been verified to have a malformed view state,
 * or has just had its previously malformed view state
 * restored to a well-formed state.</P>
 *
 * @author  Jeff Raab
 * @version 2.2
 * @since   1.0
 * @see Fragile
 */
public class MalformedDataEvent extends AlertEvent {
    
    /** 
     * The malformed data, or the well-formed data 
     * that replaced previously malformed data. 
     */
    private String s = null;
    
    /** 
     * The <CODE>ParseException</CODE> that was generated 
     * by an input component in response to malformed data. 
     */
    private ParseException ex = null;
    
    //////////////////
    // Constructors //
    //////////////////
    
    /**
     * Constructs a malformed data event 
     * generated by the given source object 
     * because the given <CODE>String</CODE> data
     * caused the given exception to be thrown.
     *
     * @param source the object generating the event
     * @param data the malformed data <CODE>String</CODE>
     * @param exception the exception thrown in response 
     *      to the malformed data
     * @see #MalformedDataEvent(Object, String)
     */
    public MalformedDataEvent(
        Object source, 
        String data, 
        ParseException exception) 
    {
        super(source, ALERT_ON);
        s = data;
        ex = exception;
    }
    
    /**
     * Constructs a malformed data event 
     * generated by the given source object 
     * because the given <CODE>String</CODE> data 
     * has successfully replaced previously malformed data.
     *
     * @param source the object generating the event
     * @param data the well-formed 
     *      replacement data <CODE>String</CODE>
     * @see #MalformedDataEvent(Object, String, ParseException)
     */
    public MalformedDataEvent(Object source, String data) {
        super(source, ALERT_OFF);
        data = s;
    }
    
    ////////////////
    // Public API //
    ////////////////

    /**
     * Returns the <CODE>String</CODE> data representing
     * either the malformed view state 
     * that caused an exception to be thrown, 
     * or the well-formed view state 
     * that replaced a previously malformed view state.
     */
    public String getData() {
        return s;
    }
    
    /**
     * Returns the exception that was thrown in response
     * to the stored malformed view state.
     */
    public ParseException getParseException() {
        return ex;
    }
}
