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

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

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

StyledDocument.getDefaultRootElement介绍

暂无

代码示例

代码示例来源:origin: groovy/groovy-core

  1. public void actionPerformed(ActionEvent ae) {
  2. JTextComponent tComp = (JTextComponent) ae.getSource();
  3. if (tComp.getDocument() instanceof StyledDocument) {
  4. doc = (StyledDocument) tComp.getDocument();
  5. try {
  6. doc.getText(0, doc.getLength(), segment);
  7. }
  8. catch (Exception e) {
  9. // should NEVER reach here
  10. e.printStackTrace();
  11. }
  12. int offset = tComp.getCaretPosition();
  13. int index = findTabLocation(offset);
  14. buffer.delete(0, buffer.length());
  15. buffer.append('\n');
  16. if (index > -1) {
  17. for (int i = 0; i < index + 4; i++) {
  18. buffer.append(' ');
  19. }
  20. }
  21. try {
  22. doc.insertString(offset, buffer.toString(),
  23. doc.getDefaultRootElement().getAttributes());
  24. }
  25. catch (BadLocationException ble) {
  26. ble.printStackTrace();
  27. }
  28. }
  29. }

代码示例来源:origin: groovy/groovy-core

  1. public int findTabLocation(int offset) {
  2. // find first {
  3. boolean cont = true;
  4. while (offset > -1 && cont) {
  5. Element el = doc.getCharacterElement(offset);
  6. Object color =
  7. el.getAttributes().getAttribute(StyleConstants.Foreground);
  8. if (!COMMENT_COLOR.equals(color)) {
  9. cont = segment.array[offset] != '{' &&
  10. segment.array[offset] != '}';
  11. }
  12. offset -= cont ? 1 : 0;
  13. }
  14. if (offset > -1 && segment.array[offset] == '{') {
  15. while (offset > -1 &&
  16. !Character.isWhitespace(segment.array[offset--])) {
  17. }
  18. }
  19. int index = offset < 0 || segment.array[offset] == '}' ? -4 : 0;
  20. if (offset > -1) {
  21. Element top = doc.getDefaultRootElement();
  22. offset = top.getElement(top.getElementIndex(offset)).getStartOffset();
  23. while (Character.isWhitespace(segment.array[offset++])) {
  24. index++;
  25. }
  26. }
  27. return index;
  28. }
  29. }

代码示例来源:origin: com.davidbracewell/hermes-core

  1. public String getText() {
  2. int caretPosition = editorPane.getStyledDocument().getLength();
  3. Element root = editorPane.getStyledDocument().getDefaultRootElement();
  4. String text = "1" + System.getProperty("line.separator");
  5. for (int i = 2; i < root.getElementIndex(caretPosition) + 2; i++) {
  6. text += i + System.getProperty("line.separator");
  7. }
  8. return text;
  9. }

代码示例来源:origin: org.codehaus.groovy/groovy-jdk14

  1. public void actionPerformed(ActionEvent ae) {
  2. JTextComponent tComp = (JTextComponent)ae.getSource();
  3. if (tComp.getDocument() instanceof StyledDocument) {
  4. doc = (StyledDocument)tComp.getDocument();
  5. try {
  6. doc.getText(0, doc.getLength(), segment);
  7. }
  8. catch (Exception e) {
  9. // should NEVER reach here
  10. e.printStackTrace();
  11. }
  12. int offset = tComp.getCaretPosition();
  13. int index = findTabLocation(offset);
  14. buffer.delete(0, buffer.length());
  15. buffer.append('\n');
  16. if (index > -1) {
  17. for (int i = 0; i < index + 4; i++) {
  18. buffer.append(' ');
  19. }
  20. }
  21. try {
  22. doc.insertString(offset, buffer.toString(),
  23. doc.getDefaultRootElement().getAttributes());
  24. }
  25. catch (BadLocationException ble) {
  26. ble.printStackTrace();
  27. }
  28. }
  29. }

代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm

  1. public void actionPerformed(ActionEvent ae) {
  2. JTextComponent tComp = (JTextComponent) ae.getSource();
  3. if (tComp.getDocument() instanceof StyledDocument) {
  4. doc = (StyledDocument) tComp.getDocument();
  5. try {
  6. doc.getText(0, doc.getLength(), segment);
  7. }
  8. catch (Exception e) {
  9. // should NEVER reach here
  10. e.printStackTrace();
  11. }
  12. int offset = tComp.getCaretPosition();
  13. int index = findTabLocation(offset);
  14. buffer.delete(0, buffer.length());
  15. buffer.append('\n');
  16. if (index > -1) {
  17. for (int i = 0; i < index + 4; i++) {
  18. buffer.append(' ');
  19. }
  20. }
  21. try {
  22. doc.insertString(offset, buffer.toString(),
  23. doc.getDefaultRootElement().getAttributes());
  24. }
  25. catch (BadLocationException ble) {
  26. ble.printStackTrace();
  27. }
  28. }
  29. }

