slightly fix combobx under nimbus laf
authorAlexey Pegov <alexey.pegov@jetbrains.com>
Tue, 24 Aug 2010 17:06:57 +0000 (21:06 +0400)
committerAlexey Pegov <alexey.pegov@jetbrains.com>
Tue, 24 Aug 2010 17:09:55 +0000 (21:09 +0400)
platform/platform-api/src/com/intellij/openapi/ui/ComboBox.java
platform/platform-impl/src/com/intellij/ui/ComboboxEditorTextField.java
platform/platform-impl/src/com/intellij/ui/EditorTextField.java
platform/util/src/com/intellij/util/ui/MacUIUtil.java

index d2d775966d4852cb074027f276340b4f8d8d9ec7..07bd44ee195561d68338396c505669aa1dfc7a3c 100644 (file)
@@ -20,7 +20,6 @@ import com.intellij.util.ui.MacUIUtil;
 import com.intellij.util.ui.UIUtil;
 
 import javax.swing.*;
-import javax.swing.border.Border;
 import java.awt.*;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -152,33 +151,18 @@ public class ComboBox extends ComboBoxWithWidePopup {
 
   public final Dimension getPreferredSize() {
     int width = myMinimumAndPreferredWidth;
+    final Dimension preferredSize = super.getPreferredSize();
     if (width < 0) {
-      width = super.getPreferredSize().width;
+      width = preferredSize.width;
     }
-    final int height = getPreferredHeight();
-    return new Dimension(width, height);
+
+    return new Dimension(width, preferredSize.height);
   }
 
   protected Dimension getOriginalPreferredSize() {
     return super.getPreferredSize();
   }
 
-  private int getPreferredHeight() {
-    final Border border = getBorder();
-    final ComboBoxEditor editor = getEditor();
-    int height;
-    if (editor != null) {
-      height = editor.getEditorComponent().getPreferredSize().height;
-      if (border != null) {
-        height += border.getBorderInsets(this).top + border.getBorderInsets(this).bottom;
-      }
-    }
-    else {
-      height = super.getPreferredSize().height;
-    }
-    return height;
-  }
-
   @Override
   public void paint(Graphics g) {
     super.paint(g);
index 2f19fc538705f07ec510a9f4aea3b36d6853e9eb..d565afbf4c80c746413c9fc73ffff3d68479424f 100644 (file)
@@ -30,8 +30,6 @@ import org.jetbrains.annotations.NotNull;
 import javax.swing.*;
 import javax.swing.border.Border;
 import java.awt.*;
-import java.awt.event.FocusEvent;
-import java.awt.event.FocusListener;
 
 /**
  * User: spLeaner
index 66a42a198eb4ac39ce4c4a4879428a4e1ce95885..4b0907ca863ef9d372d34dd5cffcdc2049fc1c2e 100644 (file)
@@ -69,7 +69,6 @@ public class EditorTextField extends JPanel implements DocumentListener, TextCom
   private boolean myIsSupplementary;
   private boolean myInheritSwingFont = true;
   private Color myEnforcedBgColor = null;
-  private boolean myUseTextFieldPreferredSize = true;
 
   public EditorTextField() {
     this("");
@@ -411,10 +410,6 @@ public class EditorTextField extends JPanel implements DocumentListener, TextCom
 
     editor.setBackgroundColor(getBackgroundColor(!myIsViewer));
 
-    if (myUseTextFieldPreferredSize && !UIUtil.isUnderQuaquaLookAndFeel()) {
-      editor.getComponent().setPreferredSize(new JTextField().getPreferredSize());
-    }
-
     editor.putUserData(SUPPLEMENTARY_KEY, myIsSupplementary);
     editor.getContentComponent().setFocusCycleRoot(false);
 
@@ -465,21 +460,11 @@ public class EditorTextField extends JPanel implements DocumentListener, TextCom
         preferredSize.height += insets.bottom;
       }
 
-      final Insets defaultInsets = new JTextField().getInsets();
-      if (defaultInsets != null) {
-        preferredSize.height -= defaultInsets.top;
-        preferredSize.width -= defaultInsets.left;
-      }
-
       return preferredSize;
     }
     return new Dimension(100, 20);
   }
 
-  public void setUseTextFieldPreferredSize(final boolean b) {
-    myUseTextFieldPreferredSize = b;
-  }
-
   public Component getNextFocusableComponent() {
     if (myEditor == null && myNextFocusable == null) return super.getNextFocusableComponent();
     if (myEditor == null) return myNextFocusable;
index 7230abb79a8e4e22c7728faf55d9fa379373b87d..d3f8aa7f0d0374ffca74bb2d5c0e158368530d30 100644 (file)
@@ -15,7 +15,7 @@
  */
 package com.intellij.util.ui;
 
-import com.intellij.util.graph.Graph;
+import com.intellij.openapi.util.SystemInfo;
 import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
@@ -106,12 +106,12 @@ public class MacUIUtil {
   }
 
   public static void drawComboboxFocusRing(@NotNull final JComboBox combobox, @NotNull final Graphics g) {
-    if (combobox.isEnabled() && combobox.isEditable() && UIUtil.isUnderAquaLookAndFeel()) {
+    if (SystemInfo.isMac && combobox.isEnabled() && combobox.isEditable() && UIUtil.isUnderAquaLookAndFeel()) {
       final Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
       if (focusOwner != null) {
         final Container ancestor = SwingUtilities.getAncestorOfClass(JComboBox.class, focusOwner);
         if (ancestor == combobox) {
-          MacUIUtil.paintComboboxFocusRing((Graphics2D) g, combobox.getBounds());
+          paintComboboxFocusRing((Graphics2D) g, combobox.getBounds());
         }
       }
     }