javax.swing.text.Element.getElementCount()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(108)

本文整理了Java中javax.swing.text.Element.getElementCount()方法的一些代码示例,展示了Element.getElementCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getElementCount()方法的具体详情如下:
包路径:javax.swing.text.Element
类名称:Element
方法名:getElementCount

Element.getElementCount介绍

暂无

代码示例

代码示例来源:origin: skylot/jadx

private void setPreferredWidth() {
  Element root = codeArea.getDocument().getDefaultRootElement();
  int lines = root.getElementCount();
  int digits = Math.max(String.valueOf(lines).length(), 3);
  if (lastDigits != digits) {
    lastDigits = digits;
    FontMetrics fontMetrics = getFontMetrics(getFont());
    int width = fontMetrics.charWidth('0') * digits;
    Insets insets = getInsets();
    int preferredWidth = insets.left + insets.right + width;
    Dimension d = getPreferredSize();
    if (d != null) {
      d.setSize(preferredWidth, NUM_HEIGHT);
      setPreferredSize(d);
      setSize(d);
    }
  }
}

代码示例来源:origin: skylot/jadx

int index = root.getElementIndex(rowStartOffset);
Element line = root.getElement(index);
for (int i = 0; i < line.getElementCount(); i++) {
  Element child = line.getElement(i);
  AttributeSet as = child.getAttributes();

代码示例来源:origin: SonarSource/sonarqube

/**
 *  Calculate the width needed to display the maximum line number
 */
private void setPreferredWidth() {
 Element root = component.getDocument().getDefaultRootElement();
 int lines = root.getElementCount();
 int digits = Math.max(String.valueOf(lines).length(), minimumDisplayDigits);
 // Update sizes when number of digits in the line number changes
 if (lastDigits != digits) {
  lastDigits = digits;
  FontMetrics fontMetrics = getFontMetrics(getFont());
  int width = fontMetrics.charWidth('0') * digits;
  Insets insets = getInsets();
  int preferredWidth = insets.left + insets.right + width;
  Dimension d = getPreferredSize();
  d.setSize(preferredWidth, HEIGHT);
  setPreferredSize(d);
  setSize(d);
 }
}

代码示例来源:origin: SonarSource/sonarqube

Element line = root.getElement(index);
for (int i = 0; i < line.getElementCount(); i++) {
 Element child = line.getElement(i);
 AttributeSet as = child.getAttributes();

代码示例来源:origin: bobbylight/RSyntaxTextArea

private int getLineCount() {
  return doc.getDefaultRootElement().getElementCount();
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

private void doError(SAXParseException e, ParserNotice.Level level) {
  int line = e.getLineNumber() - 1;
  Element root = doc.getDefaultRootElement();
  Element elem = root.getElement(line);
  int offs = elem.getStartOffset();
  int len = elem.getEndOffset() - offs;
  if (line==root.getElementCount()-1) {
    len++;
  }
  DefaultParserNotice pn = new DefaultParserNotice(XmlParser.this,
                  e.getMessage(), line, offs, len);
  pn.setLevel(level);
  result.addNotice(pn);
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

/**
 * Deserializes a document.
 *
 * @param in The stream to read from.
 * @throws ClassNotFoundException
 * @throws IOException
 */
private void readObject(ObjectInputStream in)
          throws ClassNotFoundException, IOException {
  in.defaultReadObject();
  // Install default TokenMakerFactory.  To support custom TokenMakers,
  // both JVM's should install default TokenMakerFactories that support
  // the language they want to use beforehand.
  setTokenMakerFactory(null);
  // Handle other transient stuff
  this.s = new Segment();
  int lineCount = getDefaultRootElement().getElementCount();
  lastTokensOnLines = new DynamicIntArray(lineCount);
  setSyntaxStyle(syntaxStyle); // Actually install (transient) TokenMaker
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

/**
 * Loads all of the children to initialize the view.
 * This is called by the <code>setParent</code> method.
 * Subclasses can re-implement this to initialize their
 * child views in a different manner.  The default
 * implementation creates a child view for each
 * child element.
 *
 * @param f the view factory
 */
@Override
protected void loadChildren(ViewFactory f) {
  Element e = getElement();
  int n = e.getElementCount();
  if (n > 0) {
    View[] added = new View[n];
    for (int i = 0; i < n; i++) {
      added[i] = new WrappedLine(e.getElement(i));
    }
    replace(0, 0, added);
  }
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

/**
 * {@inheritDoc}
 */
@Override
public ParseResult parse(RSyntaxDocument doc, String style) {
  result.clearNotices();
  Element root = doc.getDefaultRootElement();
  result.setParsedLines(0, root.getElementCount()-1);
  if (spf==null || doc.getLength()==0) {
    return result;
  }
  try {
    SAXParser sp = spf.newSAXParser();
    Handler handler = new Handler(doc);
    DocumentReader r = new DocumentReader(doc);
    InputSource input = new InputSource(r);
    sp.parse(input, handler);
    r.close();
  } catch (SAXParseException spe) {
    // A fatal parse error - ignore; a ParserNotice was already created.
  } catch (Exception e) {
    //e.printStackTrace(); // Will print if DTD specified and can't be found
    result.addNotice(new DefaultParserNotice(this,
        "Error parsing XML: " + e.getMessage(), 0, -1, -1));
  }
  return result;
}

代码示例来源:origin: ron190/jsql-injection

/**
 * Get position of the beginning of the line.
 * @param line Index of the line
 * @return Offset of line
 * @throws BadLocationException
 */
public int getLineStartOffset(int line) throws BadLocationException {
  Element map = this.getDocument().getDefaultRootElement();
  if (line < 0) {
    throw new BadLocationException("Negative line", -1);
  } else if (line >= map.getElementCount()) {
    throw new BadLocationException("No such line", this.getDocument().getLength() + 1);
  } else {
    Element lineElem = map.getElement(line);
    return lineElem.getStartOffset();
  }
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

/**
 * Iterate over the lines represented by the child elements
 * of the element this view represents, looking for the line
 * that is the longest.  The <em>longLine</em> variable is updated to
 * represent the longest line contained.  The <em>font</em> variable
 * is updated to indicate the font used to calculate the
 * longest line.
 */
void calculateLongestLine() {
  Component c = getContainer();
  font = c.getFont();
  metrics = c.getFontMetrics(font);
  tabSize = getTabSize() * metrics.charWidth(' ');
  Element lines = getElement();
  int n = lines.getElementCount();
  for (int i=0; i<n; i++) {
    Element line = lines.getElement(i);
    float w = getLineWidth(i);
    if (w > longLineWidth) {
      longLineWidth = w;
      longLine = line;
    }
  }
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

int visibleLineCount = getElement().getElementCount();
if (host.isCodeFoldingEnabled()) {
  visibleLineCount -= host.getFoldManager().getHiddenLineCount();

代码示例来源:origin: bobbylight/RSyntaxTextArea

int lineCount = root.getElementCount();

代码示例来源:origin: bobbylight/RSyntaxTextArea

/**
 * Returns the set of expected paintable tokens from a document.
 *
 *  @param doc The document.
 *  @return The list of tokens, in the order in which they appear.
 */
private static final List<Token> getTokens(RSyntaxDocument doc) {
  Element root = doc.getDefaultRootElement();
  int lineCount = root.getElementCount();
  List<Token> list = new ArrayList<Token>();
  for (int i=0; i<lineCount; i++) {
    Token t = doc.getTokenListForLine(i);
    while (t!=null && t.isPaintable()) {
      list.add(new TokenImpl(t)); // Copy since Tokens are pooled
      t = t.getNextToken();
    }
  }
  return list;
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

/**
 * Updates internal state information; e.g. the "last tokens on lines"
 * data.  After this, a changed update is fired to let listeners know that
 * the document's structure has changed.<p>
 *
 * This is called internally whenever the syntax style changes.
 */
private void updateSyntaxHighlightingInformation() {
  // Reinitialize the "last token on each line" array.  Note that since
  // the actual text in the document isn't changing, the number of lines
  // is the same.
  Element map = getDefaultRootElement();
  int numLines = map.getElementCount();
  int lastTokenType = Token.NULL;
  for (int i=0; i<numLines; i++) {
    setSharedSegment(i);
    lastTokenType = tokenMaker.getLastTokenTypeOnLine(s, lastTokenType);
    lastTokensOnLines.set(i, lastTokenType);
  }
  // Clear our token cache to force re-painting
  lastLine = -1;
  cachedTokenList = null;
  // Let everybody know that syntax styles have (probably) changed.
  fireChangedUpdate(new DefaultDocumentEvent(
          0, numLines-1, DocumentEvent.EventType.CHANGE));
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

moveLineUp(textArea, startLine, moveCount);
else if (moveAmt==1 && endLine < root.getElementCount()-1) {
  moveLineDown(textArea, startLine, moveCount);

代码示例来源:origin: bobbylight/RSyntaxTextArea

/**
 * Highlights all instances of tokens identical to <code>t</code> in the
 * specified document.
 *
 * @param doc The document.
 * @param t The document whose relevant occurrences should be marked.
 * @param h The highlighter to add the highlights to.
 * @param p The painter for the highlights.
 */
public static final void markOccurrencesOfToken(RSyntaxDocument doc,
    Token t, RSyntaxTextAreaHighlighter h, SmartHighlightPainter p) {
  char[] lexeme = t.getLexeme().toCharArray();
  int type = t.getType();
  int lineCount = doc.getDefaultRootElement().getElementCount();
  for (int i=0; i<lineCount; i++) {
    Token temp = doc.getTokenListForLine(i);
    while (temp!=null && temp.isPaintable()) {
      if (temp.is(type, lexeme)) {
        try {
          int end = temp.getEndOffset();
          h.addMarkedOccurrenceHighlight(temp.getOffset(),end,p);
        } catch (BadLocationException ble) {
          ble.printStackTrace(); // Never happens
        }
      }
      temp = temp.getNextToken();
    }
  }
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
  if (!textArea.isEditable() || !textArea.isEnabled()) {
    UIManager.getLookAndFeel().provideErrorFeedback(textArea);
    return;
  }
  try {
    Caret c = textArea.getCaret();
    int caretPos = c.getDot();
    Document doc = textArea.getDocument();
    Element map = doc.getDefaultRootElement();
    int lineCount = map.getElementCount();
    int line = map.getElementIndex(caretPos);
    if (line==lineCount-1) {
      UIManager.getLookAndFeel().
            provideErrorFeedback(textArea);
      return;
    }
    Element lineElem = map.getElement(line);
    caretPos = lineElem.getEndOffset() - 1;
    c.setDot(caretPos);        // Gets rid of any selection.
    doc.remove(caretPos, 1);	// Should be '\n'.
  } catch (BadLocationException ble) {
    /* Shouldn't ever happen. */
    ble.printStackTrace();
  }
  textArea.requestFocusInWindow();
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

RSyntaxDocument document = (RSyntaxDocument)getDocument();
    Element map = document.getDefaultRootElement();
    int lineCount = map.getElementCount();
int line = map.getElementIndex(offset);
if (!host.isCodeFoldingEnabled()) {

代码示例来源:origin: bobbylight/RSyntaxTextArea

int line = notice.getLine();
Element root = doc.getDefaultRootElement();
if (line>=0 && line<root.getElementCount()) {
  Element elem = root.getElement(line);
  start = elem.getStartOffset();

相关文章