javax.swing.text.StyleContext#getDefaultStyleContext ( )源码实例Demo

下面列出了javax.swing.text.StyleContext#getDefaultStyleContext ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pushfish-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();
}
 
源代码2 项目: pushfish-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();
}
 
源代码3 项目: 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();
}
 
源代码4 项目: 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();
}
 
源代码5 项目: jadx   文件: FontUtils.java
public static Font loadByStr(String fontDesc) {
	String[] parts = fontDesc.split("-");
	if (parts.length != 3) {
		throw new JadxRuntimeException("Unsupported font description format: " + fontDesc);
	}
	String name = parts[0];
	int style = parseFontStyle(parts[1]);
	int size = Integer.parseInt(parts[2]);

	StyleContext sc = StyleContext.getDefaultStyleContext();
	Font font = sc.getFont(name, style, size);
	if (font == null) {
		throw new JadxRuntimeException("Font not found: " + fontDesc);
	}
	return font;
}
 
源代码6 项目: FancyBing   文件: GuiUtil.java
public static void addStyle(JTextPane pane, String name, Color foreground,
                            Color background)
{
    StyledDocument doc = pane.getStyledDocument();
    StyleContext context = StyleContext.getDefaultStyleContext();
    Style defaultStyle = context.getStyle(StyleContext.DEFAULT_STYLE);
    Style style = doc.addStyle(name, defaultStyle);
    StyleConstants.setForeground(style, foreground);
    StyleConstants.setBackground(style, background);
}
 
源代码7 项目: FancyBing   文件: GuiUtil.java
public static void addStyle(JTextPane textPane, String name,
                            Color foreground, Color background,
                            boolean bold)
{
    StyledDocument doc = textPane.getStyledDocument();
    StyleContext context = StyleContext.getDefaultStyleContext();
    Style def = context.getStyle(StyleContext.DEFAULT_STYLE);
    Style style = doc.addStyle(name, def);
    if (foreground != null)
        StyleConstants.setForeground(style, foreground);
    if (background != null)
        StyleConstants.setBackground(style, background);
    StyleConstants.setBold(style, bold);
}
 
源代码8 项目: FancyBing   文件: GuiUtil.java
public static void setStyle(JTextPane textPane, int start, int length,
                            String name)
{
    StyledDocument doc = textPane.getStyledDocument();
    Style style;
    if (name == null)
    {
        StyleContext context = StyleContext.getDefaultStyleContext();
        style = context.getStyle(StyleContext.DEFAULT_STYLE);
    }
    else
        style = doc.getStyle(name);
    doc.setCharacterAttributes(start, length, style, true);
}
 
源代码9 项目: jason   文件: MASConsoleColorGUI.java
public void append(Color c, String s) {
    if (c == null)
        c = defaultColor;
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet as = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
    try {
        getDocument().insertString(getDocument().getLength(), s, as);
    } catch (BadLocationException e) {
    }
}
 
源代码10 项目: stendhal   文件: KTextEdit.java
/**
 * Add text using a style defined for a notification type.
 *
 * @param text text contents
 * @param type type for formatting
 */
protected void insertText(final String text, final NotificationType type) {
	ChatTextSink dest = new ChatTextSink(textPane.getDocument());
	StyleSet set = new StyleSet(StyleContext.getDefaultStyleContext(), getStyle(type.getColor(), type.getStyleDescription()));
	set.setAttribute(StyleConstants.Foreground, type.getColor());

	formatter.format(text, set, dest);
}
 
源代码11 项目: MtgDesktopCompanion   文件: ScriptPanel.java
private void appendResult(String msg, Color c)
  {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
resultPane.setCharacterAttributes(aset, false);
      int len = resultPane.getDocument().getLength();
      resultPane.setCaretPosition(len);
      resultPane.replaceSelection(msg);
      resultPane.setCaretPosition(resultPane.getDocument().getLength());
  }
 
源代码12 项目: groovy   文件: SmartDocumentFilter.java
public SmartDocumentFilter(DefaultStyledDocument styledDocument) {
    this.styledDocument = styledDocument;

    this.styleContext = StyleContext.getDefaultStyleContext();
    this.defaultStyle = this.styleContext.getStyle(StyleContext.DEFAULT_STYLE);
    StyleConstants.setFontFamily(this.defaultStyle, MONOSPACED);

    initStyles();
}
 
