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


Java StyleContext.getDefaultStyleContext方法代码示例

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


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

示例1: createSearchPanel

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
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();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:18,代码来源:OutputPanel.java

示例2: appendToPane

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private void appendToPane(JTextPane tp, String msg, MessageType t)
{
    boolean scrollToBottom = scrollPane.getVerticalScrollBar().getValue() == scrollPane.getVerticalScrollBar().getMaximum();
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = SimpleAttributeSet.EMPTY;

    MessageStyle ms = theme.getStyle(t);

    aset = sc.addAttribute(aset, StyleConstants.Foreground, ms.getForeground() == null ? tp.getForeground() : ms.getForeground());
    aset = sc.addAttribute(aset, StyleConstants.Background, ms.getBackground() == null ? tp.getBackground() : ms.getBackground());
    aset = sc.addAttribute(aset, StyleConstants.Bold, ms.isBold());
    aset = sc.addAttribute(aset, StyleConstants.Italic, ms.isItalic());
    aset = sc.addAttribute(aset, StyleConstants.Underline, ms.isUnderlined());

    StyledDocument sd = tp.getStyledDocument();
    try
    {
        sd.insertString(sd.getLength(), msg, aset);
    }
    catch(BadLocationException e)
    {
        e.printStackTrace();
    }

    if(scrollToBottom)
    {
        scrollPane.getVerticalScrollBar().setValue(scrollPane.getVerticalScrollBar().getMaximum());
    }
}
 
开发者ID:utybo,项目名称:NetClean,代码行数:30,代码来源:ClientGUI.java

示例3: appendToPane

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
 * 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();
	}
}
 
开发者ID:Mgamerz,项目名称:me3modmanager,代码行数:26,代码来源:ResourceUtils.java

示例4: print

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
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);
    }

}
 
开发者ID:automenta,项目名称:opennars,代码行数:21,代码来源:OutputLogPanel.java

示例5: print

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
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(NARWindow.class.getName()).log(Level.SEVERE, null, ex);
    }

}
 
开发者ID:opennars,项目名称:pei,代码行数:21,代码来源:NARWindow.java

示例6: append

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
@Override
public void append(String str, Color c) {

	StyleContext sc = StyleContext.getDefaultStyleContext();
	AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

	aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Sans");
	aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);

	/*
	 * int len = area.getDocument().getLength(); area.setCaretPosition(len);
	 * area.setCharacterAttributes(aset, false); area.replaceSelection(str);
	 */

	DefaultStyledDocument document = (DefaultStyledDocument) area.getDocument();
	try {
		if (area.getText().length() < 3)
			area.setText("");
		// document.insertString(0, str, aset);
		// else
		document.insertString(document.getEndPosition().getOffset() - 1, str, aset);
	} catch (BadLocationException e) {}

}
 
开发者ID:tobiasschulz,项目名称:voipcall,代码行数:25,代码来源:JTextPaneMessageOutput.java

示例7: setupTabStops

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private void setupTabStops() {
	// Ugly piece of code; needed because default tab indentation is too
	// big.
	StyleContext sc = StyleContext.getDefaultStyleContext();

	Toolkit t = Toolkit.getDefaultToolkit();
	FontMetrics fm = t.getFontMetrics(new Font("Courier", Font.PLAIN, 14));
	int cw = fm.stringWidth("    ");

	final TabStop[] tabStops = new TabStop[60];
	for (int i = 0; i < tabStops.length; i++)
		tabStops[i] = new TabStop((i + 1) * cw);

	TabSet tabs = new TabSet(tabStops);
	AttributeSet paraSet = sc.addAttribute(SimpleAttributeSet.EMPTY,
			StyleConstants.TabSet, tabs);

	pane.setParagraphAttributes(paraSet, false);
}
 
开发者ID:goblindegook,项目名称:Koopa,代码行数:20,代码来源:GrammarView.java

示例8: appendToLog

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
 * Appends a message to the logging area.
 * 
 * @param message
 *            Message to add
 * @param color
 *            Color of the message
 */
