fontFace/fontSize as property

This commit is contained in:
Vladimir Krivosheev
2017-02-16 11:52:02 +01:00
parent a82a6b0060
commit 0bbef0e69d
6 changed files with 106 additions and 86 deletions
@@ -47,75 +47,22 @@ class UISettings : BaseState(), PersistentStateComponent<UISettings> {
// These font properties should not be set in the default ctor,
// so that to make the serialization logic judge if a property
// should be stored or shouldn't by the provided filter only.
@JvmField
@Property(filter = FontFilter::class) var FONT_FACE: String? = null
@get:Property(filter = FontFilter::class)
@get:OptionTag("FONT_FACE")
var fontFace by storedProperty<String?>()
@JvmField
@Property(filter = FontFilter::class) var FONT_SIZE: Int = 0
@get:Property(filter = FontFilter::class)
@get:OptionTag("FONT_SIZE")
var fontSize by storedProperty(0)
@Property(filter = FontFilter::class) private var FONT_SCALE: Float = 0.toFloat()
@get:OptionTag("RECENT_FILES_LIMIT") var recentFilesLimit by storedProperty(50)
@get:OptionTag("CONSOLE_COMMAND_HISTORY_LIMIT") var consoleCommandHistoryLimit by storedProperty(300)
@JvmField var OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE = false
@JvmField var CONSOLE_CYCLE_BUFFER_SIZE_KB = 1024
@JvmField var EDITOR_TAB_LIMIT = 10
@Suppress("unused")
@Deprecated("Use hideToolStripes", replaceWith = ReplaceWith("hideToolStripes"))
@JvmField
@Transient
var HIDE_TOOL_STRIPES = true
@Suppress("unused")
@Deprecated("Use consoleCommandHistoryLimit", replaceWith = ReplaceWith("consoleCommandHistoryLimit"))
@JvmField
@Transient
var CONSOLE_COMMAND_HISTORY_LIMIT = 300
@Suppress("unused")
@Deprecated("Use cycleScrolling", replaceWith = ReplaceWith("cycleScrolling"))
@JvmField
@Transient
var CYCLE_SCROLLING = true
@Suppress("unused")
@Deprecated("Use showMainToolbar", replaceWith = ReplaceWith("showMainToolbar"))
@JvmField
@Transient
var SHOW_MAIN_TOOLBAR = false
@Suppress("unused")
@Deprecated("Use showCloseButton", replaceWith = ReplaceWith("showCloseButton"))
@JvmField
@Transient
var SHOW_CLOSE_BUTTON = true
@Suppress("unused")
@Deprecated("Use editorAAType", replaceWith = ReplaceWith("editorAAType"))
@JvmField
@Transient
var EDITOR_AA_TYPE: AntialiasingType? = AntialiasingType.SUBPIXEL
@Suppress("unused")
@Deprecated("Use presentationMode", replaceWith = ReplaceWith("presentationMode"))
@JvmField
@Transient
var PRESENTATION_MODE = false
@Suppress("unused")
@Deprecated("Use overrideLafFonts", replaceWith = ReplaceWith("overrideLafFonts"))
@JvmField
@Transient
var OVERRIDE_NONIDEA_LAF_FONTS = false
@Suppress("unused")
@Deprecated("Use presentationModeFontSize", replaceWith = ReplaceWith("presentationModeFontSize"))
@JvmField
@Transient
var PRESENTATION_MODE_FONT_SIZE = 24
@get:OptionTag("REUSE_NOT_MODIFIED_TABS") var reuseNotModifiedTabs by storedProperty(false)
@get:OptionTag("ANIMATE_WINDOWS") var animateWindows by storedProperty(true)
@get:OptionTag("SHOW_TOOL_WINDOW_NUMBERS") var showToolWindowsNumbers by storedProperty(true)
@@ -235,12 +182,14 @@ class UISettings : BaseState(), PersistentStateComponent<UISettings> {
OVERRIDE_NONIDEA_LAF_FONTS = overrideLafFonts
PRESENTATION_MODE_FONT_SIZE = presentationModeFontSize
CONSOLE_COMMAND_HISTORY_LIMIT = consoleCommandHistoryLimit
FONT_SIZE = fontSize
FONT_FACE = fontFace
}
private fun initDefFont() {
val fontData = systemFontFaceAndSize
if (FONT_FACE == null) FONT_FACE = fontData.first
if (FONT_SIZE <= 0) FONT_SIZE = fontData.second
if (fontFace == null) fontFace = fontData.first
if (fontSize <= 0) fontSize = fontData.second
if (FONT_SCALE <= 0) FONT_SCALE = JBUI.scale(1f)
}
@@ -249,10 +198,10 @@ class UISettings : BaseState(), PersistentStateComponent<UISettings> {
val settings = bean as UISettings
val fontData = systemFontFaceAndSize
if ("FONT_FACE" == accessor.name) {
return fontData.first != settings.FONT_FACE
return fontData.first != settings.fontFace
}
// store only in pair
return !(fontData.second == settings.FONT_SIZE && 1f == settings.FONT_SCALE)
return !(fontData.second == settings.fontSize && 1f == settings.FONT_SCALE)
}
}
@@ -282,21 +231,21 @@ class UISettings : BaseState(), PersistentStateComponent<UISettings> {
if (FONT_SCALE <= 0) {
// Reset font to default on switch from IDEA-managed HiDPI to JDK-managed HiDPI. Doesn't affect OSX.
if (UIUtil.isJDKManagedHiDPI() && !SystemInfo.isMac) FONT_SIZE = UIUtil.DEF_SYSTEM_FONT_SIZE.toInt()
if (UIUtil.isJDKManagedHiDPI() && !SystemInfo.isMac) fontSize = UIUtil.DEF_SYSTEM_FONT_SIZE.toInt()
}
else {
FONT_SIZE = JBUI.scale(FONT_SIZE / FONT_SCALE).toInt()
fontSize = JBUI.scale(fontSize / FONT_SCALE).toInt()
}
FONT_SCALE = JBUI.scale(1f)
initDefFont()
// 1. Sometimes system font cannot display standard ASCII symbols. If so we have
// find any other suitable font withing "preferred" fonts first.
var fontIsValid = isValidFont(Font(FONT_FACE, Font.PLAIN, FONT_SIZE))
var fontIsValid = isValidFont(Font(fontFace, Font.PLAIN, fontSize))
if (!fontIsValid) {
for (preferredFont in arrayOf("dialog", "Arial", "Tahoma")) {
if (isValidFont(Font(preferredFont, Font.PLAIN, FONT_SIZE))) {
FONT_FACE = preferredFont
if (isValidFont(Font(preferredFont, Font.PLAIN, fontSize))) {
fontFace = preferredFont
fontIsValid = true
break
}
@@ -307,7 +256,7 @@ class UISettings : BaseState(), PersistentStateComponent<UISettings> {
if (!fontIsValid) {
val fontNames = UIUtil.getValidFontNames(false)
if (fontNames.isNotEmpty()) {
FONT_FACE = fontNames[0]
fontFace = fontNames[0]
}
}
}
@@ -419,4 +368,72 @@ class UISettings : BaseState(), PersistentStateComponent<UISettings> {
instance.editorAAType?.let { component.putClientProperty(SwingUtilities2.AA_TEXT_PROPERTY_KEY, it.textInfo) }
}
}
//<editor-fold desc="Deprecated stuff.">
@Suppress("unused")
@Deprecated("Use fontFace", replaceWith = ReplaceWith("fontFace"))
@JvmField
@Transient
var FONT_FACE: String? = null
@Suppress("unused")
@Deprecated("Use fontSize", replaceWith = ReplaceWith("fontSize"))
@JvmField
@Transient
var FONT_SIZE: Int? = 0
@Suppress("unused")
@Deprecated("Use hideToolStripes", replaceWith = ReplaceWith("hideToolStripes"))
@JvmField
@Transient
var HIDE_TOOL_STRIPES = true
@Suppress("unused")
@Deprecated("Use consoleCommandHistoryLimit", replaceWith = ReplaceWith("consoleCommandHistoryLimit"))
@JvmField
@Transient
var CONSOLE_COMMAND_HISTORY_LIMIT = 300
@Suppress("unused")
@Deprecated("Use cycleScrolling", replaceWith = ReplaceWith("cycleScrolling"))
@JvmField
@Transient
var CYCLE_SCROLLING = true
@Suppress("unused")
@Deprecated("Use showMainToolbar", replaceWith = ReplaceWith("showMainToolbar"))
@JvmField
@Transient
var SHOW_MAIN_TOOLBAR = false
@Suppress("unused")
@Deprecated("Use showCloseButton", replaceWith = ReplaceWith("showCloseButton"))
@JvmField
@Transient
var SHOW_CLOSE_BUTTON = true
@Suppress("unused")
@Deprecated("Use editorAAType", replaceWith = ReplaceWith("editorAAType"))
@JvmField
@Transient
var EDITOR_AA_TYPE: AntialiasingType? = AntialiasingType.SUBPIXEL
@Suppress("unused")
@Deprecated("Use presentationMode", replaceWith = ReplaceWith("presentationMode"))
@JvmField
@Transient
var PRESENTATION_MODE = false
@Suppress("unused")
@Deprecated("Use overrideLafFonts", replaceWith = ReplaceWith("overrideLafFonts"))
@JvmField
@Transient
var OVERRIDE_NONIDEA_LAF_FONTS = false
@Suppress("unused")
@Deprecated("Use presentationModeFontSize", replaceWith = ReplaceWith("presentationModeFontSize"))
@JvmField
@Transient
var PRESENTATION_MODE_FONT_SIZE = 24
//</editor-fold>
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,10 @@ import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.FileStatus;
import com.intellij.psi.codeStyle.NameUtil;
import com.intellij.ui.*;
import com.intellij.ui.Gray;
import com.intellij.ui.JBColor;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.ui.speedSearch.SpeedSearchSupply;
import com.intellij.ui.speedSearch.SpeedSearchUtil;
import com.intellij.util.text.DateFormatUtil;
@@ -72,9 +75,9 @@ public class PluginsTableRenderer extends DefaultTableCellRenderer {
if (SystemInfo.isMac) {
smallFont = UIUtil.getLabelFont(UIUtil.FontSize.MINI);
} else {
smallFont = UIUtil.getLabelFont().deriveFont(Math.max(UISettings.getInstance().FONT_SIZE - JBUI.scale(3), JBUI.scaleFontSize(10)));
smallFont = UIUtil.getLabelFont().deriveFont(Math.max(UISettings.getInstance().getFontSize() - JBUI.scale(3), JBUI.scaleFontSize(10)));
}
myName.setFont(UIUtil.getLabelFont().deriveFont(UISettings.getInstance().FONT_SIZE));
myName.setFont(UIUtil.getLabelFont().deriveFont(UISettings.getInstance().getFontSize()));
myStatus.setFont(smallFont);
myCategory.setFont(smallFont);
myDownloads.setFont(smallFont);
@@ -152,15 +152,15 @@ public class AppearanceConfigurable extends BaseConfigurable implements Searchab
public void apply() {
initComponent();
UISettings settings = UISettings.getInstance();
int _fontSize = getIntValue(myComponent.myFontSizeCombo, settings.FONT_SIZE);
int _fontSize = getIntValue(myComponent.myFontSizeCombo, settings.getFontSize());
int _presentationFontSize = getIntValue(myComponent.myPresentationModeFontSize, settings.getPresentationModeFontSize());
boolean update = false;
boolean shouldUpdateUI = false;
String _fontFace = myComponent.myFontCombo.getFontName();
LafManager lafManager = LafManager.getInstance();
if (_fontSize != settings.FONT_SIZE || !Comparing.equal(settings.FONT_FACE, _fontFace)) {
settings.FONT_SIZE = _fontSize;
settings.FONT_FACE = _fontFace;
if (_fontSize != settings.getFontSize() || !Comparing.equal(settings.getFontFace(), _fontFace)) {
settings.setFontSize(_fontSize);
settings.setFontFace(_fontFace);
shouldUpdateUI = true;
update = true;
}
@@ -314,7 +314,7 @@ public class AppearanceConfigurable extends BaseConfigurable implements Searchab
UISettings settings = UISettings.getInstance();
if (settings.getOverrideLafFonts()) {
myComponent.myFontCombo.setFontName(settings.FONT_FACE);
myComponent.myFontCombo.setFontName(settings.getFontFace());
} else {
myComponent.myFontCombo.setFontName(UIUtil.getLabelFont().getFamily());
}
@@ -325,7 +325,7 @@ public class AppearanceConfigurable extends BaseConfigurable implements Searchab
myComponent.myAntialiasingInIDE.setSelectedItem(settings.getIdeAAType());
myComponent.myAntialiasingInEditor.setSelectedItem(settings.getEditorAAType());
myComponent.myFontSizeCombo.setSelectedItem(Integer.toString(settings.FONT_SIZE));
myComponent.myFontSizeCombo.setSelectedItem(Integer.toString(settings.getFontSize()));
myComponent.myPresentationModeFontSize.setSelectedItem(Integer.toString(settings.getPresentationModeFontSize()));
myComponent.myAnimateWindowsCheckBox.setSelected(settings.getAnimateWindows());
myComponent.myWindowShortcutsCheckBox.setSelected(settings.getShowToolWindowsNumbers());
@@ -388,8 +388,8 @@ public class AppearanceConfigurable extends BaseConfigurable implements Searchab
UISettings settings = UISettings.getInstance();
boolean isModified = false;
isModified |= !Comparing.equal(myComponent.myFontCombo.getFontName(), settings.FONT_FACE) && myComponent.myOverrideLAFFonts.isSelected();
isModified |= !Comparing.equal(myComponent.myFontSizeCombo.getEditor().getItem(), Integer.toString(settings.FONT_SIZE));
isModified |= !Comparing.equal(myComponent.myFontCombo.getFontName(), settings.getFontFace()) && myComponent.myOverrideLAFFonts.isSelected();
isModified |= !Comparing.equal(myComponent.myFontSizeCombo.getEditor().getItem(), Integer.toString(settings.getFontSize()));
isModified |= myComponent.myAntialiasingInIDE.getSelectedItem() != settings.getIdeAAType();
isModified |= myComponent.myAntialiasingInEditor.getSelectedItem() != settings.getEditorAAType();
@@ -744,8 +744,8 @@ public final class LafManagerImpl extends LafManager implements ApplicationCompo
UISettings uiSettings = UISettings.getInstance();
if (uiSettings.getOverrideLafFonts()) {
storeOriginalFontDefaults(uiDefaults);
JBUI.setUserScaleFactor(uiSettings.FONT_SIZE / UIUtil.DEF_SYSTEM_FONT_SIZE);
initFontDefaults(uiDefaults, uiSettings.FONT_SIZE, new FontUIResource(uiSettings.FONT_FACE, Font.PLAIN, uiSettings.FONT_SIZE));
JBUI.setUserScaleFactor(uiSettings.getFontSize() / UIUtil.DEF_SYSTEM_FONT_SIZE);
initFontDefaults(uiDefaults, uiSettings.getFontSize(), new FontUIResource(uiSettings.getFontFace(), Font.PLAIN, uiSettings.getFontSize()));
}
else {
restoreOriginalFontDefaults(uiDefaults);
@@ -29,13 +29,13 @@ class FontSizeInfoUsageCollector : UsagesCollector() {
val scheme = EditorColorsManager.getInstance().globalScheme
val ui = UISettings.shadowInstance
return setOf(
UsageDescriptor("UI font size: ${ui.FONT_SIZE}"),
UsageDescriptor("UI font size: ${ui.fontSize}"),
UsageDescriptor("Editor font size: ${scheme.editorFontSize}"),
UsageDescriptor("Console font size: ${scheme.consoleFontSize}"),
UsageDescriptor("Presentation mode font size: ${ui.presentationModeFontSize}"),
UsageDescriptor("Editor font name: ${scheme.editorFontName}"),
UsageDescriptor("Console font name: ${scheme.consoleFontName}"),
UsageDescriptor("UI font name: ${ui.FONT_FACE}")
UsageDescriptor("UI font name: ${ui.fontFace}")
)
}
@@ -130,7 +130,7 @@ public class NotificationsUtil {
public static Pair<String, Integer> getFontData() {
UISettings uiSettings = UISettings.getInstance();
if (uiSettings.getOverrideLafFonts()) {
return Pair.create(uiSettings.FONT_FACE, uiSettings.FONT_SIZE);
return Pair.create(uiSettings.getFontFace(), uiSettings.getFontSize());
}
return UIUtil.getSystemFontData();
}