源代码13 项目: yawl   文件: TextAreaOutputStream.java
private void append(String text, Color color) {
    StyleContext context = StyleContext.getDefaultStyleContext();
    AttributeSet attributeSet = context.addAttribute(SimpleAttributeSet.EMPTY,
            StyleConstants.Foreground, color);

    _textPane.setCaretPosition(_textPane.getDocument().getLength());
    _textPane.setCharacterAttributes(attributeSet, false);
    _textPane.setEditable(true);
    _textPane.replaceSelection(text);
    _textPane.setEditable(false);
}
 
源代码14 项目: netbeans   文件: ShowGoldenFilesPanel.java
public void setDocument(StyledDocument doc, List<HighlightImpl> golden, List<HighlightImpl> test, File goldenFile, File testFile) {
    this.golden = golden;
    this.test = test;
    this.goldenFile = goldenFile;
    this.testFile = testFile;
    List<HighlightImpl> missing = new ArrayList<HighlightImpl>();
    List<HighlightImpl> added   = new ArrayList<HighlightImpl>();
    
    Map<String, HighlightImpl> name2Golden = new HashMap<String, HighlightImpl>();
    Map<String, HighlightImpl> name2Test   = new HashMap<String, HighlightImpl>();
    
    for (HighlightImpl g : golden) {
        name2Golden.put(g.getHighlightTestData(), g);
    }
    
    for (HighlightImpl t : test) {
        name2Test.put(t.getHighlightTestData(), t);
    }
    
    Set<String> missingNames = new HashSet<String>(name2Golden.keySet());
    
    missingNames.removeAll(name2Test.keySet());
    
    for (String m : missingNames) {
        missing.add(name2Golden.get(m));
    }
    
    Set<String> addedNames = new HashSet<String>(name2Test.keySet());
    
    addedNames.removeAll(name2Golden.keySet());
    
    for (String a : addedNames) {
        added.add(name2Test.get(a));
    }
    
    List<HighlightImpl> modified = new ArrayList<HighlightImpl>();
    
    modified.addAll(missing);
    modified.addAll(added);
    
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet as = sc.getEmptySet();
    
    as = sc.addAttribute(as, StyleConstants.Foreground, Color.RED);
    as = sc.addAttribute(as, StyleConstants.Bold, Boolean.TRUE);
    
    for (HighlightImpl h : modified) {
        doc.setCharacterAttributes(h.getStart(), h.getEnd() - h.getStart(), as, false);
    }
    
    jEditorPane1.setContentType("text/html");
    jEditorPane1.setDocument(doc);
}
 
源代码15 项目: stendhal   文件: KTextEdit.java
/**
 * Initializes the basic styles.
 *
 * @param textPane
 *            the active text component
 * @param mainTextSize size of regular text
 */
protected void initStylesForTextPane(final JTextPane textPane, int mainTextSize) {
	// ****** General style definitions for the text pane ******
	Style regular = textPane.getStyle("regular");
	if (regular == null) {
		final Style def = StyleContext.getDefaultStyleContext().getStyle(
				StyleContext.DEFAULT_STYLE);
		regular = textPane.addStyle("regular", def);
		StyleConstants.setFontFamily(def, "Dialog");
	}
	StyleConstants.setFontSize(regular, mainTextSize);

	Style s = textPane.getStyle("normal");
	if (s == null) {
		s = textPane.addStyle("normal", regular);
		StyleConstants.setBold(s, true);
		StyleConstants.setForeground(s, HEADER_COLOR);
	}

	s = textPane.getStyle("bold");
	if (s == null) {
		s = textPane.addStyle("bold", regular);
		StyleConstants.setItalic(s, true);
		StyleConstants.setBold(s, true);
		StyleConstants.setForeground(s, Color.blue);
	}
	StyleConstants.setFontSize(regular, mainTextSize + 1);

	s = textPane.getStyle("header");
	if (s == null) {
		s = textPane.addStyle("header", regular);
		StyleConstants.setItalic(s, true);
		StyleConstants.setForeground(s, HEADER_COLOR);
	}
	StyleConstants.setFontSize(s, mainTextSize);

	s = textPane.getStyle("timestamp");
	if (s == null) {
		s = textPane.addStyle("timestamp", regular);
		StyleConstants.setItalic(s, true);
		StyleConstants.setForeground(s, HEADER_COLOR);
	}
	StyleConstants.setFontSize(s, mainTextSize - 1);

	//****** Styles used by the string formatter ******
	StyleSet defaultAttributes = new StyleSet(StyleContext.getDefaultStyleContext(), regular);

	StyleSet attributes = defaultAttributes.copy();
	attributes.setAttribute(StyleConstants.Italic, Boolean.TRUE);
	attributes.setAttribute(StyleConstants.Foreground, Color.blue);
	attributes.setAttribute("linkact", new LinkListener());

	formatter.addStyle('#', attributes);

	attributes = defaultAttributes.copy();
	attributes.setAttribute(StyleConstants.Underline, Boolean.TRUE);
	formatter.addStyle('§', attributes);
}
 
