/*
 * @(#)ListSelectionAction.java    1.0  21 May 2002
 *
 * 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.event.*;
import java.beans.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;

/**
 * <P>Encapsulates an action that is performed
 * as a result of a <CODE>ListSelectionEvent</CODE>.</P>
 * 
 * @author  Jeff Raab
 * @version 2.2
 * @since   2.1
 */
public abstract class ListSelectionAction extends AbstractAction {

    /** Constructs a list selection action with no name or icon. */
    public ListSelectionAction() {
        super();
    }
    
    /**
     * Constructs a list selection action 
     * with the given name but no icon.
     *
     * @param name the name for this action
     */
    public ListSelectionAction(String name) {
        super(name);
    }
    
    /**
     * Constructs a list selection action 
     * with the given name and icon.
     *
     * @param name the name for this action
     * @param icon the icon for this action
     */
    public ListSelectionAction(String name, Icon icon) {
        super(name, icon);
    }

    ////////////////////
    // ActionListener //
    ////////////////////

    /**
     * Performs this action by calling the 
     * <CODE>{@link #listSelectionActionPerformed(ListSelectionEvent) 
     * listSelectionActionPerformed}</CODE> method of this class
     * intended to perform tasks requiring information
     * contained in the <CODE>ListSelectionEvent</CODE> 
     * triggering this action.
     *
     * If the given event is not a 
     * <CODE>{@link ListSelectionActionEvent 
     * ListSelectionActionEvent}</CODE>,
     * this action is not performed.
     *
     * @param evt an object encapsulating an event 
     *      that triggered this action
     */
    public final void actionPerformed(ActionEvent evt) {
        if (evt instanceof ListSelectionActionEvent) {
            ListSelectionEvent levt = 
                ((ListSelectionActionEvent)evt).
                    getListSelectionEvent();

            listSelectionActionPerformed(levt);
        }
    }
    
    ////////////////
    // Public API //
    ////////////////

    /**
     * Performs the tasks encapsulated by this action.
     *
     * Subclasses should override this method to provide
     * tasks this action performs.
     *
     * @param levt the list selection event 
     *      that triggered this action
     */
    public abstract void listSelectionActionPerformed(
        ListSelectionEvent levt);
}
