javax.swing.plaf.FontUIResource源码实例Demo

类javax.swing.plaf.FontUIResource源码实例Demo

下面列出了javax.swing.plaf.FontUIResource 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FlatLaf   文件: FlatLaf.java
@Override
public Object createValue( UIDefaults table ) {
	Font defaultFont = UIManager.getFont( "defaultFont" );

	if( lastDefaultFont != defaultFont ) {
		lastDefaultFont = defaultFont;

		if( scaleFactor != 1 ) {
			// scale font
			int newFontSize = Math.round( defaultFont.getSize() * scaleFactor );
			font = new FontUIResource( defaultFont.deriveFont( (float) newFontSize ) );
		} else {
			// make sure that font is a UIResource for LaF switching
			font = (defaultFont instanceof UIResource)
				? defaultFont
				: new FontUIResource( defaultFont );
		}
	}

	return font;
}
 
源代码2 项目: jdk8u-jdk   文件: X11FontManager.java
@Override
protected FontUIResource getFontConfigFUIR(String family, int style, int size) {

    CompositeFont font2D = getFontConfigManager().getFontConfigFont(family, style);

    if (font2D == null) { // Not expected, just a precaution.
       return new FontUIResource(family, style, size);
    }

    /* The name of the font will be that of the physical font in slot,
     * but by setting the handle to that of the CompositeFont it
     * renders as that CompositeFont.
     * It also needs to be marked as a created font which is the
     * current mechanism to signal that deriveFont etc must copy
     * the handle from the original font.
     */
    FontUIResource fuir =
        new FontUIResource(font2D.getFamilyName(null), style, size);
    FontAccess.getFontAccess().setFont2D(fuir, font2D.handle);
    FontAccess.getFontAccess().setCreatedFont(fuir);
    return fuir;
}
 
源代码3 项目: radiance   文件: NeonFontSet.java
/**
 * Returns Neon-specific font resource.
 *
 * @param systemFont    The default system font.
 * @param toBoldify     If <code>true</code>, the original font (the first parameter) is
 *                      boldified.
 * @param extraFontSize Extra font size in pixels.
 * @return Neon-specific font resource.
 */
private FontUIResource getNeonFont(FontUIResource systemFont, boolean toBoldify,
        int extraFontSize) {
    boolean isOrigItalic = systemFont.isItalic();
    int newStyle = systemFont.getStyle();
    if (toBoldify) {
        if (isOrigItalic) {
            newStyle = Font.ITALIC + Font.BOLD;
        } else {
            newStyle = Font.BOLD;
        }
    }
    Font derived = systemFont.deriveFont((float) (systemFont.getSize() + extraFontSize))
            .deriveFont(newStyle);
    if (derived instanceof FontUIResource) {
        return (FontUIResource) derived;
    }
    return new FontUIResource(derived);
}
 
源代码4 项目: jdk8u-dev-jdk   文件: X11FontManager.java
@Override
protected FontUIResource getFontConfigFUIR(String family, int style, int size) {

    CompositeFont font2D = getFontConfigManager().getFontConfigFont(family, style);

    if (font2D == null) { // Not expected, just a precaution.
       return new FontUIResource(family, style, size);
    }

    /* The name of the font will be that of the physical font in slot,
     * but by setting the handle to that of the CompositeFont it
     * renders as that CompositeFont.
     * It also needs to be marked as a created font which is the
     * current mechanism to signal that deriveFont etc must copy
     * the handle from the original font.
     */
    FontUIResource fuir =
        new FontUIResource(font2D.getFamilyName(null), style, size);
    FontAccess.getFontAccess().setFont2D(fuir, font2D.handle);
    FontAccess.getFontAccess().setCreatedFont(fuir);
    return fuir;
}
 
源代码5 项目: openjdk-8   文件: X11FontManager.java
@Override
protected FontUIResource getFontConfigFUIR(String family, int style, int size) {

    CompositeFont font2D = getFontConfigManager().getFontConfigFont(family, style);

    if (font2D == null) { // Not expected, just a precaution.
       return new FontUIResource(family, style, size);
    }

    /* The name of the font will be that of the physical font in slot,
     * but by setting the handle to that of the CompositeFont it
     * renders as that CompositeFont.
     * It also needs to be marked as a created font which is the
     * current mechanism to signal that deriveFont etc must copy
     * the handle from the original font.
     */
    FontUIResource fuir =
        new FontUIResource(font2D.getFamilyName(null), style, size);
    FontAccess.getFontAccess().setFont2D(fuir, font2D.handle);
    FontAccess.getFontAccess().setCreatedFont(fuir);
    return fuir;
}
 
源代码6 项目: openstego   文件: OpenStegoFrame.java
/**
 * This method initializes the UI resources like fonts, size, etc.
 */
