Java 类javax.swing.text.StyleContext 实例源码

项目:Neukoelln_SER316    文件:AltHTMLWriter.java   
/**
 * Outputs the styles as a single element. Styles are not stored as
 * elements, but part of the document. For the time being styles are
 * written out as a comment, inside a style tag.
 */
void writeStyles(StyleSheet sheet) throws IOException {
    if (sheet != null) {
        Enumeration styles = sheet.getStyleNames();
        if (styles != null) {
            boolean outputStyle = false;
            while (styles.hasMoreElements()) {
                String name = (String) styles.nextElement();
                // Don't write out the default style.
                if (!StyleContext.DEFAULT_STYLE.equals(name)
                    && writeStyle(name, sheet.getStyle(name), outputStyle)) {
                    outputStyle = true;
                }
            }
            if (outputStyle) {
                writeStyleEndTag();
            }
        }
    }
}
项目:Reer    文件:OutputPanel.java   
private Component createSearchPanel() {
    StyleContext styleContent = StyleContext.getDefaultStyleContext();

    AttributeSet highlightStyle = gradleOutputTextPane.getDefaultStyle().copyAttributes();
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Foreground, Color.white);
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Background, Color.orange);
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Underline, true);

    AttributeSet emphasizedHighlightStyle = highlightStyle.copyAttributes();
    emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Foreground, Color.black);
    emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Background, Color.yellow);

    searchPanel = new SearchPanel(new OutputPanelSearchInteraction(gradleOutputTextPane.getTextComponent(), gradleOutputTextPane.getDefaultStyle(), highlightStyle, emphasizedHighlightStyle));
    searchPanel.hide();

    return searchPanel.getComponent();
}
项目:SER316-Dresden    文件:AltHTMLWriter.java   
/**
 * Outputs the styles as a single element. Styles are not stored as
 * elements, but part of the document. For the time being styles are
 * written out as a comment, inside a style tag.
 */
void writeStyles(StyleSheet sheet) throws IOException {
    if (sheet != null) {
        Enumeration styles = sheet.getStyleNames();
        if (styles != null) {
            boolean outputStyle = false;
            while (styles.hasMoreElements()) {
                String name = (String) styles.nextElement();
                // Don't write out the default style.
                if (!StyleContext.DEFAULT_STYLE.equals(name)
                    && writeStyle(name, sheet.getStyle(name), outputStyle)) {
                    outputStyle = true;
                }
            }
            if (outputStyle) {
                writeStyleEndTag();
            }
        }
    }
}
项目:SER316-Munich    文件:AltHTMLWriter.java   
/**
 * Outputs the styles as a single element. Styles are not stored as
 * elements, but part of the document. For the time being styles are
 * written out as a comment, inside a style tag.
 */
void writeStyles(StyleSheet sheet) throws IOException {
    if (sheet != null) {
        Enumeration styles = sheet.getStyleNames();
        if (styles != null) {
            boolean outputStyle = false;
            while (styles.hasMoreElements()) {
                String name = (String) styles.nextElement();
                // Don't write out the default style.
                if (!StyleContext.DEFAULT_STYLE.equals(name)
                    && writeStyle(name, sheet.getStyle(name), outputStyle)) {
                    outputStyle = true;
                }
            }
            if (outputStyle) {
                writeStyleEndTag();
            }
        }
    }
}
项目:SER316-Ingolstadt    文件:AltHTMLWriter.java   
/**
 * Outputs the styles as a single element. Styles are not stored as
 * elements, but part of the document. For the time being styles are
 * written out as a comment, inside a style tag.
 */
