use of javax.swing.plaf.FontUIResource in project intellij-community by JetBrains.
the class DarculaLaf method getDefaults.
@Override
public UIDefaults getDefaults() {
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) {
if (!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)));
}
}
}
} else if (Arrays.asList("CN", "JP", "KR", "TW").contains(Locale.getDefault().getCountry())) {
for (Object key : defaults.keySet()) {
if (key instanceof String && ((String) key).endsWith(".font")) {
final Font font = defaults.getFont(key);
if (font != null) {
defaults.put(key, new FontUIResource("Dialog", font.getStyle(), font.getSize()));
}
}
}
}
}
LafManagerImpl.initInputMapDefaults(defaults);
initIdeaDefaults(defaults);
patchStyledEditorKit(defaults);
patchComboBox(metalDefaults, defaults);
defaults.remove("Spinner.arrowButtonBorder");
defaults.put("Spinner.arrowButtonSize", JBUI.size(16, 5).asUIResource());
MetalLookAndFeel.setCurrentTheme(createMetalTheme());
if (SystemInfo.isWindows && Registry.is("ide.win.frame.decoration")) {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
}
if (SystemInfo.isLinux && JBUI.isUsrHiDPI()) {
applySystemFonts(defaults);
}
defaults.put("EditorPane.font", defaults.getFont("TextField.font"));
if (SystemInfo.isMacOSYosemite) {
installMacOSXFonts(defaults);
}
return defaults;
} catch (Exception e) {
log(e);
}
return super.getDefaults();
}
use of javax.swing.plaf.FontUIResource in project intellij-community by JetBrains.
the class IntroFontProperty method importSnapshotValue.
@Override
public void importSnapshotValue(final SnapshotContext context, final JComponent component, final RadComponent radComponent) {
try {
if (component.getParent() != null) {
Font componentFont = (Font) myReadMethod.invoke(component, EMPTY_OBJECT_ARRAY);
if (componentFont instanceof FontUIResource) {
final Constructor constructor = component.getClass().getConstructor(ArrayUtil.EMPTY_CLASS_ARRAY);
constructor.setAccessible(true);
JComponent newComponent = (JComponent) constructor.newInstance(ArrayUtil.EMPTY_OBJECT_ARRAY);
Font defaultFont = (Font) myReadMethod.invoke(newComponent, EMPTY_OBJECT_ARRAY);
if (defaultFont == componentFont) {
return;
}
UIDefaults defaults = UIManager.getDefaults();
Enumeration e = defaults.keys();
while (e.hasMoreElements()) {
Object key = e.nextElement();
Object value = defaults.get(key);
if (key instanceof String && value == componentFont) {
setValue(radComponent, FontDescriptor.fromSwingFont((String) key));
return;
}
}
}
Font parentFont = (Font) myReadMethod.invoke(component.getParent(), EMPTY_OBJECT_ARRAY);
if (!Comparing.equal(componentFont, parentFont)) {
String fontName = componentFont.getName().equals(parentFont.getName()) ? null : componentFont.getName();
int fontStyle = componentFont.getStyle() == parentFont.getStyle() ? -1 : componentFont.getStyle();
int fontSize = componentFont.getSize() == parentFont.getSize() ? -1 : componentFont.getSize();
setValue(radComponent, new FontDescriptor(fontName, fontStyle, fontSize));
}
}
} catch (Exception e) {
// ignore
}
}
use of javax.swing.plaf.FontUIResource in project adempiere by adempiere.
the class ThemeUtils method parseFont.
// parseColor
/**
* Parse Font
* <p>
* javax.swing.plaf.FontUIResource[family=dialog.bold,name=Dialog,style=bold,size=12]
*
* @param information string information to be parsed
* @param stdFont font used if info cannot be parsed
* @return font
*/
public static FontUIResource parseFont(String information, FontUIResource stdFont) {
if (information == null || information.length() == 0 || information.trim().length() == 0)
return stdFont;
// System.out.print("ParseFont=" + info);
try {
String name = information.substring(information.indexOf("name=") + 5, information.indexOf(",style="));
String s = information.substring(information.indexOf("style=") + 6, information.indexOf(",size="));
int style = Font.PLAIN;
if (s.equals("bold"))
style = Font.BOLD;
else if (s.equals("italic"))
style = Font.ITALIC;
else if (s.equals("bolditalic"))
style = Font.BOLD | Font.ITALIC;
int size = Integer.parseInt(information.substring(information.indexOf(",size=") + 6, information.lastIndexOf(']')));
FontUIResource retValue = new FontUIResource(name, style, size);
// System.out.println(" - " + retValue.toString());
return retValue;
} catch (Exception e) {
log.config(information + " - cannot parse: " + e.toString());
}
return stdFont;
}
use of javax.swing.plaf.FontUIResource in project JMRI by JMRI.
the class GuiLafConfigPaneXml method setUIFontSize.
public void setUIFontSize(float size) {
Enumeration<Object> keys = UIManager.getDefaults().keys();
Font f;
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof FontUIResource) {
f = UIManager.getFont(key).deriveFont(((Font) value).getStyle(), size);
UIManager.put(key, f);
}
}
}
use of javax.swing.plaf.FontUIResource in project jmeter by apache.
the class JMeterUtils method applyScaleOnFonts.
/**
* Apply HiDPI scale factor on fonts
* @param scale float scale to apply
*/
public static void applyScaleOnFonts(final float scale) {
log.info("Applying HiDPI scale: {}", scale);
SwingUtilities.invokeLater(() -> {
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
// the font objects are missing, so iterate over the keys, only
for (Object key : new ArrayList<>(defaults.keySet())) {
Object value = defaults.get(key);
log.debug("Try key {} with value {}", key, value);
if (value instanceof Font) {
Font font = (Font) value;
final float newSize = font.getSize() * scale;
if (font instanceof FontUIResource) {
defaults.put(key, new FontUIResource(font.getName(), font.getStyle(), Math.round(newSize)));
} else {
defaults.put(key, font.deriveFont(newSize));
}
}
}
JMeterUtils.refreshUI();
});
}
Aggregations