源代码16 项目: groovy   文件: StructuredSyntaxDocumentFilter.java
LexerNode(boolean isParent) {
    StyleContext sc = StyleContext.getDefaultStyleContext();
    defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE);
}
 
源代码17 项目: groovy   文件: GroovyFilter.java
private void init() {
    StyleContext styleContext = StyleContext.getDefaultStyleContext();
    Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);

    Style comment = styleContext.addStyle(COMMENT, defaultStyle);
    StyleConstants.setForeground(comment, COMMENT_COLOR);
    StyleConstants.setItalic(comment, true);

    Style quotes = styleContext.addStyle(QUOTES, defaultStyle);
    StyleConstants.setForeground(quotes, Color.MAGENTA.darker().darker());

    Style charQuotes = styleContext.addStyle(SINGLE_QUOTES, defaultStyle);
    StyleConstants.setForeground(charQuotes, Color.GREEN.darker().darker());

    Style slashyQuotes = styleContext.addStyle(SLASHY_QUOTES, defaultStyle);
    StyleConstants.setForeground(slashyQuotes, Color.ORANGE.darker());

    Style digit = styleContext.addStyle(DIGIT, defaultStyle);
    StyleConstants.setForeground(digit, Color.RED.darker());

    Style operation = styleContext.addStyle(OPERATION, defaultStyle);
    StyleConstants.setBold(operation, true);

    Style ident = styleContext.addStyle(IDENT, defaultStyle);

    Style reservedWords = styleContext.addStyle(RESERVED_WORD, defaultStyle);
    StyleConstants.setBold(reservedWords, true);
    StyleConstants.setForeground(reservedWords, Color.BLUE.darker().darker());

    Style leftParens = styleContext.addStyle(IDENT, defaultStyle);

    getRootNode().putStyle(SLASH_STAR_COMMENT, comment);
    getRootNode().putStyle(SLASH_SLASH_COMMENT, comment);
    getRootNode().putStyle(QUOTES, quotes);
    getRootNode().putStyle(SINGLE_QUOTES, charQuotes);
    getRootNode().putStyle(SLASHY_QUOTES, slashyQuotes);

    getRootNode().putStyle(new String[] {
        HEX_INTEGER_LITERAL,
        OCTAL_INTEGER_LITERAL,
        BINARY_INTEGER_LITERAL,
        DECIMAL_FLOATING_POINT_LITERAL,
        HEXADECIMAL_FLOATING_POINT_LITERAL,
        DECIMAL_INTEGER_LITERAL,
    }, digit);

    getRootNode().putStyle(OPERATION, operation);
    StructuredSyntaxDocumentFilter.LexerNode node = createLexerNode();
    node.putStyle(RESERVED_WORDS, reservedWords);
    node.putStyle(LEFT_PARENS, leftParens);
    getRootNode().putChild(OPERATION, node);

    getRootNode().putStyle(IDENT, ident);
    node = createLexerNode();
    node.putStyle(RESERVED_WORDS, reservedWords);
    getRootNode().putChild(IDENT, node);
}