@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; }
private void setupKeyColumnWidth() { FontUIResource font = (FontUIResource) UIManager.get("Table.font"); for (int j = 0; j < getColumnModel().getColumnCount(); j++) { TableColumn column = getColumnModel().getColumn(j); Integer columnWidth = columnWidthMap.get(j); if (columnWidth != null) { int fixedSize = columnWidth; if (fixedSize == -1) { double max = 0; int rowCount = getModel().getRowCount(); for (int i = 0; i < rowCount; i++) { String text = getValueAt(i, 0).toString(); int width = SwingUtils.getWidth(font, text); max = Math.max(max, width); } fixedSize = (int) (max + 16 * 2); } column.setMinWidth(fixedSize); column.setMaxWidth(fixedSize); } } }
/** * 设置全局字体 */ public static void initGlobalFont() { String lowDpiKey = "lowDpiInit"; Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); //得到屏幕的尺寸 if (screenSize.width <= 1366 && StringUtils.isEmpty(configer.getProps(lowDpiKey))) { configer.setFontSize(15); configer.setProps(lowDpiKey, "true"); configer.save(); } Font fnt = new Font(configer.getFont(), Font.PLAIN, configer.getFontSize()); 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); } }
@SuppressWarnings({"HardCodedStringLiteral"}) static void initFontDefaults(UIDefaults defaults, String fontFace, int fontSize) { defaults.put("Tree.ancestorInputMap", null); FontUIResource uiFont = new FontUIResource(fontFace, Font.PLAIN, fontSize); FontUIResource textFont = new FontUIResource("Serif", Font.PLAIN, fontSize); FontUIResource monoFont = new FontUIResource("Monospaced", Font.PLAIN, fontSize); for (String fontResource : ourPatchableFontResources) { defaults.put(fontResource, uiFont); } defaults.put("PasswordField.font", monoFont); defaults.put("TextArea.font", monoFont); defaults.put("TextPane.font", textFont); defaults.put("EditorPane.font", textFont); }
public void register(ConverterRegistry registry) { registry.addConverter(Dimension.class, String.class, this); registry.addConverter(String.class, Dimension.class, this); registry.addConverter(DimensionUIResource.class, String.class, this); registry.addConverter(Insets.class, String.class, this); registry.addConverter(String.class, Insets.class, this); registry.addConverter(InsetsUIResource.class, String.class, this); registry.addConverter(Point.class, String.class, this); registry.addConverter(String.class, Point.class, this); registry.addConverter(Rectangle.class, String.class, this); registry.addConverter(String.class, Rectangle.class, this); registry.addConverter(Font.class, String.class, this); registry.addConverter(FontUIResource.class, String.class, this); }
public static void setAccessibilityFontScale( final float scale ) { SwingUtilities.invokeLater( new Runnable() { public void run() { UIDefaults defaults = UIManager.getDefaults(); Enumeration keys = defaults.keys(); while ( keys.hasMoreElements() ) { Object key = keys.nextElement(); Object value = defaults.get( key ); if ( value != null && value instanceof Font ) { UIManager.put( key, null ); Font font = UIManager.getFont( key ); if ( font != null ) { float size = font.getSize2D(); UIManager.put( key, new FontUIResource( font.deriveFont( size * scale ) ) ); } } } } } ); }
/** * Adjust the main font for the GUI (+1 = one size up, -1 = one size down) */ public void adjustFont(int adjust) { Object[] objs = UIManager.getLookAndFeel().getDefaults().keySet().toArray(); for (int i = 0; i < objs.length; i++) { if (objs[i].toString().toUpperCase().indexOf(".FONT") != -1) { Font font = UIManager.getFont(objs[i]); font = font.deriveFont((float) (font.getSize() + adjust)); UIManager.put(objs[i], new FontUIResource(font)); } } SwingUtilities.updateComponentTreeUI(this); SwingUtilities.updateComponentTreeUI(choose); SwingUtilities.updateComponentTreeUI(options); repaint(); }
@Override protected void addBasicDefaults(LookAndFeelAddons addon, DefaultsList defaults) { super.addBasicDefaults(addon, defaults); Font font = UIManagerExt.getSafeFont("Label.font", new Font("Dialog", Font.PLAIN, 12)); font = font.deriveFont(Font.BOLD, 13f); defaults.add(JXCategory.uiClassID, BasicCategoryUI.class.getName()); defaults.add("Category.font", UIManagerExt.getSafeFont("TextPane.font", new FontUIResource("Serif", Font.PLAIN, 12))); defaults.add("Category.tipFont", new FontUIResource(font)); defaults.add("Category.background", new ColorUIResource(Color.WHITE)); defaults.add("Category.icon", LookAndFeel.makeIcon(BasicCategoryUI.class, "resources/dictionary_categories.png")); defaults.add("Category.border", new BorderUIResource( BorderFactory.createLineBorder(new Color(117, 117, 117)))); UIManagerExt.addResourceBundle( "org.jdesktop.swingx.plaf.basic.resources.Category"); }
/** * {@inheritDoc} */ @Override protected void addWindowsDefaults(LookAndFeelAddons addon, DefaultsList defaults) { super.addWindowsDefaults(addon, defaults); Font font = UIManagerExt.getSafeFont("Label.font", new Font("Dialog", Font.PLAIN, 12)); font = font.deriveFont(13f); defaults.add(JXCategory.uiClassID, WindowsTipOfTheDayUI.class.getName()); defaults.add("Category.background", new ColorUIResource(Color.GRAY)); defaults.add("Category.font", new FontUIResource(font)); defaults.add("Category.icon", LookAndFeel.makeIcon(WindowsTipOfTheDayUI.class, "resources/tipoftheday.png")); defaults.add("Category.border" ,new BorderUIResource(new WindowsTipOfTheDayUI.TipAreaBorder())); UIManagerExt.addResourceBundle( "org.jdesktop.swingx.plaf.windows.resources.TipOfTheDay"); }
@Override protected void addBasicDefaults(LookAndFeelAddons addon, DefaultsList defaults) { super.addBasicDefaults(addon, defaults); Font font = UIManagerExt.getSafeFont("Label.font", new Font("Dialog", Font.PLAIN, 12)); font = font.deriveFont(Font.BOLD, 13f); defaults.add(JXTipOfTheDay.uiClassID, BasicTipOfTheDayUI.class.getName()); defaults.add("TipOfTheDay.font", UIManagerExt.getSafeFont("TextPane.font", new FontUIResource("Serif", Font.PLAIN, 12))); defaults.add("TipOfTheDay.tipFont", new FontUIResource(font)); defaults.add("TipOfTheDay.background", new ColorUIResource(Color.WHITE)); defaults.add("TipOfTheDay.icon", LookAndFeel.makeIcon(BasicTipOfTheDayUI.class, "resources/TipOfTheDay24.gif")); defaults.add("TipOfTheDay.border", new BorderUIResource( BorderFactory.createLineBorder(new Color(117, 117, 117)))); UIManagerExt.addResourceBundle( "org.jdesktop.swingx.plaf.basic.resources.TipOfTheDay"); }
/** * {@inheritDoc} */ @Override protected void addWindowsDefaults(LookAndFeelAddons addon, DefaultsList defaults) { super.addWindowsDefaults(addon, defaults); Font font = UIManagerExt.getSafeFont("Label.font", new Font("Dialog", Font.PLAIN, 12)); font = font.deriveFont(13f); defaults.add(JXTipOfTheDay.uiClassID, WindowsTipOfTheDayUI.class.getName()); defaults.add("TipOfTheDay.background", new ColorUIResource(Color.GRAY)); defaults.add("TipOfTheDay.font", new FontUIResource(font)); defaults.add("TipOfTheDay.icon", LookAndFeel.makeIcon(WindowsTipOfTheDayUI.class, "resources/tipoftheday.png")); defaults.add("TipOfTheDay.border" ,new BorderUIResource(new WindowsTipOfTheDayUI.TipAreaBorder())); UIManagerExt.addResourceBundle( "org.jdesktop.swingx.plaf.windows.resources.TipOfTheDay"); }
/** * Sets the default font to be used in the GUI. * @param fontName The name of the font to be used as default. */ public void setUIDefaultFont(String fontName) { if(fontName == null) return; java.util.Enumeration keys = UIManager.getDefaults().keys(); while(keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = UIManager.get(key); if(value instanceof FontUIResource) { Font f = (FontUIResource)value; FontUIResource fr = new FontUIResource(fontName, f.getStyle(), f.getSize()); UIManager.put(key, fr); } } }
/** * Returns the appropriate font. The font type to return is identified * by the specified id. * * @param id the font type to return * * @return the correct font */ private FontUIResource getFont(int id) { FontUIResource font = null; switch (id) { case CONTROL_TEXT_FONT: if (isBoldMetal()) font = BOLD_CONTROL_TEXT_FONT; else font = PLAIN_CONTROL_TEXT_FONT; break; case MENU_TEXT_FONT: if (isBoldMetal()) font = BOLD_MENU_TEXT_FONT; else font = PLAIN_MENU_TEXT_FONT; break; // TODO: Add other font types and their mapping here. } return font; }
private static void installMacOSXFonts(UIDefaults defaults) { String face = "HelveticaNeue-Regular"; LafManagerImpl.initFontDefaults(defaults, face, 13); for (Object key : new HashSet<Object>(defaults.keySet())) { 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, new FontUIResource(face, font.getStyle(), font.getSize())); } } } } FontUIResource uiFont11 = new FontUIResource("HelveticaNeue-Medium", Font.PLAIN, 11); defaults.put("TableHeader.font", uiFont11); FontUIResource buttonFont = new FontUIResource("HelveticaNeue-Medium", Font.PLAIN, 13); defaults.put("Button.font", buttonFont); Font menuFont = new FontUIResource("Lucida Grande", Font.PLAIN, 14); defaults.put("Menu.font", menuFont); defaults.put("MenuItem.font", menuFont); defaults.put("MenuItem.acceleratorFont", menuFont); defaults.put("PasswordField.font", defaults.getFont("TextField.font")); }
/** * 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); }
@Override public UIDefaults getDefaults() { final float scale = 3f; final UIDefaults defaults = super.getDefaults(); final Map<Object,Object> changes = new HashMap<Object,Object>(); for (Map.Entry<Object,Object> e : defaults.entrySet()) { final Object key = e.getKey(); final Object val = e.getValue(); if (val instanceof FontUIResource) { final FontUIResource ores = (FontUIResource) val; final FontUIResource nres = new FontUIResource(ores.deriveFont(ores.getSize2D()*scale)); changes.put(key, nres); System.out.println(key + " = " + nres); } else if (val instanceof Font) { final Font ofont = (Font) val; final Font nfont = ofont.deriveFont(ofont.getSize2D()*scale); changes.put(key, nfont); System.out.println(key + " = " + nfont); } } defaults.putAll(changes); return defaults; }
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; }
/** * 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; }
@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))); }
public static FontUIResource getCompositeFontUIResource(Font font) { FontUIResource fuir = new FontUIResource(font); Font2D font2D = FontUtilities.getFont2D(font); if (!(font2D instanceof PhysicalFont)) { /* Swing should only be calling this when a font is obtained * from desktop properties, so should generally be a physical font, * an exception might be for names like "MS Serif" which are * automatically mapped to "Serif", so there's no need to do * anything special in that case. But note that suggested usage * is first to call fontSupportsDefaultEncoding(Font) and this * method should not be called if that were to return true. */ return fuir; } FontManager fm = FontManagerFactory.getInstance(); Font2D dialog = fm.findFont2D("dialog", font.getStyle(), FontManager.NO_FALLBACK); // Should never be null, but MACOSX fonts are not CompositeFonts if (dialog == null || !(dialog instanceof CompositeFont)) { return fuir; } CompositeFont dialog2D = (CompositeFont)dialog; PhysicalFont physicalFont = (PhysicalFont)font2D; ConcurrentHashMap<PhysicalFont, CompositeFont> compMap = compMapRef.get(); if (compMap == null) { // Its been collected. compMap = new ConcurrentHashMap<PhysicalFont, CompositeFont>(); compMapRef = new SoftReference<>(compMap); } CompositeFont compFont = compMap.get(physicalFont); if (compFont == null) { compFont = new CompositeFont(physicalFont, dialog2D); compMap.put(physicalFont, compFont); } FontAccess.getFontAccess().setFont2D(fuir, compFont.handle); /* marking this as a created font is needed as only created fonts * copy their creator's handles. */ FontAccess.getFontAccess().setCreatedFont(fuir); return fuir; }
private static void InitGlobalFont(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); } } }
protected void addBasicDefaults(LookAndFeelAddons addon, List defaults) { Color menuBackground = new ColorUIResource(SystemColor.menu); defaults.addAll(Arrays.asList(new Object[]{ JTaskPaneGroup.UI_CLASS_ID, "com.l2fprod.common.swing.plaf.basic.BasicTaskPaneGroupUI", "TaskPaneGroup.font", new FontUIResource( UIManager.getFont("Label.font").deriveFont(Font.BOLD)), "TaskPaneGroup.background", UIManager.getColor("List.background"), "TaskPaneGroup.specialTitleBackground", new ColorUIResource(menuBackground.darker()), "TaskPaneGroup.titleBackgroundGradientStart", menuBackground, "TaskPaneGroup.titleBackgroundGradientEnd", menuBackground, "TaskPaneGroup.titleForeground", new ColorUIResource(SystemColor.menuText), "TaskPaneGroup.specialTitleForeground", new ColorUIResource(SystemColor.menuText).brighter(), "TaskPaneGroup.animate", Boolean.TRUE, "TaskPaneGroup.focusInputMap", new UIDefaults.LazyInputMap( new Object[] { "ENTER", "toggleExpanded", "SPACE", "toggleExpanded" }), })); }