Java Code Examples for javax.swing.text.StyleContext#getDefaultStyleContext()

The following examples show how to use javax.swing.text.StyleContext#getDefaultStyleContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OutputPanel.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
}
 
Example 2
Source File: FontUtils.java    From jadx with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: OutputPanel.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
}
 
Example 4
Source File: OutputPanel.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
}
 
Example 5
Source File: OutputPanel.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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();
}
 
Example 6
Source File: GuiUtil.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: MASConsoleColorGUI.java    From jason with GNU Lesser General Public License v3.0 5 votes vote down vote up
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) {
    }
}
 
Example 8
Source File: KTextEdit.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 9
Source File: ScriptPanel.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
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());
  }
 
Example 10
Source File: SmartDocumentFilter.java    From groovy with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 11
Source File: GuiUtil.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 12
Source File: GuiUtil.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 13
Source File: TextAreaOutputStream.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 14
Source File: ShowGoldenFilesPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 15
Source File: KTextEdit.java    From stendhal with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 16
Source File: StructuredSyntaxDocumentFilter.java    From groovy with Apache License 2.0 4 votes vote down vote up
LexerNode(boolean isParent) {
    StyleContext sc = StyleContext.getDefaultStyleContext();
    defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE);
}
 
Example 17
Source File: GroovyFilter.java    From groovy with Apache License 2.0 4 votes vote down vote up
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);
}