代码示例来源:origin: org.codehaus.groovy/groovy-console

  1. public void actionPerformed(ActionEvent ae) {
  2. JTextComponent tComp = (JTextComponent) ae.getSource();
  3. if (tComp.getDocument() instanceof StyledDocument) {
  4. doc = (StyledDocument) tComp.getDocument();
  5. try {
  6. doc.getText(0, doc.getLength(), segment);
  7. }
  8. catch (Exception e) {
  9. // should NEVER reach here
  10. e.printStackTrace();
  11. }
  12. int offset = tComp.getCaretPosition();
  13. int index = findTabLocation(offset);
  14. buffer.delete(0, buffer.length());
  15. buffer.append('\n');
  16. if (index > -1) {
  17. for (int i = 0; i < index + 4; i++) {
  18. buffer.append(' ');
  19. }
  20. }
  21. try {
  22. doc.insertString(offset, buffer.toString(),
  23. doc.getDefaultRootElement().getAttributes());
  24. }
  25. catch (BadLocationException ble) {
  26. ble.printStackTrace();
  27. }
  28. }
  29. }

代码示例来源:origin: org.kohsuke.droovy/groovy

  1. public void actionPerformed(ActionEvent ae) {
  2. JTextComponent tComp = (JTextComponent)ae.getSource();
  3. if (tComp.getDocument() instanceof StyledDocument) {
  4. doc = (StyledDocument)tComp.getDocument();
  5. try {
  6. doc.getText(0, doc.getLength(), segment);
  7. }
  8. catch (Exception e) {
  9. // should NEVER reach here
  10. e.printStackTrace();
  11. }
  12. int offset = tComp.getCaretPosition();
  13. int index = findTabLocation(offset);
  14. buffer.delete(0, buffer.length());
  15. buffer.append('\n');
  16. if (index > -1) {
  17. for (int i = 0; i < index + 4; i++) {
  18. buffer.append(' ');
  19. }
  20. }
  21. try {
  22. doc.insertString(offset, buffer.toString(),
  23. doc.getDefaultRootElement().getAttributes());
  24. }
  25. catch (BadLocationException ble) {
  26. ble.printStackTrace();
  27. }
  28. }
  29. }

代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal

  1. public void actionPerformed(ActionEvent ae) {
  2. JTextComponent tComp = (JTextComponent)ae.getSource();
  3. if (tComp.getDocument() instanceof StyledDocument) {
  4. doc = (StyledDocument)tComp.getDocument();
  5. try {
  6. doc.getText(0, doc.getLength(), segment);
  7. }
  8. catch (Exception e) {
  9. // should NEVER reach here
  10. e.printStackTrace();
  11. }
  12. int offset = tComp.getCaretPosition();
  13. int index = findTabLocation(offset);
  14. buffer.delete(0, buffer.length());
  15. buffer.append('\n');
  16. if (index > -1) {
  17. for (int i = 0; i < index + 4; i++) {
  18. buffer.append(' ');
  19. }
  20. }
  21. try {
  22. doc.insertString(offset, buffer.toString(),
  23. doc.getDefaultRootElement().getAttributes());
  24. }
  25. catch (BadLocationException ble) {
  26. ble.printStackTrace();
  27. }
  28. }
  29. }

代码示例来源: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: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm

  1. public int findTabLocation(int offset) {
  2. // find first {
  3. boolean cont = true;
  4. while (offset > -1 && cont) {
  5. Element el = doc.getCharacterElement(offset);
  6. Object color =
  7. el.getAttributes().getAttribute(StyleConstants.Foreground);
  8. if (!COMMENT_COLOR.equals(color)) {
  9. cont = segment.array[offset] != '{' &&
  10. segment.array[offset] != '}';
  11. }
  12. offset -= cont ? 1 : 0;
  13. }
  14. if (offset > -1 && segment.array[offset] == '{') {
  15. while (offset > -1 &&
  16. !Character.isWhitespace(segment.array[offset--])) {
  17. }
  18. }
  19. int index = offset < 0 || segment.array[offset] == '}' ? -4 : 0;
  20. if (offset > -1) {
  21. Element top = doc.getDefaultRootElement();
  22. offset = top.getElement(top.getElementIndex(offset)).getStartOffset();
  23. while (Character.isWhitespace(segment.array[offset++])) {
  24. index++;
  25. }
  26. }
  27. return index;
  28. }
  29. }

