/** * Constructs a new <code>SyntaxView</code> wrapped around an element. * * @param elem The element representing the text to display. */ public SyntaxView(Element elem) { super(elem); tempToken = new TokenImpl(); }
lastToken.setNextToken(t); while (lastToken.getNextToken()!=null && lastToken.getNextToken().isPaintable()) { lastToken = (TokenImpl)lastToken.getNextToken(); t = new TokenImpl(new char[] { '\n' }, 0,0, docOffs, Token.WHITESPACE, 0); lastToken.setNextToken(t); lastToken = t; if (startOffs>=tokenList.getOffset()) { while (!tokenList.containsPosition(startOffs)) { tokenList = (TokenImpl)tokenList.getNextToken(); tokenList.makeStartAt(startOffs); while (temp!=null && !temp.containsPosition(endOffs)) { temp = (TokenImpl)temp.getNextToken(); temp.textCount = endOffs - temp.getOffset(); temp.setNextToken(null);
@Override public StringBuilder appendHTMLRepresentation(StringBuilder sb, RSyntaxTextArea textArea, boolean fontFamily) { return appendHTMLRepresentation(sb, textArea, fontFamily, false); }
@Nullable private Token concatTokensUntil(Token start, String endText) { StringBuilder sb = new StringBuilder(); Token current = start; while (current != null && current.getType() != TokenTypes.NULL) { String text = current.getLexeme(); if (text != null) { sb.append(text); if (text.equals(endText)) { char[] line = sb.toString().toCharArray(); TokenImpl token = new TokenImpl(line, 0, line.length - 1, start.getOffset(), start.getType(), start.getLanguageIndex()); token.setNextToken(current.getNextToken()); return token; } } current = current.getNextToken(); } return null; } }
/** * {@inheritDoc} */ @Override public TokenImpl createToken() { TokenImpl token = tokenList[currentFreeToken]; token.text = null; token.setType(Token.NULL); token.setOffset(-1); token.setNextToken(null); currentFreeToken++; if (currentFreeToken==size) { augmentTokenList(); } return token; }
/** * Adds the token specified to the current linked list of tokens. * * @param array The character array. * @param start The starting offset in the array. * @param end The ending offset in the array. * @param tokenType The token's type. * @param startOffset The offset in the document at which this token * occurs. * @param hyperlink Whether this token is a hyperlink. */ public void addToken(char[] array, int start, int end, int tokenType, int startOffset, boolean hyperlink) { if (firstToken==null) { firstToken = tokenFactory.createToken(array, start, end, startOffset, tokenType); currentToken = firstToken; // previous token is still null. } else { TokenImpl next = tokenFactory.createToken(array, start,end, startOffset, tokenType); currentToken.setNextToken(next); previousToken = currentToken; currentToken = next; } currentToken.setLanguageIndex(languageIndex); currentToken.setHyperlink(hyperlink); }
tempToken.copyFrom(token); tempToken.textCount = selStart - tempToken.getOffset(); nextX = painter.paint(tempToken,g,nextX,y,host, this, clipStart); tempToken.textCount = token.length(); tempToken.makeStartAt(selStart); token = new TokenImpl(tempToken); tempToken.copyFrom(token); tempToken.textCount = selCount; nextX = painter.paintSelected(tempToken, g, nextX,y, host, this, clipStart, useSTC); tempToken.textCount = token.length(); tempToken.makeStartAt(token.getOffset() + selCount); token = tempToken; nextX = painter.paint(token, g, nextX,y, host, this, tempToken.copyFrom(token); tempToken.textCount = selEnd - tempToken.getOffset(); nextX = painter.paintSelected(tempToken, g, nextX,y, host, this, clipStart, useSTC); tempToken.textCount = token.length(); tempToken.makeStartAt(selEnd); token = tempToken; nextX = painter.paint(token, g, nextX,y, host, this, clipStart);
tempToken.set(drawSeg.array, tokenOffset-start, p-1-start, tokenOffset, token.getType()); tempToken.setLanguageIndex(token.getLanguageIndex()); boolean paintBG = host.getPaintTokenBackgrounds(line, y); painter.paint(tempToken, g, x,y, host, this, 0, paintBG); tempToken.copyFrom(token); tempToken.makeStartAt(p); token = new TokenImpl(tempToken);
Segment s = new Segment(); while (token != null && token.isPaintable()) { fm = textArea.getFontMetricsForTokenType(token.getType()); if (fm == null) { return rect; // Don't return null as things'll error. if (token.containsPosition(pos)) { s.count = pos - token.getOffset(); token.getOffset()); rect.x = stableX + w; end = token.documentToToken(pos); s.count = token.textCount; stableX += Utilities.getTabbedTextWidth(s, fm, stableX, e, token.getOffset()); token = (TokenImpl)token.getNextToken();
tempToken = new TokenImpl(); tempToken.copyFrom(t); tempToken.makeStartAt(pos);
Style scheme = colorScheme.getStyle(getType()); Font font = textArea.getFontForTokenType(getType());//scheme.font; sb.append("<em>"); if (scheme.underline || isHyperlink()) { sb.append("<u>"); boolean needsFontTag = fontFamily || !isWhitespace(); if (needsFontTag) { sb.append("<font"); sb.append(" face=\"").append(font.getFamily()).append('"'); if (!isWhitespace()) { sb.append(" color=\"").append( getHTMLFormatForColor(scheme.foreground)).append('"'); appendHtmlLexeme(textArea, sb, tabsToSpaces); if (scheme.underline || isHyperlink()) { sb.append("</u>");
@Test public void testGetHTMLRepresentation_problemChars() { RSyntaxTextArea textArea = new RSyntaxTextArea(); char[] ch = " &\t<>'\"/".toCharArray(); TokenImpl token = new TokenImpl(ch, 0, ch.length - 1, 0, TokenTypes.IDENTIFIER, 0); // Don't bother checking font and other styles since it may be host-specific String actual = token.getHTMLRepresentation(textArea); System.out.println(actual); Assert.assertTrue(actual.startsWith("<font")); Assert.assertTrue(actual.endsWith("> &	<>'"/</font>")); }
/** * {@inheritDoc} */ @Override public void addNullToken() { if (firstToken==null) { firstToken = tokenFactory.createToken(); currentToken = firstToken; } else { TokenImpl next = tokenFactory.createToken(); currentToken.setNextToken(next); previousToken = currentToken; currentToken = next; } currentToken.setLanguageIndex(languageIndex); }
@NotNull private Token mergeLongClassNames(Token prev, Token current, boolean annotation) { int offset = current.getOffset(); if (annotation) { offset++; } JavaNode javaNode = codeArea.getJavaNodeAtOffset(jCls, offset); if (javaNode instanceof JavaClass) { String name = javaNode.getName(); String lexeme = current.getLexeme(); if (annotation && lexeme.length() > 1) { lexeme = lexeme.substring(1); } if (!lexeme.equals(name) && javaNode.getFullName().startsWith(lexeme)) { // try to replace long class name with one token Token replace = concatTokensUntil(current, name); if (replace != null && prev instanceof TokenImpl) { TokenImpl impl = ((TokenImpl) prev); impl.setNextToken(replace); current = replace; } } } return current; }
/** * Creates this token as a copy of the passed-in token. * * @param t2 The token from which to make a copy. */ public TokenImpl(Token t2) { this(); copyFrom(t2); }
tempToken.copyFrom(token); tempToken.textCount = selStart - tempToken.getOffset(); x = painter.paint(tempToken,g,x,y,host, this); tempToken.textCount = token.length(); tempToken.makeStartAt(selStart); token = new TokenImpl(tempToken); tempToken.copyFrom(token); tempToken.textCount = selCount; x = painter.paintSelected(tempToken, g, x,y, host, this, useSTC); tempToken.textCount = token.length(); tempToken.makeStartAt(token.getOffset() + selCount); token = tempToken; x = painter.paint(token, g, x,y, host, this); tempToken.copyFrom(token); tempToken.textCount = selEnd - tempToken.getOffset(); x = painter.paintSelected(tempToken, g, x,y, host, this, useSTC); tempToken.textCount = token.length(); tempToken.makeStartAt(selEnd); token = tempToken; x = painter.paint(token, g, x,y, host, this); token = new TokenImpl(drawSeg, tokenOffset-start, p-1-start, tokenOffset, token.getType(), token.getLanguageIndex()); token.setLanguageIndex(token.getLanguageIndex());
tempToken.set(drawSeg.array, tokenOffset-start, p-1-start, tokenOffset, token.getType()); tempToken.setLanguageIndex(token.getLanguageIndex()); boolean paintBG = host.getPaintTokenBackgrounds(line, y); painter.paint(tempToken, g, x,y, host, this, 0, paintBG); tempToken.copyFrom(token); tempToken.makeStartAt(p); token = new TokenImpl(tempToken);
/** * Clones a token list. This is necessary as tokens are reused in * {@link RSyntaxDocument}, so we can't simply use the ones we * are handed from it. * * @param t The token list to clone. * @return The clone of the token list. */ private TokenImpl cloneTokenList(Token t) { if (t==null) { return null; } TokenImpl clone = new TokenImpl(t); TokenImpl cloneEnd = clone; while ((t=t.getNextToken())!=null) { TokenImpl temp = new TokenImpl(t); cloneEnd.setNextToken(temp); cloneEnd = temp; } return clone; }
Segment s = new Segment(); while (token != null && token.isPaintable()) { fm = textArea.getFontMetricsForTokenType(token.getType()); if (fm == null) { return rect; // Don't return null as things'll error. if (token.containsPosition(pos)) { s.count = pos - token.getOffset(); token.getOffset()); rect.x = stableX + w; end = token.documentToToken(pos); s.count = token.textCount; stableX += Utilities.getTabbedTextWidth(s, fm, stableX, e, token.getOffset()); token = (TokenImpl)token.getNextToken();
tempToken = new TokenImpl(); tempToken.copyFrom(t); tempToken.makeStartAt(pos);