From 4af2e12b66baae69283f7c3ca95f2734ab222a55 Mon Sep 17 00:00:00 2001 From: Alexander Zolotov Date: Mon, 7 May 2018 16:24:21 +0300 Subject: [PATCH] Do not initialize icons while running the application --- .../intellij/lang/regexp/RegExpFileType.java | 11 +++--- .../EnforcedPlainTextFileTypeFactory.java | 36 ++++++++----------- .../exclude/ui/MarkAsPlainTextAction.java | 18 ++-------- 3 files changed, 23 insertions(+), 42 deletions(-) diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpFileType.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpFileType.java index d596ea991da1..814e5df82586 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/RegExpFileType.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpFileType.java @@ -18,6 +18,7 @@ package org.intellij.lang.regexp; import com.intellij.icons.AllIcons; import com.intellij.lang.Language; import com.intellij.openapi.fileTypes.LanguageFileType; +import com.intellij.openapi.util.IconLoader; import com.intellij.ui.LayeredIcon; import icons.RegExpSupportIcons; import org.jetbrains.annotations.NonNls; @@ -33,10 +34,12 @@ public class RegExpFileType extends LanguageFileType { private RegExpFileType() { super(RegExpLanguage.INSTANCE); - - myIcon = new LayeredIcon(2); - ((LayeredIcon)myIcon).setIcon(AllIcons.FileTypes.Text, 0); - ((LayeredIcon)myIcon).setIcon(RegExpSupportIcons.Regexp_filetype_icon, 1); + myIcon = new IconLoader.LazyIcon() { + @Override + protected Icon compute() { + return new LayeredIcon(AllIcons.FileTypes.Text, RegExpSupportIcons.Regexp_filetype_icon); + } + }; } public RegExpFileType(@NotNull Language language) { diff --git a/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeFactory.java b/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeFactory.java index 8b15031a560f..c12f3350922d 100644 --- a/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeFactory.java +++ b/platform/lang-impl/src/com/intellij/openapi/file/exclude/EnforcedPlainTextFileTypeFactory.java @@ -1,24 +1,11 @@ -/* - * Copyright 2000-2015 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.openapi.file.exclude; import com.intellij.icons.AllIcons; import com.intellij.openapi.fileTypes.FileTypeConsumer; import com.intellij.openapi.fileTypes.FileTypeFactory; import com.intellij.openapi.fileTypes.ex.FileTypeIdentifiableByVirtualFile; +import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.LayeredIcon; import com.intellij.util.PlatformIcons; @@ -31,13 +18,18 @@ import javax.swing.*; * @author Rustam Vishnyakov */ public class EnforcedPlainTextFileTypeFactory extends FileTypeFactory { - public static final LayeredIcon ENFORCED_PLAIN_TEXT_ICON = new LayeredIcon(2); - public static final String ENFORCED_PLAIN_TEXT = "Enforced Plain Text"; + /** + * @deprecated use {@link #ENFORCED_PLAIN_TEXT_ICON_2} instead + */ + public static final LayeredIcon ENFORCED_PLAIN_TEXT_ICON = new LayeredIcon(); - static { - ENFORCED_PLAIN_TEXT_ICON.setIcon(AllIcons.FileTypes.Text, 0); - ENFORCED_PLAIN_TEXT_ICON.setIcon(PlatformIcons.EXCLUDED_FROM_COMPILE_ICON, 1); - } + public static final Icon ENFORCED_PLAIN_TEXT_ICON_2 = new IconLoader.LazyIcon() { + @Override + protected Icon compute() { + return new LayeredIcon(AllIcons.FileTypes.Text, PlatformIcons.EXCLUDED_FROM_COMPILE_ICON); + } + }; + public static final String ENFORCED_PLAIN_TEXT = "Enforced Plain Text"; private final FileTypeIdentifiableByVirtualFile myFileType; @@ -69,7 +61,7 @@ public class EnforcedPlainTextFileTypeFactory extends FileTypeFactory { @Override public Icon getIcon() { - return ENFORCED_PLAIN_TEXT_ICON; + return ENFORCED_PLAIN_TEXT_ICON_2; } @Override diff --git a/platform/lang-impl/src/com/intellij/openapi/file/exclude/ui/MarkAsPlainTextAction.java b/platform/lang-impl/src/com/intellij/openapi/file/exclude/ui/MarkAsPlainTextAction.java index 2036520134f4..c0353f8ba07d 100644 --- a/platform/lang-impl/src/com/intellij/openapi/file/exclude/ui/MarkAsPlainTextAction.java +++ b/platform/lang-impl/src/com/intellij/openapi/file/exclude/ui/MarkAsPlainTextAction.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2011 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.openapi.file.exclude.ui; import com.intellij.openapi.actionSystem.AnActionEvent; @@ -51,7 +37,7 @@ public class MarkAsPlainTextAction extends DumbAwareAction { .filter(file -> isApplicableFor(file) && !typeManager.isMarkedAsPlainText(file)); boolean enabled = e.getProject() != null && !selectedFiles.isEmpty(); e.getPresentation().setEnabledAndVisible(enabled); - e.getPresentation().setIcon(EnforcedPlainTextFileTypeFactory.ENFORCED_PLAIN_TEXT_ICON); + e.getPresentation().setIcon(EnforcedPlainTextFileTypeFactory.ENFORCED_PLAIN_TEXT_ICON_2); } }