void writeStyles(StyleSheet sheet) throws IOException {
    if (sheet != null) {
        Enumeration styles = sheet.getStyleNames();
        if (styles != null) {
            boolean outputStyle = false;
            while (styles.hasMoreElements()) {
                String name = (String) styles.nextElement();
                // Don't write out the default style.
                if (!StyleContext.DEFAULT_STYLE.equals(name)
                    && writeStyle(name, sheet.getStyle(name), outputStyle)) {
                    outputStyle = true;
                }
            }
            if (outputStyle) {
                writeStyleEndTag();
            }
        }
    }
}
项目:Wilmersdorf_SER316    文件:AltHTMLWriter.java   
/**
 * Outputs the styles as a single element. Styles are not stored as
 * elements, but part of the document. For the time being styles are
 * written out as a comment, inside a style tag.
 */
void writeStyles(StyleSheet sheet) throws IOException {
    if (sheet != null) {
        Enumeration styles = sheet.getStyleNames();
        if (styles != null) {
            boolean outputStyle = false;
            while (styles.hasMoreElements()) {
                String name = (String) styles.nextElement();
                // Don't write out the default style.
                if (!StyleContext.DEFAULT_STYLE.equals(name)
                    && writeStyle(name, sheet.getStyle(name), outputStyle)) {
                    outputStyle = true;
                }
            }
            if (outputStyle) {
                writeStyleEndTag();
            }
        }
    }
}
项目:openvisualtraceroute    文件:PacketDetailPanel.java   
private void showPacket(final AbstractPacketPoint point) {
    SwingUtilities4.invokeInEDT(() -> {
        final String[] lines = point.getPayload().split("\n");
        int max = 0;
        for (final String line1 : lines) {
            max = Math.max(max, line1.length());
        }
        max += 5;
        for (final String line2 : lines) {
            final Color color = colorForLine(line2);
            final StyleContext sc = StyleContext.getDefaultStyleContext();
            AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.BLACK);

            aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");
            aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
            aset = sc.addAttribute(aset, StyleConstants.Bold, false);
            aset = sc.addAttribute(aset, StyleConstants.Background, color);
            final int len = _details.getDocument().getLength();
            _details.setCaretPosition(len);
            _details.setCharacterAttributes(aset, false);
            _details.replaceSelection(line2 + StringUtils.repeat(" ", max - line2.length()) + "\n");
        }
        _details.setCaretPosition(0);
    });
}
项目:Reinickendorf_SER316    文件:AltHTMLWriter.java   
/**
 * Outputs the styles as a single element. Styles are not stored as
 * elements, but part of the document. For the time being styles are
 * written out as a comment, inside a style tag.
 */
void writeStyles(StyleSheet sheet) throws IOException {
    if (sheet != null) {
        Enumeration styles = sheet.getStyleNames();
        if (styles != null) {
            boolean outputStyle = false;
            while (styles.hasMoreElements()) {
                String name = (String) styles.nextElement();
                // Don't write out the default style.
                if (!StyleContext.DEFAULT_STYLE.equals(name)
                    && writeStyle(name, sheet.getStyle(name), outputStyle)) {
                    outputStyle = true;
                }
            }
            if (outputStyle) {
                writeStyleEndTag();
            }
        }
    }
}
项目:Dahlem_SER316    文件:AltHTMLWriter.java   
/**
 * Outputs the styles as a single element. Styles are not stored as
 * elements, but part of the document. For the time being styles are
 * written out as a comment, inside a style tag.
 */
void writeStyles(StyleSheet sheet) throws IOException {
    if (sheet != null) {
        Enumeration styles = sheet.getStyleNames();
        if (styles != null) {
            boolean outputStyle = false;
            while (styles.hasMoreElements()) {
                String name = (String) styles.nextElement();
                // Don't write out the default style.
                if (!StyleContext.DEFAULT_STYLE.equals(name)
                    && writeStyle(name, sheet.getStyle(name), outputStyle)) {
                    outputStyle = true;
                }
            }
            if (outputStyle) {
                writeStyleEndTag();
            }
        }
    }
}
项目:SER316-Aachen    文件:AltHTMLWriter.java   
/**
 * Outputs the styles as a single element. Styles are not stored as
 * elements, but part of the document. For the time being styles are
 * written out as a comment, inside a style tag.
 */
