harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r517236 - in /harmony/enhanced/classlib/trunk/modules/awt/src: main/java/common/org/apache/harmony/awt/ButtonStateController.java test/api/java/common/java/awt/ButtonRTest.java
Date Mon, 12 Mar 2007 15:00:49 GMT
Author: ayza
Date: Mon Mar 12 08:00:47 2007
New Revision: 517236

URL: http://svn.apache.org/viewvc?view=rev&rev=517236
Log:
Applying patch from HARMONY-2305 ([classlib][awt] Several components can be active at the
same time)

Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ButtonStateController.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ButtonRTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ButtonStateController.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ButtonStateController.java?view=diff&rev=517236&r1=517235&r2=517236
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ButtonStateController.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/ButtonStateController.java
Mon Mar 12 08:00:47 2007
@@ -42,6 +42,8 @@
  */
 public abstract class ButtonStateController implements MouseListener, FocusListener, KeyListener
{
 
+    private static Component activeComponent;
+    
     private boolean mousePressed = false;
     private boolean keyPressed = false;
     private boolean mouseInside = false;
@@ -68,12 +70,13 @@
 
     public void mousePressed(MouseEvent me) {
         if (mousePressed || keyPressed ||
-            (me.getButton() != MouseEvent.BUTTON1)) {
-
+                (me.getButton() != MouseEvent.BUTTON1) ||
+                (activeComponent != null)) {
             return;
         }
 
         mousePressed = true;
+        activeComponent = component;
         if (mouseInside) {
             component.repaint();
         }
@@ -84,12 +87,14 @@
     }
 
     public void mouseReleased(MouseEvent me) {
-        if (!mousePressed || (me.getButton() != MouseEvent.BUTTON1)) {
+        if (!mousePressed || (me.getButton() != MouseEvent.BUTTON1) || 
+                (activeComponent != component)) {
             return;
         }
 
         mousePressed = false;
         component.repaint();
+        activeComponent = null;
         if (mouseInside) {
             when = me.getWhen();
             mod = me.getModifiers();
@@ -101,11 +106,14 @@
         // awt.54=Key event for unfocused component
         assert focused == true : Messages.getString("awt.54"); //$NON-NLS-1$
 
-        if (mousePressed || keyPressed || (ke.getKeyCode() != KeyEvent.VK_SPACE)) {
+        if (mousePressed || keyPressed ||
+                (ke.getKeyCode() != KeyEvent.VK_SPACE) ||
+                (activeComponent != null)) {
             return;
         }
 
         keyPressed = true;
+        activeComponent = component;
         component.repaint();
     }
 
@@ -113,11 +121,13 @@
         // awt.54=Key event for unfocused component
         assert focused == true : Messages.getString("awt.54"); //$NON-NLS-1$
 
-        if (!keyPressed || (ke.getKeyCode() != KeyEvent.VK_SPACE)) {
+        if (!keyPressed || (ke.getKeyCode() != KeyEvent.VK_SPACE) ||
+                (activeComponent != component)) {
             return;
         }
 
         keyPressed = false;
+        activeComponent = null;
         component.repaint();
         when = ke.getWhen();
         mod = ke.getModifiers();

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ButtonRTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ButtonRTest.java?view=diff&rev=517236&r1=517235&r2=517236
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ButtonRTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/ButtonRTest.java
Mon Mar 12 08:00:47 2007
@@ -20,6 +20,11 @@
  */
 package java.awt;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+
 import junit.framework.TestCase;
 
 public class ButtonRTest extends TestCase {
@@ -38,5 +43,50 @@
             throw new RuntimeException(e);
         }
         frm.dispose();
+    }
+    
+    // Regression test for HARMONY-2305
+    // Currently fails on Linux version of RI
+    public void testHarmony2305() throws Exception {
+        final Frame f = new Frame();
+        final Button b1 = new Button("B1"); //$NON-NLS-1$
+        final Button b2 = new Button("B2"); //$NON-NLS-1$
+        final AL l1 = new AL();
+        final AL l2 = new AL();
+        final Robot r = new Robot();
+
+        try {
+            b1.addActionListener(l1);
+            b2.addActionListener(l2);
+            f.add(BorderLayout.WEST, b1);
+            f.add(BorderLayout.EAST, b2);
+            f.setSize(100, 100);
+            f.setVisible(true);
+
+            r.setAutoWaitForIdle(true);
+            r.setAutoDelay(500);
+            r.mouseMove(b1.getLocation().x + 3, b1.getLocation().y + 3);
+            r.mousePress(InputEvent.BUTTON1_MASK);
+            r.mouseRelease(InputEvent.BUTTON1_MASK);
+            assertNotNull(l1.e);
+            assertEquals("B1", l1.e.getActionCommand()); //$NON-NLS-1$
+
+            assertNull(l2.e);
+            r.keyPress(KeyEvent.VK_SPACE);
+            r.mouseMove(b2.getLocation().x + 3, b2.getLocation().y + 3);
+            r.mousePress(InputEvent.BUTTON1_MASK);
+            r.mouseRelease(InputEvent.BUTTON1_MASK);
+            assertNull(l2.e);
+        } finally {
+            f.dispose();
+        }
+    }
+
+    static class AL implements ActionListener {
+        ActionEvent e;
+
+        public void actionPerformed(final ActionEvent e) {
+            this.e = e;
+        }
     }
 }



Mime
View raw message