private void setupUI() {
    // Special handling to ensure that Japanese fonts are readable
    if (Locale.getDefault().getLanguage().equals(Locale.JAPANESE.getLanguage())) {
        Object key = null;
        Object value = null;
        Enumeration<?> keys = UIManager.getDefaults().keys();
        while (keys.hasMoreElements()) {
            key = keys.nextElement();
            value = UIManager.get(key);
            if (value instanceof FontUIResource) {
                UIManager.put(key, ((FontUIResource) value).deriveFont(12.0f));
            }
        }
        getMainContentPane().setFont(new Font("Japanese", Font.PLAIN, 12));
    }
}
 
源代码7 项目: openjdk-jdk9   文件: X11FontManager.java
@Override
protected FontUIResource getFontConfigFUIR(String family, int style, int size) {

    CompositeFont font2D = getFontConfigManager().getFontConfigFont(family, style);

    if (font2D == null) { // Not expected, just a precaution.
       return new FontUIResource(family, style, size);
    }

    /* The name of the font will be that of the physical font in slot,
     * but by setting the handle to that of the CompositeFont it
     * renders as that CompositeFont.
     * It also needs to be marked as a created font which is the
     * current mechanism to signal that deriveFont etc must copy
     * the handle from the original font.
     */
    FontUIResource fuir =
        new FontUIResource(font2D.getFamilyName(null), style, size);
    FontAccess.getFontAccess().setFont2D(fuir, font2D.handle);
    FontAccess.getFontAccess().setCreatedFont(fuir);
    return fuir;
}
 
源代码8 项目: runelite   文件: SwingUtil.java
/**
 * Sets default Swing font.
 * IMPORTANT! Needs to be called before main frame creation
 *
 * @param font the new font to use
 */
public static void setFont(@Nonnull final Font font)
{
	final FontUIResource f = new FontUIResource(font);
	final Enumeration keys = UIManager.getDefaults().keys();

	while (keys.hasMoreElements())
	{
		final Object key = keys.nextElement();
		final Object value = UIManager.get(key);

		if (value instanceof FontUIResource)
		{
			UIManager.put(key, f);
		}
	}
}
 
源代码9 项目: jdk8u-dev-jdk   文件: DefaultSynthStyleFactory.java
/**
 * Returns the style to use if there are no matching styles.
 */
private SynthStyle getDefaultStyle() {
    if (_defaultStyle == null) {
        _defaultStyle = new DefaultSynthStyle();
        ((DefaultSynthStyle)_defaultStyle).setFont(
            new FontUIResource(Font.DIALOG, Font.PLAIN,12));
    }
    return _defaultStyle;
}
 
源代码10 项目: openjdk-jdk9   文件: DefaultTreeCellEditor.java
public Font getFont() {
    Font     font = super.getFont();

    // Prefer the parent containers font if our font is a
    // FontUIResource
    if(font instanceof FontUIResource) {
        Container     parent = getParent();

        if(parent != null && parent.getFont() != null)
            font = parent.getFont();
    }
    return font;
}
 
源代码11 项目: jdk8u-jdk   文件: CFontManager.java
@Override
protected FontUIResource getFontConfigFUIR(
        String family, int style, int size)
{
    String mappedName = FontUtilities.mapFcName(family);
    if (mappedName == null) {
        mappedName = "sansserif";
    }
    return new FontUIResource(mappedName, style, size);
}
 
protected FontUIResource getObject() {
    return new FontUIResource(
            new Font(
                    Collections.singletonMap(
                            TextAttribute.STRIKETHROUGH,
                            TextAttribute.STRIKETHROUGH_ON)));
}
 
源代码13 项目: mybatis-generator-gui   文件: GUIUtil.java
public static void setFont(Font font) {
    FontUIResource fontRes = new FontUIResource(font);
    for (Enumeration<Object> keys = UIManager.getDefaults().keys();
         keys.hasMoreElements(); ) {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);
        if (value instanceof FontUIResource) {
            UIManager.put(key, fontRes);
        }
    }
}
 
源代码14 项目: hottub   文件: DefaultTreeCellEditor.java
public Font getFont() {
    Font     font = super.getFont();

    // Prefer the parent containers font if our font is a
    // FontUIResource
    if(font instanceof FontUIResource) {
        Container     parent = getParent();

        if(parent != null && parent.getFont() != null)
            font = parent.getFont();
    }
    return font;
}
 
源代码15 项目: dragonwell8_jdk   文件: DefaultSynthStyleFactory.java
/**
 * Returns the style to use if there are no matching styles.
 */
private SynthStyle getDefaultStyle() {
    if (_defaultStyle == null) {
        _defaultStyle = new DefaultSynthStyle();
        ((DefaultSynthStyle)_defaultStyle).setFont(
            new FontUIResource(Font.DIALOG, Font.PLAIN,12));
    }
    return _defaultStyle;
}
 
