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