KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > ui > InteractionsScriptController


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.ui;
35
36 import java.awt.event.*;
37 import javax.swing.*;
38 import java.io.Serializable JavaDoc;
39
40 import edu.rice.cs.drjava.model.repl.InteractionsScriptModel;
41
42 /**
43  * Controller for an interactions script.
44  * @version $Id: InteractionsScriptController.java 3553 2006-02-20 21:22:09Z rcartwright $
45  */

46 public class InteractionsScriptController implements Serializable JavaDoc {
47   /** Associated model. */
48   private InteractionsScriptModel _model;
49   /** Associated view. */
50   private InteractionsScriptPane _pane;
51   /** Interactions pane. */
52   private InteractionsPane _interactionsPane;
53
54   /**
55    * Builds a new interactions script pane and links it to the given model.
56    * @param model the InteractionsScriptModel to use
57    * @param closeAction how to close this script.
58    */

59   public InteractionsScriptController(InteractionsScriptModel model, Action closeAction,
60                                       InteractionsPane interactionsPane) {
61     _model = model;
62     _closeScriptAction = closeAction;
63     _interactionsPane = interactionsPane;
64     _pane = new InteractionsScriptPane(4, 1);
65
66     // Previous
67
_setupAction(_prevInteractionAction, "Previous", "Insert Previous Interaction from Script");
68     _pane.addButton(_prevInteractionAction);
69     // Next
70
_setupAction(_nextInteractionAction, "Next", "Insert Next Interaction from Script");
71     _pane.addButton(_nextInteractionAction);
72     // Execute
73
_setupAction(_executeInteractionAction, "Execute", "Execute Current Interaction");
74     _pane.addButton(_executeInteractionAction);
75     // Close
76
_setupAction(_closeScriptAction, "Close", "Close Interactions Script");
77     _pane.addButton(_closeScriptAction);
78     setActionsEnabled();
79   }
80
81   /**
82    * Sets the navigation actions to be enabled, if appropriate.
83    */

84   public void setActionsEnabled() {
85     _nextInteractionAction.setEnabled(_model.hasNextInteraction());
86     _prevInteractionAction.setEnabled(_model.hasPrevInteraction());
87     _executeInteractionAction.setEnabled(true);
88   }
89
90   /**
91    * Disables navigation actions
92    */

93   public void setActionsDisabled() {
94     _nextInteractionAction.setEnabled(false);
95     _prevInteractionAction.setEnabled(false);
96     _executeInteractionAction.setEnabled(false);
97   }
98
99   /**
100    * @return the interactions script pane controlled by this controller.
101    */

102   public InteractionsScriptPane getPane() {
103     return _pane;
104   }
105
106   /** Action to go back in the script. */
107   private Action _prevInteractionAction = new AbstractAction("Previous") {
108     public void actionPerformed(ActionEvent e) {
109       _model.prevInteraction();
110       setActionsEnabled();
111       _interactionsPane.requestFocusInWindow();
112     }
113   };
114   /** Action to go forward in the script. */
115   private Action _nextInteractionAction = new AbstractAction("Next") {
116     public void actionPerformed(ActionEvent e) {
117       _model.nextInteraction();
118       setActionsEnabled();
119       _interactionsPane.requestFocusInWindow();
120     }
121   };
122   /** Action to execute the current interaction. */
123   private Action _executeInteractionAction = new AbstractAction("Execute") {
124     public void actionPerformed(ActionEvent e) {
125       _model.executeInteraction();
126       _interactionsPane.requestFocusInWindow();
127     }
128   };
129   /** Action to end the script. (Defined in constructor.) */
130   private Action _closeScriptAction; /* = new AbstractAction("<=Close=>") {
131     public void actionPerformed(ActionEvent e) {
132       _model.closeScript();
133       _pane.setMaximumSize(new Dimension(0,0));
134     }
135   };*/

136
137   /**
138    * Sets up fields on the given Action, such as the name and tooltip.
139    * @param a Action to modify
140    * @param name Default name for the Action (for buttons)
141    * @param desc Short description of the Action (for tooltips)
142    */

143   protected void _setupAction(Action a, String JavaDoc name, String JavaDoc desc) {
144     a.putValue(Action.DEFAULT, name);
145     a.putValue(Action.SHORT_DESCRIPTION, desc);
146   }
147 }
Popular Tags