harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r587519 - in /harmony/enhanced/classlib/trunk/modules/awt/src: main/java/common/java/awt/event/ test/api/java/common/java/awt/event/
Date Tue, 23 Oct 2007 14:34:27 GMT
Author: apetrenko
Date: Tue Oct 23 07:34:26 2007
New Revision: 587519

URL: http://svn.apache.org/viewvc?rev=587519&view=rev
Log:
Patch for HARMONY-4761 "[classlib][awt] InputEvent.getModifiers() 
doesn't return modifiers for mouse release event"

Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/InputEvent.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/KeyEvent.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/MouseEvent.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/event/InputEventTest.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/event/MouseEventTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/InputEvent.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/InputEvent.java?rev=587519&r1=587518&r2=587519&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/InputEvent.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/InputEvent.java
Tue Oct 23 07:34:26 2007
@@ -58,113 +58,54 @@
 
     public static final int ALT_GRAPH_DOWN_MASK = 8192;
 
-    private static final int DOWN_MASKS = SHIFT_DOWN_MASK | CTRL_DOWN_MASK |
-            META_DOWN_MASK | ALT_DOWN_MASK | BUTTON1_DOWN_MASK |
-            BUTTON2_DOWN_MASK | BUTTON3_DOWN_MASK | ALT_GRAPH_DOWN_MASK;
+    static final int MASKS = SHIFT_MASK | CTRL_MASK | META_MASK | ALT_MASK
+            | ALT_GRAPH_MASK | BUTTON1_MASK | BUTTON2_MASK | BUTTON3_MASK;
 
-    private long when;
-    private int modifiersEx;
-
-    public static String getModifiersExText(int modifiers/*Ex*/) {
-        return MouseEvent.addMouseModifiersExText(
-                KeyEvent.getKeyModifiersExText(modifiers), modifiers);
-    }
-
-    static int extractExFlags(int modifiers) {
-        int exFlags = modifiers & DOWN_MASKS;
-
-        if ((modifiers & SHIFT_MASK) != 0) {
-            exFlags |= SHIFT_DOWN_MASK;
-        }
-        if ((modifiers & CTRL_MASK) != 0) {
-            exFlags |= CTRL_DOWN_MASK;
-        }
-        if ((modifiers & META_MASK) != 0) {
-            exFlags |= META_DOWN_MASK;
-        }
-        if ((modifiers & ALT_MASK) != 0) {
-            exFlags |= ALT_DOWN_MASK;
-        }
-        if ((modifiers & ALT_GRAPH_MASK) != 0) {
-            exFlags |= ALT_GRAPH_DOWN_MASK;
-        }
-        if ((modifiers & BUTTON1_MASK) != 0) {
-            exFlags |= BUTTON1_DOWN_MASK;
-        }
-        if ((modifiers & BUTTON2_MASK) != 0) {
-            exFlags |= BUTTON2_DOWN_MASK;
-        }
-        if ((modifiers & BUTTON3_MASK) != 0) {
-            exFlags |= BUTTON3_DOWN_MASK;
-        }
-
-        return exFlags;
-    }
+    static final int DOWN_MASKS = SHIFT_DOWN_MASK | CTRL_DOWN_MASK
+            | META_DOWN_MASK | ALT_DOWN_MASK | ALT_GRAPH_DOWN_MASK
+            | BUTTON1_DOWN_MASK | BUTTON2_DOWN_MASK | BUTTON3_DOWN_MASK;
 
+    private long when;
+    int modifiers;
+    
     InputEvent(Component source, int id, long when, int modifiers) {
         super(source, id);
 
         this.when = when;
-        modifiersEx = extractExFlags(modifiers);
+        this.modifiers = modifiers;
     }
 
