Hi,

Some more hacking on Free Swing (this stuff really seems to work for a
lot of things now!). Emir uses something called the plastic theme. It
seems to use the BasicComboBoxUI protected fields that cache the minimum
size. So I implemented them and wrote some documentation on how I think
they should behave. It just sets the cache when the minimumSize is
requested and invalidates it in all the listeners that I thought were
relevant. It seems to work for me (and the Free Swing Demo), but it
would be nice if a Free Swing hacker could take a look.

2005-11-21  Mark Wielaard  <[EMAIL PROTECTED]>

    * javax/swing/plaf/basic/BasicComboBoxUI.java (cachedMinimumSize):
    Document.
    (isMinimumSizeDirty): Likewise. And initialize to true.
    (getMinimumSize): Use and set cachedMinimumSize.
    (FocusHandler.focusGained): Set isMinimumSizeDirty to true.
    (FocusHandler.focusLost): Likewise.
    (ItemHandler.itemStateChanged): Likewise.
    (ListDataHandler.contentsChanged): Likewise.
    (ListDataHandler.intervalAdded): Likewise.
    (ListDataHandler.intervalRemoved): Likewise.
    (PropertyChangeHandler.propertyChange): Likewise.

Comments welcome.

Cheers,

Mark
Index: javax/swing/plaf/basic/BasicComboBoxUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicComboBoxUI.java,v
retrieving revision 1.29
diff -u -r1.29 BasicComboBoxUI.java
--- javax/swing/plaf/basic/BasicComboBoxUI.java	15 Nov 2005 20:32:46 -0000	1.29
+++ javax/swing/plaf/basic/BasicComboBoxUI.java	21 Nov 2005 20:47:35 -0000
@@ -190,10 +190,19 @@
    */
   Dimension displaySize;
 
-  // FIXME: This fields aren't used anywhere at this moment.
-  protected Dimension cachedMinimumSize;
+  // FIXME: This field isn't used anywhere at this moment.
   protected CellRendererPane currentValuePane;
-  protected boolean isMinimumSizeDirty;
+
+  /**
+   * The current minimum size if isMinimumSizeDirty is false.
+   * Setup by getMinimumSize() and invalidated by the various listeners.
+   */
+  protected Dimension cachedMinimumSize;
+
+  /**
+   * Indicates whether or not the cachedMinimumSize field is valid or not.
+   */
+  protected boolean isMinimumSizeDirty = true;
 
   /**
    * Creates a new <code>BasicComboBoxUI</code> object.
@@ -668,7 +677,7 @@
 
   /**
    * Returns the minimum size for this [EMAIL PROTECTED] JComboBox} for this
-   * look and feel.
+   * look and feel. Also makes sure cachedMinimimSize is setup correctly.
    *
    * @param c The [EMAIL PROTECTED] JComponent} to find the minimum size for.
    *
@@ -676,10 +685,15 @@
    */
   public Dimension getMinimumSize(JComponent c)
   {
-    Dimension d = getDisplaySize();
-    int arrowButtonWidth = d.height;
-    Dimension result = new Dimension(d.width + arrowButtonWidth, d.height);
-    return result;
+    if (isMinimumSizeDirty)
+      {
+	Dimension d = getDisplaySize();
+	int arrowButtonWidth = d.height;
+	cachedMinimumSize = new Dimension(d.width + arrowButtonWidth,
+					  d.height);
+	isMinimumSizeDirty = false;
+      }
+    return new Dimension(cachedMinimumSize);
   }
 
   /** The value returned by the getMaximumSize() method. */
@@ -1062,6 +1076,9 @@
      */
     public void focusGained(FocusEvent e)
     {
+      // Lets assume every change invalidates the minimumsize.
+      isMinimumSizeDirty = true;
+
       hasFocus = true;
       comboBox.repaint();
     }
@@ -1074,6 +1091,9 @@
      */
     public void focusLost(FocusEvent e)
     {
+      // Lets assume every change invalidates the minimumsize.
+      isMinimumSizeDirty = true;
+
       hasFocus = false;
       setPopupVisible(comboBox, false);
       comboBox.repaint();
@@ -1102,6 +1122,9 @@
      */
     public void itemStateChanged(ItemEvent e)
     {
+      // Lets assume every change invalidates the minimumsize.
+      isMinimumSizeDirty = true;
+
       if (e.getStateChange() == ItemEvent.SELECTED && comboBox.isEditable())
         comboBox.getEditor().setItem(e.getItem());
       comboBox.repaint();
@@ -1149,6 +1172,9 @@
     public void contentsChanged(ListDataEvent e)
     {
       // if the item is selected or deselected
+
+      // Lets assume every change invalidates the minimumsize.
+      isMinimumSizeDirty = true;
     }
 
     /**
@@ -1158,6 +1184,9 @@
      */
     public void intervalAdded(ListDataEvent e)
     {
+      // Lets assume every change invalidates the minimumsize.
+      isMinimumSizeDirty = true;
+
       ComboBoxModel model = comboBox.getModel();
       ListCellRenderer renderer = comboBox.getRenderer();
 
@@ -1179,6 +1208,9 @@
      */
     public void intervalRemoved(ListDataEvent e)
     {
+      // Lets assume every change invalidates the minimumsize.
+      isMinimumSizeDirty = true;
+
       // recalculate display size of the JComboBox.
       displaySize = getDisplaySize();
       comboBox.repaint();
@@ -1206,6 +1238,9 @@
      */
     public void propertyChange(PropertyChangeEvent e)
     {
+      // Lets assume every change invalidates the minimumsize.
+      isMinimumSizeDirty = true;
+
       if (e.getPropertyName().equals("enabled"))
         {
 	  arrowButton.setEnabled(comboBox.isEnabled());

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to