From 1cf769a6dd737433bd2051552312ff602f6bdf99 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 6 Apr 2011 18:39:59 +0200 Subject: [PATCH] empty advertiser tweaks --- .../codeInsight/lookup/impl/Advertiser.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/Advertiser.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/Advertiser.java index ec00c14336d9..dbb308326d3c 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/Advertiser.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/Advertiser.java @@ -38,11 +38,17 @@ public class Advertiser { private final JPanel myComponent = new JPanel(new GridBagLayout()) { @Override public Dimension getPreferredSize() { - Dimension sup = super.getPreferredSize(); + List texts = getTexts(); + if (texts.isEmpty()) { + return new Dimension(-1, 0); + } + int maxSize = 0; - for (JLabel label : getTexts()) { + for (JLabel label : texts) { maxSize = Math.max(maxSize, label.getPreferredSize().width); } + + Dimension sup = super.getPreferredSize(); return new Dimension(maxSize + sup.width - myTextPanel.getPreferredSize().width, sup.height); } }; @@ -87,7 +93,8 @@ public class Advertiser { } public void showRandomText() { - myCurrentItem = new Random().nextInt(myTexts.size()); + int count = myTexts.size(); + myCurrentItem = count > 0 ? new Random().nextInt(count) : 0; updateAdvertisements(); }