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


Java Font.MONOSPACED属性代码示例

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


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

示例1: generate

public static BufferedImage generate(String name, String email) throws NoSuchAlgorithmException {
	Long index = getColorIndex(email);
	String family;
	if (Holder.ALL_FONT_FAMILIES.contains(DEFAULT_FONT)) {
		family = DEFAULT_FONT;
	} else {
		family = Font.MONOSPACED;
	}

	Color background = COLORS[index.intValue()];
	Color foreground = Color.white;

	return generate(
			DEFAULT_WIDTH,
			DEFAULT_HEIGHT,
			name,
			family,
			background,
			foreground);
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:20,代码来源:AvatarGenerator.java

示例2: makeText

private static void makeText(Graphics2D graphics, ImageSize maxSize, Random rand) {
	switchColor(graphics, rand);
	
	String fontName = Font.SANS_SERIF;
	switch (rand.nextInt(4)) {
		case 0: fontName = Font.SANS_SERIF; break;
		case 1: fontName = Font.MONOSPACED; break;
		case 2: fontName = Font.SERIF; break;
		case 3: fontName = Font.DIALOG; break;
	}
	
	int fontStyle = Font.PLAIN;
	switch (rand.nextInt(3)) {
		case 0: fontStyle = Font.PLAIN; break;
		case 1: fontStyle = Font.BOLD; break;
		case 2: fontStyle = Font.ITALIC; break;
	}
	
	int fontSize = rand.nextInt(MAX_FONT_SIZE + 1);
	
	graphics.setFont(new Font(fontName, fontStyle, fontSize));
	
	int textLength = rand.nextInt(MAX_TEXT_LENGTH + 1);
	String str = Stream.generate(() -> rand.nextInt(MAX_CHAR_SIZE))
			.limit(textLength)
			.map(i -> (char)i.intValue())
			.collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString();
	
	graphics.drawString(str, rand.nextInt(maxSize.getWidth()), rand.nextInt(maxSize.getHeight()));
}
 
开发者ID:DescartesResearch,项目名称:Pet-Supply-Store,代码行数:30,代码来源:ImageCreator.java

示例3: main

public static void main(String[] args) {
    Font font = new Font(Font.MONOSPACED, Font.PLAIN, 12);
    FontRenderContext frc = new FontRenderContext(null, false, false);
    GlyphVector gv = font.layoutGlyphVector(frc, "abc".toCharArray(), 1, 3,
                                            Font.LAYOUT_LEFT_TO_RIGHT);
    int idx0 = gv.getGlyphCharIndex(0);
    if (idx0 != 0) {
       throw new RuntimeException("Expected 0, got " + idx0);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:GetGlyphCharIndexTest.java

示例4: getInstalledFontFamilyNames

/**
 * Get a list of installed fonts in the requested {@link Locale}.
 * The list contains the fonts Family Names.
 * If Locale is null, the default locale is used.
 *
 * @param requestedLocale, if null the default locale is used.
 * @return list of installed fonts in the system.
 */
public String[] getInstalledFontFamilyNames(Locale requestedLocale) {
    if (requestedLocale == null) {
        requestedLocale = Locale.getDefault();
    }
    if (allFamilies != null && lastDefaultLocale != null &&
        requestedLocale.equals(lastDefaultLocale)) {
            String[] copyFamilies = new String[allFamilies.length];
            System.arraycopy(allFamilies, 0, copyFamilies,
                             0, allFamilies.length);
            return copyFamilies;
    }

    TreeMap<String,String> familyNames = new TreeMap<String,String>();
    //  these names are always there and aren't localised
    String str;
    str = Font.SERIF;         familyNames.put(str.toLowerCase(), str);
    str = Font.SANS_SERIF;    familyNames.put(str.toLowerCase(), str);
    str = Font.MONOSPACED;    familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG;        familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG_INPUT;  familyNames.put(str.toLowerCase(), str);

    /* Platform APIs may be used to get the set of available family
     * names for the current default locale so long as it is the same
     * as the start-up system locale, rather than loading all fonts.
     */
    if (requestedLocale.equals(getSystemStartupLocale()) &&
        getFamilyNamesFromPlatform(familyNames, requestedLocale)) {
        /* Augment platform names with JRE font family names */
        getJREFontFamilyNames(familyNames, requestedLocale);
    } else {
        loadFontFiles();
        Font2D[] physicalfonts = getPhysicalFonts();
        for (int i=0; i < physicalfonts.length; i++) {
            if (!(physicalfonts[i] instanceof NativeFont)) {
                String name =
                    physicalfonts[i].getFamilyName(requestedLocale);
                familyNames.put(name.toLowerCase(requestedLocale), name);
            }
        }
    }

    // Add any native font family names here
    addNativeFontFamilyNames(familyNames, requestedLocale);

    String[] retval =  new String[familyNames.size()];
    Object [] keyNames = familyNames.keySet().toArray();
    for (int i=0; i < keyNames.length; i++) {
        retval[i] = (String)familyNames.get(keyNames[i]);
    }
    if (requestedLocale.equals(Locale.getDefault())) {
        lastDefaultLocale = requestedLocale;
        allFamilies = new String[retval.length];
        System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length);
    }
    return retval;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:64,代码来源:SunFontManager.java

示例5: getFont

/**
 * Returns the font for the values in the passed in AttributeSet.
 * It is assumed the keys will be CSS.Attribute keys.
 * <code>sc</code> is the StyleContext that will be messaged to get
 * the font once the size, name and style have been determined.
 */
Font getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss) {
    ss = getStyleSheet(ss);
    int size = getFontSize(a, defaultSize, ss);

    /*
     * If the vertical alignment is set to either superscirpt or
     * subscript we reduce the font size by 2 points.
     */
    StringValue vAlignV = (StringValue)a.getAttribute
                          (CSS.Attribute.VERTICAL_ALIGN);
    if ((vAlignV != null)) {
        String vAlign = vAlignV.toString();
        if ((vAlign.indexOf("sup") >= 0) ||
            (vAlign.indexOf("sub") >= 0)) {
            size -= 2;
        }
    }

    FontFamily familyValue = (FontFamily)a.getAttribute
                                        (CSS.Attribute.FONT_FAMILY);
    String family = (familyValue != null) ? familyValue.getValue() :
                              Font.SANS_SERIF;
    int style = Font.PLAIN;
    FontWeight weightValue = (FontWeight) a.getAttribute
                              (CSS.Attribute.FONT_WEIGHT);
    if ((weightValue != null) && (weightValue.getValue() > 400)) {
        style |= Font.BOLD;
    }
    Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE);
    if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) {
        style |= Font.ITALIC;
    }
    if (family.equalsIgnoreCase("monospace")) {
        family = Font.MONOSPACED;
    }
    Font f = sc.getFont(family, style, size);
    if (f == null
        || (f.getFamily().equals(Font.DIALOG)
            && ! family.equalsIgnoreCase(Font.DIALOG))) {
        family = Font.SANS_SERIF;
        f = sc.getFont(family, style, size);
    }
    return f;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:50,代码来源:CSS.java

示例6: getInstalledFontFamilyNames

/**
 * Get a list of installed fonts in the requested {@link Locale}.
 * The list contains the fonts Family Names.
 * If Locale is null, the default locale is used.
 *
 * @param requestedLocale, if null the default locale is used.
 * @return list of installed fonts in the system.
 */
public String[] getInstalledFontFamilyNames(Locale requestedLocale) {
    if (requestedLocale == null) {
        requestedLocale = Locale.getDefault();
    }
    if (allFamilies != null && lastDefaultLocale != null &&
        requestedLocale.equals(lastDefaultLocale)) {
            String[] copyFamilies = new String[allFamilies.length];
            System.arraycopy(allFamilies, 0, copyFamilies,
                             0, allFamilies.length);
            return copyFamilies;
    }

    TreeMap<String,String> familyNames = new TreeMap<String,String>();
    //  these names are always there and aren't localised
    String str;
    str = Font.SERIF;         familyNames.put(str.toLowerCase(), str);
    str = Font.SANS_SERIF;    familyNames.put(str.toLowerCase(), str);
    str = Font.MONOSPACED;    familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG;        familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG_INPUT;  familyNames.put(str.toLowerCase(), str);

    /* Platform APIs may be used to get the set of available family
     * names for the current default locale so long as it is the same
     * as the start-up system locale, rather than loading all fonts.
     */
    if (requestedLocale.equals(getSystemStartupLocale()) &&
        getFamilyNamesFromPlatform(familyNames, requestedLocale)) {
        /* Augment platform names with JRE font family names */
        getJREFontFamilyNames(familyNames, requestedLocale);
    } else {
        loadFontFiles();
        Font2D[] physicalfonts = getPhysicalFonts();
        for (int i=0; i < physicalfonts.length; i++) {
            if (!(physicalfonts[i] instanceof NativeFont)) {
                String name =
                    physicalfonts[i].getFamilyName(requestedLocale);
                familyNames.put(name.toLowerCase(requestedLocale), name);
            }
        }
    }

    // Add any native font family names here
    addNativeFontFamilyNames(familyNames, requestedLocale);

    String[] retval =  new String[familyNames.size()];
    Object [] keyNames = familyNames.keySet().toArray();
    for (int i=0; i < keyNames.length; i++) {
        retval[i] = familyNames.get(keyNames[i]);
    }
    if (requestedLocale.equals(Locale.getDefault())) {
        lastDefaultLocale = requestedLocale;
        allFamilies = new String[retval.length];
        System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length);
    }
    return retval;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:64,代码来源:SunFontManager.java

示例7: getFont

/**
 * Returns the font for the values in the passed in AttributeSet.
 * It is assumed the keys will be CSS.Attribute keys.
 * <code>sc</code> is the StyleContext that will be messaged to get
 * the font once the size, name and style have been determined.
 */
Font getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss) {
    ss = getStyleSheet(ss);
    int size = getFontSize(a, defaultSize, ss);

    /*
     * If the vertical alignment is set to either superscript or
     * subscript we reduce the font size by 2 points.
     */
    StringValue vAlignV = (StringValue)a.getAttribute
                          (CSS.Attribute.VERTICAL_ALIGN);
    if ((vAlignV != null)) {
        String vAlign = vAlignV.toString();
        if ((vAlign.indexOf("sup") >= 0) ||
            (vAlign.indexOf("sub") >= 0)) {
            size -= 2;
        }
    }

    FontFamily familyValue = (FontFamily)a.getAttribute
                                        (CSS.Attribute.FONT_FAMILY);
    String family = (familyValue != null) ? familyValue.getValue() :
                              Font.SANS_SERIF;
    int style = Font.PLAIN;
    FontWeight weightValue = (FontWeight) a.getAttribute
                              (CSS.Attribute.FONT_WEIGHT);
    if ((weightValue != null) && (weightValue.getValue() > 400)) {
        style |= Font.BOLD;
    }
    Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE);
    if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) {
        style |= Font.ITALIC;
    }
    if (family.equalsIgnoreCase("monospace")) {
        family = Font.MONOSPACED;
    }
    Font f = sc.getFont(family, style, size);
    if (f == null
        || (f.getFamily().equals(Font.DIALOG)
            && ! family.equalsIgnoreCase(Font.DIALOG))) {
        family = Font.SANS_SERIF;
        f = sc.getFont(family, style, size);
    }
    return f;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:50,代码来源:CSS.java

示例8: setUpGrid

public static void setUpGrid() {

        plotFont = new Font(Font.MONOSPACED, Font.PLAIN, 12);
        plot = new Plot2DPanel();

    }
 
开发者ID:Cvarier,项目名称:2D-Elliptic-Mesh-Generator,代码行数:6,代码来源:EllipticMeshGenerator2D.java


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