private void removeTags() { if (editorPane.getContentType().equals("text/html")) { editorPane.setText(htmlContents); editorPane.revalidate(); editorPane.repaint(); } else { DefaultStyledDocument doc = (DefaultStyledDocument)editorPane.getDocument(); SimpleAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setForeground(attr, Color.BLACK); StyleConstants.setBackground(attr, Color.WHITE); doc.setCharacterAttributes(0, doc.getLength(), attr, false); } saveTaggedAs.setEnabled(false); }
private void removeTags() { if (editorPane.getContentType().equals("text/html")) { if (htmlContents != null) { editorPane.setText(htmlContents); } editorPane.revalidate(); editorPane.repaint(); } else { DefaultStyledDocument doc = (DefaultStyledDocument)editorPane.getDocument(); SimpleAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setForeground(attr, Color.BLACK); StyleConstants.setBackground(attr, Color.WHITE); doc.setCharacterAttributes(0, doc.getLength(), attr, false); } saveTaggedAs.setEnabled(false); }
try { String entity = finalText.substring(start, end); doc.setCharacterAttributes(start, entity.length(), attSet, false); } catch (Exception ex) { throw new RuntimeException(ex);
styledDocument.setCharacterAttributes(matchEnd, offset - matchEnd, defaultStyle, styledDocument.setCharacterAttributes(offset, matchEnd - offset, style, true); styledDocument.setCharacterAttributes(matchEnd, checkPoint - matchEnd, defaultStyle,
try { String entity = finalText.substring(start, end); doc.setCharacterAttributes(start, entity.length(), attSet, false); } catch (Exception ex) { log.err(ex);
if (wordR == after || String.valueOf(text.charAt(wordR)).matches("\\W")) { if (text.substring(wordL, wordR).matches("(\\W)*(private|public|protected)")) setCharacterAttributes(wordL, wordR - wordL, attr, false); else setCharacterAttributes(wordL, wordR - wordL, attrBlack, false); wordL = wordR; setCharacterAttributes(before, after - before, attr, false); } else { setCharacterAttributes(before, after - before, attrBlack, false);
/** * Searches for a quote token. * * @param content the content to search * @param startOffset the start of the search * @param endOffset the end of the search * @return the new position */ protected int getQuoteToken(String content, int startOffset, int endOffset) { String quoteDelimiter = content.substring(startOffset, startOffset + 1); String escapeString = escapeQuote(quoteDelimiter); int index; int endOfQuote = startOffset; // skip over the escape quotes in this quote index = content.indexOf(escapeString, endOfQuote + 1); while ((index > -1) && (index < endOffset)) { endOfQuote = index + 1; index = content.indexOf(escapeString, endOfQuote); } // now find the matching delimiter index = content.indexOf(quoteDelimiter, endOfQuote + 1); if ((index < 0) || (index > endOffset)) { endOfQuote = endOffset; } else { endOfQuote = index; } m_Self.setCharacterAttributes(startOffset, endOfQuote - startOffset + 1, DEFAULT_STRING, false); return endOfQuote + 1; }
/** * Searches for a quote token. * * @param content the content to search * @param startOffset the start of the search * @param endOffset the end of the search * @return the new position */ protected int getQuoteToken(String content, int startOffset, int endOffset) { String quoteDelimiter = content.substring(startOffset, startOffset + 1); String escapeString = escapeQuote(quoteDelimiter); int index; int endOfQuote = startOffset; // skip over the escape quotes in this quote index = content.indexOf(escapeString, endOfQuote + 1); while ((index > -1) && (index < endOffset)) { endOfQuote = index + 1; index = content.indexOf(escapeString, endOfQuote); } // now find the matching delimiter index = content.indexOf(quoteDelimiter, endOfQuote + 1); if ((index < 0) || (index > endOffset)) { endOfQuote = endOffset; } else { endOfQuote = index; } m_Self.setCharacterAttributes(startOffset, endOfQuote - startOffset + 1, DEFAULT_STRING, false); return endOfQuote + 1; }
/** * Removes any prior style changes used to highlight a search result. */ private void clearSearchResult() { doc.setCharacterAttributes(0, doc.getLength(), styles.clearSearchResult(), false); }
/** * Searches for a keyword token. * * @param content the content to search in * @param startOffset the position to start the search fromm * @param endOffset the position to end the search * @return the new position */ protected int getOtherToken(String content, int startOffset, int endOffset) { int endOfToken = startOffset + 1; while (endOfToken <= endOffset) { if (isDelimiter(content.substring(endOfToken, endOfToken + 1))) { break; } endOfToken++; } String token = content.substring(startOffset, endOfToken); // see if this token has a highlighting format associated with it MutableAttributeSet attr = getKeywordFormatting(token); if (attr != null) { m_Self.setCharacterAttributes(startOffset, endOfToken - startOffset, attr, false); } return endOfToken + 1; }
/** * Searches for a keyword token. * * @param content the content to search in * @param startOffset the position to start the search fromm * @param endOffset the position to end the search * @return the new position */ protected int getOtherToken(String content, int startOffset, int endOffset) { int endOfToken = startOffset + 1; while (endOfToken <= endOffset) { if (isDelimiter(content.substring(endOfToken, endOfToken + 1))) { break; } endOfToken++; } String token = content.substring(startOffset, endOfToken); // see if this token has a highlighting format associated with it MutableAttributeSet attr = getKeywordFormatting(token); if (attr != null) { m_Self.setCharacterAttributes(startOffset, endOfToken - startOffset, attr, false); } return endOfToken + 1; }
/** Enables/disables coloring of the text. * @param coloring <TT>true</TT> if text coloring should be enabled, * <TT>false</TT> otherwise. * @see #isColoringEnabled() */ public void setColoringEnable(boolean coloring) { m_enableColoring = coloring; if (m_enableColoring) m_refresher.redrawTune(); else { ((DefaultStyledDocument)getDocument()).setCharacterAttributes( 0,getDocument().getEndPosition().getOffset(),m_defaultStyle, true); //setSelectedTextColor(SELECTION_FOREGROUND_COLOR); //setSelectionColor(SELECTION_BACKGROUND_COLOR); } }
|| isMultiLineComment() || startingMultiLineComment(content, startOffset, endOffset)) { m_Self.setCharacterAttributes(startOffset, endOffset - startOffset + 1, DEFAULT_COMMENT, false); return; .setCharacterAttributes(startOffset, lineLength, DEFAULT_NORMAL, true); m_Self.setCharacterAttributes(index, endOffset - index + 1, DEFAULT_COMMENT, false); endOffset = index - 1;
/** * Changes the background color of the given line and scrolls to it if * primary is true. * * @param element The line to highlight * @param primary If true, then it uses a different background color and * scrolls to the line */ private void highlightLine(Element element, boolean primary) { int startOffset = element.getStartOffset(); int endOffset = element.getEndOffset() - 1; int length = endOffset - startOffset; // MutableAttributeSet style = primary && !subduedHl ? styles.searchResult2(primary) : styles.searchResult(primary); MutableAttributeSet style = primary ? styles.searchResult2(primary) : styles.searchResult(primary); doc.setCharacterAttributes(startOffset, length, style, false); if (primary) { scrollManager.scrollToOffset(startOffset); } }
doc.setCharacterAttributes(start, length, style, false);
doc.setCharacterAttributes(lineStart, msgEnd - lineStart, styles.deleted(), false); setLineDeleted(lineStart);
/** * Highlight comment lines to matching end delimiter. * * @param content the content to parse * @param line the line number */ protected void commentLinesAfter(String content, int line) { int offset = m_RootElement.getElement(line).getEndOffset(); // End of comment not found, nothing to do int endDelimiter = -1; if (getMultiLineComment()) { endDelimiter = indexOf(content, getMultiLineCommentEnd(), offset); } if (endDelimiter < 0) { return; } // Matching start/end of comment found, comment the lines int startDelimiter = lastIndexOf(content, getMultiLineCommentStart(), endDelimiter); if (startDelimiter < 0 || startDelimiter <= offset) { m_Self.setCharacterAttributes(offset, endDelimiter - offset + 1, DEFAULT_COMMENT, false); } }
/** * Highlight comment lines to matching end delimiter. * * @param content the content to parse * @param line the line number */ protected void commentLinesAfter(String content, int line) { int offset = m_RootElement.getElement(line).getEndOffset(); // End of comment not found, nothing to do int endDelimiter = -1; if (getMultiLineComment()) { endDelimiter = indexOf(content, getMultiLineCommentEnd(), offset); } if (endDelimiter < 0) { return; } // Matching start/end of comment found, comment the lines int startDelimiter = lastIndexOf(content, getMultiLineCommentStart(), endDelimiter); if (startDelimiter < 0 || startDelimiter <= offset) { m_Self.setCharacterAttributes(offset, endDelimiter - offset + 1, DEFAULT_COMMENT, false); } }
/** * Highlight lines when a multi line comment is still 'open' (ie. matching end * delimiter has not yet been encountered). * * @param content the content to check * @param line the line number * @return true if there are comment lines before */ protected boolean commentLinesBefore(String content, int line) { int offset = m_RootElement.getElement(line).getStartOffset(); // Start of comment not found, nothing to do int startDelimiter = -1; if (getMultiLineComment()) { startDelimiter = lastIndexOf(content, getMultiLineCommentStart(), offset - 2); } if (startDelimiter < 0) { return false; } // Matching start/end of comment found, nothing to do int endDelimiter = indexOf(content, getMultiLineCommentEnd(), startDelimiter); if (endDelimiter < offset & endDelimiter != -1) { return false; } // End of comment not found, highlight the lines m_Self.setCharacterAttributes(startDelimiter, offset - startDelimiter + 1, DEFAULT_COMMENT, false); return true; }
/** * Highlight lines when a multi line comment is still 'open' (ie. matching end * delimiter has not yet been encountered). * * @param content the content to check * @param line the line number * @return true if there are comment lines before */ protected boolean commentLinesBefore(String content, int line) { int offset = m_RootElement.getElement(line).getStartOffset(); // Start of comment not found, nothing to do int startDelimiter = -1; if (getMultiLineComment()) { startDelimiter = lastIndexOf(content, getMultiLineCommentStart(), offset - 2); } if (startDelimiter < 0) { return false; } // Matching start/end of comment found, nothing to do int endDelimiter = indexOf(content, getMultiLineCommentEnd(), startDelimiter); if (endDelimiter < offset & endDelimiter != -1) { return false; } // End of comment not found, highlight the lines m_Self.setCharacterAttributes(startDelimiter, offset - startDelimiter + 1, DEFAULT_COMMENT, false); return true; }