SwingHelper: wrapWithInfoButton added, get rid of warnings
authorSergey Simonchik <sergey.simonchik@jetbrains.com>
Thu, 21 May 2015 14:15:46 +0000 (17:15 +0300)
committerSergey Simonchik <sergey.simonchik@jetbrains.com>
Thu, 21 May 2015 14:15:46 +0000 (17:15 +0300)
platform/platform-impl/src/com/intellij/util/ui/SwingHelper.java

index a32625a0187871f9b0cbe22d27bb891e2f2307da..ee4adc19a472914e0a9b10331211412841f0880e 100644 (file)
@@ -25,10 +25,7 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptor;
 import com.intellij.openapi.fileChooser.FileChooserFactory;
 import com.intellij.openapi.ide.CopyPasteManager;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.ComponentWithBrowseButton;
-import com.intellij.openapi.ui.DialogWrapper;
-import com.intellij.openapi.ui.TextComponentAccessor;
-import com.intellij.openapi.ui.TextFieldWithBrowseButton;
+import com.intellij.openapi.ui.*;
 import com.intellij.openapi.util.SystemInfo;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.ui.HyperlinkLabel;
@@ -50,6 +47,7 @@ import javax.swing.table.TableColumn;
 import java.awt.*;
 import java.awt.datatransfer.StringSelection;
 import java.awt.datatransfer.Transferable;
+import java.awt.event.ActionListener;
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
@@ -197,7 +195,7 @@ public class SwingHelper {
     rootPane.revalidate();
     rootPane.repaint();
 
-    LOG.info("DialogWrapper '" + dialogWrapper.getTitle() + "' has been resized (added width: " + dw + ", added height: " + dh + ")");
+    LOG.info("DialogWrapper '" + dialogWrapper.getTitle() + "' has been re-sized (added width: " + dw + ", added height: " + dh + ")");
   }
 
   public static <T> void updateItems(@NotNull JComboBox comboBox,
@@ -275,7 +273,8 @@ public class SwingHelper {
     textFieldWithHistory.addPopupMenuListener(new PopupMenuListener() {
       @Override
       public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
-        setHistory(textFieldWithHistory, historyProvider.produce(), true);
+        List<String> history = historyProvider.produce();
+        setHistory(textFieldWithHistory, ContainerUtil.notNullize(history), true);
         // one-time initialization
         textFieldWithHistory.removePopupMenuListener(this);
       }
@@ -566,6 +565,19 @@ public class SwingHelper {
     return textFieldWithHistoryWithBrowseButton;
   }
 
+  @NotNull
+  public static <C extends JComponent> ComponentWithBrowseButton<C> wrapWithInfoButton(@NotNull final C component,
+                                                                                       @NotNull String infoButtonTooltip,
+                                                                                       @NotNull ActionListener listener) {
+    ComponentWithBrowseButton<C> comp = new ComponentWithBrowseButton<C>(component, listener);
+    FixedSizeButton uiHelpButton = comp.getButton();
+    uiHelpButton.setToolTipText(infoButtonTooltip);
+    uiHelpButton.setIcon(UIUtil.getBalloonInformationIcon());
+    uiHelpButton.setHorizontalAlignment(SwingConstants.CENTER);
+    uiHelpButton.setVerticalAlignment(SwingConstants.CENTER);
+    return comp;
+  }
+
   private static class CopyLinkAction extends AnAction {
 
     private final String myUrl;