/** * Highlights this paragraph as a string of given type * * @param stringIndex the type * @return true if we have found a string-end */ public boolean highlightAsString(Object stringIndex) { Highlighter hl = getHighlighter(); String pText = _para.getText(); Map strTypes = hl.getStringQuotes(); TextAttributes attributes = hl.getStringAttributes(stringIndex); // clear all types because we determine them again _hlTypes.clear(); char c = ((Character) strTypes.get(stringIndex)).charValue(); int p = 0; int eIndex; do { eIndex = pText.indexOf(c, p); // search for string-end if (eIndex >= 0 && !StringUtils.isEscaped(pText, eIndex, hl.getEscapeChar())) { _hlTypes.add(new HighlightType(HighlightType.CONTAINS_STRING_END, stringIndex)); // mark visible area _visibleArea.setStart(eIndex + 1); _visibleArea.setEnd(); highlightText(0, eIndex + 1, attributes, pText); // mark paragraph-content as dirty (highlightDefault() might do nothing) _para.getTextField().getViewManager().markParagraphDirty(_para); // highlight the rest, by default highlightDefault(); return true; } p = eIndex + 1; } while (eIndex >= 0); // ok, no string-end, so we are in the string _visibleArea.setInvisible(); highlightText(0, _para.getElementLength(), attributes, pText); _para.getTextField().getViewManager().markParagraphDirty(_para); _hlTypes.add(new HighlightType(HighlightType.CONTAINS_STRING, stringIndex)); return false; }
/** * Highlights this paragraph as a comment of given type * * @param commentId the type * @return true if we have found a comment-end */ public boolean highlightAsComment(Object commentId) { Highlighter hl = getHighlighter(); String pText = _para.getText(); Map mlTypes = hl.getMultiCommentLimiters(); TextAttributes attributes = hl.getMLCommentAttributes(commentId); // clear all types because we determine them again _hlTypes.clear(); Pair p = (Pair) mlTypes.get(commentId); String end = (String) p.getValue(); int eIndex = pText.indexOf(end); // have we found the comment-end? if (eIndex >= 0) { _hlTypes.add(new HighlightType(HighlightType.CONTAINS_COMMENT_END, commentId)); // mark the visible area _visibleArea.setStart(eIndex + end.length()); _visibleArea.setEnd(); highlightText(0, eIndex + end.length(), attributes, pText); // mark paragraph-content as dirty (highlightDefault() might do nothing) _para.getTextField().getViewManager().markParagraphDirty(_para); // highlight the rest by default highlightDefault(); return true; } // ok, no comment-end, so we are in a comment _visibleArea.setInvisible(); highlightText(0, _para.getElementLength(), attributes, pText); _para.getTextField().getViewManager().markParagraphDirty(_para); _hlTypes.add(new HighlightType(HighlightType.CONTAINS_COMMENT, commentId)); return false; }