1 33 34 package edu.rice.cs.drjava.ui; 35 36 import javax.swing.*; 37 import java.awt.Font ; 38 import java.awt.event.*; 39 import java.io.File ; 40 41 import edu.rice.cs.drjava.config.FileOption; 42 import edu.rice.cs.drjava.model.repl.*; 43 44 48 public class SimpleInteractionsWindow extends JFrame { 49 private final SimpleInteractionsModel _model; 51 private final InteractionsDJDocument _adapter; 52 private final InteractionsPane _pane; 53 private final InteractionsController _controller; 54 55 public SimpleInteractionsWindow() { this("Interactions Window"); } 56 57 public SimpleInteractionsWindow(String title) { 58 super(title); 59 setSize(600, 400); 60 61 _adapter = new InteractionsDJDocument(); 62 _model = new SimpleInteractionsModel(_adapter); 64 _pane = new InteractionsPane(_adapter) { 65 public int getPromptPos() { 66 return _model.getDocument().getPromptPos(); 67 } 68 }; 69 _controller = new InteractionsController(_model, _adapter, _pane); 70 71 _pane.setFont(Font.decode("monospaced")); 72 73 _model.addListener(new InteractionsListener() { 74 public void interactionStarted() { _pane.setEditable(false); } 75 public void interactionEnded() { 76 _controller.moveToPrompt(); 77 _pane.setEditable(true); 78 } 79 public void interpreterResetting() { _pane.setEditable(false); } 80 public void interactionErrorOccurred(int offset, int length) { _pane.highlightError(offset, length); } 81 public void interpreterReady(File wd) { 82 _controller.moveToPrompt(); 83 _pane.setEditable(true); 84 } 85 public void interpreterExited(int status) { } 86 public void interpreterChanged(boolean inProgress) { _pane.setEditable(inProgress); } 87 public void interpreterResetFailed(Throwable t) { interpreterReady(FileOption.NULL_FILE); } 88 public void interactionIncomplete() { 89 int caretPos = _pane.getCaretPosition(); 90 _controller.getConsoleDoc().insertNewLine(caretPos); 91 } 92 public void slaveJVMUsed() { } 93 }); 94 95 JScrollPane scroll = new JScrollPane(_pane); 96 getContentPane().add(scroll); 97 98 this.addWindowListener(new WindowAdapter() { 100 public void windowClosing(WindowEvent ev) { close(); } 101 }); 102 } 103 104 107 protected void close() { System.exit(0); } 108 109 110 public InteractionsController getController() { return _controller; } 111 112 113 public void defineVariable(String name, Object value) { _model.defineVariable(name, value); } 114 115 116 public void defineConstant(String name, Object value) { _model.defineConstant(name, value); } 117 118 119 public void setInterpreterPrivateAccessible(boolean accessible) { 120 _model.setInterpreterPrivateAccessible(accessible); 121 } 122 123 124 public static void main(String [] args) { 125 SimpleInteractionsWindow w = new SimpleInteractionsWindow(); 126 if (args.length > 0 && args[0].equals("-debug")) { 127 w.defineVariable("FRAME", w); 128 w.defineVariable("CONTROLLER", w.getController()); 129 w.setInterpreterPrivateAccessible(true); 130 } 131 w.setVisible(true); 132 } 133 } 134 | Popular Tags |