|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| SimpleInteractionsWindow.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 | /*BEGIN_COPYRIGHT_BLOCK | |
| 2 | * | |
| 3 | * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@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 javax.swing.*; | |
| 40 | import java.awt.Font; | |
| 41 | import java.awt.event.*; | |
| 42 | import java.io.File; | |
| 43 | ||
| 44 | import edu.rice.cs.drjava.model.repl.*; | |
| 45 | import edu.rice.cs.util.FileOps; | |
| 46 | import edu.rice.cs.util.swing.SwingFrame; | |
| 47 | ||
| 48 | ||
| 49 | /** A standalone Interactions Window that provides the functionality of DrJava's Interactions Pane in a single JVM. | |
| 50 | * Useful for quickly testing small pieces of code if DrJava is not running. | |
| 51 | * @version $Id: SimpleInteractionsWindow.java 5175 2010-01-20 08:46:32Z mgricken $ | |
| 52 | */ | |
| 53 | public class SimpleInteractionsWindow extends SwingFrame { | |
| 54 | //private final SimpleRMIInteractionsModel _rmiModel; | |
| 55 | private final SimpleInteractionsModel _model; | |
| 56 | private final InteractionsDJDocument _adapter; | |
| 57 | private final InteractionsPane _pane; | |
| 58 | private final InteractionsController _controller; | |
| 59 | ||
| 60 | 0 | public SimpleInteractionsWindow() { this("Interactions Window"); } |
| 61 | ||
| 62 | 0 | public SimpleInteractionsWindow(String title) { |
| 63 | 0 | super(title); |
| 64 | 0 | setSize(600, 400); |
| 65 | ||
| 66 | 0 | _adapter = new InteractionsDJDocument(); |
| 67 | //_rmiModel = new SimpleRMIInteractionsModel(_adapter); | |
| 68 | 0 | _model = new SimpleInteractionsModel(_adapter); |
| 69 | 0 | _pane = new InteractionsPane(_adapter) { |
| 70 | 0 | public int getPromptPos() { return _model.getDocument().getPromptPos(); } |
| 71 | }; | |
| 72 | 0 | _controller = new InteractionsController(_model, _adapter, _pane, new Runnable() { public void run() { } }); |
| 73 | ||
| 74 | 0 | _pane.setFont(Font.decode("monospaced")); |
| 75 | ||
| 76 | 0 | _model.addListener(new InteractionsListener() { |
| 77 | 0 | public void interactionStarted() { _pane.setEditable(false); } |
| 78 | 0 | public void interactionEnded() { |
| 79 | 0 | _controller.moveToPrompt(); |
| 80 | 0 | _pane.setEditable(true); |
| 81 | } | |
| 82 | 0 | public void interpreterResetting() { _pane.setEditable(false); } |
| 83 | 0 | public void interactionErrorOccurred(int offset, int length) { _pane.highlightError(offset, length); } |
| 84 | 0 | public void interpreterReady(File wd) { |
| 85 | 0 | _controller.moveToPrompt(); |
| 86 | 0 | _pane.setEditable(true); |
| 87 | } | |
| 88 | 0 | public void interpreterExited(int status) { } |
| 89 | 0 | public void interpreterChanged(boolean inProgress) { _pane.setEditable(inProgress); } |
| 90 | 0 | public void interpreterResetFailed(Throwable t) { interpreterReady(FileOps.NULL_FILE); } |
| 91 | 0 | public void interactionIncomplete() { |
| 92 | 0 | int caretPos = _pane.getCaretPosition(); |
| 93 | 0 | _controller.getConsoleDoc().insertNewline(caretPos); |
| 94 | } | |
| 95 | }); | |
| 96 | ||
| 97 | 0 | JScrollPane scroll = new JScrollPane(_pane); |
| 98 | 0 | getContentPane().add(scroll); |
| 99 | ||
| 100 | // Add listener to quit if window is closed | |
| 101 | 0 | this.addWindowListener(new WindowAdapter() { |
| 102 | 0 | public void windowClosing(WindowEvent ev) { close(); } |
| 103 | }); | |
| 104 | ||
| 105 | 0 | initDone(); // call mandated by SwingFrame contract |
| 106 | } | |
| 107 | ||
| 108 | /** Terminates this process. This is overridden in DrJava so that is disposes of itself instead of calling | |
| 109 | * System.exit(0). | |
| 110 | */ | |
| 111 | 0 | protected void close() { System.exit(0); } |
| 112 | ||
| 113 | /** Accessor for the controller. */ | |
| 114 | 0 | public InteractionsController getController() { return _controller; } |
| 115 | ||
| 116 | /** Main method to create a SimpleInteractionsWindow from the console. Doesn't take any command line arguments. */ | |
| 117 | 0 | public static void main(String[] args) { |
| 118 | 0 | SimpleInteractionsWindow w = new SimpleInteractionsWindow(); |
| 119 | 0 | if (args.length > 0 && args[0].equals("-debug")) { |
| 120 | // TODO: define apropriate context | |
| 121 | // w.defineVariable("FRAME", w); | |
| 122 | // w.defineVariable("CONTROLLER", w.getController()); | |
| 123 | } | |
| 124 | 0 | w.setVisible(true); |
| 125 | } | |
| 126 | } |
|
||||||||||