void writeStyles(StyleSheet sheet) throws IOException {
    if (sheet != null) {
        Enumeration styles = sheet.getStyleNames();
        if (styles != null) {
            boolean outputStyle = false;
            while (styles.hasMoreElements()) {
                String name = (String) styles.nextElement();
                // Don't write out the default style.
                if (!StyleContext.DEFAULT_STYLE.equals(name)
                    && writeStyle(name, sheet.getStyle(name), outputStyle)) {
                    outputStyle = true;
                }
            }
            if (outputStyle) {
                writeStyleEndTag();
            }
        }
    }
}
项目:emuRox    文件:DebuggerWindow.java   
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;
}
项目:exterminator    文件:CoqDoc.java   
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));
    }
}
项目:exterminator    文件:CoqDoc.java   
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;
}
项目:exterminator    文件:CoqDoc.java   
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));
    }
}
项目:PhET    文件:PStyledText.java   
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;
}
项目:spring16project-Modula-2    文件:AltHTMLWriter.java   
/**
 * Outputs the styles as a single element. Styles are not stored as
 * elements, but part of the document. For the time being styles are
 * written out as a comment, inside a style tag.
 */
void writeStyles(StyleSheet sheet) throws IOException {
    if (sheet != null) {
        Enumeration styles = sheet.getStyleNames();
        if (styles != null) {
            boolean outputStyle = false;
            while (styles.hasMoreElements()) {
                String name = (String) styles.nextElement();
                // Don't write out the default style.
                if (!StyleContext.DEFAULT_STYLE.equals(name)
                    && writeStyle(name, sheet.getStyle(name), outputStyle)) {
                    outputStyle = true;
                }
            }
            if (outputStyle) {
                writeStyleEndTag();
            }
        }
    }
}
项目:spring16project-Fortran    文件:AltHTMLWriter.java   
/**
 * Outputs the styles as a single element. Styles are not stored as
 * elements, but part of the document. For the time being styles are written
 * out as a comment, inside a style tag.
 */
void writeStyles(StyleSheet sheet) throws IOException {
    if (sheet != null) {
        Enumeration styles = sheet.getStyleNames();
        if (styles != null) {
            boolean outputStyle = false;
            while (styles.hasMoreElements()) {
                String name = (String) styles.nextElement();
                // Don't write out the default style.
                if (!StyleContext.DEFAULT_STYLE.equals(name)
                        && writeStyle(name, sheet.getStyle(name), outputStyle)) {
                    outputStyle = true;
                }
            }
            if (outputStyle) {
                writeStyleEndTag();
            }
        }
    }
}
项目:OpenUHS    文件:UHSTextArea.java   
/**
 * Returns a default-populated StyleContext for UHSTextAreas.
 *
 * <p>Changes to a style will immediately affect existing
 * components using its descendants only. The style itself
 * will not update for some reason.</p>
 *
 * <blockquote><pre>
 * @{code
 * Java's default
 * - base
 * - - regular
 * - - - visitable
 * - - - link
 * - - - hyper
 * - - - monospaced
 * }
 * </pre></blockquote>
 */
