当前位置: 首页>>代码示例>>Java>>正文


Java DefaultStyledDocument类代码示例

本文整理汇总了Java中javax.swing.text.DefaultStyledDocument的典型用法代码示例。如果您正苦于以下问题:Java DefaultStyledDocument类的具体用法?Java DefaultStyledDocument怎么用?Java DefaultStyledDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DefaultStyledDocument类属于javax.swing.text包,在下文中一共展示了DefaultStyledDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCodeArea

import javax.swing.text.DefaultStyledDocument; //导入依赖的package包/类
private JTextPane getCodeArea(){
    final StyleContext sc = new StyleContext();
    final DefaultStyledDocument doc = new DefaultStyledDocument(sc);

    final JTextPane codeArea = new JTextPane(doc);
    codeArea.setBackground(new Color(0x25401C));
    codeArea.setCaretColor(new Color(0xD1E8CE));

    final Style bodyStyle = sc.addStyle("body", null);
    bodyStyle.addAttribute(StyleConstants.Foreground, new Color(0x789C6C));
    bodyStyle.addAttribute(StyleConstants.FontSize, 13);
    bodyStyle.addAttribute(StyleConstants.FontFamily, "monospaced");
    bodyStyle.addAttribute(StyleConstants.Bold, true);

    doc.setLogicalStyle(0, bodyStyle);

    return codeArea;
}
 
开发者ID:rossdrew,项目名称:emuRox,代码行数:19,代码来源:DebuggerWindow.java

示例2: applyStyle

import javax.swing.text.DefaultStyledDocument; //导入依赖的package包/类
/**
 * Apply the list of style to the script text pane. See 
 * {@link syntaxhighlighter.parser.Parser#parse(syntaxhighlighter.brush.Brush, boolean, char[], int, int)}.
 */
protected void applyStyle() {
  if (theme == null || styleList == null) {
    return;
  }

  DefaultStyledDocument document = (DefaultStyledDocument) getDocument();
  // clear all the existing style
  document.setCharacterAttributes(0, document.getLength(), theme.getPlain().getAttributeSet(), true);

  // apply style according to the style list
  for (String key : styleList.keySet()) {
    List<ParseResult> posList = styleList.get(key);

    SimpleAttributeSet attributeSet = theme.getStyle(key).getAttributeSet();
    for (ParseResult pos : posList) {
      document.setCharacterAttributes(pos.getOffset(), pos.getLength(), attributeSet, true);
    }
  }

  repaint();
}
 
开发者ID:Amine-H,项目名称:new-Line,代码行数:26,代码来源:SyntaxHighlighterPane.java

示例3: highlightText

import javax.swing.text.DefaultStyledDocument; //导入依赖的package包/类
/**
 * This highlights the text within the specified range
 *
 * @param startingIndex where to start the highlight
 * @param endingIndex where to end the highlight
 * @param ensureVisible true to scroll to the text
 * @param isEmphasized true to use an emphasized highlight (versus a regular highlight). Useful for showing the 'current' highlighted result.
 */
