ensure that non-customized lookup items have identical icon height (16) so that the lookup height remains constant while typing

This commit is contained in:
peter
2010-04-12 19:31:20 +04:00
parent 98b3f5b983
commit 9cc579cd4d
3 changed files with 50 additions and 9 deletions
@@ -19,6 +19,7 @@ import com.intellij.openapi.util.Iconable;
import com.intellij.psi.PsiElement;
import com.intellij.psi.meta.PsiMetaData;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.ui.TruncatingIcon;
import com.intellij.util.Icons;
import com.intellij.util.ui.EmptyIcon;
import org.jetbrains.annotations.Nullable;
@@ -44,6 +45,15 @@ public class DefaultLookupItemRenderer extends LookupElementRenderer<LookupItem>
@Nullable
public static Icon getRawIcon(final LookupItem item, boolean real) {
final Icon icon = _getRawIcon(item, real);
if (icon != null && icon.getIconHeight() > SAMPLE_ICON.getIconHeight()) {
return new TruncatingIcon(icon, icon.getIconWidth(), SAMPLE_ICON.getIconHeight());
}
return icon;
}
@Nullable
private static Icon _getRawIcon(LookupItem item, boolean real) {
Icon icon = (Icon)item.getAttribute(LookupItem.ICON_ATTR);
if (icon != null) return icon;
@@ -73,7 +83,7 @@ public class DefaultLookupItemRenderer extends LookupElementRenderer<LookupItem>
}
return null;
}
@Nullable
private static String getText3(final LookupItem item) {
@@ -25,7 +25,7 @@ import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.colors.EditorFontType;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.RowIcon;
import com.intellij.ui.LayeredIcon;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.ui.popup.PopupIcons;
@@ -280,11 +280,11 @@ public class LookupCellRenderer implements ListCellRenderer {
return myEmptyIcon;
}
if (icon.getIconWidth() < myEmptyIcon.getIconWidth()) {
final RowIcon rowIcon = new RowIcon(2);
rowIcon.setIcon(icon, 0);
rowIcon.setIcon(new EmptyIcon(myEmptyIcon.getIconWidth() - icon.getIconWidth()), 1);
return rowIcon;
if (icon.getIconHeight() < myEmptyIcon.getIconHeight() || icon.getIconWidth() < myEmptyIcon.getIconWidth()) {
final LayeredIcon layeredIcon = new LayeredIcon(2);
layeredIcon.setIcon(icon, 0, 0, (myEmptyIcon.getIconHeight() - icon.getIconHeight()) / 2);
layeredIcon.setIcon(myEmptyIcon, 1);
return layeredIcon;
}
return icon;
@@ -294,8 +294,8 @@ public class LookupCellRenderer implements ListCellRenderer {
final LookupElementPresentation p = new LookupElementPresentation();
item.renderElement(p);
final Icon icon = p.getIcon();
if (icon != null && icon.getIconWidth() > myEmptyIcon.getIconWidth()) {
myEmptyIcon = new EmptyIcon(icon.getIconWidth(), 2);
if (icon != null && (icon.getIconWidth() > myEmptyIcon.getIconWidth() || icon.getIconHeight() > myEmptyIcon.getIconHeight())) {
myEmptyIcon = new EmptyIcon(Math.max(icon.getIconWidth(), myEmptyIcon.getIconWidth()), Math.max(icon.getIconHeight(), myEmptyIcon.getIconHeight()));
}
int maxWidth = Math.min(RealLookupElementPresentation.calculateWidth(p, myNormalMetrics, myBoldMetrics), myMaxWidth);
@@ -0,0 +1,31 @@
package com.intellij.ui;
import javax.swing.*;
import java.awt.*;
/**
* @author peter
*/
public class TruncatingIcon implements Icon {
private final int myWidth;
private final int myHeight;
private final Icon myDelegate;
public TruncatingIcon(Icon delegate, int width, int height) {
myDelegate = delegate;
myWidth = width;
myHeight = height;
}
public void paintIcon(Component c, Graphics g, int x, int y) {
myDelegate.paintIcon(c, g, x, y);
}
public int getIconWidth() {
return myWidth;
}
public int getIconHeight() {
return myHeight;
}
}