private void appendToLog(final String message, final Color color) {
	final StyleContext sc = StyleContext.getDefaultStyleContext();
	AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);

	aset = sc.addAttribute(aset, StyleConstants.FontFamily, DEFAULT_FONT);
	aset = sc.addAttribute(aset, StyleConstants.Alignment, Integer.valueOf(StyleConstants.ALIGN_JUSTIFIED));

	final int len = this.mLogArea.getDocument().getLength();
	this.mLogArea.setCaretPosition(len);
	this.mLogArea.setCharacterAttributes(aset, false);
	this.mLogArea.setEditable(true);
	this.mLogArea.replaceSelection(message);
	this.mLogArea.setEditable(false);
}
 
开发者ID:ZabuzaW,项目名称:KivaBot,代码行数:23,代码来源:MainFrameView.java

示例9: getDefaultFont

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
 * Returns the default font for text areas.
 *
 * @return The default font.
 */
public static final Font getDefaultFont() {

	// Use StyleContext to get a composite font for better Asian language
	// support; see Sun bug S282887.
	StyleContext sc = StyleContext.getDefaultStyleContext();
	Font font = null;

	if (isOSX()) {
		// Snow Leopard (1.6) uses Menlo as default monospaced font,
		// pre-Snow Leopard used Monaco.
		font = sc.getFont("Menlo", Font.PLAIN, 12);
		if (!"Menlo".equals(font.getFamily())) {
			font = sc.getFont("Monaco", Font.PLAIN, 12);
			if (!"Monaco".equals(font.getFamily())) { // Shouldn't happen
				font = sc.getFont("Monospaced", Font.PLAIN, 13);
			}
		}
	}
	else {
		// Consolas added in Vista, used by VS2010+.
		font = sc.getFont("Consolas", Font.PLAIN, 13);
		if (!"Consolas".equals(font.getFamily())) {
			font = sc.getFont("Monospaced", Font.PLAIN, 13);
		}
	}

	//System.out.println(font.getFamily() + ", " + font.getName());
	return font;

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:36,代码来源:RTextAreaBase.java

示例10: changeBaseFont

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
 * Changes the "base font" for this syntax scheme.  This is called by
 * <code>RSyntaxTextArea</code> when its font changes via
 * <code>setFont()</code>.  This looks for tokens that use a derivative of
 * the text area's old font (but bolded and/or italicized) and make them
 * use the new font with those stylings instead.  This is desirable because
 * most programmers prefer a single font to be used in their text editor,
 * but might want bold (say for keywords) or italics.
 *
 * @param old The old font of the text area.
 * @param font The new font of the text area.
 */
void changeBaseFont(Font old, Font font) {
	for (int i=0; i<styles.length; i++) {
		Style style = styles[i];
		if (style!=null && style.font!=null) {
			if (style.font.getFamily().equals(old.getFamily()) &&
					style.font.getSize()==old.getSize()) {
				int s = style.font.getStyle(); // Keep bold or italic
				StyleContext sc = StyleContext.getDefaultStyleContext();
				style.font= sc.getFont(font.getFamily(), s, font.getSize());
			}
		}
	}
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:26,代码来源:SyntaxScheme.java

示例11: append

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
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) {            
    }
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:11,代码来源:MASConsoleColorGUI.java

示例12: addStyle

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
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);
}
 
开发者ID:havkarl,项目名称:gogui2,代码行数:11,代码来源:GuiUtil.java

示例13: setStyle

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
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);
}
 
开发者ID:havkarl,项目名称:gogui2,代码行数:15,代码来源:GuiUtil.java

示例14: append

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public void append(Color c, String s) {
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

    int len = getDocument().getLength();
    setCaretPosition(len);
    setCharacterAttributes(aset, false);
    replaceSelection(s);
}
 
开发者ID:fcpauldiaz,项目名称:Compilador,代码行数:10,代码来源:ColorPane.java

示例15: getInitialFontHeight

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
 * Get the height of the font at the beginning of the document.
 * 
 * @return height of font at the start of the document.
 */
public double getInitialFontHeight() {

    // Small assumption here that there is one root element - can fix
    // for more general support later
    final Element rootElement = document.getDefaultRootElement();
    final Element curElement = drillDownFromRoot(0, rootElement);
    final StyleContext context = StyleContext.getDefaultStyleContext();
    final Font font = context.getFont(curElement.getAttributes());

    final FontMetrics curFM = context.getFontMetrics(font);

    return curFM.getMaxAscent() + curFM.getMaxDescent() + curFM.getLeading();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:PStyledText.java


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