Java Code Examples for javax.swing.plaf.FontUIResource

The following examples show how to use javax.swing.plaf.FontUIResource. These examples are extracted from open source projects. 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 Project: FlatLaf   Source File: FlatLaf.java    License: Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source Project: jdk8u-jdk   Source File: X11FontManager.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source Project: radiance   Source File: NeonFontSet.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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);
}
 
Example 4
Source Project: jdk8u-dev-jdk   Source File: X11FontManager.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example 5
Source Project: openjdk-8   Source File: X11FontManager.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example 6
Source Project: openstego   Source File: OpenStegoFrame.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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));
    }
}
 
Example 7
Source Project: openjdk-jdk9   Source File: X11FontManager.java    License: GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example 8
Source Project: runelite   Source File: SwingUtil.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example 9
/**
 * 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;
}
 
Example 10
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;
}
 
Example 11
Source Project: jdk8u-jdk   Source File: CFontManager.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 12
protected FontUIResource getObject() {
    return new FontUIResource(
            new Font(
                    Collections.singletonMap(
                            TextAttribute.STRIKETHROUGH,
                            TextAttribute.STRIKETHROUGH_ON)));
}
 
Example 13
Source Project: mybatis-generator-gui   Source File: GUIUtil.java    License: MIT License 5 votes vote down vote up
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);
        }
    }
}
 
Example 14
Source Project: hottub   Source File: DefaultTreeCellEditor.java    License: GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 15
/**
 * 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;
}
 
Example 16
protected FontUIResource getObject() {
    return new FontUIResource(
            new Font(
                    Collections.singletonMap(
                            TextAttribute.STRIKETHROUGH,
                            TextAttribute.STRIKETHROUGH_ON)));
}
 
Example 17
/**
 * 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;
}
 
Example 18
Source Project: consulo   Source File: LafManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
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"));
}
 
Example 19
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;
}
 
Example 20
Source Project: openjdk-jdk9   Source File: CFontManager.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 21
Source Project: FCMFrame   Source File: Main.java    License: Apache License 2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example 22
Source Project: consulo   Source File: DarculaLaf.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 23
/**
 * 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;
}
 
Example 24
Source Project: stendhal   Source File: StyledLookAndFeel.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
		}
	}
}
 
Example 25
Source Project: jdk8u60   Source File: CFontManager.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 26
protected FontUIResource getObject() {
    return new FontUIResource(
            new Font(
                    Collections.singletonMap(
                            TextAttribute.STRIKETHROUGH,
                            TextAttribute.STRIKETHROUGH_ON)));
}
 
Example 27
Source Project: JDKSourceCode1.8   Source File: DefaultSynthStyleFactory.java    License: MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 28
Source Project: consulo   Source File: ModernDarkLaf.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 29
protected FontUIResource getObject() {
    return new FontUIResource(
            new Font(
                    Collections.singletonMap(
                            TextAttribute.STRIKETHROUGH,
                            TextAttribute.STRIKETHROUGH_ON)));
}
 
Example 30
/**
 * 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);
}