SyntaxDecorator that applies BibTeX syntax highlighting and search-term highlighting
to the CodeArea used in org.jabref.gui.entryeditor.SourceTab .
Highlighting itself is delegated to the Veneer BibTeXSyntaxHighlighter, which
computes highlight regions over the full source text. Since CodeArea builds one
RichParagraph per line, this class:
BibTeXHighlightRegions so the (relatively expensive) lexing only happens when
the text has actually changed;
Instances are stateful (they hold the last computed text/region cache) and are intended to
be long-lived, one per CodeArea, rather than recreated per paragraph.
| Modifier and Type | Field and Description |
|---|---|
| private String | |
| private volatile boolean | |
| private List | |
| private Supplier | |
| private int[] | |
| private final StateManager | |
| private final BibTeXSyntaxHighlighter |
| Access | Constructor and Description |
|---|---|
| public | BibTeXHighlighter(StateManager
used to retrieve the active search query for term highlighting stateManager, BibTeXSyntaxHighlighter the syntax highlighter used to compute highlight regions for BibTeX source code syntaxHighlighter)Creates a new highlighter. |
| Modifier and Type | Method and Description |
|---|---|
| private void | addSearchHighlights(RichParagraph.
Adds background highlight rectangles for matches in the current line. |
| private void | addSegmentWithSearchCheck(RichParagraph.
Helper to add a text segment, splitting it if it intersects with search matches. |
| private void | addSyntaxSegments(RichParagraph.
the paragraph builder to append segments to builder,the plain text of the current line text, int the offset of this line's first character within the full cached text lineStart, List<Range> list of active search match ranges within this line matches)Adds the syntax-highlighted segments for the given line to the builder, translating each
cached |
| private void | appendSegment(RichParagraph.
|
| public RichParagraph | Returns: the styledRichParagraph for the requested linethe code text model backing the model, int CodeAreathe paragraph (line) index to render index)Implements jfx. Builds the styled paragraph for a single line of the model, applying both BibTeX syntax highlighting and (if a search query is active) search-match highlighting. |
| private List | |
| public void | handleChange(CodeTextModel m, TextPos start, TextPos end, int charsTop, int linesAdded, int charsBottom)
Implements jfx. Marks the cache as dirty so that subsequent rendering calls will rebuild syntax highlight regions for the updated text model. |
| private void | refreshCacheIfNeeded(CodeTextModel
the code text model backing the model)CodeAreaRecomputes the highlight-region cache if the model's full text has changed since the
last call or if the cache was invalidated by |
| public void | setFieldPositionsProvider(Supplier<Map<Field, Range>>
supplier providing a mapping of fields to their global ranges fieldPositionsProvider)Sets the provider for BibTeX field ranges within the source text. |
| cachedFullText | back to summary |
|---|---|
| private String cachedFullText | |
| cacheDirty | back to summary |
|---|---|
| private volatile boolean cacheDirty | |
| cachedRegions | back to summary |
|---|---|
| private List<BibTeXSyntaxHighlighter. | |
| fieldPositionsProvider | back to summary |
|---|---|
| private Supplier<Map<Field, Range>> fieldPositionsProvider | |
| lineStarts | back to summary |
|---|---|
| private int[] lineStarts | |
| stateManager | back to summary |
|---|---|
| private final StateManager stateManager | |
| syntaxHighlighter | back to summary |
|---|---|
| private final BibTeXSyntaxHighlighter syntaxHighlighter | |
| BibTeXHighlighter | back to summary |
|---|---|
| public BibTeXHighlighter(StateManager stateManager, BibTeXSyntaxHighlighter syntaxHighlighter) Creates a new highlighter.
| |
| addSearchHighlights | back to summary |
|---|---|
| private void addSearchHighlights(RichParagraph. Adds background highlight rectangles for matches in the current line. | |
| addSegmentWithSearchCheck | back to summary |
|---|---|
| private void addSegmentWithSearchCheck(RichParagraph. Helper to add a text segment, splitting it if it intersects with search matches. | |
| addSyntaxSegments | back to summary |
|---|---|
| private void addSyntaxSegments(RichParagraph. Adds the syntax-highlighted segments for the given line to the builder, translating each
cached
| |
| appendSegment | back to summary |
|---|---|
| private void appendSegment(RichParagraph. | |
| createRichParagraph | back to summary |
|---|---|
| public RichParagraph createRichParagraph(CodeTextModel model, int index) Implements jfx. Builds the styled paragraph for a single line of the model, applying both BibTeX syntax highlighting and (if a search query is active) search-match highlighting.
| |
| getSearchMatches | back to summary |
|---|---|
| private List Finds search matches in the current line. | |
| handleChange | back to summary |
|---|---|
| public void handleChange(CodeTextModel m, TextPos start, TextPos end, int charsTop, int linesAdded, int charsBottom) Implements jfx. Marks the cache as dirty so that subsequent rendering calls will rebuild syntax highlight regions for the updated text model.
| |
| refreshCacheIfNeeded | back to summary |
|---|---|
| private void refreshCacheIfNeeded(CodeTextModel model) Recomputes the highlight-region cache if the model's full text has changed since the
last call or if the cache was invalidated by
| |
| setFieldPositionsProvider | back to summary |
|---|---|
| public void setFieldPositionsProvider(Supplier<Map<Field, Range>> fieldPositionsProvider) Sets the provider for BibTeX field ranges within the source text. | |