|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| InteractionsScriptController.java | - | 0% | 0% | 0% |
|
||||||||||||||
| 1 | /*BEGIN_COPYRIGHT_BLOCK | |
| 2 | * | |
| 3 | * Copyright (c) 2001-2010, JavaPLT group at Rice University (javaplt@rice.edu) | |
| 4 | * All rights reserved. | |
| 5 | * | |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * * Redistributions of source code must retain the above copyright | |
| 9 | * notice, this list of conditions and the following disclaimer. | |
| 10 | * * Redistributions in binary form must reproduce the above copyright | |
| 11 | * notice, this list of conditions and the following disclaimer in the | |
| 12 | * documentation and/or other materials provided with the distribution. | |
| 13 | * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the | |
| 14 | * names of its contributors may be used to endorse or promote products | |
| 15 | * derived from this software without specific prior written permission. | |
| 16 | * | |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
| 21 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
| 25 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
| 26 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
| 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 28 | * | |
| 29 | * This software is Open Source Initiative approved Open Source Software. | |
| 30 | * Open Source Initative Approved is a trademark of the Open Source Initiative. | |
| 31 | * | |
| 32 | * This file is part of DrJava. Download the current version of this project | |
| 33 | * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/ | |
| 34 | * | |
| 35 | * END_COPYRIGHT_BLOCK*/ | |
| 36 | ||
| 37 | package edu.rice.cs.drjava.ui; | |
| 38 | ||
| 39 | import java.awt.event.*; | |
| 40 | import javax.swing.*; | |
| 41 | //import java.io.Serializable; | |
| 42 | ||
| 43 | import edu.rice.cs.drjava.model.repl.InteractionsScriptModel; | |
| 44 | ||
| 45 | /** Controller for an interactions script. | |
| 46 | * @version $Id: InteractionsScriptController.java 5175 2010-01-20 08:46:32Z mgricken $ | |
| 47 | */ | |
| 48 | public class InteractionsScriptController /* implements Serializable */ { | |
| 49 | /** Associated model. */ | |
| 50 | private InteractionsScriptModel _model; | |
| 51 | /** Associated view. */ | |
| 52 | private InteractionsScriptPane _pane; | |
| 53 | /** Interactions pane. */ | |
| 54 | private InteractionsPane _interactionsPane; | |
| 55 | ||
| 56 | /** Builds a new interactions script pane and links it to the given model. | |
| 57 | * @param model the InteractionsScriptModel to use | |
| 58 | * @param closeAction how to close this script. | |
| 59 | */ | |
| 60 | 0 | public InteractionsScriptController(InteractionsScriptModel model, Action closeAction, |
| 61 | InteractionsPane interactionsPane) { | |
| 62 | 0 | _model = model; |
| 63 | 0 | _closeScriptAction = closeAction; |
| 64 | 0 | _interactionsPane = interactionsPane; |
| 65 | 0 | _pane = new InteractionsScriptPane(4, 1); |
| 66 | ||
| 67 | // Previous | |
| 68 | 0 | _setupAction(_prevInteractionAction, "Previous", "Insert Previous Interaction from Script"); |
| 69 | 0 | _pane.addButton(_prevInteractionAction); |
| 70 | // Next | |
| 71 | 0 | _setupAction(_nextInteractionAction, "Next", "Insert Next Interaction from Script"); |
| 72 | 0 | _pane.addButton(_nextInteractionAction); |
| 73 | // Execute | |
| 74 | 0 | _setupAction(_executeInteractionAction, "Execute", "Execute Current Interaction"); |
| 75 | 0 | _pane.addButton(_executeInteractionAction); |
| 76 | // Close | |
| 77 | 0 | _setupAction(_closeScriptAction, "Close", "Close Interactions Script"); |
| 78 | 0 | _pane.addButton(_closeScriptAction); |
| 79 | 0 | setActionsEnabled(); |
| 80 | } | |
| 81 | ||
| 82 | /** Sets the navigation actions to be enabled, if appropriate. */ | |
| 83 | 0 | public void setActionsEnabled() { |
| 84 | 0 | _nextInteractionAction.setEnabled(_model.hasNextInteraction()); |
| 85 | 0 | _prevInteractionAction.setEnabled(_model.hasPrevInteraction()); |
| 86 | 0 | _executeInteractionAction.setEnabled(true); |
| 87 | } | |
| 88 | ||
| 89 | /** Disables navigation actions */ | |
| 90 | 0 | public void setActionsDisabled() { |
| 91 | 0 | _nextInteractionAction.setEnabled(false); |
| 92 | 0 | _prevInteractionAction.setEnabled(false); |
| 93 | 0 | _executeInteractionAction.setEnabled(false); |
| 94 | } | |
| 95 | ||
| 96 | /** @return the interactions script pane controlled by this controller. */ | |
| 97 | 0 | public InteractionsScriptPane getPane() { return _pane; } |
| 98 | ||
| 99 | /** Action to go back in the script. */ | |
| 100 | private Action _prevInteractionAction = new AbstractAction("Previous") { | |
| 101 | 0 | public void actionPerformed(ActionEvent e) { |
| 102 | 0 | _model.prevInteraction(); |
| 103 | 0 | setActionsEnabled(); |
| 104 | 0 | _interactionsPane.requestFocusInWindow(); |
| 105 | } | |
| 106 | }; | |
| 107 | /** Action to go forward in the script. */ | |
| 108 | private Action _nextInteractionAction = new AbstractAction("Next") { | |
| 109 | 0 | public void actionPerformed(ActionEvent e) { |
| 110 | 0 | _model.nextInteraction(); |
| 111 | 0 | setActionsEnabled(); |
| 112 | 0 | _interactionsPane.requestFocusInWindow(); |
| 113 | } | |
| 114 | }; | |
| 115 | /** Action to execute the current interaction. */ | |
| 116 | private Action _executeInteractionAction = new AbstractAction("Execute") { | |
| 117 | 0 | public void actionPerformed(ActionEvent e) { |
| 118 | 0 | _model.executeInteraction(); |
| 119 | 0 | _interactionsPane.requestFocusInWindow(); |
| 120 | } | |
| 121 | }; | |
| 122 | /** Action to end the script. (Defined in constructor.) */ | |
| 123 | private Action _closeScriptAction; /* = new AbstractAction("<=Close=>") { | |
| 124 | public void actionPerformed(ActionEvent e) { | |
| 125 | _model.closeScript(); | |
| 126 | _pane.setMaximumSize(new Dimension(0,0)); | |
| 127 | } | |
| 128 | };*/ | |
| 129 | ||
| 130 | /** Sets up fields on the given Action, such as the name and tooltip. | |
| 131 | * @param a Action to modify | |
| 132 | * @param name Default name for the Action (for buttons) | |
| 133 | * @param desc Short description of the Action (for tooltips) | |
| 134 | */ | |
| 135 | 0 | protected void _setupAction(Action a, String name, String desc) { |
| 136 | 0 | a.putValue(Action.DEFAULT, name); |
| 137 | 0 | a.putValue(Action.SHORT_DESCRIPTION, desc); |
| 138 | } | |
| 139 | } |
|
||||||||||