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

x33g5p2x  于2022-01-29 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(185)

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

StyledDocument.getParagraphElement介绍

暂无

代码示例

代码示例来源:origin: net.sf.jt400/jt400

  1. /**
  2. Returns the element that represents the paragraph that encloses
  3. a given offset within the document.
  4. @param offset The offset within the document.
  5. @return The element that represents the paragraph.
  6. **/
  7. public synchronized Element getParagraphElement (int offset)
  8. {
  9. return document_.getParagraphElement (offset);
  10. }

代码示例来源:origin: org.swinglabs.swingx/swingx-all

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @Override
  5. public Element getParagraphElement(int pos) {
  6. return ((StyledDocument) delegate).getParagraphElement(pos);
  7. }

代码示例来源:origin: tmyroadctfig/swingx

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @Override
  5. public Element getParagraphElement(int pos) {
  6. return ((StyledDocument) delegate).getParagraphElement(pos);
  7. }

代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public Element getParagraphElement(int pos) {
  5. return ((StyledDocument) delegate).getParagraphElement(pos);
  6. }

代码示例来源:origin: org.netbeans.api/org-openide-text

  1. public Element getParagraphElement(int pos) {
  2. return ((StyledDocument) original).getParagraphElement(pos);
  3. }

代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

  1. public Element getParagraphElement (int pos) {
  2. return ((StyledDocument)original).getParagraphElement (pos);
  3. }

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

  1. public Element getParagraphElement (int pos) {
  2. return ((StyledDocument)original).getParagraphElement (pos);
  3. }

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mercurial

  1. @Override
  2. public void run() {
  3. StyledDocument sd = (StyledDocument) doc;
  4. Iterator<AnnotateLine> it = lines.iterator();
  5. previousRevisions = Collections.synchronizedMap(new HashMap<String, HgRevision>());
  6. originalFiles = Collections.synchronizedMap(new HashMap<String, File>());
  7. elementAnnotations = Collections.synchronizedMap(new HashMap<Element, AnnotateLine>(lines.size()));
  8. while (it.hasNext()) {
  9. AnnotateLine line = it.next();
  10. int lineNum = ann2editorPermutation[line.getLineNum() -1];
  11. if (lineNum == -1) {
  12. continue;
  13. }
  14. try {
  15. int lineOffset = NbDocument.findLineOffset(sd, lineNum -1);
  16. Element element = sd.getParagraphElement(lineOffset);
  17. elementAnnotations.put(element, line);
  18. } catch (IndexOutOfBoundsException ex) {
  19. // TODO how could I get line behind document end?
  20. // furtunately user does not spot it
  21. Mercurial.LOG.log(Level.INFO, null, ex);
  22. }
  23. }
  24. }
  25. });

代码示例来源:origin: org.netbeans.api/org-openide-text

  1. public void run() {
  2. int offset = annoPos.getOffset();
  3. int lineStartOffset = doc.getParagraphElement(offset).getStartOffset();
  4. if (offset != lineStartOffset) { // not at line start -> correct
  5. try {
  6. annoPos = doc.createPosition(lineStartOffset);
  7. } catch (BadLocationException e) {
  8. throw new IllegalArgumentException(); // should never fail
  9. }
  10. }
  11. }

代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

  1. public void run() {
  2. int offset = annoPos.getOffset();
  3. int lineStartOffset = doc.getParagraphElement(offset).getStartOffset();
  4. if (offset != lineStartOffset) { // not at line start -> correct
  5. try {
  6. annoPos = doc.createPosition(lineStartOffset);
  7. } catch (BadLocationException e) {
  8. throw new IllegalArgumentException(); // should never fail
  9. }
  10. }
  11. }

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

  1. public void run() {
  2. int offset = annoPos.getOffset();
  3. int lineStartOffset = doc.getParagraphElement(offset).getStartOffset();
  4. if (offset != lineStartOffset) { // not at line start -> correct
  5. try {
  6. annoPos = doc.createPosition(lineStartOffset);
  7. } catch (BadLocationException e) {
  8. throw new IllegalArgumentException(); // should never fail
  9. }
  10. }
  11. }

代码示例来源:origin: org.netbeans.api/org-openide-text

  1. /** Find the root element of all lines.
  2. * All conforming NetBeans documents
  3. * should return a valid element.
  4. *
  5. * @param doc styled document (expecting NetBeans document)
  6. * @return the root element
  7. * @exception NullPointerException If the <code>doc</code> parameter
  8. * is <code>null</code>.
  9. */
  10. public static Element findLineRootElement(StyledDocument doc) {
  11. checkDocParameter(doc);
  12. Element e = doc.getParagraphElement(0).getParentElement();
  13. if (e == null) {
  14. // try default root (should work for text/plain)
  15. e = doc.getDefaultRootElement();
  16. }
  17. return e;
  18. }