public void highlightText(int startingIndex, int endingIndex, boolean ensureVisible, boolean isEmphasized) {
    int length = endingIndex - startingIndex;

    AttributeSet style;
    if (isEmphasized) {
        style = emphasizedHighlightStyle;
    } else {
        style = highlightStyle;
    }

    ((DefaultStyledDocument) textComponentToSearch.getDocument()).setCharacterAttributes(startingIndex, length, style, true);

    if (ensureVisible) {
        Utility.scrollToText(textComponentToSearch, startingIndex, endingIndex);
        textComponentToSearch.setCaretPosition(endingIndex);
    }

    textComponentToSearch.repaint();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:28,代码来源:TextPaneSearchInteraction.java

示例4: handleBadLocationException

import javax.swing.text.DefaultStyledDocument; //导入依赖的package包/类
/**
 * Try and recover from a BadLocationException thrown when inserting a string
 * into the log area. This method must only be called on the AWT event
 * handling thread.
 */
private void handleBadLocationException(BadLocationException e,
    String textToInsert, Style style) {
  originalErr.println("BadLocationException encountered when writing to "
      + "the log area: " + e);
  originalErr.println("trying to recover...");

  Document newDocument = new DefaultStyledDocument();
  try {
    StringBuilder sb = new StringBuilder();
    sb.append("An error occurred when trying to write a message to the log area.  The log\n");
    sb.append("has been cleared to try and recover from this problem.\n\n");
    sb.append(textToInsert);

    newDocument.insertString(0, sb.toString(), style);
  } catch(BadLocationException e2) {
    // oh dear, all bets are off now...
    e2.printStackTrace(originalErr);
    return;
  }
  // replace the log area's document with the new one
  setDocument(newDocument);
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:28,代码来源:LogArea.java

示例5: writeWhitespaceNode

import javax.swing.text.DefaultStyledDocument; //导入依赖的package包/类
private static void writeWhitespaceNode(DefaultStyledDocument doc,
        StyleContext styles, Node node, int indent,
        Collection<IdentifierLocation> idLocations, boolean flagged) throws BadLocationException {
    if(isWhitespaceNewlineNode(node)) {
        doc.insertString(doc.getLength(), "\n", styles.getStyle(STYLE_WS));
        if(indent > 0) {
            doc.insertString(doc.getLength(), indent(indent), styles.getStyle(STYLE_WS));
        }

    } else if(isWhitespaceIndentNode(node)) {
        doc.insertString(doc.getLength(), indent(1), styles.getStyle(STYLE_WS));
        NodeList children = node.getChildNodes();
        for(int i = 0; i < children.getLength(); i++) {
            write(doc, styles, children.item(i), indent + 1, idLocations, flagged);
        }

    } else {
        doc.insertString(doc.getLength(), " ", styles.getStyle(STYLE_WS));
    }
}
 
开发者ID:jhuapl-saralab,项目名称:exterminator,代码行数:21,代码来源:CoqDoc.java

示例6: makeDocument

import javax.swing.text.DefaultStyledDocument; //导入依赖的package包/类
public static DefaultStyledDocument makeDocument(CoqDocable term,
        StyleContext styles, Collection<IdentifierLocation> idLocations,
        String optionalSuffix) {
    DefaultStyledDocument document = new DefaultStyledDocument();

    try {
        write(document, styles,
                term.makeCoqDocTerm(CoqDoc.makeDocument()), 0,
                idLocations, false);
        if(optionalSuffix != null) {
            document.insertString(document.getLength(), " ",
                    styles.getStyle(STYLE_WS));
            document.insertString(document.getLength(), optionalSuffix,
                    styles.getStyle(STYLE_TEXT));
        }
    } catch(BadLocationException e) {
        throw new RuntimeException(e);
    }

    return document;
}
 
开发者ID:jhuapl-saralab,项目名称:exterminator,代码行数:22,代码来源:CoqDoc.java

示例7: write

import javax.swing.text.DefaultStyledDocument; //导入依赖的package包/类
private static void write(DefaultStyledDocument doc, StyleContext styles,
        Node node, int indent, Collection<IdentifierLocation> idLocations,
        boolean flagged)
                throws BadLocationException {
    if(isWhitespaceNode(node)) {
        writeWhitespaceNode(doc, styles, node, indent, idLocations, flagged);
    } else if(isTextNode(node)) {
        writeTextNode(doc, styles, node, indent, idLocations, flagged);
    } else if(isKeywordNode(node)) {
        writeKeywordNode(doc, styles, node, indent, idLocations, flagged);
    } else if(isIdentifierNode(node)) {
        writeIdentifierNode(doc, styles, node, indent, idLocations, flagged);
    } else if(isTermNode(node)) {
        writeTermNode(doc, styles, node, indent, idLocations, flagged);
    } else if(isFlaggedNode(node)) {
        writeFlaggedNode(doc, styles, node, indent, idLocations, true);
    } else {
        throw new IllegalArgumentException("Unknown node type: " + XMLUtils.nodeToString(node));
    }
}
 
开发者ID:jhuapl-saralab,项目名称:exterminator,代码行数:21,代码来源:CoqDoc.java

示例8: extractFont

import javax.swing.text.DefaultStyledDocument; //导入依赖的package包/类
private Font extractFont(final StyleContext style, final int pos, final Element rootElement,
        final AttributeSet attributes) {
    Font font = null;
    if (attributes.isDefined(StyleConstants.FontSize) || attributes.isDefined(StyleConstants.FontFamily)) {
        font = style.getFont(attributes);
    }

    if (font == null) {
        if (document instanceof DefaultStyledDocument) {
            font = extractFontFromDefaultStyledDocument((DefaultStyledDocument) document, style, pos, rootElement);
        }
        else {
            font = style.getFont(rootElement.getAttributes());
        }
    }
    return font;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:18,代码来源:PStyledText.java

示例9: extractText

import javax.swing.text.DefaultStyledDocument; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
public String extractText(InputStream stream, String type, String encoding) throws IOException {

	try {
		RTFEditorKit rek = new RTFEditorKit();
		DefaultStyledDocument doc = new DefaultStyledDocument();
		rek.read(stream, doc, 0);
		String text = doc.getText(0, doc.getLength());
		return text;
	} catch (Throwable e) {
		logger.warn("Failed to extract RTF text content", e);
		throw new IOException(e.getMessage(), e);
	} finally {
		stream.close();
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:19,代码来源:RTFTextExtractor.java

示例10: writeStyles

import javax.swing.text.DefaultStyledDocument; //导入依赖的package包/类
/**
 * Write the styles used.
 */
protected void writeStyles() throws IOException
{
  if(doc instanceof DefaultStyledDocument)
    {
      Enumeration<?> styles = ((DefaultStyledDocument)doc).getStyleNames();
      while(styles.hasMoreElements())
        writeStyle(doc.getStyle((String)styles.nextElement()));
    }
  else
    { // What else to do here?
      Style s = doc.getStyle("default");
      if(s != null)
        writeStyle( s );
    }
}
 
开发者ID:vilie,项目名称:javify,代码行数:19,代码来源:MinimalHTMLWriter.java

示例11: blockOpen

import javax.swing.text.DefaultStyledDocument; //导入依赖的package包/类
/**
 * Instructs the parse buffer to create a block element with the given
 * attributes.
 *
 * @param t the tag that requires opening a new block
 * @param attr the attribute set for the new block
 */
protected void blockOpen(HTML.Tag t, MutableAttributeSet attr)
{
  if (inImpliedParagraph())
    blockClose(HTML.Tag.IMPLIED);

  // Push the new tag on top of the stack.
  parseStack.push(t);

  DefaultStyledDocument.ElementSpec element;

  AbstractDocument.AttributeContext ctx = getAttributeContext();
  AttributeSet copy = attr.copyAttributes();
  copy = ctx.addAttribute(copy, StyleConstants.NameAttribute, t);
  element = new DefaultStyledDocument.ElementSpec(copy,
                           DefaultStyledDocument.ElementSpec.StartTagType);
  parseBuffer.addElement(element);
}
 
开发者ID:vilie,项目名称:javify,代码行数:25,代码来源:HTMLDocument.java

示例12: addSpecialElement

import javax.swing.text.DefaultStyledDocument; //导入依赖的package包/类
/**
 * Adds content that is specified in the attribute set.
 *
 * @param t the HTML.Tag
 * @param a the attribute set specifying the special content
 */
protected void addSpecialElement(HTML.Tag t, MutableAttributeSet a)
{
  if (t != HTML.Tag.FRAME && ! inParagraph())
    {
      blockOpen(HTML.Tag.IMPLIED, new SimpleAttributeSet());
    }

  a.addAttribute(StyleConstants.NameAttribute, t);

  // The two spaces are required because some special elements like HR
  // must be broken. At least two characters are needed to break into the
  // two parts.
  DefaultStyledDocument.ElementSpec spec =
    new DefaultStyledDocument.ElementSpec(a.copyAttributes(),
      DefaultStyledDocument.ElementSpec.ContentType,
      new char[] {' '}, 0, 1 );
  parseBuffer.add(spec);
}
 
开发者ID:vilie,项目名称:javify,代码行数:25,代码来源:HTMLDocument.java

示例13: testTrim

import javax.swing.text.DefaultStyledDocument; //导入依赖的package包/类
@Test
public void testTrim() throws Exception {
  final StyledDocument doc = new DefaultStyledDocument();
  final StringBuilder buffer = new StringBuilder();
  for (int i = 0; i < 10; i++) {
    buffer.append("\n");
  }
  doc.insertString(0, buffer.toString(), null);
  ChatMessagePanel.trimLines(doc, 20);
  assertEquals(10, doc.getLength());
  ChatMessagePanel.trimLines(doc, 10);
  assertEquals(10, doc.getLength());
  ChatMessagePanel.trimLines(doc, 5);
  assertEquals(5, doc.getLength());
  ChatMessagePanel.trimLines(doc, 1);
  assertEquals(1, doc.getLength());
}
 
开发者ID:triplea-game,项目名称:triplea,代码行数:18,代码来源:ChatPanelTest.java

示例14: writeStyles

import javax.swing.text.DefaultStyledDocument; //导入依赖的package包/类
/**
  * Write the styles used.
  */
 protected void writeStyles() throws IOException
 {
   if(doc instanceof DefaultStyledDocument)
     {
Enumeration styles = ((DefaultStyledDocument)doc).getStyleNames();
while(styles.hasMoreElements())
  writeStyle(doc.getStyle((String)styles.nextElement()));
     }
   else
     { // What else to do here?
Style s = doc.getStyle("default");
if(s != null)
  writeStyle( s );
     }
 }
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:19,代码来源:MinimalHTMLWriter.java

示例15: blockOpen

import javax.swing.text.DefaultStyledDocument; //导入依赖的package包/类
/**
 * Instructs the parse buffer to create a block element with the given 
 * attributes.
 * 
 * @param t the tag that requires opening a new block
 * @param attr the attribute set for the new block
 */
protected void blockOpen(HTML.Tag t, MutableAttributeSet attr)
{
  if (inImpliedParagraph())
    blockClose(HTML.Tag.IMPLIED);

  // Push the new tag on top of the stack.
  parseStack.push(t);

  DefaultStyledDocument.ElementSpec element;

  AbstractDocument.AttributeContext ctx = getAttributeContext();
  AttributeSet copy = attr.copyAttributes();
  copy = ctx.addAttribute(copy, StyleConstants.NameAttribute, t);
  element = new DefaultStyledDocument.ElementSpec(copy,
                           DefaultStyledDocument.ElementSpec.StartTagType);
  parseBuffer.addElement(element);
}
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:25,代码来源:HTMLDocument.java


注:本文中的javax.swing.text.DefaultStyledDocument类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。