protected FontUIResource getObject() {
    return new FontUIResource(
            new Font(
                    Collections.singletonMap(
                            TextAttribute.STRIKETHROUGH,
                            TextAttribute.STRIKETHROUGH_ON)));
}
 
/**
 * Returns the style to use if there are no matching styles.
 */
private SynthStyle getDefaultStyle() {
    if (_defaultStyle == null) {
        _defaultStyle = new DefaultSynthStyle();
        ((DefaultSynthStyle)_defaultStyle).setFont(
            new FontUIResource(Font.DIALOG, Font.PLAIN,12));
    }
    return _defaultStyle;
}
 
源代码18 项目: consulo   文件: LafManagerImpl.java
public static void installMacOSXFonts(UIDefaults defaults) {
  final String face = "Helvetica Neue";
  final FontUIResource uiFont = getFont(face, 13, Font.PLAIN);
  initFontDefaults(defaults, uiFont);
  for (Object key : new HashSet<>(defaults.keySet())) {
    if (!(key instanceof String)) continue;
    if (!StringUtil.endsWithIgnoreCase(((String)key), "font")) continue;
    Object value = defaults.get(key);
    if (value instanceof FontUIResource) {
      FontUIResource font = (FontUIResource)value;
      if (font.getFamily().equals("Lucida Grande") || font.getFamily().equals("Serif")) {
        if (!key.toString().contains("Menu")) {
          defaults.put(key, getFont(face, font.getSize(), font.getStyle()));
        }
      }
    }
  }

  FontUIResource uiFont11 = getFont(face, 11, Font.PLAIN);
  defaults.put("TableHeader.font", uiFont11);

  FontUIResource buttonFont = getFont("Helvetica Neue", 13, Font.PLAIN);
  defaults.put("Button.font", buttonFont);
  Font menuFont = getFont("Lucida Grande", 14, Font.PLAIN);
  defaults.put("Menu.font", menuFont);
  defaults.put("MenuItem.font", menuFont);
  defaults.put("MenuItem.acceleratorFont", menuFont);
  defaults.put("PasswordField.font", defaults.getFont("TextField.font"));
}
 
源代码19 项目: TencentKona-8   文件: DefaultTreeCellEditor.java
public Font getFont() {
    Font     font = super.getFont();

    // Prefer the parent containers font if our font is a
    // FontUIResource
    if(font instanceof FontUIResource) {
        Container     parent = getParent();

        if(parent != null && parent.getFont() != null)
            font = parent.getFont();
    }
    return font;
}
 
源代码20 项目: openjdk-jdk9   文件: CFontManager.java
@Override
protected FontUIResource getFontConfigFUIR(
        String family, int style, int size)
{
    String mappedName = FontUtilities.mapFcName(family);
    if (mappedName == null) {
        mappedName = "sansserif";
    }
    return new FontUIResource(mappedName, style, size);
}
 
源代码21 项目: FCMFrame   文件: Main.java
public static void initGlobalFontSetting(Font fnt) {
    FontUIResource fontRes = new FontUIResource(fnt);
    for (Enumeration<?> keys = UIManager.getDefaults().keys(); keys.hasMoreElements(); ) {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);
        if (value instanceof FontUIResource) {
        	UIManager.put(key, fontRes);
        }
    }
}
 
源代码22 项目: consulo   文件: DarculaLaf.java
@Nonnull
@Override
public UIDefaults getDefaultsImpl(UIDefaults superDefaults) {
  try {
    final UIDefaults metalDefaults = new MetalLookAndFeel().getDefaults();
    final UIDefaults defaults = base.getDefaults();
    if (SystemInfo.isLinux && !Registry.is("darcula.use.native.fonts.on.linux")) {
      Font font = findFont("DejaVu Sans");
      if (font != null) {
        for (Object key : defaults.keySet()) {
          if (key instanceof String && ((String)key).endsWith(".font")) {
            defaults.put(key, new FontUIResource(font.deriveFont(13f)));
          }
        }
      }
    }

    LafManagerImplUtil.initInputMapDefaults(defaults);
    defaults.put(SupportTextBoxWithExpandActionExtender.class, SupportTextBoxWithExpandActionExtender.INSTANCE);
    defaults.put(SupportTextBoxWithExtensionsExtender.class, SupportTextBoxWithExtensionsExtender.INSTANCE);

    initIdeaDefaults(defaults);
    patchStyledEditorKit(defaults);
    patchComboBox(metalDefaults, defaults);
    defaults.remove("Spinner.arrowButtonBorder");
    defaults.put("Spinner.arrowButtonSize", JBUI.size(16, 5).asUIResource());
    MetalLookAndFeel.setCurrentTheme(createMetalTheme());
    defaults.put("EditorPane.font", defaults.getFont("TextField.font"));
    return defaults;
  }
  catch (Exception e) {
    log(e);
  }
  return super.getDefaultsImpl(superDefaults);
}
 