代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

  1. /** Find the root element of all lines.
  2. * All conforming NetBeans documents
  3. * should return a valid element.
  4. *
  5. * @param doc styled document (expecting NetBeans document)
  6. * @return the root element
  7. * @exception NullPointerException If the <code>doc</code> parameter
  8. * is <code>null</code>.
  9. */
  10. public static Element findLineRootElement (StyledDocument doc) {
  11. checkDocParameter(doc);
  12. Element e = doc.getParagraphElement (0).getParentElement ();
  13. if (e == null) {
  14. // try default root (should work for text/plain)
  15. e = doc.getDefaultRootElement ();
  16. }
  17. return e;
  18. }

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

  1. /** Find the root element of all lines.
  2. * All conforming NetBeans documents
  3. * should return a valid element.
  4. *
  5. * @param doc styled document (expecting NetBeans document)
  6. * @return the root element
  7. * @exception NullPointerException If the <code>doc</code> parameter
  8. * is <code>null</code>.
  9. */
  10. public static Element findLineRootElement (StyledDocument doc) {
  11. checkDocParameter(doc);
  12. Element e = doc.getParagraphElement (0).getParentElement ();
  13. if (e == null) {
  14. // try default root (should work for text/plain)
  15. e = doc.getDefaultRootElement ();
  16. }
  17. return e;
  18. }

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2

  1. /**
  2. * Map document position to contents of whole line at that position.
  3. * SHOULD be combined with addrFromLine to givew:
  4. * Address viewToModel(pos)
  5. */
  6. private String getLineAt(int pos) {
  7. // By default a "paragraph" is a line
  8. Element pp = styledDoc.getParagraphElement(pos);
  9. int startPos = pp.getStartOffset();
  10. int endPos = pp.getEndOffset();
  11. int length = endPos - startPos;
  12. String line = null;
  13. try {
  14. line = styledDoc.getText(startPos, length);
  15. } catch (Exception x) {
  16. }
  17. return line;
  18. }

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mercurial

  1. StyledDocument sd = (StyledDocument) doc;
  2. int lineOffset = NbDocument.findLineOffset(sd, line);
  3. Element element = sd.getParagraphElement(lineOffset);
  4. AnnotateLine al = elementAnnotations.get(element);

代码示例来源:origin: jcoplien/trygve

  1. public void setBreakpointToEOLAt(int byteOffset, int lineNumber) {
  2. final StyledDocument doc = (StyledDocument)editPane.getDocument();
  3. final Element paragraphElement = doc.getParagraphElement(byteOffset);
  4. if (paragraphElement.getClass() == BranchElement.class) {
  5. final SimpleAttributeSet sas = new SimpleAttributeSet();
  6. StyleConstants.setBackground(sas, Color.cyan);
  7. // Look for ending delimiter
  8. int length = 1;
  9. try {
  10. for (int i = byteOffset; ; i++) {
  11. if (i >= doc.getLength()) {
  12. length = i - byteOffset + 1;
  13. break;
  14. } else if (doc.getText(i, 1).equals("\n")) {
  15. length = i - byteOffset;
  16. break;
  17. }
  18. }
  19. } catch (BadLocationException ble) {
  20. length = 0;
  21. }
  22. if (0 < length) {
  23. doc.setCharacterAttributes(byteOffset, length, sas, false);
  24. }
  25. }
  26. }
  27. public void unsetBreakpointToEOLAt(int byteOffset, int lineNumber) {

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-beans

  1. static int getRowFirstNonWhite(StyledDocument doc, int offset)
  2. throws BadLocationException {
  3. Element lineElement = doc.getParagraphElement(offset);
  4. int start = lineElement.getStartOffset();
  5. while (start + 1 < lineElement.getEndOffset()) {
  6. try {
  7. if (doc.getText(start, 1).charAt(0) != ' ') {
  8. break;
  9. }
  10. } catch (BadLocationException ex) {
  11. throw (BadLocationException) new BadLocationException(
  12. "calling getText(" + start + ", " + (start + 1)
  13. + ") on doc of length: " + doc.getLength(), start).initCause(ex);
  14. }
  15. start++;
  16. }
  17. return start;
  18. }

代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop

  1. manager.setSelected("font-underline", StyleConstants.isUnderline(set));
  2. elem = document.getParagraphElement(dot);
  3. set = elem.getAttributes();

代码示例来源:origin: org.swinglabs.swingx/swingx-all

  1. manager.setSelected("font-underline", StyleConstants.isUnderline(set));
  2. elem = document.getParagraphElement(dot);
  3. set = elem.getAttributes();

相关文章