3261N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Implements the Highlighter interfaces. Implements a simple highlight 0N/A * painter that renders in a solid color. 0N/A * @author Timothy Prinzing 0N/A * Creates a new DefaultHighlighther object. 0N/A // ---- Highlighter methods ---------------------------------------------- 0N/A * Renders the highlights. 0N/A * @param g the graphics context 0N/A // PENDING(prinz) - should cull ranges not visible 0N/A for (
int i =
0; i <
len; i++) {
0N/A // Avoid allocing unless we need it. 0N/A * Called when the UI is being installed into the 0N/A * interface of a JTextComponent. Installs the editor, and 0N/A * removes any existing highlights. 0N/A * @param c the editor component 0N/A * @see Highlighter#install 0N/A * Called when the UI is being removed from the interface of 0N/A * @param c the component 0N/A * @see Highlighter#deinstall 0N/A * Adds a highlight to the view. Returns a tag that can be used 0N/A * to refer to the highlight. 0N/A * @param p0 the start offset of the range to highlight >= 0 0N/A * @param p1 the end offset of the range to highlight >= p0 0N/A * @param p the painter to use to actually render the highlight 0N/A * @return an object that can be used as a tag 0N/A * to refer to the highlight 0N/A * @exception BadLocationException if the specified location is invalid 0N/A * Removes a highlight from the view. 0N/A * @param tag the reference to the highlight 0N/A * Removes all highlights. 0N/A for (
int i =
0; i <
len; i++) {
0N/A for (
int i =
0; i <
len; i++) {
0N/A * Changes a highlight. 0N/A * @param tag the highlight tag 0N/A * @param p0 the beginning of the range >= 0 0N/A * @param p1 the end of the range >= p0 0N/A * @exception BadLocationException if the specified location is invalid 0N/A // Mark the highlights region as invalid, it will reset itself 0N/A // next time asked to paint. 0N/A * Makes a copy of the highlights. Does not actually clone each highlight, 0N/A * but only makes references to them. 0N/A * @see Highlighter#getHighlights 0N/A * When leaf Views (such as LabelView) are rendering they should 0N/A * call into this method. If a highlight is in the given region it will 0N/A * be drawn immediately. 0N/A * @param g Graphics used to draw 0N/A * @param p0 starting offset of view 0N/A * @param p1 ending offset of view 0N/A * @param viewBounds Bounds of View 0N/A * @param editor JTextComponent 0N/A * @param view View instance being rendered 0N/A * Queues damageRange() call into event dispatch thread 0N/A * to be sure that views are in consistent state. 0N/A * Queues damageRange() call into event dispatch thread 0N/A * to be sure that views are in consistent state. 0N/A * If true, highlights are drawn as the Views draw the text. That is 0N/A * the Views will call into <code>paintLayeredHighlight</code> which 0N/A * will result in a rectangle being drawn before the text is drawn 0N/A * (if the offsets are in a highlighted region that is). For this to 0N/A * work the painter supplied must be an instance of 0N/A * LayeredHighlightPainter. 0N/A // ---- member variables -------------------------------------------- 0N/A * Default implementation of LayeredHighlighter.LayerPainter that can 0N/A * be used for painting highlights. 0N/A * As of 1.4 this field is final. 0N/A * Simple highlight painter that fills a highlighted area with 0N/A * Constructs a new highlight painter. If <code>c</code> is null, 0N/A * the JTextComponent will be queried for its selection color. 0N/A * @param c the color for the highlight 0N/A * Returns the color of the highlight. 0N/A // --- HighlightPainter methods --------------------------------------- 0N/A * Paints a highlight. 0N/A * @param g the graphics context 0N/A * @param offs0 the starting model offset >= 0 0N/A * @param offs1 the ending model offset >= offs1 0N/A * @param bounds the bounding box for the highlight 0N/A * @param c the editor 0N/A // --- determine locations --- 0N/A // same line, render a rectangle 0N/A // --- LayerPainter methods ---------------------------- 0N/A * Paints a portion of a highlight. 0N/A * @param g the graphics context 0N/A * @param offs0 the starting model offset >= 0 0N/A * @param offs1 the ending model offset >= offs1 0N/A * @param bounds the bounding box of the view, which is not 0N/A * necessarily the region to paint. 0N/A * @param c the editor 0N/A * @param view View painting for 0N/A * @return region drawing occured in 0N/A // Contained in view, can just use bounds. 0N/A // Should only render part of View. 0N/A // --- determine locations --- 0N/A // If we are asked to highlight, we should draw something even 0N/A // if the model-to-view projection is of zero width (6340106). 0N/A * LayeredHighlightPainter is used when a drawsLayeredHighlights is 0N/A * true. It maintains a rectangle of the region to paint. 0N/A * Restricts the region based on the receivers offsets and messages 0N/A * the painter to paint the region. 0N/A // Restrict the region to what we represent 0N/A // Paint the appropriate region using the painter and union 0N/A // the effected region with our bounds. 0N/A * This class invokes <code>mapper.damageRange</code> in 0N/A * EventDispatchThread. The only one instance per Highlighter 0N/A * is cretaed. When a number of ranges should be damaged 0N/A * it collects them into queue and damages 0N/A * them in consecutive order in <code>run</code> 0N/A * Executes range(s) damage and cleans range queue. 0N/A public synchronized void run() {
0N/A // the Document should be the same to properly 0N/A // display highlights 0N/A for (
int i =
0; i <
len; i++){
0N/A // release reference 0N/A * Adds the range to be damaged into the range queue. If the 0N/A * range queue is empty (the first call or run() was already 0N/A * invoked) then adds this class instance into EventDispatch 0N/A * The method also tracks if the current document changed or 0N/A * component is null. In this case it removes all ranges added 0N/A * before from range queue.