fix renderer cosmetics (focus border) and popup width

This commit is contained in:
Konstantin Bulenkov
2011-09-20 18:05:43 +02:00
parent 9a856b703d
commit 19ea755d95
2 changed files with 18 additions and 6 deletions
@@ -63,7 +63,7 @@ public class GotoRelatedFileAction extends AnAction {
if (ApplicationManager.getApplication().isUnitTestMode()) {
System.out.println(items);
}
createPopup(items, "Goto Related").showInBestPositionFor(context);
createPopup(items, "Go to Related Files").showInBestPositionFor(context);
}
public static JBPopup createPopup(final List<? extends GotoRelatedItem> items, final String title) {
@@ -77,6 +77,10 @@ public class GotoRelatedFileAction extends AnAction {
}
return getPsiElementPopup(elements, new DefaultPsiElementCellRenderer() {
{
setFocusBorderEnabled(false);
}
@Override
public String getElementText(PsiElement element) {
String customName = itemsMap.get(element).getCustomName();
@@ -92,7 +96,9 @@ public class GotoRelatedFileAction extends AnAction {
@Override
public String getContainerText(PsiElement element, String name) {
PsiFile file = element.getContainingFile();
return file != null && !getElementText(element).equals(file.getName()) ? "(" + file.getName() + ")" : null;
return file != null && !getElementText(element).equals(file.getName())
? "(" + file.getName() + ")"
: null;
}
@Override
@@ -122,7 +128,8 @@ public class GotoRelatedFileAction extends AnAction {
if (element instanceof PsiElement) {
//noinspection SuspiciousMethodCalls
itemsMap.get(element).navigate();
} else {
}
else {
((GotoRelatedItem)element).navigate();
}
return true;
@@ -132,7 +139,7 @@ public class GotoRelatedFileAction extends AnAction {
}
public static JBPopup getPsiElementPopup(final Object[] elements, final PsiElementListCellRenderer<PsiElement> renderer,
final String title, final Processor<Object> processor) {
final String title, final Processor<Object> processor) {
final JList list = new JBList(elements);
list.setCellRenderer(renderer);
@@ -153,7 +160,7 @@ public class GotoRelatedFileAction extends AnAction {
builder.setTitle(title);
}
renderer.installSpeedSearch(builder, true);
builder.setMinSize(new Dimension(200, -1));
return builder.setItemChoosenCallback(runnable).createPopup();
}
@@ -51,6 +51,7 @@ import java.util.Comparator;
public abstract class PsiElementListCellRenderer<T extends PsiElement> extends JPanel implements ListCellRenderer, MatcherHolder {
private Matcher myMatcher;
private boolean myFocusBorderEnabled = true;
protected PsiElementListCellRenderer() {
super(new BorderLayout());
@@ -118,7 +119,7 @@ public abstract class PsiElementListCellRenderer<T extends PsiElement> extends J
setIcon(IconUtil.getEmptyIcon(false));
append(value == null ? "" : value.toString(), new SimpleTextAttributes(Font.PLAIN, list.getForeground()));
}
setPaintFocusBorder(hasFocus && UIUtil.isToUseDottedCellBorder());
setPaintFocusBorder(hasFocus && UIUtil.isToUseDottedCellBorder() && myFocusBorderEnabled);
setBackground(selected ? UIUtil.getListSelectionBackground() : bgColor);
}
@@ -160,6 +161,10 @@ public abstract class PsiElementListCellRenderer<T extends PsiElement> extends J
return this;
}
protected void setFocusBorderEnabled(boolean enabled) {
myFocusBorderEnabled = enabled;
}
protected boolean customizeNonPsiElementLeftRenderer(ColoredListCellRenderer renderer,
JList list,
Object value,