private static StyleContext getDefaultStyleContext() {
    StyleContext result = new StyleContext();
    Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle( StyleContext.DEFAULT_STYLE );
        Style baseStyle = result.addStyle( "base", defaultStyle );
            Style regularStyle = result.addStyle( STYLE_NAME_REGULAR, baseStyle );

                Style visitableStyle = result.addStyle( STYLE_NAME_VISITABLE, regularStyle );
                    StyleConstants.setForeground( visitableStyle, VISITABLE_COLOR );

                Style linkStyle = result.addStyle( STYLE_NAME_LINK, regularStyle );
                    StyleConstants.setForeground( linkStyle, LINK_COLOR );

                Style hyperStyle = result.addStyle( STYLE_NAME_HYPERLINK, regularStyle );
                    StyleConstants.setForeground( hyperStyle, HYPER_COLOR );
                    StyleConstants.setUnderline( hyperStyle, true );

                Style monospacedStyle = result.addStyle( STYLE_NAME_MONOSPACED, regularStyle );
                    StyleConstants.setFontFamily( monospacedStyle, "Monospaced" );

    return result;
}
项目:cuba    文件:DesktopToolTipManager.java   
@Override
public void setTipText(String tipText) {
    UIDefaults lafDefaults = UIManager.getLookAndFeelDefaults();
    int maxTooltipWidth = lafDefaults.getInt("Tooltip.maxWidth");
    if (maxTooltipWidth == 0) {
        maxTooltipWidth = DesktopComponentsHelper.TOOLTIP_WIDTH;
    }

    FontMetrics fontMetrics = StyleContext.getDefaultStyleContext().getFontMetrics(getFont());
    int actualWidth = SwingUtilities.computeStringWidth(fontMetrics, tipText);

    if (actualWidth < maxTooltipWidth) {
        tipText = "<html>" + tipText + "</html>";
    } else {
        tipText = "<html><body width=\"" + maxTooltipWidth + "px\">" + tipText + "</body></html>";
    }

    super.setTipText(tipText);
}
项目:spring16project-Korn    文件:AltHTMLWriter.java   
/**
 * Outputs the styles as a single element. Styles are not stored as
 * elements, but part of the document. For the time being styles are
 * written out as a comment, inside a style tag.
 */
void writeStyles(StyleSheet sheet) throws IOException {
    if (sheet != null) {
        Enumeration styles = sheet.getStyleNames();
        if (styles != null) {
            boolean outputStyle = false;
            while (styles.hasMoreElements()) {
                String name = (String) styles.nextElement();
                // Don't write out the default style.
                if (!StyleContext.DEFAULT_STYLE.equals(name)
                    && writeStyle(name, sheet.getStyle(name), outputStyle)) {
                    outputStyle = true;
                }
            }
            if (outputStyle) {
                writeStyleEndTag();
            }
        }
    }
}
项目:repo.kmeanspp.silhouette_score    文件:ReaderToTextPane.java   
/**
 * Sets up the thread.
 *
 * @param input     the Reader to monitor
 * @param output    the TextArea to send output to
 * @param color the color to use
 */