源代码23 项目: openjdk-jdk9   文件: DefaultSynthStyleFactory.java
/**
 * Returns the style to use if there are no matching styles.
 */
private SynthStyle getDefaultStyle() {
    if (_defaultStyle == null) {
        _defaultStyle = new DefaultSynthStyle();
        ((DefaultSynthStyle)_defaultStyle).setFont(
            new FontUIResource(Font.DIALOG, Font.PLAIN,12));
    }
    return _defaultStyle;
}
 
源代码24 项目: stendhal   文件: StyledLookAndFeel.java
/**
 * Set the default font size used in components.
 *
 * @param size new font size
 */
public void setDefaultFontSize(final int size) {
	UIDefaults defaults = getDefaults();

	for (Object key : defaults.keySet()) {
		if ((key instanceof String) && (((String) key).endsWith(".font"))) {
			FontUIResource font = (FontUIResource) defaults.get(key);
			// For some reason changing it in defaults does not work
			// reliably. Going through UIManager fixes it.
			UIManager.put(key, new FontUIResource(font.getName(), font.getStyle(), size));
		}
	}
}
 
源代码25 项目: jdk8u60   文件: CFontManager.java
@Override
protected FontUIResource getFontConfigFUIR(
        String family, int style, int size)
{
    String mappedName = FontUtilities.mapFcName(family);
    if (mappedName == null) {
        mappedName = "sansserif";
    }
    return new FontUIResource(mappedName, style, size);
}
 
源代码26 项目: jdk8u60   文件: javax_swing_plaf_FontUIResource.java
protected FontUIResource getObject() {
    return new FontUIResource(
            new Font(
                    Collections.singletonMap(
                            TextAttribute.STRIKETHROUGH,
                            TextAttribute.STRIKETHROUGH_ON)));
}
 
/**
 * Returns the style to use if there are no matching styles.
 */
private SynthStyle getDefaultStyle() {
    if (_defaultStyle == null) {
        _defaultStyle = new DefaultSynthStyle();
        ((DefaultSynthStyle)_defaultStyle).setFont(
            new FontUIResource(Font.DIALOG, Font.PLAIN,12));
    }
    return _defaultStyle;
}
 
源代码28 项目: consulo   文件: ModernDarkLaf.java
@Nonnull
@Override
public UIDefaults getDefaultsImpl(UIDefaults superDefaults) {
  try {
    final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("getDefaults");
    superMethod.setAccessible(true);
    final UIDefaults metalDefaults = (UIDefaults)superMethod.invoke(new MetalLookAndFeel());
    final UIDefaults defaults = (UIDefaults)superMethod.invoke(base);
    if (SystemInfo.isLinux && !Registry.is("darcula.use.native.fonts.on.linux")) {
      Font font = findFont("DejaVu Sans");
      if (font != null) {
        for (Object key : defaults.keySet()) {
          if (key instanceof String && ((String)key).endsWith(".font")) {
            defaults.put(key, new FontUIResource(font.deriveFont(13f)));
          }
        }
      }
    }

    LafManagerImplUtil.initInputMapDefaults(defaults);
    defaults.put(SupportTextBoxWithExpandActionExtender.class, SupportTextBoxWithExpandActionExtender.INSTANCE);
    defaults.put(SupportTextBoxWithExtensionsExtender.class, SupportTextBoxWithExtensionsExtender.INSTANCE);

    initIdeaDefaults(defaults);
    patchStyledEditorKit(defaults);
    patchComboBox(metalDefaults, defaults);
    defaults.remove("Spinner.arrowButtonBorder");
    defaults.put("Spinner.arrowButtonSize", new Dimension(16, 5));

    MetalLookAndFeel.setCurrentTheme(createMetalTheme());

    defaults.put("EditorPane.font", defaults.getFont("TextField.font"));
    return defaults;
  }
  catch (Exception e) {
    log(e);
  }
  return super.getDefaultsImpl(superDefaults);
}
 
protected FontUIResource getObject() {
    return new FontUIResource(
            new Font(
                    Collections.singletonMap(
                            TextAttribute.STRIKETHROUGH,
                            TextAttribute.STRIKETHROUGH_ON)));
}
 
源代码30 项目: visualvm   文件: EnhancedTreeCellRenderer.java
/**
 * Subclassed to map <code>FontUIResource</code>s to null. If
 * <code>font</code> is null, or a <code>FontUIResource</code>, this
 * has the effect of letting the font of the JTree show
 * through. On the other hand, if <code>font</code> is non-null, and not
 * a <code>FontUIResource</code>, the font becomes <code>font</code>.
 */
public void setFont(Font font) {
    if (font instanceof FontUIResource) {
        font = null;
    }

    super.setFont(font);
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包
 同包方法