diff --git a/java/java-impl/src/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsDialog.java b/java/java-impl/src/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsDialog.java index 37a641c1063c..1c6b36c5d53f 100644 --- a/java/java-impl/src/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsDialog.java +++ b/java/java-impl/src/com/intellij/refactoring/encapsulateFields/EncapsulateFieldsDialog.java @@ -626,7 +626,7 @@ public String getAccessorsVisibility() { private static final Icon OVERRIDING_METHOD_ICON = IconLoader.getIcon("/general/overridingMethod.png"); private static final Icon IMPLEMENTING_METHOD_ICON = IconLoader.getIcon("/general/implementingMethod.png"); - private static final Icon EMPTY_OVERRIDE_ICON = new EmptyIcon(16, 16); + private static final Icon EMPTY_OVERRIDE_ICON = EmptyIcon.ICON_16; private class MyTableRenderer extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, final Object value, diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/DefaultLookupItemRenderer.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/DefaultLookupItemRenderer.java index 02e7ef4b71b2..7884fbad8394 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/DefaultLookupItemRenderer.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/DefaultLookupItemRenderer.java @@ -64,7 +64,7 @@ public class DefaultLookupItemRenderer extends LookupElementRenderer int flags = Iconable.ICON_FLAG_VISIBILITY; if (!real) { if (item.getObject() instanceof String) { - return new EmptyIcon(0, 0); + return EmptyIcon.ICON_0; } return new EmptyIcon(SAMPLE_ICON.getIconWidth() * 2, SAMPLE_ICON.getIconHeight()); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java index 190a586c88f4..771e1a777742 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java @@ -39,7 +39,7 @@ import javax.swing.border.EmptyBorder; import java.awt.*; public class LookupCellRenderer implements ListCellRenderer { - private Icon myEmptyIcon = new EmptyIcon(5); + private Icon myEmptyIcon = EmptyIcon.create(5); private final Font NORMAL_FONT; private final Font BOLD_FONT; private final FontMetrics myNormalMetrics; diff --git a/platform/lang-impl/src/com/intellij/codeInspection/actions/InspectionListCellRenderer.java b/platform/lang-impl/src/com/intellij/codeInspection/actions/InspectionListCellRenderer.java index c2a473f48d19..c5b3b82815c1 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/actions/InspectionListCellRenderer.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/actions/InspectionListCellRenderer.java @@ -27,7 +27,7 @@ import java.awt.*; */ @SuppressWarnings({"GtkPreferredJComboBoxRenderer"}) public class InspectionListCellRenderer extends DefaultListCellRenderer { - private static final EmptyIcon EMPTY_ICON = new EmptyIcon(18, 18); + private static final Icon EMPTY_ICON = EmptyIcon.ICON_18; public Component getListCellRendererComponent(JList list, Object value, int index, boolean sel, boolean focus) { final JPanel panel = new JPanel(new BorderLayout()); diff --git a/platform/lang-impl/src/com/intellij/execution/actions/EditRunConfigurationsAction.java b/platform/lang-impl/src/com/intellij/execution/actions/EditRunConfigurationsAction.java index c10e07febecd..6099f0201244 100644 --- a/platform/lang-impl/src/com/intellij/execution/actions/EditRunConfigurationsAction.java +++ b/platform/lang-impl/src/com/intellij/execution/actions/EditRunConfigurationsAction.java @@ -28,7 +28,7 @@ public class EditRunConfigurationsAction extends AnAction{ public EditRunConfigurationsAction() { LayeredIcon icon = new LayeredIcon(2); icon.setIcon(IconLoader.getIcon("/actions/editSource.png"),0,2,2); - icon.setIcon(new EmptyIcon(18), 1); + icon.setIcon(EmptyIcon.ICON_18, 1); getTemplatePresentation().setIcon(icon); } diff --git a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesTableCellRenderer.java b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesTableCellRenderer.java index b5e9d063ed9a..4eb93a10718c 100644 --- a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesTableCellRenderer.java +++ b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesTableCellRenderer.java @@ -32,6 +32,7 @@ import com.intellij.usages.impl.NullUsage; import com.intellij.usages.impl.UsageNode; import com.intellij.usages.impl.UsageViewImpl; import com.intellij.usages.rules.UsageInFile; +import com.intellij.util.ui.EmptyIcon; import com.intellij.util.ui.UIUtil; import javax.swing.*; @@ -55,8 +56,10 @@ class ShowUsagesTableCellRenderer implements TableCellRenderer { JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0,0)); Color fileBgColor = getBackgroundColor(isSelected, usage); - panel.setBackground(isSelected ? UIUtil.getListSelectionBackground() : fileBgColor == null ? list.getBackground() : fileBgColor); - panel.setForeground(isSelected ? UIUtil.getListSelectionForeground() : list.getForeground()); + final Color bg = UIUtil.getListSelectionBackground(); + final Color fg = UIUtil.getListSelectionForeground(); + panel.setBackground(isSelected ? bg : fileBgColor == null ? list.getBackground() : fileBgColor); + panel.setForeground(isSelected ? fg : list.getForeground()); if (usage == null) { panel.setLayout(new BorderLayout()); @@ -85,9 +88,11 @@ class ShowUsagesTableCellRenderer implements TableCellRenderer { TextChunk[] text = presentation.getText(); if (column == 1) { - textChunks.setIcon(presentation.getIcon()); + final Icon icon = presentation.getIcon(); + textChunks.setIcon(icon == null ? EmptyIcon.ICON_16 : icon); if (text.length != 0) { - SimpleTextAttributes attributes = + SimpleTextAttributes attributes = isSelected ? + new SimpleTextAttributes(bg, fg, fg, SimpleTextAttributes.STYLE_ITALIC) : deriveAttributesWithColor(SimpleTextAttributes.fromTextAttributes(text[0].getAttributes()), fileBgColor); textChunks.append(text[0].getText(), attributes); } @@ -96,8 +101,6 @@ class ShowUsagesTableCellRenderer implements TableCellRenderer { for (int i = 1; i < text.length; i++) { TextChunk textChunk = text[i]; final SimpleTextAttributes attrs = SimpleTextAttributes.fromTextAttributes(textChunk.getAttributes()); - final Color bg = UIUtil.getListSelectionBackground(); - final Color fg = UIUtil.getListSelectionForeground(); SimpleTextAttributes attributes = isSelected ? new SimpleTextAttributes(bg, fg, fg, attrs.getStyle()) : deriveAttributesWithColor(attrs, fileBgColor); textChunks.append(textChunk.getText(), attributes); diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java index ba6d60675e9e..b893b4b677b8 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java @@ -466,7 +466,7 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup if (closedIcon == null && openIcon != null) closedIcon = openIcon; if (openIcon == null && closedIcon != null) openIcon = closedIcon; if (openIcon == null) { - openIcon = closedIcon = new EmptyIcon(5, 5); + openIcon = closedIcon = EmptyIcon.create(5); } final MyItemLabel label = diff --git a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java index df826b1ca476..004fee80c9c3 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java +++ b/platform/lang-impl/src/com/intellij/ide/util/gotoByName/GotoActionModel.java @@ -45,7 +45,7 @@ public class GotoActionModel implements ChooseByNameModel, CustomMatcherModel { private final ActionManager myActionManager = ActionManager.getInstance(); - private static final EmptyIcon EMPTY_ICON = new EmptyIcon(18, 18); + private static final Icon EMPTY_ICON = EmptyIcon.ICON_18; private String myPattern; diff --git a/platform/lang-impl/src/com/intellij/refactoring/ui/AbstractMemberSelectionTable.java b/platform/lang-impl/src/com/intellij/refactoring/ui/AbstractMemberSelectionTable.java index 218aa029477b..dd8e442f1e70 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/ui/AbstractMemberSelectionTable.java +++ b/platform/lang-impl/src/com/intellij/refactoring/ui/AbstractMemberSelectionTable.java @@ -53,7 +53,7 @@ public abstract class AbstractMemberSelectionTable myMemberInfos; diff --git a/platform/lang-impl/src/com/intellij/ui/DeferredIconImpl.java b/platform/lang-impl/src/com/intellij/ui/DeferredIconImpl.java index 7b34748412d9..bfb60079a737 100644 --- a/platform/lang-impl/src/com/intellij/ui/DeferredIconImpl.java +++ b/platform/lang-impl/src/com/intellij/ui/DeferredIconImpl.java @@ -44,7 +44,7 @@ public class DeferredIconImpl implements DeferredIcon { private volatile boolean myIsScheduled = false; private T myParam; private WeakReference myLastTarget = null; - private static final EmptyIcon EMPTY_ICON = new EmptyIcon(16, 16); + private static final Icon EMPTY_ICON = EmptyIcon.ICON_16; private boolean myNeedReadAction; private boolean myDone; diff --git a/platform/lang-impl/src/com/intellij/ui/tabs/FileColorSettingsTable.java b/platform/lang-impl/src/com/intellij/ui/tabs/FileColorSettingsTable.java index 66ae80271e0a..03c811de1780 100644 --- a/platform/lang-impl/src/com/intellij/ui/tabs/FileColorSettingsTable.java +++ b/platform/lang-impl/src/com/intellij/ui/tabs/FileColorSettingsTable.java @@ -258,7 +258,7 @@ public abstract class FileColorSettingsTable extends StripeTable { myManager = manager; - setIcon(new EmptyIcon(16)); + setIcon(EmptyIcon.ICON_16); } private void setIconColor(final Color color) { diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/ActiveIcon.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/ActiveIcon.java index 633ecee05165..9cdfdd4671e8 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/ActiveIcon.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/ActiveIcon.java @@ -38,7 +38,7 @@ public class ActiveIcon implements Icon { } protected void setIcons(@Nullable final Icon regular, @Nullable final Icon inactive) { - myRegular = regular != null ? regular : new EmptyIcon(0); + myRegular = regular != null ? regular : EmptyIcon.ICON_0; myInactive = inactive != null ? inactive : myRegular; } diff --git a/platform/platform-api/src/com/intellij/ui/treeStructure/SimpleTree.java b/platform/platform-api/src/com/intellij/ui/treeStructure/SimpleTree.java index e468d675dc50..de8a8674e957 100644 --- a/platform/platform-api/src/com/intellij/ui/treeStructure/SimpleTree.java +++ b/platform/platform-api/src/com/intellij/ui/treeStructure/SimpleTree.java @@ -602,7 +602,7 @@ public class SimpleTree extends Tree implements CellEditorListener { public Icon getEmptyHandle() { if (myEmptyHandle == null) { final Icon expand = getExpandedHandle(); - myEmptyHandle = expand != null ? new EmptyIcon(expand) : new EmptyIcon(0, 0); + myEmptyHandle = expand != null ? new EmptyIcon(expand) : EmptyIcon.create(0); } return myEmptyHandle; diff --git a/platform/platform-api/src/com/intellij/util/IconUtil.java b/platform/platform-api/src/com/intellij/util/IconUtil.java index 58f0d465d810..9b4c3a7b13f9 100644 --- a/platform/platform-api/src/com/intellij/util/IconUtil.java +++ b/platform/platform-api/src/com/intellij/util/IconUtil.java @@ -158,7 +158,7 @@ public class IconUtil { private static Icon createEmptyIconLike(final String baseIconPath) { Icon baseIcon = IconLoader.findIcon(baseIconPath); if (baseIcon == null) { - return new EmptyIcon(16, 16); + return EmptyIcon.ICON_16; } return new EmptyIcon(baseIcon.getIconWidth(), baseIcon.getIconHeight()); } diff --git a/platform/platform-api/src/com/intellij/util/ui/AnimatedIcon.java b/platform/platform-api/src/com/intellij/util/ui/AnimatedIcon.java index d23a8677248f..29924c4110e6 100644 --- a/platform/platform-api/src/com/intellij/util/ui/AnimatedIcon.java +++ b/platform/platform-api/src/com/intellij/util/ui/AnimatedIcon.java @@ -80,7 +80,7 @@ public abstract class AnimatedIcon extends JComponent implements Disposable { if (icons.length > 0) { myEmptyPassiveIcon = new EmptyIcon(icons[0]); } else { - myEmptyPassiveIcon = new EmptyIcon(0); + myEmptyPassiveIcon = EmptyIcon.ICON_0; } setOpaque(false); diff --git a/platform/platform-impl/src/com/intellij/ide/actions/ShowFilePathAction.java b/platform/platform-impl/src/com/intellij/ide/actions/ShowFilePathAction.java index e48004da82af..fa2d1bd5b2b3 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/ShowFilePathAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/ShowFilePathAction.java @@ -110,7 +110,7 @@ public class ShowFilePathAction extends AnAction { eachIcon = FileSystemView.getFileSystemView().getSystemIcon(ioFile); } else { - eachIcon = new EmptyIcon(16, 16); + eachIcon = EmptyIcon.ICON_16; } icons.add(eachIcon); @@ -208,4 +208,4 @@ public class ShowFilePathAction extends AnAction { return PlatformDataKeys.VIRTUAL_FILE.getData(e.getDataContext()); } -} \ No newline at end of file +} diff --git a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.java b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.java index 7518435cd1c2..dca05d5c1783 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.java @@ -71,7 +71,7 @@ import java.util.Set; public class CustomizableActionsPanel { private static final Logger LOG = Logger.getInstance("#com.intellij.ide.ui.customization.CustomizableActionsPanel"); - private static final Icon EMPTY_ICON = new EmptyIcon(18, 18); + private static final Icon EMPTY_ICON = EmptyIcon.ICON_18; private static final Icon QUICK_LIST_ICON = IconLoader.getIcon("/actions/quickList.png"); diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionButton.java b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionButton.java index 59ac69bc1f17..416b9e8e0881 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionButton.java +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionButton.java @@ -36,7 +36,7 @@ import java.beans.PropertyChangeListener; public class ActionButton extends JComponent implements ActionButtonComponent { private static final Insets ICON_INSETS = new Insets(2, 2, 2, 2); - private static final Icon ourEmptyIcon = new EmptyIcon(18, 18); + private static final Icon ourEmptyIcon = EmptyIcon.ICON_18; private Dimension myMinimumButtonSize; private PropertyChangeListener myActionButtonSynchronizer; diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionMenuItem.java b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionMenuItem.java index 0c6593cb715a..376a6f59efba 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionMenuItem.java +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionMenuItem.java @@ -46,7 +46,7 @@ import java.util.Set; public class ActionMenuItem extends JMenuItem { private static final Icon ourCheckedIcon = new SizedIcon(Icons.CHECK_ICON, 18, 18); - private static final Icon ourUncheckedIcon = new EmptyIcon(18, 18); + private static final Icon ourUncheckedIcon = EmptyIcon.ICON_18; private final ActionRef myAction; private final Presentation myPresentation; diff --git a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeRenderer.java b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeRenderer.java index 6ef38d1db31a..e513445d0552 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeRenderer.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeRenderer.java @@ -25,7 +25,7 @@ import java.awt.*; import java.util.*; public class FileTypeRenderer extends DefaultListCellRenderer { - private static final Icon EMPTY_ICON = new EmptyIcon(18, 18); + private static final Icon EMPTY_ICON = EmptyIcon.ICON_18; private final FileTypeListProvider myFileTypeListProvider; diff --git a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/ui/ActionsTree.java b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/ui/ActionsTree.java index 9b03a41a3042..68badb04defa 100644 --- a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/ui/ActionsTree.java +++ b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/ui/ActionsTree.java @@ -48,7 +48,7 @@ import java.util.ArrayList; import java.util.Enumeration; public class ActionsTree { - private static final Icon EMPTY_ICON = new EmptyIcon(18, 18); + private static final Icon EMPTY_ICON = EmptyIcon.ICON_18; private static final Icon QUICK_LIST_ICON = IconLoader.getIcon("/actions/quickList.png"); private static final Icon OPEN_ICON = new DefaultTreeCellRenderer().getOpenIcon(); private static final Icon CLOSE_ICON = new DefaultTreeCellRenderer().getClosedIcon(); diff --git a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/ui/QuickListPanel.java b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/ui/QuickListPanel.java index cfd976b53876..5935584d8ee2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/ui/QuickListPanel.java +++ b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/ui/QuickListPanel.java @@ -44,7 +44,7 @@ import java.awt.event.*; import java.util.ArrayList; public class QuickListPanel { - private static final Icon EMPTY_ICON = new EmptyIcon(18, 18); + private static final Icon EMPTY_ICON = EmptyIcon.ICON_18; private static final Icon QUICK_LIST_ICON = IconLoader.getIcon("/actions/quickList.png"); private JButton myRemoveActionButton; @@ -372,4 +372,4 @@ public class QuickListPanel { return this; } } -} \ No newline at end of file +} diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java index 279bbbbed6ae..b4682ae2ae10 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java @@ -913,7 +913,7 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa public MyTitleButton(AnAction action) { myAction = action; - myButton = new InplaceButton(null, new EmptyIcon(16), this) { + myButton = new InplaceButton(null, EmptyIcon.ICON_16, this) { @Override public boolean isActive() { return MyTitleButton.this.isActive(); diff --git a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java index 573eeb4ab56e..3e647c932495 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java @@ -218,7 +218,7 @@ public class AbstractPopup implements JBPopup { myHeaderAlwaysFocusable = headerAlwaysFocusable; myMovable = movable; - ActiveIcon actualIcon = titleIcon == null ? new ActiveIcon(new EmptyIcon(0)) : titleIcon; + ActiveIcon actualIcon = titleIcon == null ? new ActiveIcon(EmptyIcon.ICON_0) : titleIcon; myHeaderPanel = new JPanel(new BorderLayout()); diff --git a/platform/platform-impl/src/com/intellij/ui/popup/ComponentPopupBuilderImpl.java b/platform/platform-impl/src/com/intellij/ui/popup/ComponentPopupBuilderImpl.java index 06d9e7466934..453ae0c539f6 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/ComponentPopupBuilderImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/ComponentPopupBuilderImpl.java @@ -57,7 +57,7 @@ public class ComponentPopupBuilderImpl implements ComponentPopupBuilder { private IconButton myCancelButton; private MouseChecker myCancelOnMouseOutCallback; private boolean myCancelOnWindow; - private ActiveIcon myTitleIcon = new ActiveIcon(new EmptyIcon(0)); + private ActiveIcon myTitleIcon = new ActiveIcon(EmptyIcon.ICON_0); private boolean myCancelKeyEnabled = true; private boolean myLocateByContent = false; private boolean myPlacewithinScreen = true; diff --git a/platform/util/src/com/intellij/util/ui/ColorIcon.java b/platform/util/src/com/intellij/util/ui/ColorIcon.java new file mode 100644 index 000000000000..32cbea9e4c81 --- /dev/null +++ b/platform/util/src/com/intellij/util/ui/ColorIcon.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2010 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. + */ +package com.intellij.util.ui; + +import org.jetbrains.annotations.NotNull; + +import java.awt.*; + +/** + * @author Konstantin Bulenkov + */ +public class ColorIcon extends EmptyIcon { + private final Color myColor; + + public ColorIcon(int size, @NotNull Color color) { + super(size, size); + myColor = color; + } + + public Color getIconColor() { + return myColor; + } + + @Override + public void paintIcon(final Component component, final Graphics g, final int i, final int j) { + final int iconWidth = getIconWidth(); + final int iconHeight = getIconHeight(); + g.setColor(getIconColor()); + g.fillRect(i, j, iconWidth, iconHeight); + } +} diff --git a/platform/util/src/com/intellij/util/ui/EmptyIcon.java b/platform/util/src/com/intellij/util/ui/EmptyIcon.java index 2090893ba38e..72bfd15505df 100644 --- a/platform/util/src/com/intellij/util/ui/EmptyIcon.java +++ b/platform/util/src/com/intellij/util/ui/EmptyIcon.java @@ -20,30 +20,56 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; +import java.util.HashMap; +/** + * @author max + * @author Konstantin Bulenkov + * + * @see com.intellij.util.ui.ColorIcon + */ public class EmptyIcon implements Icon { - private final int myWidth; - private final int myHeight; + private static final HashMap cache = new HashMap(); + public static final Icon ICON_16 = create(16); + public static final Icon ICON_18 = create(18); + public static final Icon ICON_8 = create(8); + public static final Icon ICON_0 = create(0); + private final int width; + private final int height; + + public static Icon create(int size) { + Icon icon = cache.get(size); + if (icon == null && size < 129) { + cache.put(size, icon = new EmptyIcon(size, size)); + } + return icon == null ? new EmptyIcon(size, size) : icon; + } + + /** + * @deprecated use EmptyIcon.create for caching + * + * @param size icon's size + */ public EmptyIcon(int size) { this(size, size); } public EmptyIcon(int width, int height) { - myWidth = width; - myHeight = height; + this.width = width; + this.height = height; } - public EmptyIcon(@NotNull Icon template) { - this(template.getIconWidth(), template.getIconHeight()); + public EmptyIcon(@NotNull Icon base) { + this(base.getIconWidth(), base.getIconHeight()); } public int getIconWidth() { - return myWidth; + return width; } public int getIconHeight() { - return myHeight; + return height; } public void paintIcon(Component component, Graphics g, int i, int j) { @@ -55,13 +81,14 @@ public class EmptyIcon implements Icon { final EmptyIcon icon = (EmptyIcon)o; - if (myHeight != icon.myHeight) return false; - if (myWidth != icon.myWidth) return false; + if (height != icon.height) return false; + if (width != icon.width) return false; return true; } public int hashCode() { - return myWidth + myHeight; + int sum = width + height; + return sum * (sum + 1)/2 + width; } } diff --git a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/LanguageReference.java b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/LanguageReference.java index 65b760e0d65a..1fd3dd69b22f 100644 --- a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/LanguageReference.java +++ b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/LanguageReference.java @@ -63,7 +63,7 @@ final class LanguageReference extends StringLiteralReference { // // IDEA-10012 // return new LanguageLookupValue(s, StdFileTypes.JSP.getIcon(), "Expression Language"); } - return LookupElementBuilder.create(s).setIcon(new EmptyIcon(16)); + return LookupElementBuilder.create(s).setIcon(EmptyIcon.ICON_16); } }); } diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectLanguageAction.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectLanguageAction.java index 20b7c449627d..448f70b5d99d 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectLanguageAction.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/inject/InjectLanguageAction.java @@ -129,7 +129,7 @@ public class InjectLanguageAction implements IntentionAction { final Language language = InjectedLanguage.findLanguageById(value); assert language != null; final FileType ft = language.getAssociatedFileType(); - setIcon(ft != null ? ft.getIcon() : new EmptyIcon(16)); + setIcon(ft != null ? ft.getIcon() : EmptyIcon.ICON_16); setText(value + (ft != null ? " (" + ft.getDescription() + ")" : "")); } }); diff --git a/plugins/android/src/org/jetbrains/android/AndroidColorAnnotator.java b/plugins/android/src/org/jetbrains/android/AndroidColorAnnotator.java index b7d705bcb540..0738bddb933a 100644 --- a/plugins/android/src/org/jetbrains/android/AndroidColorAnnotator.java +++ b/plugins/android/src/org/jetbrains/android/AndroidColorAnnotator.java @@ -28,6 +28,7 @@ import com.intellij.openapi.editor.markup.GutterIconRenderer; import com.intellij.psi.PsiElement; import com.intellij.psi.xml.XmlTag; import com.intellij.ui.ColorChooser; +import com.intellij.util.ui.ColorIcon; import com.intellij.util.ui.EmptyIcon; import com.intellij.util.xml.DomElement; import com.intellij.util.xml.DomManager; @@ -103,16 +104,8 @@ public class AndroidColorAnnotator implements Annotator { @NotNull @Override public Icon getIcon() { - return new EmptyIcon(ICON_SIZE) { - @Override - public void paintIcon(Component component, Graphics g, int i, int j) { - Color color = getCurrentColor(); - if (color != null) { - g.setColor(color); - g.fillRect(i, j, getIconWidth(), getIconHeight()); - } - } - }; + final Color color = getCurrentColor(); + return color == null ? EmptyIcon.create(ICON_SIZE) : new ColorIcon(ICON_SIZE, color); } // see android.graphics.Color#parseColor in android.jar library