This fixes the global PopupHelper implementation so that it consumes the
mouse event when popups have been closed. This also fixes the nasty
ComboBox popup problem, where the popup helper closes the popup, and
some listener (which receives the same event as the PopupHelper) toggles
it open immediately.

2006-06-13  Roman Kennke  <[EMAIL PROTECTED]>

        * java/awt/Component.java
        (getGraphics): Translate child graphics correctly.
        (dispatchEvent): Only dispatch event if it hasn't been consumed
        yet by the global dispatcher.
        * javax/swing/plaf/basic/BasicLookAndFeel.java
        Added some API docs.
        (PopupHelper.mousePressed): Consume the event after closing
        opened menus.

/Roman

-- 
“Improvement makes straight roads, but the crooked roads, without
Improvement, are roads of Genius.” - William Blake
Index: javax/swing/plaf/basic/BasicLookAndFeel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicLookAndFeel.java,v
retrieving revision 1.93
diff -u -1 -0 -r1.93 BasicLookAndFeel.java
--- javax/swing/plaf/basic/BasicLookAndFeel.java	13 Jun 2006 09:28:57 -0000	1.93
+++ javax/swing/plaf/basic/BasicLookAndFeel.java	13 Jun 2006 12:37:07 -0000
@@ -72,21 +72,23 @@
 import javax.swing.border.BevelBorder;
 import javax.swing.border.Border;
 import javax.swing.plaf.BorderUIResource;
 import javax.swing.plaf.ColorUIResource;
 import javax.swing.plaf.DimensionUIResource;
 import javax.swing.plaf.FontUIResource;
 import javax.swing.plaf.IconUIResource;
 import javax.swing.plaf.InsetsUIResource;
 
 /**
- * BasicLookAndFeel
+ * A basic implementation of Swing's Look and Feel framework. This can serve
+ * as a base for custom look and feel implementations.
+ *
  * @author Andrew Selkirk
  */
 public abstract class BasicLookAndFeel extends LookAndFeel
   implements Serializable
 {
 
   /**
    * Helps closing menu popups when the user clicks outside of any menu area.
    * This is implemented as an AWTEventListener that listens on the event
    * queue directly, grabs all mouse events from there and finds out of they
@@ -119,22 +121,26 @@
      *
      * @param ev the mouse pressed event
      */
     private void mousePressed(MouseEvent ev)
     {
       // Autoclose all menus managed by the MenuSelectionManager.
       MenuSelectionManager m = MenuSelectionManager.defaultManager();
       Component target = ev.getComponent();
       if (target instanceof Container)
         target = ((Container) target).findComponentAt(ev.getPoint());
-      if (! m.isComponentPartOfCurrentMenu(target))
-        m.clearSelectedPath();
+      if (m.getSelectedPath().length > 0
+          && ! m.isComponentPartOfCurrentMenu(target))
+        {
+          m.clearSelectedPath();
+          ev.consume();
+        }
     }
 
   }
 
   /**
    * An action that can play an audio file.
    *
    * @author Roman Kennke ([EMAIL PROTECTED])
    */
   private class AudioAction extends AbstractAction
@@ -190,20 +196,23 @@
     }
   }
 
   static final long serialVersionUID = -6096995660290287879L;
 
   /**
    * Helps closing menu popups when user clicks outside of the menu area.
    */
   private transient PopupHelper popupHelper;
 
+  /**
+   * Maps the audio actions for this l&f.
+   */
   private ActionMap audioActionMap;
 
   /**
    * Creates a new instance of the Basic look and feel.
    */
   public BasicLookAndFeel()
   {
     // Nothing to do here.
   }
 
@@ -418,42 +427,50 @@
             catch (NumberFormatException e)
               {
                 e.printStackTrace();
               }
             defaults.put(systemColors[i], new ColorUIResource(color));
           }
       }
   }
 
   /**
-   * loadResourceBundle
-   * @param defaults TODO
+   * Loads the resource bundle in 'resources/basic' and adds the contained
+   * key/value pairs to the <code>defaults</code> table.
+   *
+   * @param defaults the UI defaults to load the resources into
    */
+  // FIXME: This method is not used atm and private and thus could be removed.
+  // However, I consider this method useful for providing localized
+  // descriptions and similar stuff and therefore think that we should use it
+  // instead and provide the resource bundles.
   private void loadResourceBundle(UIDefaults defaults)
   {
     ResourceBundle bundle;
     Enumeration e;
     String key;
     String value;
     bundle = ResourceBundle.getBundle("resources/basic");
     // Process Resources
     e = bundle.getKeys();
     while (e.hasMoreElements())
       {
         key = (String) e.nextElement();
         value = bundle.getString(key);
         defaults.put(key, value);
       }
   }
 
   /**
-   * initComponentDefaults
+   * Populates the <code>defaults</code> table with UI default values for
+   * colors, fonts, keybindings and much more.
+   *
    * @param defaults  the defaults table (<code>null</code> not permitted).
    */
   protected void initComponentDefaults(UIDefaults defaults)
   {
     Object[] uiDefaults;
     
     Color highLight = new Color(249, 247, 246);
     Color light = new Color(239, 235, 231);
     Color shadow = new Color(139, 136, 134);
     Color darkShadow = new Color(16, 16, 16);
Index: java/awt/Component.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Component.java,v
retrieving revision 1.120
diff -u -1 -0 -r1.120 Component.java
--- java/awt/Component.java	4 Jun 2006 20:21:39 -0000	1.120
+++ java/awt/Component.java	13 Jun 2006 12:37:08 -0000
@@ -1732,23 +1732,22 @@
    */
   public Graphics getGraphics()
   {
     if (peer != null)
       {
         Graphics gfx = peer.getGraphics();
         // Create peer for lightweights.
         if (gfx == null && parent != null)
           {
             gfx = parent.getGraphics();
-            Rectangle bounds = getBounds();
-            gfx.setClip(bounds);
-            gfx.translate(bounds.x, bounds.y);
+            gfx.clipRect(getX(), getY(), getWidth(), getHeight());
+            gfx.translate(getX(), getY());
             return gfx;
           }
         gfx.setFont(font);
         return gfx;
       }
     return null;
   }
 
   /**
    * Returns the font metrics for the specified font in this component.
@@ -2308,21 +2307,22 @@
     Event oldEvent = translateEvent(e);
     if (oldEvent != null)
       postEvent (oldEvent);
 
     // Give toolkit a chance to dispatch the event
     // to globally registered listeners.
     Toolkit.getDefaultToolkit().globalDispatchEvent(e);
 
     // Some subclasses in the AWT package need to override this behavior,
     // hence the use of dispatchEventImpl().
-    dispatchEventImpl(e);
+    if (! e.isConsumed())
+      dispatchEventImpl(e);
   }
 
   /**
    * AWT 1.0 event handler.
    *
    * This method simply calls handleEvent and returns the result.
    *
    * @param e the event to handle
    * @return true if the event was handled, false otherwise
    * @deprecated use [EMAIL PROTECTED] #dispatchEvent(AWTEvent)} instead

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

Reply via email to