public ReaderToTextPane(Reader input, JTextPane output, Color color) {
  StyledDocument      doc;
  Style               style;

  setDaemon(true);

  m_Color  = color;
  m_Input  = new LineNumberReader(input);
  m_Output = output;

  doc   = m_Output.getStyledDocument();
  style = StyleContext.getDefaultStyleContext()
                      .getStyle(StyleContext.DEFAULT_STYLE);
  style = doc.addStyle(getStyleName(), style);
  StyleConstants.setFontFamily(style, "monospaced");
  StyleConstants.setForeground(style, m_Color);
}
项目:IpTweet    文件:Participants.java   
public void setUsers(User[] users){
    textPane.removeAll();
    StringBuilder sb = new StringBuilder();
    final Style cwStyle = new StyleContext().addStyle("ConstantWidth", null);
    StyleConstants.setBold(cwStyle, true);
    boolean firstUser = true;
    for(User user: users){
        if(firstUser){
            firstUser = false;
        }
        else{
            sb.append(", ");
        }
        sb.append(user.getDisplayName());
    }
    try {
        textPane.getDocument().insertString(textPane.getDocument().getLength(), "Participants: ", cwStyle);
        StyleConstants.setBold(cwStyle, false);
        textPane.getDocument().insertString(textPane.getDocument().getLength(), sb.toString(), cwStyle);
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
项目:me3modmanager    文件:ResourceUtils.java   
/**
 * Appends stylized text to a textpane
 * 
 * @param tp
 *            Textpane
 * @param msg
 *            Message to append. Will automatically place newline at end.
 * @param c
 *            Color of text.
 */
public static void appendToPane(JTextPane tp, String msg, Color c) {
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

    int len = tp.getDocument().getLength(); // same value as
    // getText().length();
    tp.setCaretPosition(len); // place caret at the end (with no selection)

    StyledDocument doc = tp.getStyledDocument();
    try {
        doc.insertString(doc.getLength(), msg + "\n", aset);
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
项目:metasfresh    文件:AltHTMLWriter.java   
/**
 * Outputs the styles as a single element. Styles are not stored as
 * elements, but part of the document. For the time being styles are
 * written out as a comment, inside a style tag.
 */
void writeStyles(StyleSheet sheet) throws IOException {
    if (sheet != null) {
        Enumeration styles = sheet.getStyleNames();
        if (styles != null) {
            boolean outputStyle = false;
            while (styles.hasMoreElements()) {
                String name = (String) styles.nextElement();
                // Don't write out the default style.
                if (!StyleContext.DEFAULT_STYLE.equals(name)
                    && writeStyle(name, sheet.getStyle(name), outputStyle)) {
                    outputStyle = true;
                }
            }
            if (outputStyle) {
                writeStyleEndTag();
            }
        }
    }
}
项目:groovy    文件:ConsoleSupport.java   
protected void addStylesToDocument(JTextPane outputArea) {
    StyledDocument doc = outputArea.getStyledDocument();

    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

    Style regular = doc.addStyle("regular", def);
    StyleConstants.setFontFamily(def, "Monospaced");

    promptStyle = doc.addStyle("prompt", regular);
    StyleConstants.setForeground(promptStyle, Color.BLUE);

    commandStyle = doc.addStyle("command", regular);
    StyleConstants.setForeground(commandStyle, Color.MAGENTA);

    outputStyle = doc.addStyle("output", regular);
    StyleConstants.setBold(outputStyle, true);
}
项目:autoweka    文件:ReaderToTextPane.java   
/**
 * Sets up the thread.
 *
 * @param input     the Reader to monitor
 * @param output    the TextArea to send output to
 * @param color the color to use
 */
public ReaderToTextPane(Reader input, JTextPane output, Color color) {
  StyledDocument      doc;
  Style               style;

  setDaemon(true);

  m_Color  = color;
  m_Input  = new LineNumberReader(input);
  m_Output = output;

  doc   = m_Output.getStyledDocument();
  style = StyleContext.getDefaultStyleContext()
                      .getStyle(StyleContext.DEFAULT_STYLE);
  style = doc.addStyle(getStyleName(), style);
  StyleConstants.setFontFamily(style, "monospaced");
  StyleConstants.setForeground(style, m_Color);
}
项目:umple    文件:ReaderToTextPane.java   
/**
 * Sets up the thread.
 *
 * @param input     the Reader to monitor
 * @param output    the TextArea to send output to
 * @param color the color to use
 */
public ReaderToTextPane(Reader input, JTextPane output, Color color) {
  StyledDocument      doc;
  Style               style;

  setDaemon(true);

  m_Color  = color;
  m_Input  = new LineNumberReader(input);
  m_Output = output;

  doc   = m_Output.getStyledDocument();
  style = StyleContext.getDefaultStyleContext()
                      .getStyle(StyleContext.DEFAULT_STYLE);
  style = doc.addStyle(getStyleName(), style);
  StyleConstants.setFontFamily(style, "monospaced");
  StyleConstants.setForeground(style, m_Color);
}
项目:Pushjet-Android    文件:OutputPanel.java   
private Component createSearchPanel() {
    StyleContext styleContent = StyleContext.getDefaultStyleContext();

    AttributeSet highlightStyle = gradleOutputTextPane.getDefaultStyle().copyAttributes();
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Foreground, Color.white);
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Background, Color.orange);
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Underline, true);

    AttributeSet emphasizedHighlightStyle = highlightStyle.copyAttributes();
    emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Foreground, Color.black);
    emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Background, Color.yellow);

    searchPanel = new SearchPanel(new OutputPanelSearchInteraction(gradleOutputTextPane.getTextComponent(), gradleOutputTextPane.getDefaultStyle(), highlightStyle, emphasizedHighlightStyle));
    searchPanel.hide();

    return searchPanel.getComponent();
}
项目:Pushjet-Android    文件:OutputPanel.java   
private Component createSearchPanel() {
    StyleContext styleContent = StyleContext.getDefaultStyleContext();

    AttributeSet highlightStyle = gradleOutputTextPane.getDefaultStyle().copyAttributes();
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Foreground, Color.white);
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Background, Color.orange);
    highlightStyle = styleContent.addAttribute(highlightStyle, StyleConstants.Underline, true);

    AttributeSet emphasizedHighlightStyle = highlightStyle.copyAttributes();
    emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Foreground, Color.black);
    emphasizedHighlightStyle = styleContent.addAttribute(emphasizedHighlightStyle, StyleConstants.Background, Color.yellow);

    searchPanel = new SearchPanel(new OutputPanelSearchInteraction(gradleOutputTextPane.getTextComponent(), gradleOutputTextPane.getDefaultStyle(), highlightStyle, emphasizedHighlightStyle));
    searchPanel.hide();

    return searchPanel.getComponent();
}
项目:otroslogviewer    文件:StackTraceColorizer.java   
protected void initStyles() {
  styleContext = new StyleContext();
  Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
  StyleConstants.setFontFamily(defaultStyle, "courier");
  styleStackTrace = styleContext.addStyle("stackTrace", defaultStyle);

  StyleConstants.setBackground(styleStackTrace, new Color(255, 224, 193));
  StyleConstants.setForeground(styleStackTrace, Color.BLACK);
  stylePackage = styleContext.addStyle("stylePackage", styleStackTrace);
  styleClass = styleContext.addStyle("styleClass", stylePackage);
  StyleConstants.setForeground(styleClass, new Color(11, 143, 61));
  StyleConstants.setBold(styleClass, true);
  styleMethod = styleContext.addStyle("styleMethod", styleStackTrace);
  StyleConstants.setForeground(styleMethod, new Color(83, 112, 223));
  StyleConstants.setItalic(styleMethod, true);
  StyleConstants.setBold(styleMethod, true);
  styleFile = styleContext.addStyle("styleFile", styleStackTrace);
  StyleConstants.setForeground(styleFile, Color.BLACK);
  StyleConstants.setUnderline(styleFile, true);

  styleCodeComment = styleContext.addStyle("styleCodeComment", defaultStyle);
  StyleConstants.setForeground(styleCodeComment, Color.DARK_GRAY);
  StyleConstants.setItalic(styleCodeComment, true);
}
项目:otroslogviewer    文件:SearchResultColorizer.java   
@Override
public Collection<MessageFragmentStyle> colorize(String textToColorize) throws BadLocationException {
  Collection<MessageFragmentStyle> list = new ArrayList<>();
  if (StringUtils.isEmpty(searchString)) {
    return list;
  }
  StyleContext sc = new StyleContext();
  Style searchStyle = sc.addStyle("searchResult", sc.getStyle(StyleContext.DEFAULT_STYLE));
  StyleConstants.setBackground(searchStyle, color);
  if (searchMode.equals(SearchMode.STRING_CONTAINS)) {
    list.addAll(colorizeString(textToColorize, searchStyle, searchString));
  } else if (searchMode.equals(SearchMode.REGEX)) {
    list.addAll(MessageColorizerUtils.colorizeRegex(searchStyle, textToColorize, Pattern.compile(searchString, Pattern.CASE_INSENSITIVE), 0));
  }
  for (MessageFragmentStyle style : list) {
    style.setSearchResult(true);
  }
  return list;
}
项目:otroslogviewer    文件:MessageColorizerEditor.java   
protected void refreshView() {
  LOGGER.info("refreshing view");
  Style defaultStyle = textPane.getStyle(StyleContext.DEFAULT_STYLE);
  String text = textPane.getText();
  textPane.getStyledDocument().setCharacterAttributes(0, text.length(), defaultStyle, true);
  try {
    PropertyPatternMessageColorizer propertyPatternMessageColorize = createMessageColorizer();
    if (propertyPatternMessageColorize.colorizingNeeded(text)) {
      Collection<MessageFragmentStyle> colorize = propertyPatternMessageColorize.colorize(text);
      for (MessageFragmentStyle mfs : colorize) {
        textPane.getStyledDocument().setCharacterAttributes(mfs.getOffset(), mfs.getLength(), mfs.getStyle(), mfs.isReplace());
      }
    }
  } catch (Exception e) {
    LOGGER.error(String.format("Can't init PropertyPatternMessageColorizer:%s", e.getMessage()));
    statusObserver.updateStatus(String.format("Error: %s", e.getMessage()), StatusObserver.LEVEL_ERROR);
  }

}
项目:seaglass    文件:SeaGlassTextPaneUI.java   
/**
 * Update the font in the default style of the document.
 *
 * @param font the new font to use or null to remove the font attribute
 *             from the document's style
 */
