1 33 34 package edu.rice.cs.drjava.ui; 35 36 import java.awt.event.*; 37 import javax.swing.*; 38 import java.io.Serializable ; 39 40 import edu.rice.cs.drjava.model.repl.InteractionsScriptModel; 41 42 46 public class InteractionsScriptController implements Serializable { 47 48 private InteractionsScriptModel _model; 49 50 private InteractionsScriptPane _pane; 51 52 private InteractionsPane _interactionsPane; 53 54 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 _setupAction(_prevInteractionAction, "Previous", "Insert Previous Interaction from Script"); 68 _pane.addButton(_prevInteractionAction); 69 _setupAction(_nextInteractionAction, "Next", "Insert Next Interaction from Script"); 71 _pane.addButton(_nextInteractionAction); 72 _setupAction(_executeInteractionAction, "Execute", "Execute Current Interaction"); 74 _pane.addButton(_executeInteractionAction); 75 _setupAction(_closeScriptAction, "Close", "Close Interactions Script"); 77 _pane.addButton(_closeScriptAction); 78 setActionsEnabled(); 79 } 80 81 84 public void setActionsEnabled() { 85 _nextInteractionAction.setEnabled(_model.hasNextInteraction()); 86 _prevInteractionAction.setEnabled(_model.hasPrevInteraction()); 87 _executeInteractionAction.setEnabled(true); 88 } 89 90 93 public void setActionsDisabled() { 94 _nextInteractionAction.setEnabled(false); 95 _prevInteractionAction.setEnabled(false); 96 _executeInteractionAction.setEnabled(false); 97 } 98 99 102 public InteractionsScriptPane getPane() { 103 return _pane; 104 } 105 106 107 private Action _prevInteractionAction = new AbstractAction("Previous") { 108 public void actionPerformed(ActionEvent e) { 109 _model.prevInteraction(); 110 setActionsEnabled(); 111 _interactionsPane.requestFocusInWindow(); 112 } 113 }; 114 115 private Action _nextInteractionAction = new AbstractAction("Next") { 116 public void actionPerformed(ActionEvent e) { 117 _model.nextInteraction(); 118 setActionsEnabled(); 119 _interactionsPane.requestFocusInWindow(); 120 } 121 }; 122 123 private Action _executeInteractionAction = new AbstractAction("Execute") { 124 public void actionPerformed(ActionEvent e) { 125 _model.executeInteraction(); 126 _interactionsPane.requestFocusInWindow(); 127 } 128 }; 129 130 private Action _closeScriptAction; 136 137 143 protected void _setupAction(Action a, String name, String desc) { 144 a.putValue(Action.DEFAULT, name); 145 a.putValue(Action.SHORT_DESCRIPTION, desc); 146 } 147 } | Popular Tags |