
org.fife.ui.rtextarea.LineHighlightManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rsyntaxtextarea Show documentation
Show all versions of rsyntaxtextarea Show documentation
RSyntaxTextArea is the syntax highlighting text editor for Swing applications. Features include syntax highlighting for 40+ languages, code folding, code completion, regex find and replace, macros, code templates, undo/redo, line numbering and bracket matching.
The newest version!
/*
* 02/10/2009
*
* LineHighlightManager - Manages line highlights.
*
* This library is distributed under a modified BSD license. See the included
* LICENSE file for details.
*/
package org.fife.ui.rtextarea;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.*;
import javax.swing.text.BadLocationException;
import javax.swing.text.Position;
/**
* Manages line highlights in an RTextArea
.
*
* @author Robert Futrell
* @version 1.0
*/
class LineHighlightManager {
private RTextArea textArea;
private List lineHighlights;
private LineHighlightInfoComparator comparator;
/**
* Constructor.
*
* @param textArea The parent text area.
*/
LineHighlightManager(RTextArea textArea) {
this.textArea = textArea;
comparator = new LineHighlightInfoComparator();
}
/**
* Highlights the specified line.
*
* @param line The line to highlight.
* @param color The color to highlight with.
* @return A tag for the highlight.
* @throws BadLocationException If line
is not a valid line
* number.
* @see #removeLineHighlight(Object)
*/
public Object addLineHighlight(int line, Color color)
throws BadLocationException {
int offs = textArea.getLineStartOffset(line);
LineHighlightInfo lhi = new LineHighlightInfo(
textArea.getDocument().createPosition(offs), color);
if (lineHighlights==null) {
lineHighlights = new ArrayList<>(1);
}
int index = Collections.binarySearch(lineHighlights, lhi, comparator);
if (index<0) { // Common case
index = -(index+1);
}
lineHighlights.add(index, lhi);
repaintLine(lhi);
return lhi;
}
/**
* Returns the current line highlights' tags.
*
* @return The current line highlights' tags, or an empty list if there
* are none.
*/
protected List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy