// Copyright (c) 1996-98 The Regents of the University of California. All
// Rights Reserved. Permission to use, copy, modify, and distribute this
// software and its documentation for educational, research and non-profit
// purposes, without fee, and without a written agreement is hereby granted,
// provided that the above copyright notice and this paragraph appear in all
// copies. Permission to incorporate this software into commercial products may
// be obtained by contacting the University of California. David F. Redmiles
// Department of Information and Computer Science (ICS) University of
// California Irvine, California 92697-3425 Phone: 714-824-3823. This software
// program and documentation are copyrighted by The Regents of the University
// of California. The software program and documentation are supplied "as is",
// without any accompanying services from The Regents. The Regents do not
// warrant that the operation of the program will be uninterrupted or
// error-free. The end-user understands that the program was developed for
// research purposes and is advised not to rely exclusively on the program for
// any reason. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY
// PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
// DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY
// DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
// SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
// ENHANCEMENTS, OR MODIFICATIONS.
// File: ExecuteActionWindow.java
// Classes: ExecuteActionWindow
// Original Author: jrobbins@ics.uci.edu
// $Id: ExecuteActionWindow.java,v 1.11 1997/06/10 23:42:39 jrobbins Exp $
package uci.graphedit;
import java.awt.*;
import java.util.*;
/** The ExecuteActionWindow lists out several Actions that the user
* can execute by clicking on the action name. This allows
* programmers to add new Actions without having to work out where
* exactly in the interface to put it, and allows users to execute
* actions without having to know the right keystrokes or get into
* the proper mode. Users can also see on-line help for each Action
* from this list.
*
* FEATURE: execute_action_window
*
* FEATURE: view_action_documentation
*/
public class ExecuteActionWindow extends Frame {
////////////////////////////////////////////////////////////////
// instance variables
List _actionNames = new List();
Button _execute = new Button("Execute");
/**
* FEATURE: view_action_documentation
*/
Button _about = new Button("About");
Button _close = new Button("Close");
////////////////////////////////////////////////////////////////
// constructors
public ExecuteActionWindow() {
Enumeration acts = Action.registeredActions();
while (acts.hasMoreElements()) {
Action a = (Action) acts.nextElement();
_actionNames.addItem(a.name());
}
setBackground(Color.lightGray);
add("Center", _actionNames);
Panel buttons = new Panel();
buttons.setLayout(new FlowLayout());
buttons.add(_execute);
buttons.add(_about);
_execute.disable();
_about.disable();
buttons.add(_close);
add("South", buttons);
pack();
Dimension d = size();
resize(d.width, Math.min(d.height * 2, 350));
}
////////////////////////////////////////////////////////////////
// event handlers
public boolean handleEvent(Event e) {
switch(e.id) {
case Event.WINDOW_DESTROY:
if (e.target == this) {
close();
return true;
}
break;
case Event.LIST_SELECT:
_execute.enable();
_about.enable();
return true;
case Event.LIST_DESELECT:
_execute.disable();
_about.disable();
return true;
}
return super.handleEvent(e);
}
public boolean action(Event e, Object what) {
if (e.target == _close) {
close();
return true;
}
else if (e.target == _execute) {
executeCommand(e);
return true;
}
else if (e.target == _about) {
describeCommand();
return true;
}
else if (e.target == _actionNames) {
executeCommand(e);
return true;
}
return false;
}
public void close() { dispose(); }
////////////////////////////////////////////////////////////////
// user interface
protected void executeCommand(Event e) {
Editor ce = Globals.curEditor();
System.out.println("executing: " + _actionNames.getSelectedItem());
Action act = Action.actionAtIndex(_actionNames.getSelectedIndex());
ce.executeAction(act, e);
}
protected void describeCommand() {
Editor ce = Globals.curEditor();
Action act = Action.actionAtIndex(_actionNames.getSelectedIndex());
Action showIt = null;
try { showIt = new ActionShowURL(act.about()); }
catch (Exception e) { System.out.println("malformed?"); }
ce.executeAction(showIt, null);
}
} /* end class ExecuteActionWindow */