private void updateFont(Font font) {
    StyledDocument doc = (StyledDocument)getComponent().getDocument();
    Style style = doc.getStyle(StyleContext.DEFAULT_STYLE);

    if (style == null) {
        return;
    }

    if (font == null) {
        style.removeAttribute(StyleConstants.FontFamily);
        style.removeAttribute(StyleConstants.FontSize);
        style.removeAttribute(StyleConstants.Bold);
        style.removeAttribute(StyleConstants.Italic);
    } else {
        StyleConstants.setFontFamily(style, font.getName());
        StyleConstants.setFontSize(style, font.getSize());
        StyleConstants.setBold(style, font.isBold());
        StyleConstants.setItalic(style, font.isItalic());
    }
}
项目:piccolo2d.java    文件:PStyledText.java   
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;
}
项目:jarman    文件:ExploreFileDlg.java   
/**
 * Add styles to the document.
 * 
 * @param doc the StyledDocument to add styles to
 */
protected void addStylesToDocument(final StyledDocument doc)
{
  //Initialize some styles.
  Style def = StyleContext.getDefaultStyleContext().
                  getStyle(StyleContext.DEFAULT_STYLE);

  Style regular = doc.addStyle("regular", def);
  StyleConstants.setFontFamily(def, "SansSerif");
  StyleConstants.setFontSize(def, 12);
  StyleConstants.setLineSpacing(def, 2.0f);

  Style s = doc.addStyle("italic", regular);
  StyleConstants.setItalic(s, true);

  s = doc.addStyle("bold", regular);
  StyleConstants.setBold(s, true);

  s = doc.addStyle("small", regular);
  StyleConstants.setFontSize(s, 10);

  s = doc.addStyle("large", regular);
  StyleConstants.setFontSize(s, 14);
}
项目:humo    文件:TextViewHelper.java   
public static StyledDocument createStyleDocument()
   {
StyleContext styleContext= new StyleContext();

Color grey= new Color(0.95f, 0.95f, 0.95f);

Color color= UIManager.getColor("EditorPane.background");

if (!color.equals(Color.WHITE))
{
    grey= new Color(0.25f, 0.25f, 0.25f);
}

Color orange= new Color(Integer.parseInt("008EFF", 16));
createStyle(styleContext, DEFAULT_STYLE, Color.black, "monospaced", color, 11, null);
createStyle(styleContext, CURSOR_STYLE, new Color(0.8f, 0, 0), "monospaced", grey, 11, null);
createStyle(styleContext, CURLY_STYLE, Color.BLACK, "monospaced", color, 11, true);
createStyle(styleContext, FETCH_STYLE, new Color(0, 0.5f, 0), "monospaced", grey, 11, null);
createStyle(styleContext, SPECIAL_STYLE, new Color(0.5f, 0.5f, 0), "monospaced", grey, 11, null);
createStyle(styleContext, PRODUCTION_FOUND_STYLE, Color.BLUE, "monospaced", grey, 11, true);
createStyle(styleContext, PRODUCTION_BEFORE_REPLACEMENT_STYLE, orange, "monospaced", grey, 11, true);
return new DefaultStyledDocument(styleContext);
   }
