From 74237fe6b0613dc1f05db1855b27da7fc376a6b7 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 7 May 2018 15:51:34 +0200 Subject: [PATCH] IDEA-CR-32392 LafIconLookup.getIcon should be not always strict --- .../src/com/intellij/util/ui/LafIconLookup.kt | 18 ++++++++++++++--- .../ide/ui/laf/darcula/DarculaLaf.java | 2 +- .../laf/intellij/WinIntelliJTextFieldUI.java | 20 +++---------------- .../testSrc/com/intellij/ui/SvgRenderer.kt | 5 +++-- .../com/intellij/openapi/util/IconLoader.java | 14 +++++++++++-- 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/platform/platform-api/src/com/intellij/util/ui/LafIconLookup.kt b/platform/platform-api/src/com/intellij/util/ui/LafIconLookup.kt index bffe906f76b2..f2520fe50a0b 100644 --- a/platform/platform-api/src/com/intellij/util/ui/LafIconLookup.kt +++ b/platform/platform-api/src/com/intellij/util/ui/LafIconLookup.kt @@ -2,7 +2,9 @@ package com.intellij.util.ui import com.intellij.icons.AllIcons +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.util.IconLoader +import com.intellij.util.ThreeState import javax.swing.Icon /** @@ -12,11 +14,11 @@ object LafIconLookup { @JvmStatic @JvmOverloads fun getIcon(name: String, selected: Boolean = false, focused: Boolean = false, enabled: Boolean = true, editable: Boolean = false, pressed: Boolean = false): Icon { - return findIcon(name, selected = selected, focused = focused, enabled = enabled, editable = editable, pressed = pressed, isThrowErrorIfNotFound = true) + return findIcon(name, selected = selected, focused = focused, enabled = enabled, editable = editable, pressed = pressed) ?: AllIcons.Actions.Stub } - fun findIcon(name: String, selected: Boolean = false, focused: Boolean = false, enabled: Boolean = true, editable: Boolean = false, pressed: Boolean = false, isThrowErrorIfNotFound: Boolean = false): Icon? { + fun findIcon(name: String, selected: Boolean = false, focused: Boolean = false, enabled: Boolean = true, editable: Boolean = false, pressed: Boolean = false, isThrowErrorIfNotFound: ThreeState = ThreeState.UNSURE): Icon? { var key = name if (editable) key += "Editable" if (selected) key += "Selected" @@ -37,7 +39,17 @@ object LafIconLookup { } key = dir + key - return IconLoader.findIcon("/com/intellij/ide/ui/laf/icons/$key.png", LafIconLookup::class.java, true, isThrowErrorIfNotFound) + @Suppress("DEPRECATION") + return IconLoader.findIcon("/com/intellij/ide/ui/laf/icons/$key.png", LafIconLookup::class.java, resolveIsThrowErrorIfNotFound(isThrowErrorIfNotFound)) + } + + private fun resolveIsThrowErrorIfNotFound(value: ThreeState): Boolean { + if (value != ThreeState.UNSURE) { + return value == ThreeState.YES + } + + val app = ApplicationManager.getApplication() + return app.isUnitTestMode || app.isInternal } @JvmStatic diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java index d447bc367553..e013bac997d2 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaLaf.java @@ -362,7 +362,7 @@ public class DarculaLaf extends BasicLookAndFeel { } if (value.endsWith(".png") || value.endsWith(".svg")) { - Icon icon = IconLoader.findIcon(value, DarculaLaf.class, true); + Icon icon = IconLoader.findIcon(value, DarculaLaf.class); if (icon != null) { return icon; } diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJTextFieldUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJTextFieldUI.java index 1296c7dc2d10..ba19f2c64b74 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJTextFieldUI.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/intellij/WinIntelliJTextFieldUI.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.ui.laf.intellij; import com.intellij.ide.ui.laf.darcula.DarculaUIUtil; @@ -140,7 +126,7 @@ public class WinIntelliJTextFieldUI extends TextFieldWithPopupHandlerUI { } }; } - return icon != null ? icon : IconLoader.findIcon("/com/intellij/ide/ui/laf/icons/search.png", DarculaTextFieldUI.class, true); + return icon != null ? icon : IconLoader.findIcon("/com/intellij/ide/ui/laf/icons/search.png", DarculaTextFieldUI.class); } @Override @@ -152,7 +138,7 @@ public class WinIntelliJTextFieldUI extends TextFieldWithPopupHandlerUI { protected Icon getClearIcon(boolean hovered, boolean clickable) { if (!clickable) return null; Icon icon = UIManager.getIcon("TextField.darcula.clear.icon"); - return icon != null ? icon : IconLoader.findIcon("/com/intellij/ide/ui/laf/icons/clear.png", DarculaTextFieldUI.class, true); + return icon != null ? icon : IconLoader.findIcon("/com/intellij/ide/ui/laf/icons/clear.png", DarculaTextFieldUI.class); } @Override diff --git a/platform/platform-tests/testSrc/com/intellij/ui/SvgRenderer.kt b/platform/platform-tests/testSrc/com/intellij/ui/SvgRenderer.kt index 9bcc75b659e9..6216cb3524e5 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/SvgRenderer.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/SvgRenderer.kt @@ -8,6 +8,7 @@ import com.intellij.openapi.util.SystemInfoRt import com.intellij.openapi.util.io.FileUtilRt import com.intellij.openapi.util.text.StringUtilRt import com.intellij.testFramework.assertions.Assertions.assertThat +import com.intellij.util.ThreeState import com.intellij.util.ui.LafIconLookup import gnu.trove.THashMap import org.apache.batik.anim.dom.SVGDOMImplementation @@ -58,7 +59,7 @@ internal class SvgRenderer(val svgFileDir: Path, private val deviceConfiguration for (name in arrayOf("checkBox", "radio", "gear", "spinnerRight")) { val iconWrapper = when (name) { "gear" -> IconLoader.getIcon("/general/gear.png") - else -> LafIconLookup.findIcon(name) + else -> LafIconLookup.findIcon(name, isThrowErrorIfNotFound = ThreeState.NO) } ?: continue if (isImage(iconWrapper)) { @@ -66,7 +67,7 @@ internal class SvgRenderer(val svgFileDir: Path, private val deviceConfiguration } } for (name in arrayOf("checkBox", "radio")) { - val iconWrapper = LafIconLookup.findIcon(name, selected = true) ?: continue + val iconWrapper = LafIconLookup.findIcon(name, selected = true, isThrowErrorIfNotFound = ThreeState.NO) ?: continue if (isImage(iconWrapper)) { return getIconRelativePath(iconWrapper.toString()) } diff --git a/platform/util/src/com/intellij/openapi/util/IconLoader.java b/platform/util/src/com/intellij/openapi/util/IconLoader.java index 3aba9bc3056a..94518000157e 100644 --- a/platform/util/src/com/intellij/openapi/util/IconLoader.java +++ b/platform/util/src/com/intellij/openapi/util/IconLoader.java @@ -168,16 +168,26 @@ public final class IconLoader { */ @Nullable public static Icon findIcon(@NotNull final String path, @NotNull final Class aClass) { - return findIcon(path, aClass, false); + //noinspection deprecation + return findIcon(path, aClass, false, STRICT); } + /** + * @deprecated Use {@link #findIcon(String, Class)} + */ @Nullable + @Deprecated public static Icon findIcon(@NotNull String path, @NotNull final Class aClass, boolean computeNow) { return findIcon(path, aClass, computeNow, STRICT); } + /** + * @deprecated Use {@link #findIcon(String, Class)} + */ + @SuppressWarnings("DeprecatedIsStillUsed") @Nullable - public static Icon findIcon(@NotNull String path, @NotNull Class aClass, boolean computeNow, boolean strict) { + @Deprecated + public static Icon findIcon(@NotNull String path, @NotNull Class aClass, @SuppressWarnings("unused") boolean unused, boolean strict) { String originalPath = path; Pair patchedPath = patchPath(path); path = patchedPath.first;