代码示例来源:origin: org.codehaus.groovy/groovy-jdk14

  1. public int findTabLocation(int offset) {
  2. // find first {
  3. boolean cont = true;
  4. while (offset > -1 && cont) {
  5. Element el = doc.getCharacterElement(offset);
  6. Object color =
  7. el.getAttributes().getAttribute(StyleConstants.Foreground);
  8. if (!COMMENT_COLOR.equals(color)) {
  9. cont = segment.array[offset] != '{' &&
  10. segment.array[offset] != '}';
  11. }
  12. offset -= cont ? 1 : 0;
  13. }
  14. if (offset > -1 && segment.array[offset] == '{') {
  15. while (offset > -1 &&
  16. !Character.isWhitespace(segment.array[offset--])){
  17. }
  18. }
  19. int index = offset < 0 || segment.array[offset] == '}' ? -4 : 0;
  20. if (offset > -1) {
  21. Element top = doc.getDefaultRootElement();
  22. offset = top.getElement(top.getElementIndex(offset)).getStartOffset();
  23. while (Character.isWhitespace(segment.array[offset++])) {
  24. index++;
  25. }
  26. }
  27. return index;
  28. }
  29. }

代码示例来源:origin: org.kohsuke.droovy/groovy

  1. public int findTabLocation(int offset) {
  2. // find first {
  3. boolean cont = true;
  4. while (offset > -1 && cont) {
  5. Element el = doc.getCharacterElement(offset);
  6. Object color =
  7. el.getAttributes().getAttribute(StyleConstants.Foreground);
  8. if (!COMMENT_COLOR.equals(color)) {
  9. cont = segment.array[offset] != '{' &&
  10. segment.array[offset] != '}';
  11. }
  12. offset -= cont ? 1 : 0;
  13. }
  14. if (offset > -1 && segment.array[offset] == '{') {
  15. while (offset > -1 &&
  16. !Character.isWhitespace(segment.array[offset--])){
  17. }
  18. }
  19. int index = offset < 0 || segment.array[offset] == '}' ? -4 : 0;
  20. if (offset > -1) {
  21. Element top = doc.getDefaultRootElement();
  22. offset = top.getElement(top.getElementIndex(offset)).getStartOffset();
  23. while (Character.isWhitespace(segment.array[offset++])) {
  24. index++;
  25. }
  26. }
  27. return index;
  28. }
  29. }

代码示例来源:origin: org.codehaus.groovy/groovy-console

  1. public int findTabLocation(int offset) {
  2. // find first {
  3. boolean cont = true;
  4. while (offset > -1 && cont) {
  5. Element el = doc.getCharacterElement(offset);
  6. Object color =
  7. el.getAttributes().getAttribute(StyleConstants.Foreground);
  8. if (!COMMENT_COLOR.equals(color)) {
  9. cont = segment.array[offset] != '{' &&
  10. segment.array[offset] != '}';
  11. }
  12. offset -= cont ? 1 : 0;
  13. }
  14. if (offset > -1 && segment.array[offset] == '{') {
  15. while (offset > -1 &&
  16. !Character.isWhitespace(segment.array[offset--])) {
  17. }
  18. }
  19. int index = offset < 0 || segment.array[offset] == '}' ? -4 : 0;
  20. if (offset > -1) {
  21. Element top = doc.getDefaultRootElement();
  22. offset = top.getElement(top.getElementIndex(offset)).getStartOffset();
  23. while (Character.isWhitespace(segment.array[offset++])) {
  24. index++;
  25. }
  26. }
  27. return index;
  28. }
  29. }

代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal

  1. public int findTabLocation(int offset) {
  2. // find first {
  3. boolean cont = true;
  4. while (offset > -1 && cont) {
  5. Element el = doc.getCharacterElement(offset);
  6. Object color =
  7. el.getAttributes().getAttribute(StyleConstants.Foreground);
  8. if (!COMMENT_COLOR.equals(color)) {
  9. cont = segment.array[offset] != '{' &&
  10. segment.array[offset] != '}';
  11. }
  12. offset -= cont ? 1 : 0;
  13. }
  14. if (offset > -1 && segment.array[offset] == '{') {
  15. while (offset > -1 &&
  16. !Character.isWhitespace(segment.array[offset--])){
  17. }
  18. }
  19. int index = offset < 0 || segment.array[offset] == '}' ? -4 : 0;
  20. if (offset > -1) {
  21. Element top = doc.getDefaultRootElement();
  22. offset = top.getElement(top.getElementIndex(offset)).getStartOffset();
  23. while (Character.isWhitespace(segment.array[offset++])) {
  24. index++;
  25. }
  26. }
  27. return index;
  28. }
  29. }

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-bu

  1. Element root=_doc.getDefaultRootElement();
  2. int nbl =root.getElementCount();

相关文章