|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| InteractionsEditorKit.java | 57.1% | 76.2% | 85.7% | 71.4% |
|
||||||||||||||
| 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.model.repl; | |
| 38 | ||
| 39 | import edu.rice.cs.drjava.model.definitions.ColoringGlyphPainter; | |
| 40 | import javax.swing.text.*; | |
| 41 | ||
| 42 | ||
| 43 | /** | |
| 44 | * This is an editor kit for editing Java source files. It functions as the controller in the MVC arrangement. | |
| 45 | * It implements a factory for new documents, and it also has a factory for Views (the things that render the document). | |
| 46 | * @version $Id: InteractionsEditorKit.java 5175 2010-01-20 08:46:32Z mgricken $ | |
| 47 | */ | |
| 48 | public class InteractionsEditorKit extends StyledEditorKit { | |
| 49 | ||
| 50 | /** Creates a new editor kit | |
| 51 | */ | |
| 52 | 21 | public InteractionsEditorKit() { |
| 53 | } | |
| 54 | ||
| 55 | ||
| 56 | private static ViewFactory _factory = new ViewFactory() { | |
| 57 | ||
| 58 | 3372 | public View create(Element elem) { |
| 59 | 3372 | String kind = elem.getName(); |
| 60 | ||
| 61 | 3372 | if (kind != null) { |
| 62 | 3372 | if (kind.equals(AbstractDocument.ContentElementName)) { |
| 63 | 1539 | return _createColoringView(elem); |
| 64 | 1833 | } else if (kind.equals(AbstractDocument.ParagraphElementName)) { |
| 65 | 1096 | return new ParagraphView(elem); |
| 66 | 737 | } else if (kind.equals(AbstractDocument.SectionElementName)) { |
| 67 | 733 | return new BoxView(elem, View.Y_AXIS); |
| 68 | 4 | } else if (kind.equals(StyleConstants.ComponentElementName)) { |
| 69 | 4 | return new ComponentView(elem); |
| 70 | 0 | } else if (kind.equals(StyleConstants.IconElementName)) { |
| 71 | 0 | return new IconView(elem); |
| 72 | } | |
| 73 | } | |
| 74 | ||
| 75 | // default to text display | |
| 76 | 0 | return _createColoringView(elem); |
| 77 | } | |
| 78 | ||
| 79 | }; | |
| 80 | ||
| 81 | /** Get the MIME content type of the document. | |
| 82 | * @return "text/java" | |
| 83 | */ | |
| 84 | 406 | public String getContentType() { return "text/java"; } |
| 85 | ||
| 86 | /** We want to use our ColoringView to render text, so here we return a factory that creates ColoringViews. */ | |
| 87 | 4238 | public final ViewFactory getViewFactory() { return _factory; } |
| 88 | ||
| 89 | 406 | public InteractionsDJDocument createDefaultDocument() { |
| 90 | 406 | return new InteractionsDJDocument(); |
| 91 | } | |
| 92 | ||
| 93 | /** We only need to re-implement the painter for the GlyphView to modify its behavior. The GlyphView delegates its | |
| 94 | * paint method to the painter. It also allows the painter to obtain the document to which the element | |
| 95 | * belongs. | |
| 96 | * @param elem The Element to pass to the GlyphView | |
| 97 | * @return A GlyphView with modified behavior | |
| 98 | */ | |
| 99 | 1539 | private static GlyphView _createColoringView(Element elem) { |
| 100 | 1539 | final GlyphView view = new GlyphView(elem); |
| 101 | 1539 | view.setGlyphPainter(new ColoringGlyphPainter(new Runnable() { |
| 102 | 0 | public void run() { |
| 103 | 0 | if (view.getContainer() != null) view.getContainer().repaint(); |
| 104 | } | |
| 105 | })); | |
| 106 | 1539 | return view; |
| 107 | } | |
| 108 | } | |
| 109 | ||
| 110 |
|
||||||||||