001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.drjava.ui;
038:
039: import java.awt.event.*;
040: import javax.swing.*;
041: import java.io.Serializable;
042:
043: import edu.rice.cs.drjava.model.repl.InteractionsScriptModel;
044:
045: /**
046: * Controller for an interactions script.
047: * @version $Id: InteractionsScriptController.java 4255 2007-08-28 19:17:37Z mgricken $
048: */
049: public class InteractionsScriptController implements Serializable {
050: /** Associated model. */
051: private InteractionsScriptModel _model;
052: /** Associated view. */
053: private InteractionsScriptPane _pane;
054: /** Interactions pane. */
055: private InteractionsPane _interactionsPane;
056:
057: /**
058: * Builds a new interactions script pane and links it to the given model.
059: * @param model the InteractionsScriptModel to use
060: * @param closeAction how to close this script.
061: */
062: public InteractionsScriptController(InteractionsScriptModel model,
063: Action closeAction, InteractionsPane interactionsPane) {
064: _model = model;
065: _closeScriptAction = closeAction;
066: _interactionsPane = interactionsPane;
067: _pane = new InteractionsScriptPane(4, 1);
068:
069: // Previous
070: _setupAction(_prevInteractionAction, "Previous",
071: "Insert Previous Interaction from Script");
072: _pane.addButton(_prevInteractionAction);
073: // Next
074: _setupAction(_nextInteractionAction, "Next",
075: "Insert Next Interaction from Script");
076: _pane.addButton(_nextInteractionAction);
077: // Execute
078: _setupAction(_executeInteractionAction, "Execute",
079: "Execute Current Interaction");
080: _pane.addButton(_executeInteractionAction);
081: // Close
082: _setupAction(_closeScriptAction, "Close",
083: "Close Interactions Script");
084: _pane.addButton(_closeScriptAction);
085: setActionsEnabled();
086: }
087:
088: /**
089: * Sets the navigation actions to be enabled, if appropriate.
090: */
091: public void setActionsEnabled() {
092: _nextInteractionAction.setEnabled(_model.hasNextInteraction());
093: _prevInteractionAction.setEnabled(_model.hasPrevInteraction());
094: _executeInteractionAction.setEnabled(true);
095: }
096:
097: /**
098: * Disables navigation actions
099: */
100: public void setActionsDisabled() {
101: _nextInteractionAction.setEnabled(false);
102: _prevInteractionAction.setEnabled(false);
103: _executeInteractionAction.setEnabled(false);
104: }
105:
106: /**
107: * @return the interactions script pane controlled by this controller.
108: */
109: public InteractionsScriptPane getPane() {
110: return _pane;
111: }
112:
113: /** Action to go back in the script. */
114: private Action _prevInteractionAction = new AbstractAction(
115: "Previous") {
116: public void actionPerformed(ActionEvent e) {
117: _model.prevInteraction();
118: setActionsEnabled();
119: _interactionsPane.requestFocusInWindow();
120: }
121: };
122: /** Action to go forward in the script. */
123: private Action _nextInteractionAction = new AbstractAction("Next") {
124: public void actionPerformed(ActionEvent e) {
125: _model.nextInteraction();
126: setActionsEnabled();
127: _interactionsPane.requestFocusInWindow();
128: }
129: };
130: /** Action to execute the current interaction. */
131: private Action _executeInteractionAction = new AbstractAction(
132: "Execute") {
133: public void actionPerformed(ActionEvent e) {
134: _model.executeInteraction();
135: _interactionsPane.requestFocusInWindow();
136: }
137: };
138: /** Action to end the script. (Defined in constructor.) */
139: private Action _closeScriptAction; /* = new AbstractAction("<=Close=>") {
140: public void actionPerformed(ActionEvent e) {
141: _model.closeScript();
142: _pane.setMaximumSize(new Dimension(0,0));
143: }
144: };*/
145:
146: /**
147: * Sets up fields on the given Action, such as the name and tooltip.
148: * @param a Action to modify
149: * @param name Default name for the Action (for buttons)
150: * @param desc Short description of the Action (for tooltips)
151: */
152: protected void _setupAction(Action a, String name, String desc) {
153: a.putValue(Action.DEFAULT, name);
154: a.putValue(Action.SHORT_DESCRIPTION, desc);
155: }
156: }
|