IDEA-330211 cleanup IdeaLaf

GitOrigin-RevId: b64aa56aade15bea9eb52dd1d8ad2a8e84de6b22
This commit is contained in:
Vladimir Krivosheev
2023-08-21 10:15:20 +03:00
committed by intellij-monorepo-bot
parent 1641908d85
commit 7179ee2e20
4 changed files with 112 additions and 121 deletions

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.codeInsight.hints.presentation
import com.intellij.ide.ui.AntialiasingType
@@ -12,7 +12,6 @@ import com.intellij.openapi.editor.impl.EditorImpl
import com.intellij.openapi.editor.impl.FontInfo
import com.intellij.util.concurrency.annotations.RequiresEdt
import com.intellij.util.ui.StartupUiUtil
import com.intellij.util.ui.UIUtil
import org.jetbrains.annotations.ApiStatus
import java.awt.Font
import java.awt.FontMetrics
@@ -79,7 +78,7 @@ class InlayTextMetrics(
editorFont.deriveFont(fontType, size)
} else {
val familyName = StartupUiUtil.labelFont.family
UIUtil.getFontWithFallback(familyName, fontType, size)
StartupUiUtil.getFontWithFallback(familyName, fontType, size)
}
val context = getCurrentContext(editor.component)
val metrics = FontInfo.getFontMetrics(font, context)

View File