项目:jo-widgets    文件:FontProvider.java   
public static Font deriveFont(final Font baseFont, final String newFontName, final Integer newSize, final Markup newMarkup) {
    Assert.paramNotNull(baseFont, "baseFont");

    Integer newStyle = null;
    if (Markup.DEFAULT.equals(newMarkup)) {
        newStyle = Integer.valueOf(Font.PLAIN);
    }
    else if (Markup.STRONG.equals(newMarkup)) {
        newStyle = Integer.valueOf(Font.BOLD);
    }
    else if (Markup.EMPHASIZED.equals(newMarkup)) {
        newStyle = Integer.valueOf(Font.ITALIC);
    }

    final String fontName = newFontName != null ? newFontName : baseFont.getName();
    final int size = newSize != null ? (newSize.intValue() * 100 / 72) : baseFont.getSize();
    final int style = newStyle != null ? newStyle.intValue() : baseFont.getStyle();

    //Workaround because otherwise composite Font's wont't work
    //http://elliotth.blogspot.de/2007/04/far-east-asian-fonts-with-java-7-on.html
    //return new Font(fontName, style, size);
    return StyleContext.getDefaultStyleContext().getFont(fontName, style, size);
}
项目:opennars    文件:OutputLogPanel.java   
protected void print(Color c, float size, String text, boolean bold) {
    StyleContext sc = StyleContext.getDefaultStyleContext();

    MutableAttributeSet aset = ioText.getInputAttributes();


    Font f = ioText.getFont();
    StyleConstants.setForeground(aset, c);
    //StyleConstants.setFontSize(aset, (int)(f.getSize()*size));
    StyleConstants.setBold(aset, bold);

    try {
        doc.insertString(doc.getLength(), text, null);

        ioText.getStyledDocument().setCharacterAttributes(doc.getLength() - text.length(), text.length(), aset, true);
    } catch (BadLocationException ex) {
        Logger.getLogger(NARControls.class.getName()).log(Level.SEVERE, null, ex);
    }

}
项目:goworks    文件:Rule.java   
public Rule(String name) {
    super();
       Parameters.notNull("name", name);
       if (name.isEmpty()) {
           throw new IllegalArgumentException();
       }

       setLayout(new FlowLayout(FlowLayout.LEFT));
       setBorder(new EmptyBorder(new Insets(15, 0, 0, 0)));
       setOpaque(false);
       setName("RULE_" + name);
    this.ruleName = name;
       this.attributes = Diagram.lookupAttributes("identifier");

       StyleContext context = new StyleContext();
       setFont(context.getFont(this.attributes));
       setForeground(context.getForeground(attributes));

       String family = StyleConstants.getFontFamily(attributes);
       int size = StyleConstants.getFontSize(attributes);
       int x = 0;
}
项目:cn1    文件:OptionTest.java   
/**
 * Tests constructor.
 * Non-mutable (<code>StyleContext.SmallAttributeSet</code>) is passed
 * as parameter.
 */
public void testOptionSmallAttrSet() {
    AttributeContext context = new StyleContext();
    attrs = context.addAttribute(context.getEmptySet(), "key", "value");

    item = new Option(attrs);
    final AttributeSet itAttrs = item.getAttributes();
    assertFalse(itAttrs instanceof MutableAttributeSet);
    assertTrue(itAttrs instanceof StyleContext.SmallAttributeSet);
    assertSame(attrs, itAttrs);
    assertEquals(attrs, itAttrs);
    assertNull(item.getLabel());
    assertNull(item.getValue());
    assertFalse(item.isSelected());
    assertNull(item.toString());

    assertEquals("value", itAttrs.getAttribute("key"));
}