+    public static String getModifiersExText(int modifiers) {
+        return MouseEvent.addMouseModifiersExText(
+                KeyEvent.getKeyModifiersExText(modifiers), modifiers);
+    }
+    
     public int getModifiers() {
-        int modifiers = 0;
-
-        if ((modifiersEx & SHIFT_DOWN_MASK) != 0) {
-            modifiers |= SHIFT_MASK;
-        }
-        if ((modifiersEx & CTRL_DOWN_MASK) != 0) {
-            modifiers |= CTRL_MASK;
-        }
-        if ((modifiersEx & META_DOWN_MASK) != 0) {
-            modifiers |= META_MASK;
-        }
-        if ((modifiersEx & ALT_DOWN_MASK) != 0) {
-            modifiers |= ALT_MASK;
-        }
-        if ((modifiersEx & ALT_GRAPH_DOWN_MASK) != 0) {
-            modifiers |= ALT_GRAPH_MASK;
-        }
-        if ((modifiersEx & BUTTON1_DOWN_MASK) != 0) {
-            modifiers |= BUTTON1_MASK;
-        }
-        if ((modifiersEx & BUTTON2_DOWN_MASK) != 0) {
-            modifiers |= BUTTON2_MASK;
-        }
-        if ((modifiersEx & BUTTON3_DOWN_MASK) != 0) {
-            modifiers |= BUTTON3_MASK;
-        }
-
-        return modifiers;
+        return modifiers & MASKS;
     }
 
     public int getModifiersEx() {
-        return modifiersEx;
-    }
-
-    void setModifiers(int modifiers) {
-        modifiersEx = extractExFlags(modifiers);
+    	return modifiers & DOWN_MASKS;
     }
 
     public boolean isAltDown() {
-        return ((modifiersEx & ALT_DOWN_MASK) != 0);
+        return ((modifiers & ALT_DOWN_MASK) != 0);
     }
 
     public boolean isAltGraphDown() {
-        return ((modifiersEx & ALT_GRAPH_DOWN_MASK) != 0);
+        return ((modifiers & ALT_GRAPH_DOWN_MASK) != 0);
     }
 
     public boolean isControlDown() {
-        return ((modifiersEx & CTRL_DOWN_MASK) != 0);
+        return ((modifiers & CTRL_DOWN_MASK) != 0);
     }
 
     public boolean isMetaDown() {
-        return ((modifiersEx & META_DOWN_MASK) != 0);
+        return ((modifiers & META_DOWN_MASK) != 0);
     }
 
     public boolean isShiftDown() {
-        return ((modifiersEx & SHIFT_DOWN_MASK) != 0);
+        return ((modifiers & SHIFT_DOWN_MASK) != 0);
     }
 
     public long getWhen() {
@@ -180,5 +121,4 @@
     public boolean isConsumed() {
         return super.isConsumed();
     }
-
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/KeyEvent.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/KeyEvent.java?rev=587519&r1=587518&r2=587519&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/KeyEvent.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/KeyEvent.java
Tue Oct 23 07:34:26 2007
@@ -436,7 +436,7 @@
     private int keyLocation;
 
     public static String getKeyModifiersText(int modifiers) {
-        return getKeyModifiersExText(extractExFlags(modifiers));
+        return getKeyModifiersExText(extractModifiers(modifiers));
     }
 
     static String getKeyModifiersExText(int modifiersEx) {
@@ -554,7 +554,7 @@
                     long when, int modifiers,
                     int keyCode, char keyChar,
                     int keyLocation) {
-        super(src, id, when, modifiers);
+        super(src, id, when, extractModifiers(modifiers));
 
         if (id == KEY_TYPED) {
             if (keyCode != VK_UNDEFINED) {
@@ -598,10 +598,9 @@
         return keyLocation;
     }
 
-    @Override
     @Deprecated
     public void setModifiers(int modifiers) {
-        super.setModifiers(modifiers);
+        this.modifiers = extractModifiers(modifiers);
     }
 
     public boolean isActionKey() {
@@ -678,4 +677,29 @@
         return paramString;
     }
 
+    private static int extractModifiers(int modifiers) {
+        int mod = 0;
+
+        if (((modifiers & SHIFT_MASK) != 0)
+                || ((modifiers & SHIFT_DOWN_MASK) != 0)) {
+            mod |= SHIFT_MASK | SHIFT_DOWN_MASK;
+        }
+        if (((modifiers & CTRL_MASK) != 0)
+                || ((modifiers & CTRL_DOWN_MASK) != 0)) {
+            mod |= CTRL_MASK | CTRL_DOWN_MASK;
+        }
+        if (((modifiers & META_MASK) != 0)
+                || ((modifiers & META_DOWN_MASK) != 0)) {
+            mod |= META_MASK | META_DOWN_MASK;
+        }
+        if (((modifiers & ALT_MASK) != 0) || ((modifiers & ALT_DOWN_MASK) != 0))
{
+            mod |= ALT_MASK | ALT_DOWN_MASK;
+        }
+        if (((modifiers & ALT_GRAPH_MASK) != 0)
+                || ((modifiers & ALT_GRAPH_DOWN_MASK) != 0)) {
+            mod |= ALT_GRAPH_MASK | ALT_GRAPH_DOWN_MASK;
+        }
+
+        return mod;
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/MouseEvent.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/MouseEvent.java?rev=587519&r1=587518&r2=587519&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/MouseEvent.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/MouseEvent.java
Tue Oct 23 07:34:26 2007
@@ -63,6 +63,37 @@
     private int button;
     private int x;
     private int y;
+    
+    public MouseEvent(Component source, int id, long when, int modifiers,
+            int x, int y, int clickCount, boolean popupTrigger) {
+        this(source, id, when, modifiers, x, y, clickCount, popupTrigger,
+                NOBUTTON);
+    }
+
+    public MouseEvent(Component source, int id, long when, int modifiers,
+            int x, int y, int clickCount, boolean popupTrigger, int button) {
+        super(source, id, when, modifiers);
+
+        if ((button < NOBUTTON) || (button > BUTTON3)) {
+            // awt.18B=Invalid button value
+            throw new IllegalArgumentException(Messages.getString("awt.18B")); //$NON-NLS-1$
+        }
+
+        this.popupTrigger = popupTrigger;
+        this.clickCount = clickCount;
+        this.button = button;
+        this.x = x;
+        this.y = y;
+
+        if (getModifiers() != 0) {
+            setModifiersEx();
+        } else if (getModifiersEx() != 0) {
+            setModifiers();
+        } else if ((button != NOBUTTON)
+                && ((id >= MOUSE_CLICKED) && (id <= MOUSE_RELEASED)))
{
+            setButtonModifiers();
+        }
+    }
 
     public static String getMouseModifiersText(int modifiers) {
         final StringBuffer text = new StringBuffer();
@@ -77,7 +108,15 @@
             text.append(Toolkit.getProperty("AWT.control", "Ctrl")).append("+"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
         }
         if ((modifiers & ALT_MASK) != 0) {
-            text.append(Toolkit.getProperty("AWT.alt", "Alt")).append("+"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
+            // XXX: The following hook is required to avoid conflicts between
+            // ALT_MASK and BUTTON2_MASK which have the same value.
+            if ((modifiers & BUTTON2_DOWN_MASK) != 0) {
+                if ((modifiers & ALT_DOWN_MASK) != 0) {
+                    text.append(Toolkit.getProperty("AWT.alt", "Alt")).append("+"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
+                }
+            } else {
+                text.append(Toolkit.getProperty("AWT.alt", "Alt")).append("+"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
+            }
         }
         if ((modifiers & ALT_GRAPH_MASK) != 0) {
             text.append(Toolkit.getProperty("AWT.altGraph", "Alt Graph")).append("+"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
@@ -113,31 +152,6 @@
         return text;
     }
 
-    public MouseEvent(Component source, int id, long when,
-                      int modifiers, int x, int y,
-                      int clickCount, boolean popupTrigger) {
-        this(source, id, when, modifiers, x, y,
-             clickCount, popupTrigger, NOBUTTON);
-    }
-
-    public MouseEvent(Component source, int id, long when,
-                      int modifiers, int x, int y,
-                      int clickCount, boolean popupTrigger, int button) {
-        super(source, id, when, modifiers);
-
-        if ((button != NOBUTTON) && (button != BUTTON1) &&
-                (button != BUTTON2) && (button != BUTTON3)) {
-            // awt.18B=Invalid button value
-            throw new IllegalArgumentException(Messages.getString("awt.18B")); //$NON-NLS-1$
-        }
-
-        this.popupTrigger = popupTrigger;
-        this.clickCount = clickCount;
-        this.button = button;
-        this.x = x;
-        this.y = y;
-    }
-
     public int getButton() {
         return button;
     }
@@ -215,12 +229,130 @@
                 ",button=" + button; //$NON-NLS-1$
         if (getModifiersEx() > 0) {
             paramString += 
-                    ",modifiers=" + getModifiersExText(getModifiersEx()) + //$NON-NLS-1$
-                    ",extModifiers=" + getModifiersExText(getModifiersEx()); //$NON-NLS-1$
+                    ",modifiers=" + getMouseModifiersText(modifiers) + //$NON-NLS-1$
+                    ",extModifiers=" + getModifiersExText(modifiers); //$NON-NLS-1$
         }
         paramString += ",clickCount=" + getClickCount(); //$NON-NLS-1$
 
         return paramString;
     }
 
+    private void setModifiers() {
+        modifiers &= ~MASKS; // clear modifiers
+
+        if ((modifiers & SHIFT_DOWN_MASK) != 0) {
+            modifiers |= SHIFT_MASK;
+        }
+        if ((modifiers & CTRL_DOWN_MASK) != 0) {
+            modifiers |= CTRL_MASK;
+        }
+        if ((modifiers & META_DOWN_MASK) != 0) {
+            modifiers |= META_MASK;
+        }
+        if ((modifiers & ALT_DOWN_MASK) != 0) {
+            modifiers |= ALT_MASK;
+        }
+        if ((modifiers & ALT_GRAPH_DOWN_MASK) != 0) {
+            modifiers |= ALT_GRAPH_MASK;
+        }
+
+        if ((id >= MOUSE_CLICKED) && (id <= MOUSE_RELEASED)) {
+            switch (button) {
+            case BUTTON1:
+                modifiers |= BUTTON1_MASK;
+                break;
+            case BUTTON2:
+                modifiers |= BUTTON2_MASK;
+                break;
+            case BUTTON3:
+                modifiers |= BUTTON3_MASK;
+                break;
+            }
+        } else {
+            if ((modifiers & BUTTON1_DOWN_MASK) != 0) {
+                modifiers |= BUTTON1_MASK;
+            }
+            if ((modifiers & BUTTON2_DOWN_MASK) != 0) {
+                modifiers |= BUTTON2_MASK;
+            }
+            if ((modifiers & BUTTON3_DOWN_MASK) != 0) {
+                modifiers |= BUTTON3_MASK;
+            }
+        }
+    }
+
+    private void setModifiersEx() {
+        modifiers &= ~DOWN_MASKS; // clear ex modifiers
+
+        if ((modifiers & SHIFT_MASK) != 0) {
+            modifiers |= SHIFT_DOWN_MASK;
+        }
+        if ((modifiers & CTRL_MASK) != 0) {
+            modifiers |= CTRL_DOWN_MASK;
+        }
+        if ((modifiers & META_MASK) != 0) {
+            modifiers |= META_DOWN_MASK;
+        }
+        if ((modifiers & ALT_MASK) != 0) {
+            modifiers |= ALT_DOWN_MASK;
+        }
+        if ((modifiers & ALT_GRAPH_MASK) != 0) {
+            modifiers |= ALT_GRAPH_DOWN_MASK;
+        }
+
+        if ((id >= MOUSE_CLICKED) && (id <= MOUSE_RELEASED)) {
+            if ((modifiers & BUTTON1_MASK) != 0) {
+                button = BUTTON1;
+
+                if (id == MOUSE_PRESSED) {
+                    modifiers |= BUTTON1_DOWN_MASK;
+                }
+            } else if ((modifiers & BUTTON2_MASK) != 0) {
+                button = BUTTON2;
+
+                if (id == MOUSE_PRESSED) {
+                    modifiers |= BUTTON2_DOWN_MASK;
+                }
+            } else if ((modifiers & BUTTON3_MASK) != 0) {
+                button = BUTTON3;
+
+                if (id == MOUSE_PRESSED) {
+                    modifiers |= BUTTON3_DOWN_MASK;
+                }
+            }
+        } else {
+            if ((modifiers & BUTTON1_MASK) != 0) {
+                modifiers |= BUTTON1_DOWN_MASK;
+            }
+            if ((modifiers & BUTTON2_MASK) != 0) {
+                modifiers |= BUTTON2_DOWN_MASK;
+            }
+            if ((modifiers & BUTTON3_MASK) != 0) {
+                modifiers |= BUTTON3_DOWN_MASK;
+            }
+        }
+    }
+
+    private void setButtonModifiers() {
+        switch (button) {
+        case BUTTON1:
+            modifiers |= BUTTON1_MASK;
+            if (id == MOUSE_PRESSED) {
+                modifiers |= BUTTON1_DOWN_MASK;
+            }
+            break;
+        case BUTTON2:
+            modifiers |= BUTTON2_MASK;
+            if (id == MOUSE_PRESSED) {
+                modifiers |= BUTTON2_DOWN_MASK;
+            }
+            break;
+        case BUTTON3:
+            modifiers |= BUTTON3_MASK;
+            if (id == MOUSE_PRESSED) {
+                modifiers |= BUTTON3_DOWN_MASK;
+            }
+            break;
+        }
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/event/InputEventTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/event/InputEventTest.java?rev=587519&r1=587518&r2=587519&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/event/InputEventTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/event/InputEventTest.java
Tue Oct 23 07:34:26 2007
@@ -28,9 +28,9 @@
 public class InputEventTest extends TestCase {
 
     public final void testInputEvent() {
-        Button button = new Button("Button");
+        Button button = new Button("Button"); //$NON-NLS-1$
         InputEvent event = new InputEvent(button, 0, 1000000000,
-                InputEvent.ALT_DOWN_MASK | InputEvent.BUTTON1_MASK) {};
+                InputEvent.ALT_MASK | InputEvent.BUTTON1_MASK) {};
 
         assertEquals(event.getSource(), button);
         assertEquals(event.getID(), 0);
@@ -39,7 +39,7 @@
     }
 
     public final void testConsuming() {
-        Button button = new Button("Button");
+        Button button = new Button("Button"); //$NON-NLS-1$
         InputEvent event = new InputEvent(button, 0, 1000000000,
                 InputEvent.ALT_DOWN_MASK | InputEvent.BUTTON1_MASK) {};
 
@@ -49,135 +49,75 @@
     }
 
     public final void testGetModifiers() {
-        Button button = new Button("Button");
-        InputEvent event = new InputEvent(button, 0, 1000000000, 0) {};
+        Button button = new Button("Button"); //$NON-NLS-1$
+        InputEvent event = new InputEvent(button, 0, 1000000000,
+                InputEvent.MASKS | InputEvent.DOWN_MASKS) {};
 
-        event.setModifiers(InputEvent.BUTTON1_MASK);
-        assertEquals(event.getModifiers(), InputEvent.BUTTON1_MASK);
-        event.setModifiers(InputEvent.BUTTON2_MASK);
-        assertEquals(event.getModifiers(), InputEvent.BUTTON2_MASK);
-        event.setModifiers(InputEvent.BUTTON3_MASK);
-        assertEquals(event.getModifiers(), InputEvent.BUTTON3_MASK);
-        event.setModifiers(InputEvent.BUTTON1_DOWN_MASK);
-        assertEquals(event.getModifiers(), InputEvent.BUTTON1_MASK);
-        event.setModifiers(InputEvent.BUTTON2_DOWN_MASK);
-        assertEquals(event.getModifiers(), InputEvent.BUTTON2_MASK);
-        event.setModifiers(InputEvent.BUTTON3_DOWN_MASK);
-        assertEquals(event.getModifiers(), InputEvent.BUTTON3_MASK);
-        event.setModifiers(InputEvent.ALT_MASK);
-        assertEquals(event.getModifiers(), InputEvent.ALT_MASK);
-        event.setModifiers(InputEvent.ALT_DOWN_MASK);
-        assertEquals(event.getModifiers(), InputEvent.ALT_MASK);
-        event.setModifiers(InputEvent.ALT_GRAPH_DOWN_MASK);
-        assertEquals(event.getModifiers(), InputEvent.ALT_GRAPH_MASK);
-        event.setModifiers(InputEvent.ALT_GRAPH_MASK);
-        assertEquals(event.getModifiers(), InputEvent.ALT_GRAPH_MASK);
-        event.setModifiers(InputEvent.CTRL_MASK);
-        assertEquals(event.getModifiers(), InputEvent.CTRL_MASK);
-        event.setModifiers(InputEvent.CTRL_DOWN_MASK);
-        assertEquals(event.getModifiers(), InputEvent.CTRL_MASK);
-        event.setModifiers(InputEvent.SHIFT_DOWN_MASK);
-        assertEquals(event.getModifiers(), InputEvent.SHIFT_MASK);
-        event.setModifiers(InputEvent.SHIFT_MASK);
-        assertEquals(event.getModifiers(), InputEvent.SHIFT_MASK);
-        event.setModifiers(InputEvent.META_MASK);
-        assertEquals(event.getModifiers(), InputEvent.META_MASK);
-        event.setModifiers(InputEvent.META_DOWN_MASK);
-        assertEquals(event.getModifiers(), InputEvent.META_MASK);
+        assertEquals(InputEvent.MASKS, event.getModifiers());
     }
 
     public final void testGetModifiersEx() {
-        Button button = new Button("Button");
-        InputEvent event = new InputEvent(button, 0, 1000000000, 0) {};
+        Button button = new Button("Button"); //$NON-NLS-1$
+        InputEvent event = new InputEvent(button, 0, 1000000000,
+                InputEvent.MASKS | InputEvent.DOWN_MASKS) {};
 
-        event.setModifiers(InputEvent.BUTTON1_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.BUTTON1_DOWN_MASK);
-        event.setModifiers(InputEvent.BUTTON2_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.BUTTON2_DOWN_MASK | InputEvent.ALT_DOWN_MASK);
-        event.setModifiers(InputEvent.BUTTON3_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.BUTTON3_DOWN_MASK | InputEvent.META_DOWN_MASK);
-        event.setModifiers(InputEvent.BUTTON1_DOWN_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.BUTTON1_DOWN_MASK);
-        event.setModifiers(InputEvent.BUTTON2_DOWN_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.BUTTON2_DOWN_MASK);
-        event.setModifiers(InputEvent.BUTTON3_DOWN_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.BUTTON3_DOWN_MASK);
-        event.setModifiers(InputEvent.ALT_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.BUTTON2_DOWN_MASK | InputEvent.ALT_DOWN_MASK);
-        event.setModifiers(InputEvent.ALT_DOWN_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.ALT_DOWN_MASK);
-        event.setModifiers(InputEvent.ALT_GRAPH_DOWN_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.ALT_GRAPH_DOWN_MASK);
-        event.setModifiers(InputEvent.ALT_GRAPH_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.ALT_GRAPH_DOWN_MASK);
-        event.setModifiers(InputEvent.CTRL_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.CTRL_DOWN_MASK);
-        event.setModifiers(InputEvent.CTRL_DOWN_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.CTRL_DOWN_MASK);
-        event.setModifiers(InputEvent.SHIFT_DOWN_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.SHIFT_DOWN_MASK);
-        event.setModifiers(InputEvent.SHIFT_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.SHIFT_DOWN_MASK);
-        event.setModifiers(InputEvent.META_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.BUTTON3_DOWN_MASK | InputEvent.META_DOWN_MASK);
-        event.setModifiers(InputEvent.META_DOWN_MASK);
-        assertEquals(event.getModifiersEx(), InputEvent.META_DOWN_MASK);
+        assertEquals(InputEvent.DOWN_MASKS, event.getModifiersEx());
     }
 
     public final void testIsAltDown() {
-        Button button = new Button("Button");
+        Button button = new Button("Button"); //$NON-NLS-1$
         InputEvent event = new InputEvent(button, 0, 1000000000, 0) {};
 
         assertFalse(event.isAltDown());
-        event.setModifiers(InputEvent.ALT_DOWN_MASK);
+        event = new InputEvent(button, 0, 1000000000, InputEvent.ALT_DOWN_MASK) {};
         assertTrue(event.isAltDown());
     }
 
     public final void testIsAltGraphDown() {
-        Button button = new Button("Button");
+        Button button = new Button("Button"); //$NON-NLS-1$
         InputEvent event = new InputEvent(button, 0, 1000000000, 0) {};
 
         assertFalse(event.isAltGraphDown());
-        event.setModifiers(InputEvent.ALT_GRAPH_DOWN_MASK);
+        event = new InputEvent(button, 0, 1000000000, 
+                InputEvent.ALT_GRAPH_DOWN_MASK) {};
         assertTrue(event.isAltGraphDown());
     }
 
     public final void testIsControlDown() {
-        Button button = new Button("Button");
+        Button button = new Button("Button"); //$NON-NLS-1$
         InputEvent event = new InputEvent(button, 0, 1000000000, 0) {};
 
         assertFalse(event.isControlDown());
-        event.setModifiers(InputEvent.CTRL_DOWN_MASK);
+        event = new InputEvent(button, 0, 1000000000, InputEvent.CTRL_DOWN_MASK) {};
         assertTrue(event.isControlDown());
     }
 
     public final void testIsMetaDown() {
-        Button button = new Button("Button");
+        Button button = new Button("Button"); //$NON-NLS-1$
         InputEvent event = new InputEvent(button, 0, 1000000000, 0) {};
 
         assertFalse(event.isMetaDown());
-        event.setModifiers(InputEvent.META_DOWN_MASK);
+        event = new InputEvent(button, 0, 1000000000, InputEvent.META_DOWN_MASK) {};
         assertTrue(event.isMetaDown());
     }
 
     public final void testIsShiftDown() {
-        Button button = new Button("Button");
+        Button button = new Button("Button"); //$NON-NLS-1$
         InputEvent event = new InputEvent(button, 0, 1000000000, 0) {};
 
         assertFalse(event.isShiftDown());
-        event.setModifiers(InputEvent.SHIFT_DOWN_MASK);
+        event = new InputEvent(button, 0, 1000000000, InputEvent.SHIFT_DOWN_MASK) {};
         assertTrue(event.isShiftDown());
     }
 
     public final void testGetModifiersExText() {
-        assertTrue(InputEvent.getModifiersExText(InputEvent.ALT_DOWN_MASK).indexOf("Alt")
!= -1);
-        assertTrue(InputEvent.getModifiersExText(InputEvent.ALT_GRAPH_DOWN_MASK).indexOf("Alt
Graph") != -1);
-        assertTrue(InputEvent.getModifiersExText(InputEvent.CTRL_DOWN_MASK).indexOf("Ctrl")
!= -1);
-        assertTrue(InputEvent.getModifiersExText(InputEvent.SHIFT_DOWN_MASK).indexOf("Shift")
!= -1);
-        assertTrue(InputEvent.getModifiersExText(InputEvent.META_DOWN_MASK).indexOf("Meta")
!= -1);
-        assertTrue(InputEvent.getModifiersExText(InputEvent.BUTTON1_DOWN_MASK).indexOf("Button1")
!= -1);
-        assertTrue(InputEvent.getModifiersExText(InputEvent.BUTTON2_DOWN_MASK).indexOf("Button2")
!= -1);
-        assertTrue(InputEvent.getModifiersExText(InputEvent.BUTTON3_DOWN_MASK).indexOf("Button3")
!= -1);
+        assertTrue(InputEvent.getModifiersExText(InputEvent.ALT_DOWN_MASK).indexOf("Alt")
!= -1); //$NON-NLS-1$
+        assertTrue(InputEvent.getModifiersExText(InputEvent.ALT_GRAPH_DOWN_MASK).indexOf("Alt
Graph") != -1); //$NON-NLS-1$
+        assertTrue(InputEvent.getModifiersExText(InputEvent.CTRL_DOWN_MASK).indexOf("Ctrl")
!= -1); //$NON-NLS-1$
+        assertTrue(InputEvent.getModifiersExText(InputEvent.SHIFT_DOWN_MASK).indexOf("Shift")
!= -1); //$NON-NLS-1$
+        assertTrue(InputEvent.getModifiersExText(InputEvent.META_DOWN_MASK).indexOf("Meta")
!= -1); //$NON-NLS-1$
+        assertTrue(InputEvent.getModifiersExText(InputEvent.BUTTON1_DOWN_MASK).indexOf("Button1")
!= -1); //$NON-NLS-1$
+        assertTrue(InputEvent.getModifiersExText(InputEvent.BUTTON2_DOWN_MASK).indexOf("Button2")
!= -1); //$NON-NLS-1$
+        assertTrue(InputEvent.getModifiersExText(InputEvent.BUTTON3_DOWN_MASK).indexOf("Button3")
!= -1); //$NON-NLS-1$
     }
-
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/event/MouseEventTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/event/MouseEventTest.java?rev=587519&r1=587518&r2=587519&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/event/MouseEventTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/event/MouseEventTest.java
Tue Oct 23 07:34:26 2007
@@ -21,6 +21,7 @@
 package java.awt.event;
 
 import java.awt.Button;
+import java.awt.Component;
 import java.awt.Point;
 
 import junit.framework.TestCase;
@@ -44,19 +45,51 @@
     }
 
     public final void testMouseEventComponentintlongintintintintbooleanint() {
-        Button button = new Button("Button");
-        MouseEvent event = new MouseEvent(button, MouseEvent.MOUSE_PRESSED, 1000000000,
-                InputEvent.BUTTON2_DOWN_MASK, 100, 200,
-                10, true, MouseEvent.BUTTON1);
-
-        assertEquals(event.getSource(), button);
-        assertEquals(event.getID(), MouseEvent.MOUSE_PRESSED);
-        assertEquals(event.getButton(), MouseEvent.BUTTON1);
-        assertEquals(event.getClickCount(), 10);
-        assertEquals(event.getPoint(), new Point(100, 200));
-        assertEquals(event.getX(), 100);
-        assertEquals(event.getY(), 200);
+        final Button button = new Button("Button");
+        MouseEvent event = new MouseEvent(button, MouseEvent.MOUSE_PRESSED,
+                1000000000, InputEvent.BUTTON2_DOWN_MASK, 100, 200, 10, true,
+                MouseEvent.BUTTON1);
+
+        assertEquals(button, event.getSource());
+        assertEquals(MouseEvent.MOUSE_PRESSED, event.getID());
+        assertEquals(MouseEvent.BUTTON1, event.getButton());
+        assertEquals(10, event.getClickCount());
+        assertEquals(new Point(100, 200), event.getPoint());
+        assertEquals(100, event.getX());
+        assertEquals(200, event.getY());
         assertTrue(event.isPopupTrigger());
+        assertEquals(InputEvent.BUTTON1_MASK, event.getModifiers());
+        assertEquals(InputEvent.BUTTON2_DOWN_MASK, event.getModifiersEx());
+
+        event = new MouseEvent(button, MouseEvent.MOUSE_PRESSED, 0,
+                InputEvent.BUTTON1_MASK, 0, 0, 0, true, MouseEvent.NOBUTTON);
+        assertEquals(InputEvent.BUTTON1_MASK, event.getModifiers());
+        assertEquals(InputEvent.BUTTON1_DOWN_MASK, event.getModifiersEx());
+        assertEquals(MouseEvent.BUTTON1, event.getButton());
+
+        event = new MouseEvent(button, MouseEvent.MOUSE_PRESSED, 0, 0, 0, 0, 0,
+                true, MouseEvent.BUTTON1);
+        assertEquals(InputEvent.BUTTON1_MASK, event.getModifiers());
+        assertEquals(MouseEvent.BUTTON1, event.getButton());
+
+        event = new MouseEvent(button, MouseEvent.MOUSE_RELEASED, 1000000000,
+                0, 100, 200, 10, true, MouseEvent.BUTTON1);
+        assertEquals(InputEvent.BUTTON1_MASK, event.getModifiers());
+        assertEquals(0, event.getModifiersEx());
+
+        event = new MouseEvent(button, MouseEvent.MOUSE_CLICKED, 1000000000, 0,
+                100, 200, 10, true, MouseEvent.BUTTON1);
+        assertEquals(InputEvent.BUTTON1_MASK, event.getModifiers());
+        assertEquals(0, event.getModifiersEx());
+
+        event = new MouseEvent(button, MouseEvent.MOUSE_PRESSED, 0,
+                InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON2_DOWN_MASK
+                        | InputEvent.BUTTON3_DOWN_MASK, 0, 0, 0, true,
+                MouseEvent.BUTTON3);
+        assertEquals(InputEvent.BUTTON3_MASK, event.getModifiers());
+        assertEquals(InputEvent.BUTTON1_DOWN_MASK
+                | InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON3_DOWN_MASK,
+                event.getModifiersEx());
     }
 
     public final void testTranslatePoint() {
@@ -97,24 +130,19 @@
     }
 
     public final void testParamString() {
-        // This test case fails on the RI because the method
-        // InputEvent.getModifiers() works incorrectly.
-        // TODO: Reimplement the method InputEvent.getModifiers()
-
-        // Button button = new Button("Button");
-        // MouseEvent event = new MouseEvent(button, MouseEvent.MOUSE_PRESSED,
-        // 1000000000,
-        // InputEvent.BUTTON2_DOWN_MASK, 100, 200,
-        // 10, true, MouseEvent.BUTTON1);
-        //
-        // assertEquals(event.paramString(),
-        // "MOUSE_PRESSED,(100,200),button=1,modifiers=Button1,extModifiers=Button2,clickCount=10");
-        // event = new MouseEvent(button, MouseEvent.MOUSE_PRESSED + 1024,
-        // 1000000000,
-        // InputEvent.BUTTON2_MASK, 100, 200,
-        // 10, true, MouseEvent.BUTTON1);
-        // assertEquals(event.paramString(),
-        // "unknown
-        // type,(100,200),button=1,modifiers=Alt+Button2,extModifiers=Alt+Button2,clickCount=10");
+        Button button = new Button("Button");
+        MouseEvent event = new MouseEvent(button, MouseEvent.MOUSE_PRESSED,
+                1000000000, InputEvent.BUTTON2_DOWN_MASK, 100, 200, 10, true,
+                MouseEvent.BUTTON1);
+
+        assertEquals(
+                event.paramString(),
+                "MOUSE_PRESSED,(100,200),button=1,modifiers=Button1,extModifiers=Button2,clickCount=10");
+        event = new MouseEvent(button, MouseEvent.MOUSE_PRESSED + 1024,
+                1000000000, InputEvent.BUTTON2_MASK, 100, 200, 10, true,
+                MouseEvent.BUTTON1);
+        assertEquals(
+                event.paramString(),
+                "unknown type,(100,200),button=1,modifiers=Alt+Button2,extModifiers=Alt+Button2,clickCount=10");
     }
 }



Mime
View raw message