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


Java StyleContext.getFont方法代码示例

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


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

示例1: extractFont

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

示例2: 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

示例3: 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

示例4: extractFontFromDefaultStyledDocument

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private Font extractFontFromDefaultStyledDocument(final DefaultStyledDocument styledDocument,
        final StyleContext style, final int pos, final Element rootElement) {
    Font font = style.getFont(styledDocument.getCharacterElement(pos).getAttributes());
    if (font == null) {
        font = style.getFont(styledDocument.getParagraphElement(pos).getAttributes());
        if (font == null) {
            font = style.getFont(rootElement.getAttributes());
        }
    }
    return font;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:12,代码来源:PStyledText.java

示例5: 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

示例6: 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:intuit,项目名称:Tank,代码行数:26,代码来源:SyntaxScheme.java

示例7: getFont

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
private static Font getFont(String family, int style, int size) {
	// Use StyleContext to get a composite font for Asian glyphs.
	StyleContext sc = StyleContext.getDefaultStyleContext();
	return sc.getFont(family, style, size);
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:6,代码来源:Theme.java

示例8: restoreDefaults

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
 * Restores all colors and fonts to their default values.
 * 
 * @param baseFont
 *            The base font to use when creating this scheme. If this is <code>null</code>, then a default
 *            monospaced font is used.
 */
public void restoreDefaults(Font baseFont) {

    // Colors used by tokens.
    Color comment = new Color(0, 128, 0);
    Color docComment = new Color(164, 0, 0);
    Color keyword = Color.BLUE;
    Color function = new Color(173, 128, 0);
    Color literalNumber = new Color(100, 0, 200);
    Color literalString = new Color(220, 0, 156);
    Color error = new Color(148, 148, 0);

    // Special fonts.
    if (baseFont == null) {
        baseFont = RSyntaxTextArea.getDefaultFont();
    }
    // WORKAROUND for Sun JRE bug 6282887 (Asian font bug in 1.4/1.5)
    StyleContext sc = StyleContext.getDefaultStyleContext();
    Font boldFont = sc.getFont(baseFont.getFamily(), Font.BOLD,
            baseFont.getSize());
    Font italicFont = sc.getFont(baseFont.getFamily(), Font.ITALIC,
            baseFont.getSize());
    Font commentFont = italicFont;// baseFont.deriveFont(Font.ITALIC);
    Font keywordFont = boldFont;// baseFont.deriveFont(Font.BOLD);

    styles[Token.COMMENT_EOL] = new Style(comment, null, commentFont);
    styles[Token.COMMENT_MULTILINE] = new Style(comment, null, commentFont);
    styles[Token.COMMENT_DOCUMENTATION] = new Style(docComment, null, commentFont);
    styles[Token.RESERVED_WORD] = new Style(keyword, null, keywordFont);
    styles[Token.FUNCTION] = new Style(function, null);
    styles[Token.LITERAL_BOOLEAN] = new Style(literalNumber, null);
    styles[Token.LITERAL_NUMBER_DECIMAL_INT] = new Style(literalNumber, null);
    styles[Token.LITERAL_NUMBER_FLOAT] = new Style(literalNumber, null);
    styles[Token.LITERAL_NUMBER_HEXADECIMAL] = new Style(literalNumber, null);
    styles[Token.LITERAL_STRING_DOUBLE_QUOTE] = new Style(literalString, null);
    styles[Token.LITERAL_CHAR] = new Style(literalString, null);
    styles[Token.LITERAL_BACKQUOTE] = new Style(literalString, null);
    styles[Token.DATA_TYPE] = new Style(new Color(0, 128, 128), null);
    styles[Token.VARIABLE] = new Style(new Color(255, 153, 0), null);
    styles[Token.IDENTIFIER] = new Style(null, null);
    styles[Token.WHITESPACE] = new Style(Color.gray, null);
    styles[Token.SEPARATOR] = new Style(Color.RED, null);
    styles[Token.OPERATOR] = new Style(new Color(128, 64, 64), null);
    styles[Token.PREPROCESSOR] = new Style(new Color(128, 128, 128), null);
    styles[Token.MARKUP_TAG_DELIMITER] = new Style(Color.RED, null);
    styles[Token.MARKUP_TAG_NAME] = new Style(Color.BLUE, null);
    styles[Token.MARKUP_TAG_ATTRIBUTE] = new Style(new Color(63, 127, 127), null);
    // styles[Token.ERROR] = null;
    styles[Token.ERROR_IDENTIFIER] = new Style(error, null);
    styles[Token.ERROR_NUMBER_FORMAT] = new Style(error, null);
    styles[Token.ERROR_STRING_DOUBLE] = new Style(error, null);
    styles[Token.ERROR_CHAR] = new Style(error, null);

}
 
开发者ID:intuit,项目名称:Tank,代码行数:61,代码来源:SyntaxScheme.java

示例9: Node

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
public Node(String label, SnapshotPositionRegion sourceSpan, int labelPaddingX, int labelPaddingY, int arcSize, AttributeSet attributes) {
    Parameters.notNull("label", label);
    this.label = label;
    this.sourceSpan = sourceSpan;
    this.labelPaddingX = labelPaddingX;
    this.labelPaddingY = labelPaddingY;
    this.arcSize = arcSize;

    AttributeSet defaultAttributes = Diagram.lookupAttributes(FontColorNames.DEFAULT_COLORING);

    Color foreground = (Color)attributes.getAttribute(StyleConstants.Foreground);
    if (foreground == null) {
        foreground = (Color)defaultAttributes.getAttribute(StyleConstants.Foreground);
    }

    if (foreground != null) {
        this.setForeground(foreground);
    }

    StyleContext context = new StyleContext();
    Font font = context.getFont(attributes);
    if (font == null) {
        font = context.getFont(defaultAttributes);
    }

    if (font != null) {
        this.setFont(font);
    }

    Color background = (Color)attributes.getAttribute(StyleConstants.Background);
    if (background == null) {
        background = (Color)defaultAttributes.getAttribute(StyleConstants.Background);
    }

    if (background != null) {
        this.setBackground(background);
    }

    Dimension size = getLabelSize();
    setPreferredSize(size);
    enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:43,代码来源:Node.java

示例10: getFont

import javax.swing.text.StyleContext; //导入方法依赖的package包/类
/**
 * Returns the specified font.
 *
 * @param family The font family.
 * @param style The style of font.
 * @param size The size of the font.
 * @return The font.
 */
private static Font getFont(String family, int style, int size) {
	// Use StyleContext to get a composite font for Asian glyphs.
	StyleContext sc = StyleContext.getDefaultStyleContext();
	return sc.getFont(family, style, size);
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:14,代码来源:ThemeNULL.java


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