@@ -12,7 +12,6 @@ import com.intellij.util.ui.StartupUiUtil.initInputMapDefaults
import java.awt.Color
import java.awt.Font
import java.awt.Insets
import java.util.function.Supplier
import javax.swing.UIDefaults
import javax.swing.plaf.ColorUIResource
import javax.swing.plaf.metal.MetalLookAndFeel
@@ -20,120 +19,120 @@ import javax.swing.plaf.metal.MetalLookAndFeel
/**
* @author Konstantin Bulenkov
*/
internal class IdeaLaf(private val myCustomFontDefaults: Map<Any, Any>?) : MetalLookAndFeel() {
internal class IdeaLaf(private val customFontDefaults: Map<Any, Any>?) : MetalLookAndFeel() {
public override fun initComponentDefaults(defaults: UIDefaults) {
super.initComponentDefaults(defaults)
initInputMapDefaults(defaults)
initIdeaDefaults(defaults)
if (myCustomFontDefaults != null) {
defaults.putAll(myCustomFontDefaults)
if (customFontDefaults == null) {
val systemFont = getSystemFontData(uiDefaults = { defaults })
initFontDefaults(defaults, getFontWithFallback(familyName = systemFont.first, style = Font.PLAIN, size = systemFont.second.toFloat()))
}
else {
val systemFont = getSystemFontData(
Supplier { defaults })
initFontDefaults(defaults, getFontWithFallback(systemFont.first, Font.PLAIN, systemFont.second.toFloat()))
}
}
companion object {
val TOOLTIP_BACKGROUND_COLOR: ColorUIResource = ColorUIResource(255, 255, 231)
@Suppress("HardCodedStringLiteral")
fun initIdeaDefaults(defaults: UIDefaults) {
defaults["Menu.maxGutterIconWidth"] = 18
defaults["MenuItem.maxGutterIconWidth"] = 18
// TODO[vova,anton] REMOVE!!! INVESTIGATE??? Borland???
defaults["MenuItem.acceleratorDelimiter"] = "-"
defaults["TitledBorder.titleColor"] = ColorUIResource(10, 36, 106)
val col = ColorUIResource(230, 230, 230)
defaults["ScrollBar.background"] = col
defaults["ScrollBar.track"] = col
defaults["TextField.border"] = createLazyValue(Supplier { BegBorders.getTextFieldBorder() })
defaults["PasswordField.border"] = createLazyValue(Supplier { BegBorders.getTextFieldBorder() })
defaults["PopupMenu.border"] = createLazyValue(Supplier { BegPopupMenuBorder() })
defaults["ScrollPane.border"] = createLazyValue(Supplier { BegBorders.getScrollPaneBorder() })
defaults["ToggleButtonUI"] = createLazyValue(Supplier { BegToggleButtonUI::class.java.getName() })
defaults["RadioButtonUI"] = createLazyValue(Supplier { BegRadioButtonUI::class.java.getName() })
defaults["TabbedPaneUI"] = createLazyValue(Supplier { BegTabbedPaneUI::class.java.getName() })
defaults["TableUI"] = createLazyValue(Supplier { BegTableUI::class.java.getName() })
defaults["TreeUI"] = createLazyValue(Supplier { BegTreeUI::class.java.getName() })
defaults["TabbedPane.tabInsets"] = Insets(0, 4, 0, 4)
defaults["ToolTip.background"] = TOOLTIP_BACKGROUND_COLOR
defaults["ToolTip.border"] = ColoredSideBorder(Color.gray, Color.gray, Color.black, Color.black, 1)
defaults["Tree.ancestorInputMap"] = null
defaults["FileView.directoryIcon"] = createLazyValue(Supplier { AllIcons.Nodes.Folder })
defaults["FileChooser.upFolderIcon"] = createLazyValue(Supplier { AllIcons.Nodes.UpFolder })
defaults["FileChooser.newFolderIcon"] = createLazyValue(Supplier { AllIcons.Nodes.Folder })
defaults["FileChooser.homeFolderIcon"] = createLazyValue(Supplier { AllIcons.Nodes.HomeFolder })
defaults["OptionPane.errorIcon"] = createLazyValue(Supplier { AllIcons.General.ErrorDialog })
defaults["OptionPane.informationIcon"] = createLazyValue(Supplier { AllIcons.General.InformationDialog })
defaults["OptionPane.warningIcon"] = createLazyValue(Supplier { AllIcons.General.WarningDialog })
defaults["OptionPane.questionIcon"] = createLazyValue(Supplier { AllIcons.General.QuestionDialog })
defaults["Table.ancestorInputMap"] = UIDefaults.LazyValue {
makeInputMap(arrayOf<Any>(
"ctrl C", "copy",
"ctrl V", "paste",
"ctrl X", "cut",
"COPY", "copy",
"PASTE", "paste",
"CUT", "cut",
"control INSERT", "copy",
"shift INSERT", "paste",
"shift DELETE", "cut",
"RIGHT", TableActions.Right.ID,
"KP_RIGHT", TableActions.Right.ID,
"LEFT", TableActions.Left.ID,
"KP_LEFT", TableActions.Left.ID,
"DOWN", TableActions.Down.ID,
"KP_DOWN", TableActions.Down.ID,
"UP", TableActions.Up.ID,
"KP_UP", TableActions.Up.ID,
"shift RIGHT", TableActions.ShiftRight.ID,
"shift KP_RIGHT", TableActions.ShiftRight.ID,
"shift LEFT", TableActions.ShiftLeft.ID,
"shift KP_LEFT", TableActions.ShiftLeft.ID,
"shift DOWN", TableActions.ShiftDown.ID,
"shift KP_DOWN", TableActions.ShiftDown.ID,
"shift UP", TableActions.ShiftUp.ID,
"shift KP_UP", TableActions.ShiftUp.ID,
"PAGE_UP", TableActions.PageUp.ID,
"PAGE_DOWN", TableActions.PageDown.ID,
"HOME", "selectFirstColumn",
"END", "selectLastColumn",
"shift PAGE_UP", TableActions.ShiftPageUp.ID,
"shift PAGE_DOWN", TableActions.ShiftPageDown.ID,
"shift HOME", "selectFirstColumnExtendSelection",
"shift END", "selectLastColumnExtendSelection",
"ctrl PAGE_UP", "scrollLeftChangeSelection",
"ctrl PAGE_DOWN", "scrollRightChangeSelection",
"ctrl HOME", TableActions.CtrlHome.ID,
"ctrl END", TableActions.CtrlEnd.ID,
"ctrl shift PAGE_UP", "scrollRightExtendSelection",
"ctrl shift PAGE_DOWN", "scrollLeftExtendSelection",
"ctrl shift HOME", TableActions.CtrlShiftHome.ID,
"ctrl shift END", TableActions.CtrlShiftEnd.ID,
"TAB", "selectNextColumnCell",
"shift TAB", "selectPreviousColumnCell", //"ENTER", "selectNextRowCell",
"shift ENTER", "selectPreviousRowCell",
"ctrl A", "selectAll", //"ESCAPE", "cancel",
"F2", "startEditing"
))
}
}
fun fillFallbackDefaults(defaults: UIDefaults) {
// These icons are only needed to prevent Swing from trying to fetch defaults with AWT ImageFetcher threads (IDEA-322089),
// but might as well just put something sensibly-looking there, just in case they show up due to some bug:
val folderIcon = createLazyValue(Supplier { AllIcons.Nodes.Folder })
defaults["Tree.openIcon"] = folderIcon
defaults["Tree.closedIcon"] = folderIcon
defaults["Tree.leafIcon"] = createLazyValue(Supplier { AllIcons.FileTypes.Any_type })
// These two are actually set by our themes, so we don't want to override them here:
//defaults.put("Tree.expandedIcon", AllIcons.Toolbar.Expand);
//defaults.put("Tree.collapsedIcon", AllIcons.Actions.ArrowExpand);
}
private fun createLazyValue(supplier: Supplier<Any>): UIDefaults.LazyValue {
return UIDefaults.LazyValue { supplier.get() }
defaults.putAll(customFontDefaults)
}
}
}
private val TOOLTIP_BACKGROUND_COLOR = ColorUIResource(255, 255, 231)
@Suppress("UseDPIAwareInsets", "UseJBColor")
private fun initIdeaDefaults(defaults: UIDefaults) {
defaults["Menu.maxGutterIconWidth"] = 18
defaults["MenuItem.maxGutterIconWidth"] = 18
// TODO[vova,anton] REMOVE!!! INVESTIGATE??? Borland???
defaults["MenuItem.acceleratorDelimiter"] = "-"
defaults["TitledBorder.titleColor"] = ColorUIResource(10, 36, 106)
val colorUiResource = ColorUIResource(230, 230, 230)
defaults["ScrollBar.background"] = colorUiResource
defaults["ScrollBar.track"] = colorUiResource
defaults["TextField.border"] = createLazyValue { BegBorders.getTextFieldBorder() }
defaults["PasswordField.border"] = createLazyValue { BegBorders.getTextFieldBorder() }
defaults["PopupMenu.border"] = createLazyValue { BegPopupMenuBorder() }
defaults["ScrollPane.border"] = createLazyValue { BegBorders.getScrollPaneBorder() }
defaults["ToggleButtonUI"] = createLazyValue { BegToggleButtonUI::class.java.getName() }
defaults["RadioButtonUI"] = createLazyValue { BegRadioButtonUI::class.java.getName() }
defaults["TabbedPaneUI"] = createLazyValue { BegTabbedPaneUI::class.java.getName() }
defaults["TableUI"] = createLazyValue { BegTableUI::class.java.getName() }
defaults["TreeUI"] = createLazyValue { BegTreeUI::class.java.getName() }
defaults["TabbedPane.tabInsets"] = Insets(0, 4, 0, 4)
defaults["ToolTip.background"] = TOOLTIP_BACKGROUND_COLOR
defaults["ToolTip.border"] = ColoredSideBorder(Color.gray, Color.gray, Color.black, Color.black, 1)
defaults["Tree.ancestorInputMap"] = null
defaults["FileView.directoryIcon"] = createLazyValue { AllIcons.Nodes.Folder }
defaults["FileChooser.upFolderIcon"] = createLazyValue { AllIcons.Nodes.UpFolder }
defaults["FileChooser.newFolderIcon"] = createLazyValue { AllIcons.Nodes.Folder }
defaults["FileChooser.homeFolderIcon"] = createLazyValue { AllIcons.Nodes.HomeFolder }
defaults["OptionPane.errorIcon"] = createLazyValue { AllIcons.General.ErrorDialog }
defaults["OptionPane.informationIcon"] = createLazyValue { AllIcons.General.InformationDialog }
defaults["OptionPane.warningIcon"] = createLazyValue { AllIcons.General.WarningDialog }
defaults["OptionPane.questionIcon"] = createLazyValue { AllIcons.General.QuestionDialog }
defaults["Table.ancestorInputMap"] = UIDefaults.LazyValue {
MetalLookAndFeel.makeInputMap(arrayOf<Any>(
"ctrl C", "copy",
"ctrl V", "paste",
"ctrl X", "cut",
"COPY", "copy",
"PASTE", "paste",
"CUT", "cut",
"control INSERT", "copy",
"shift INSERT", "paste",
"shift DELETE", "cut",
"RIGHT", TableActions.Right.ID,
"KP_RIGHT", TableActions.Right.ID,
"LEFT", TableActions.Left.ID,
"KP_LEFT", TableActions.Left.ID,
"DOWN", TableActions.Down.ID,
"KP_DOWN", TableActions.Down.ID,
"UP", TableActions.Up.ID,
"KP_UP", TableActions.Up.ID,
"shift RIGHT", TableActions.ShiftRight.ID,
"shift KP_RIGHT", TableActions.ShiftRight.ID,
"shift LEFT", TableActions.ShiftLeft.ID,
"shift KP_LEFT", TableActions.ShiftLeft.ID,
"shift DOWN", TableActions.ShiftDown.ID,
"shift KP_DOWN", TableActions.ShiftDown.ID,
"shift UP", TableActions.ShiftUp.ID,
"shift KP_UP", TableActions.ShiftUp.ID,
"PAGE_UP", TableActions.PageUp.ID,
"PAGE_DOWN", TableActions.PageDown.ID,
"HOME", "selectFirstColumn",
"END", "selectLastColumn",
"shift PAGE_UP", TableActions.ShiftPageUp.ID,
"shift PAGE_DOWN", TableActions.ShiftPageDown.ID,
"shift HOME", "selectFirstColumnExtendSelection",
"shift END", "selectLastColumnExtendSelection",
"ctrl PAGE_UP", "scrollLeftChangeSelection",
"ctrl PAGE_DOWN", "scrollRightChangeSelection",
"ctrl HOME", TableActions.CtrlHome.ID,
"ctrl END", TableActions.CtrlEnd.ID,
"ctrl shift PAGE_UP", "scrollRightExtendSelection",
"ctrl shift PAGE_DOWN", "scrollLeftExtendSelection",
"ctrl shift HOME", TableActions.CtrlShiftHome.ID,
"ctrl shift END", TableActions.CtrlShiftEnd.ID,
"TAB", "selectNextColumnCell",
"shift TAB", "selectPreviousColumnCell", //"ENTER", "selectNextRowCell",
"shift ENTER", "selectPreviousRowCell",
"ctrl A", "selectAll", //"ESCAPE", "cancel",
"F2", "startEditing"
))
}
}
internal fun fillFallbackDefaults(defaults: UIDefaults) {
// These icons are only needed to prevent Swing from trying to fetch defaults with AWT ImageFetcher threads (IDEA-322089),
// but might as well just put something sensibly-looking there, just in case they show up due to some bug:
val folderIcon = createLazyValue { AllIcons.Nodes.Folder }
defaults["Tree.openIcon"] = folderIcon
defaults["Tree.closedIcon"] = folderIcon
defaults["Tree.leafIcon"] = createLazyValue { AllIcons.FileTypes.Any_type }
// Our themes actually set these two, so we don't want to override them here:
//defaults.put("Tree.expandedIcon", AllIcons.Toolbar.Expand);
//defaults.put("Tree.collapsedIcon", AllIcons.Actions.ArrowExpand);
}
private inline fun createLazyValue(crossinline supplier: () -> Any): UIDefaults.LazyValue {
return UIDefaults.LazyValue { supplier() }
}

View File

@@ -611,7 +611,7 @@ class LafManagerImpl(private val coroutineScope: CoroutineScope) : LafManager(),
private fun doSetLaF(lookAndFeelInfo: LookAndFeelInfo, installEditorScheme: Boolean): Boolean {
val defaults = UIManager.getDefaults()
defaults.clear()
IdeaLaf.fillFallbackDefaults(defaults)
fillFallbackDefaults(defaults)
defaults.putAll(ourDefaults)
if (!isFirstSetup) {
colorPatcherProvider = null
@@ -625,9 +625,6 @@ class LafManagerImpl(private val coroutineScope: CoroutineScope) : LafManager(),
try {
UIManager.setLookAndFeel(laf)
AppUIUtil.updateForDarcula(true)
//if (lafNameOrder.containsKey(lookAndFeelInfo.getName())) {
// updateIconsUnderSelection(true);
//}
}
catch (e: Exception) {
LOG.error(e)

View File

@@ -1945,7 +1945,7 @@ public final class UIUtil {
}
}
catch (Throwable e) {
// this might happen e.g. if we're running under newer runtime, forbidding access to sun.font package
// this might happen e.g., if we're running under newer runtime, forbidding access to sun.font package
getLogger().warn(e);
// this might not give the same result, but we have no choice here
return StartupUiUtil.getFontWithFallback(font.getFamily(), font.getStyle(), font.getSize());
@@ -1958,10 +1958,6 @@ public final class UIUtil {
return StartupUiUtil.getFontWithFallback(familyName, style, size);
}
public static @NotNull FontUIResource getFontWithFallback(@Nullable String familyName, @JdkConstants.FontStyle int style, float size) {
return StartupUiUtil.getFontWithFallback(familyName, style, size);
}
//Escape error-prone HTML data (if any) when we use it in renderers, see IDEA-170768
public static <T> T htmlInjectionGuard(T toRender) {
if (toRender instanceof String && Strings.toLowerCase((String)toRender).startsWith("<html>")) {