private static void patchHiDPI(UIDefaults defaults) { if (!JBUI.isHiDPI()) return; List<String> myIntKeys = Arrays.asList("Tree.leftChildIndent", "Tree.rightChildIndent"); List<String> patched = new ArrayList<String>(); for (Map.Entry<Object, Object> entry : defaults.entrySet()) { Object value = entry.getValue(); String key = entry.getKey().toString(); if (value instanceof DimensionUIResource) { entry.setValue(JBUI.size((DimensionUIResource) value).asUIResource()); } else if (value instanceof InsetsUIResource) { entry.setValue(JBUI.insets(((InsetsUIResource) value)).asUIResource()); } else if (value instanceof Integer) { if (key.endsWith(".maxGutterIconWidth") || myIntKeys.contains(key)) { if (!"true".equals(defaults.get(key + ".hidpi.patched"))) { entry.setValue(Integer.valueOf(JBUI.scale((Integer) value))); patched.add(key); } } } } for (String key : patched) { defaults.put(key + ".hidpi.patched", "true"); } }
@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.isHiDPI()) { applySystemFonts(defaults); } defaults.put("EditorPane.font", defaults.getFont("TextField.font")); return defaults; } catch (Exception e) { log(e); } return super.getDefaults(); }
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed") private void patchStyledEditorKit(UIDefaults defaults) { URL url = getClass().getResource(getPrefix() + (JBUI.isHiDPI() ? "@2x.css" : ".css")); StyleSheet styleSheet = UIUtil.loadStyleSheet(url); defaults.put("StyledEditorKit.JBDefaultStyle", styleSheet); try { Field keyField = HTMLEditorKit.class.getDeclaredField("DEFAULT_STYLES_KEY"); keyField.setAccessible(true); AppContext.getAppContext().put(keyField.get(null), UIUtil.loadStyleSheet(url)); } catch (Exception e) { log(e); } }