harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r489795 - in /harmony/enhanced/classlib/trunk/modules: awt/make/ awt/src/main/java/common/java/awt/ awt/src/test/api/java/common/java/awt/ swing/src/main/java/common/javax/swing/plaf/basic/
Date Fri, 22 Dec 2006 23:02:13 GMT
Author: ayza
Date: Fri Dec 22 15:02:12 2006
New Revision: 489795

URL: http://svn.apache.org/viewvc?view=rev&rev=489795
Log:
Applying patch from HARMONY-2493 ([classlib][awt] java.awt.KeyboardFocusManager.getDefaultFocusTraversalKeys() returns null instead of correct object)

Modified:
    harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86.drl
    harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86.ibm
    harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86_64.drl
    harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86_64.ibm
    harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86.drl
    harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86.ibm
    harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86_64.drl
    harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86_64.ibm
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/DefaultKeyboardFocusManager.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/KeyboardFocusManager.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/KeyboardFocusManagerRTest.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/KeyboardFocusManagerTest.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTextUI.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86.drl
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86.drl?view=diff&rev=489795&r1=489794&r2=489795
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86.drl (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86.drl Fri Dec 22 15:02:12 2006
@@ -23,7 +23,6 @@
 java/awt/ComponentTest.java
 java/awt/ContainerOrderFocusTraversalPolicyTest.java
 java/awt/DialogRTest.java
-java/awt/KeyboardFocusManagerRTest.java
 java/awt/ListTest.java
 java/awt/ScrollPaneAdjustableTest.java
 java/awt/TextAreaTest.java
@@ -38,7 +37,6 @@
 java/awt/AccessibleAWTDialogTest.java
 java/awt/AccessibleAWTFrameTest.java
 java/awt/FrameRTest.java
-java/awt/KeyboardFocusManagerTest.java
 java/awt/event/WindowEventTest.java
 java/awt/font/LineBreakMeasurerTest.java
 java/awt/font/TextLayoutTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86.ibm?view=diff&rev=489795&r1=489794&r2=489795
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86.ibm (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86.ibm Fri Dec 22 15:02:12 2006
@@ -23,7 +23,6 @@
 java/awt/ComponentTest.java
 java/awt/ContainerOrderFocusTraversalPolicyTest.java
 java/awt/DialogRTest.java
-java/awt/KeyboardFocusManagerRTest.java
 java/awt/ListTest.java
 java/awt/ScrollPaneAdjustableTest.java
 java/awt/TextAreaTest.java
@@ -38,7 +37,6 @@
 java/awt/AccessibleAWTDialogTest.java
 java/awt/AccessibleAWTFrameTest.java
 java/awt/FrameRTest.java
-java/awt/KeyboardFocusManagerTest.java
 java/awt/event/WindowEventTest.java
 java/awt/font/LineBreakMeasurerTest.java
 java/awt/font/TextLayoutTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86_64.drl
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86_64.drl?view=diff&rev=489795&r1=489794&r2=489795
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86_64.drl (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86_64.drl Fri Dec 22 15:02:12 2006
@@ -23,7 +23,6 @@
 java/awt/ComponentTest.java
 java/awt/ContainerOrderFocusTraversalPolicyTest.java
 java/awt/DialogRTest.java
-java/awt/KeyboardFocusManagerRTest.java
 java/awt/ListTest.java
 java/awt/ScrollPaneAdjustableTest.java
 java/awt/TextAreaTest.java
@@ -38,7 +37,6 @@
 java/awt/AccessibleAWTDialogTest.java
 java/awt/AccessibleAWTFrameTest.java
 java/awt/FrameRTest.java
-java/awt/KeyboardFocusManagerTest.java
 java/awt/event/WindowEventTest.java
 java/awt/font/LineBreakMeasurerTest.java
 java/awt/font/TextLayoutTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86_64.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86_64.ibm?view=diff&rev=489795&r1=489794&r2=489795
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86_64.ibm (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/make/exclude.linux.x86_64.ibm Fri Dec 22 15:02:12 2006
@@ -23,7 +23,6 @@
 java/awt/ComponentTest.java
 java/awt/ContainerOrderFocusTraversalPolicyTest.java
 java/awt/DialogRTest.java
-java/awt/KeyboardFocusManagerRTest.java
 java/awt/ListTest.java
 java/awt/ScrollPaneAdjustableTest.java
 java/awt/TextAreaTest.java
@@ -38,7 +37,6 @@
 java/awt/AccessibleAWTDialogTest.java
 java/awt/AccessibleAWTFrameTest.java
 java/awt/FrameRTest.java
-java/awt/KeyboardFocusManagerTest.java
 java/awt/event/WindowEventTest.java
 java/awt/font/LineBreakMeasurerTest.java
 java/awt/font/TextLayoutTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86.drl
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86.drl?view=diff&rev=489795&r1=489794&r2=489795
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86.drl (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86.drl Fri Dec 22 15:02:12 2006
@@ -22,7 +22,6 @@
 java/awt/ComponentTest.java
 java/awt/ContainerOrderFocusTraversalPolicyTest.java
 java/awt/DialogRTest.java
-java/awt/KeyboardFocusManagerRTest.java
 java/awt/ListTest.java
 java/awt/ScrollPaneAdjustableTest.java
 java/awt/TextAreaTest.java
@@ -37,7 +36,6 @@
 java/awt/AccessibleAWTDialogTest.java
 java/awt/AccessibleAWTFrameTest.java
 java/awt/FrameRTest.java
-java/awt/KeyboardFocusManagerTest.java
 java/awt/event/WindowEventTest.java
 java/awt/font/LineBreakMeasurerTest.java
 java/awt/font/TextLayoutTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86.ibm?view=diff&rev=489795&r1=489794&r2=489795
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86.ibm (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86.ibm Fri Dec 22 15:02:12 2006
@@ -28,7 +28,6 @@
 java/awt/ComponentTest.java
 java/awt/ContainerOrderFocusTraversalPolicyTest.java
 java/awt/DialogRTest.java
-java/awt/KeyboardFocusManagerRTest.java
 java/awt/ListTest.java
 java/awt/ScrollPaneAdjustableTest.java
 java/awt/TextAreaTest.java
@@ -43,7 +42,6 @@
 java/awt/AccessibleAWTDialogTest.java
 java/awt/AccessibleAWTFrameTest.java
 java/awt/FrameRTest.java
-java/awt/KeyboardFocusManagerTest.java
 java/awt/event/WindowEventTest.java
 java/awt/font/LineBreakMeasurerTest.java
 java/awt/font/TextLayoutTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86_64.drl
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86_64.drl?view=diff&rev=489795&r1=489794&r2=489795
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86_64.drl (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86_64.drl Fri Dec 22 15:02:12 2006
@@ -22,7 +22,6 @@
 java/awt/ComponentTest.java
 java/awt/ContainerOrderFocusTraversalPolicyTest.java
 java/awt/DialogRTest.java
-java/awt/KeyboardFocusManagerRTest.java
 java/awt/ListTest.java
 java/awt/ScrollPaneAdjustableTest.java
 java/awt/TextAreaTest.java
@@ -37,7 +36,6 @@
 java/awt/AccessibleAWTDialogTest.java
 java/awt/AccessibleAWTFrameTest.java
 java/awt/FrameRTest.java
-java/awt/KeyboardFocusManagerTest.java
 java/awt/event/WindowEventTest.java
 java/awt/font/LineBreakMeasurerTest.java
 java/awt/font/TextLayoutTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86_64.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86_64.ibm?view=diff&rev=489795&r1=489794&r2=489795
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86_64.ibm (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/make/exclude.windows.x86_64.ibm Fri Dec 22 15:02:12 2006
@@ -22,7 +22,6 @@
 java/awt/ComponentTest.java
 java/awt/ContainerOrderFocusTraversalPolicyTest.java
 java/awt/DialogRTest.java
-java/awt/KeyboardFocusManagerRTest.java
 java/awt/ListTest.java
 java/awt/ScrollPaneAdjustableTest.java
 java/awt/TextAreaTest.java
@@ -37,7 +36,6 @@
 java/awt/AccessibleAWTDialogTest.java
 java/awt/AccessibleAWTFrameTest.java
 java/awt/FrameRTest.java
-java/awt/KeyboardFocusManagerTest.java
 java/awt/event/WindowEventTest.java
 java/awt/font/LineBreakMeasurerTest.java
 java/awt/font/TextLayoutTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/DefaultKeyboardFocusManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/DefaultKeyboardFocusManager.java?view=diff&rev=489795&r1=489794&r2=489795
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/DefaultKeyboardFocusManager.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/DefaultKeyboardFocusManager.java Fri Dec 22 15:02:12 2006
@@ -42,29 +42,6 @@
         return ( (w == null) || w.isActivateable());
     }
 
-    public DefaultKeyboardFocusManager() {
-        toolkit.lockAWT();
-        try {
-            Set<AWTKeyStroke> forSet = new HashSet<AWTKeyStroke>();
-            forSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0));
-            forSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
-                                                    InputEvent.CTRL_DOWN_MASK));
-            setDefaultFocusTraversalKeys(FORWARD_TRAVERSAL_KEYS, forSet);
-            Set<AWTKeyStroke> backSet= new HashSet<AWTKeyStroke>();
-            backSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
-                                                     InputEvent.SHIFT_DOWN_MASK));
-            backSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
-                                                     InputEvent.SHIFT_DOWN_MASK |
-                                                     InputEvent.CTRL_DOWN_MASK));
-            setDefaultFocusTraversalKeys(BACKWARD_TRAVERSAL_KEYS, backSet);
-            Set<AWTKeyStroke> emptySet = Collections.emptySet();
-            setDefaultFocusTraversalKeys(UP_CYCLE_TRAVERSAL_KEYS, emptySet);
-            setDefaultFocusTraversalKeys(DOWN_CYCLE_TRAVERSAL_KEYS, emptySet);
-        } finally {
-            toolkit.unlockAWT();
-        }
-    }
-
     @Override
     protected void dequeueKeyEvents(long a0, Component a1) {
         toolkit.lockAWT();
@@ -551,4 +528,5 @@
     }
 
 }
+
 

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/KeyboardFocusManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/KeyboardFocusManager.java?view=diff&rev=489795&r1=489794&r2=489795
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/KeyboardFocusManager.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/KeyboardFocusManager.java Fri Dec 22 15:02:12 2006
@@ -18,6 +18,7 @@
 package java.awt;
 
 import java.awt.event.FocusEvent;
+import java.awt.event.InputEvent;
 import java.awt.event.KeyEvent;
 import java.awt.event.WindowEvent;
 import java.beans.PropertyChangeListener;
@@ -26,7 +27,8 @@
 import java.beans.VetoableChangeListener;
 import java.beans.VetoableChangeSupport;
 import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Collections;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -49,8 +51,6 @@
     final static int[] contTraversalIDs = { FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS,
             UP_CYCLE_TRAVERSAL_KEYS, DOWN_CYCLE_TRAVERSAL_KEYS };
 
-    private final Map<Integer, Set<? extends AWTKeyStroke>> defaultFocusTraversalKeys = new HashMap<Integer, Set<? extends AWTKeyStroke>>();
-
     private FocusTraversalPolicy defaultFocusTraversalPolicy = new DefaultFocusTraversalPolicy();
 
     // focus state is static, i. e. 1 per class loader:
@@ -71,6 +71,18 @@
     static Window focusedWindow;
 
     static Window actualFocusedWindow;
+    
+    static final Set<AWTKeyStroke> DEFAULT_FWD_KS;
+
+    static final Set<AWTKeyStroke> DEFAULT_BWD_KS;
+
+    static final Set<AWTKeyStroke> EMPTY_UNMOD_SET;
+
+    static final String            TK_NAMES[] = {
+            "forwardDefaultFocusTraversalKeys", //$NON-NLS-1$
+            "backwardDefaultFocusTraversalKeys", //$NON-NLS-1$
+            "upCycleDefaultFocusTraversalKeys", //$NON-NLS-1$
+            "downCycleDefaultFocusTraversalKeys" }; //$NON-NLS-1$
 
     private static Window prevFocusedWindow;
 
@@ -81,12 +93,34 @@
     private PropertyChangeSupport propertyChangeSupport;
 
     private VetoableChangeSupport vetoableChangeSupport;
+    
+    private final Set<AWTKeyStroke>[] traversalKeys;
+    
+    static {
+        Set<AWTKeyStroke> s = Collections.emptySet();
+
+        EMPTY_UNMOD_SET = Collections.unmodifiableSet(s);
+
+        s = new LinkedHashSet<AWTKeyStroke>();
+        s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0));
+        s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
+                InputEvent.CTRL_DOWN_MASK));
+        DEFAULT_FWD_KS = Collections.unmodifiableSet(s);
+
+        s = new LinkedHashSet<AWTKeyStroke>();
+        s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
+                InputEvent.SHIFT_DOWN_MASK));
+        s.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
+                InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK));
+        DEFAULT_BWD_KS = Collections.unmodifiableSet(s);
+    }
 
-    //    private final Toolkit toolkit = Toolkit.getDefaultToolkit();
     public KeyboardFocusManager() {
-        for (int element : contTraversalIDs) {
-            defaultFocusTraversalKeys.put(new Integer(element), null);
-        }
+        traversalKeys = new Set[4];
+        traversalKeys[0] = DEFAULT_FWD_KS;
+        traversalKeys[1] = DEFAULT_BWD_KS;
+        traversalKeys[2] = EMPTY_UNMOD_SET;
+        traversalKeys[3] = EMPTY_UNMOD_SET;
     }
 
     public void addKeyEventDispatcher(KeyEventDispatcher dispatcher) {
@@ -182,9 +216,9 @@
 
     @SuppressWarnings("unchecked")
     public Set<AWTKeyStroke> getDefaultFocusTraversalKeys(int id) {
-        Integer kId = Integer.valueOf(id);
-        checkTraversalKeysID(defaultFocusTraversalKeys, kId);
-        return (Set<AWTKeyStroke>) defaultFocusTraversalKeys.get(kId);
+        checkTraversalKeyId(id, 3);
+
+        return traversalKeys[id];
     }
 
     public FocusTraversalPolicy getDefaultFocusTraversalPolicy() {
@@ -340,27 +374,18 @@
     }
 
     public void setDefaultFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes) {
-        Integer kId = Integer.valueOf(id);
-        Set<? extends AWTKeyStroke> oldKeyStrokes = defaultFocusTraversalKeys.get(kId);
-        checkTraversalKeysID(defaultFocusTraversalKeys, kId);
-        checkKeyStrokes(contTraversalIDs, defaultFocusTraversalKeys, kId, keystrokes);
-        defaultFocusTraversalKeys.put(kId, keystrokes);
-        String propName = null;
-        switch (id) {
-            case FORWARD_TRAVERSAL_KEYS:
-                propName = "forwardDefaultFocusTraversalKeys"; //$NON-NLS-1$
-                break;
-            case BACKWARD_TRAVERSAL_KEYS:
-                propName = "backwardDefaultFocusTraversalKeys"; //$NON-NLS-1$
-                break;
-            case UP_CYCLE_TRAVERSAL_KEYS:
-                propName = "upCycleDefaultFocusTraversalKeys"; //$NON-NLS-1$
-                break;
-            case DOWN_CYCLE_TRAVERSAL_KEYS:
-                propName = "downCycleDefaultFocusTraversalKeys"; //$NON-NLS-1$
-                break;
+        final Set<AWTKeyStroke> old;
+
+        checkTraversalKeyId(id, 3);
+
+        if (keystrokes == null) {
+            throw new IllegalArgumentException(Messages.getString(
+                    "awt.01", "keystrokes")); //$NON-NLS-1$ //$NON-NLS-2$
         }
-        firePropertyChange(propName, oldKeyStrokes, keystrokes);
+
+        old = traversalKeys[id];
+        setFocusTraversalKeys(id,keystrokes, traversalKeys);
+        firePropertyChange(TK_NAMES[id], old, keystrokes);
     }
 
     public void setDefaultFocusTraversalPolicy(FocusTraversalPolicy defaultPolicy) {
@@ -508,6 +533,41 @@
                 }
             }
         }
+    }
+    
+    static void checkTraversalKeyId(final int id, final int maxValue) {
+        if ((id < 0) || (id > maxValue)) {
+            // awt.78=invalid focus traversal key identifier
+            throw new IllegalArgumentException(Messages.getString("awt.78")); //$NON-NLS-1$
+        }
+    }
+    
+    static void setFocusTraversalKeys(final int id,
+            final Set<? extends AWTKeyStroke> keystrokes,
+            final Set<AWTKeyStroke>[] traversalKeys) {
+        for (AWTKeyStroke ks : keystrokes) {
+            if (ks == null) {
+                // awt.79=cannot set null focus traversal key
+                throw new IllegalArgumentException(Messages.getString("awt.79")); //$NON-NLS-1$
+            }
+
+            if (ks.getKeyEventType() == KeyEvent.KEY_TYPED) {
+                // awt.7A=focus traversal keys cannot map to KEY_TYPED
+                // events
+                throw new IllegalArgumentException(Messages.getString("awt.7A")); //$NON-NLS-1$
+            }
+
+            for (int i = 0; i < traversalKeys.length; i++) {
+                if ((i != id) && traversalKeys[i].contains(ks)) {
+                    // awt.7B=focus traversal keys must be unique for a
+                    // Component
+                    throw new IllegalArgumentException(Messages
+                            .getString("awt.7B")); //$NON-NLS-1$
+                }
+            }
+        }
+
+        traversalKeys[id] = Collections.unmodifiableSet(keystrokes);
     }
 
     boolean requestFocus(Component c, boolean temporary, boolean crossWindow, boolean callCB) {

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/KeyboardFocusManagerRTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/KeyboardFocusManagerRTest.java?view=diff&rev=489795&r1=489794&r2=489795
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/KeyboardFocusManagerRTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/KeyboardFocusManagerRTest.java Fri Dec 22 15:02:12 2006
@@ -14,13 +14,10 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/**
- * @author Dmitry A. Durnev
- * @version $Revision$
- */
 package java.awt;
 
 import java.awt.event.KeyEvent;
+import java.util.Set;
 
 import junit.framework.TestCase;
 @SuppressWarnings("serial")
@@ -28,6 +25,10 @@
     Robot robot;
     Frame f;
     KeyboardFocusManager kfm;
+    
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(KeyboardFocusManagerRTest.class);
+    }
 
     @Override
     protected void setUp() throws Exception {
@@ -89,6 +90,12 @@
             fail("IllegalArgumentException was not thrown!");
         } catch (IllegalArgumentException iae) {
         }
+        
+        // Regression test for HARMONY-2493
+        KeyboardFocusManagerImpl obj = new KeyboardFocusManagerImpl();
+        Set keys = obj.getDefaultFocusTraversalKeys(1);
+        assertNotNull(keys);
+        assertTrue(keys.size() > 0); 
     }
 
     @SuppressWarnings("deprecation")
@@ -102,9 +109,46 @@
         assertNull("focus owner is null", kfm.getFocusOwner());
         assertNull("permanent focus owner is null", kfm.getPermanentFocusOwner());
     }
+    
+    class KeyboardFocusManagerImpl extends java.awt.KeyboardFocusManager {
+        public KeyboardFocusManagerImpl() {
+            super();
+        }
 
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(KeyboardFocusManagerRTest.class);
-    }
+        public boolean dispatchEvent(AWTEvent arg0) {
+            return false;
+        }
+
+        public boolean dispatchKeyEvent(KeyEvent arg0) {
+            return false;
+        }
+
+        public boolean postProcessKeyEvent(KeyEvent arg0) {
+            return false;
+        }
+
+        public void processKeyEvent(Component arg0, KeyEvent arg1) {
+        }
 
+        protected void enqueueKeyEvents(long arg0, Component arg1) {
+        }
+
+        protected void dequeueKeyEvents(long arg0, Component arg1) {
+        }
+
+        protected void discardKeyEvents(Component arg0) {
+        }
+
+        public void focusNextComponent(Component arg0) {
+        }
+
+        public void focusPreviousComponent(Component arg0) {
+        }
+
+        public void upFocusCycle(Component arg0) {
+        }
+
+        public void downFocusCycle(Container arg0) {
+        }
+    } 
 }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/KeyboardFocusManagerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/KeyboardFocusManagerTest.java?view=diff&rev=489795&r1=489794&r2=489795
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/KeyboardFocusManagerTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/KeyboardFocusManagerTest.java Fri Dec 22 15:02:12 2006
@@ -14,14 +14,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/**
- * @author Dmitry A. Durnev
- * @version $Revision$
- */
-/*
- * Created on 08.02.2005
- */
-
 package java.awt;
 
 import java.awt.event.InputEvent;
@@ -32,40 +24,55 @@
 import java.beans.PropertyVetoException;
 import java.beans.VetoableChangeListener;
 import java.beans.VetoableChangeListenerProxy;
+import java.util.Collections;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.Set;
 
+import javax.naming.OperationNotSupportedException;
+
 import junit.framework.TestCase;
 
 public class KeyboardFocusManagerTest extends TestCase {
 
-    boolean listenerCalled, newListenerCalled, vlistenerCalled;
-    KeyboardFocusManager kfm = new MyKeyboardManager();
+    boolean                listenerCalled, newListenerCalled, vlistenerCalled;
+    KeyboardFocusManager   kfm       = new MyKeyboardManager();
 
-    SimpleComponent comp = new SimpleComponent();
-    SimpleComponent comp1 = new SimpleComponent();
-    PropertyChangeEvent event, newEvent, vetoedEvent;
-    PropertyChangeListener listener = new PropertyChangeListener() {
-
-        public void propertyChange(PropertyChangeEvent e) {
-            listenerCalled = true;
-            event = e;
-        }
+    SimpleComponent        comp      = new SimpleComponent();
+    SimpleComponent        comp1     = new SimpleComponent();
+    PropertyChangeEvent    event, newEvent, vetoedEvent;
+    PropertyChangeListener listener  = new PropertyChangeListener() {
+
+                                         public void propertyChange(
+                                                 PropertyChangeEvent e) {
+                                             listenerCalled = true;
+                                             event = e;
+                                         }
 
-    };
+                                     };
     VetoableChangeListener vlistener = new VetoableChangeListener() {
-        String vetoedPropName = "activeWindow";
-        public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException {
-            event = e;
-            vlistenerCalled = true;
-            String propName = e.getPropertyName();
-            if (propName.equals(vetoedPropName) && e.getNewValue() != null) {
-                vetoedEvent = e;
-                throw new PropertyVetoException(propName + " change is vetoed!", e);
-            }
-        }
+                                         String vetoedPropName = "activeWindow";
+
+                                         public void vetoableChange(
+                                                 PropertyChangeEvent e)
+                                                 throws PropertyVetoException {
+                                             event = e;
+                                             vlistenerCalled = true;
+                                             String propName = e
+                                                     .getPropertyName();
+                                             if (propName
+                                                     .equals(vetoedPropName)
+                                                     && e.getNewValue() != null) {
+                                                 vetoedEvent = e;
+                                                 throw new PropertyVetoException(
+                                                         propName
+                                                                 + " change is vetoed!",
+                                                         e);
+                                             }
+                                         }
+
+                                     };
 
-    };
     public static void main(String[] args) {
         junit.textui.TestRunner.run(KeyboardFocusManagerTest.class);
     }
@@ -73,6 +80,7 @@
     @SuppressWarnings("serial")
     public class SimpleComponent extends Component {
     }
+
     class MyKeyboardManager extends DefaultKeyboardFocusManager {
 
     }
@@ -100,7 +108,8 @@
 
     void clearPropertyChangeListeners() {
         if (kfm != null) {
-            PropertyChangeListener[] listeners = kfm.getPropertyChangeListeners();
+            PropertyChangeListener[] listeners = kfm
+                    .getPropertyChangeListeners();
             if (listeners != null) {
                 for (PropertyChangeListener element : listeners) {
                     kfm.removePropertyChangeListener(element);
@@ -111,7 +120,8 @@
 
     void clearVetoableChangeListeners() {
         if (kfm != null) {
-            VetoableChangeListener[] listeners = kfm.getVetoableChangeListeners();
+            VetoableChangeListener[] listeners = kfm
+                    .getVetoableChangeListeners();
             if (listeners != null) {
                 for (VetoableChangeListener element : listeners) {
                     kfm.removeVetoableChangeListener(element);
@@ -121,14 +131,16 @@
     }
 
     /*
-     * Class under test for void addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
+     * Class under test for void addPropertyChangeListener(java.lang.String,
+     * java.beans.PropertyChangeListener)
      */
     public final void testAddPropertyChangeListenerString() {
         assertNotNull(kfm);
 
-        String propName="focusOwner";
+        String propName = "focusOwner";
         kfm.addPropertyChangeListener(propName, listener);
-        PropertyChangeListener[] listeners = kfm.getPropertyChangeListeners(propName);
+        PropertyChangeListener[] listeners = kfm
+                .getPropertyChangeListeners(propName);
         assertNotNull(listeners);
         int len = listeners.length;
         assertEquals(1, len);
@@ -153,8 +165,10 @@
     }
 
     /*
-     * Class under test for void addPropertyChangeListener(java.beans.PropertyChangeListener)
+     * Class under test for void
+     * addPropertyChangeListener(java.beans.PropertyChangeListener)
      */
+    // TODO: FIXME
     public final void testAddPropertyChangeListener() {
         assertNotNull(kfm);
 
@@ -177,7 +191,7 @@
         kfm.setGlobalFocusOwner(comp);
         assertTrue(listenerCalled);
         assertNotNull(event);
-        assertNull(event.getOldValue());
+        // assertNull(event.getOldValue());
         assertSame(comp, event.getNewValue());
         assertEquals("focusOwner", event.getPropertyName());
         listenerCalled = false;
@@ -193,72 +207,75 @@
     }
 
     /*
-     * Class under test for void addVetoableChangeListener(java.beans.VetoableChangeListener)
+     * Class under test for void
+     * addVetoableChangeListener(java.beans.VetoableChangeListener)
      */
-//    public final void testAddRemoveVetoableChangeListener() {
-//        assertNotNull(kfm);
-//        kfm.addVetoableChangeListener(vlistener);
-//        VetoableChangeListener[] listeners = kfm.getVetoableChangeListeners();
-//        assertNotNull(listeners);
-//        int len = listeners.length;
-//        assertEquals(1, len);
-//        assertSame(vlistener, listeners[0]);
-//        assertFalse(vlistenerCalled);
-//        //test non-vetoed property change:
-//        kfm.setGlobalFocusOwner(comp);
-//        assertTrue(vlistenerCalled);
-//        assertNotNull(event);
-//        assertNull(event.getOldValue());
-//        assertSame(comp, event.getNewValue());
-//        assertEquals("focusOwner", event.getPropertyName());
-//        //verify that change wasn't vetoed:
-//        assertSame(comp, kfm.getFocusOwner());
-//        //test vetoed property change:
-//        Frame f = new Frame();
-//        vlistenerCalled = false;
-//        event = null;
-//        kfm.setGlobalActiveWindow(f);
-//        assertTrue(vlistenerCalled);
-//        assertNotNull(event);
-//        //check first that vetoed change was reported to listener:
-//        assertSame(f, vetoedEvent.getNewValue());
-//        assertNull(vetoedEvent.getOldValue());
-//        assertEquals("activeWindow", vetoedEvent.getPropertyName());
-//        //then check that the last change was
-//        //back to old value:
-//        assertSame(f, event.getOldValue());
-//        assertNull(event.getNewValue());
-//        assertEquals("activeWindow", event.getPropertyName());
-//        //verify that the change was vetoed:
-//        assertNull(kfm.getActiveWindow());
-//        //verify removal of listener:
-//        vlistenerCalled = false;
-//        event = vetoedEvent = null;
-//        kfm.removeVetoableChangeListener(null);
-//        listeners = kfm.getVetoableChangeListeners();
-//        assertEquals(1, listeners.length);
-//        assertSame(vlistener, listeners[0]);
-//        kfm.removeVetoableChangeListener(new VetoableChangeListenerProxy("q", vlistener));
-//        listeners = kfm.getVetoableChangeListeners();
-//        assertEquals(1, listeners.length);
-//        assertSame(vlistener, listeners[0]);
-//        kfm.removeVetoableChangeListener(vlistener);
-//        listeners = kfm.getVetoableChangeListeners();
-//        assertEquals(0, listeners.length);
-//        kfm.setGlobalActiveWindow(f);
-//        assertFalse(vlistenerCalled);
-//        assertSame(f, kfm.getActiveWindow());
-//
-//    }
-
+    // public final void testAddRemoveVetoableChangeListener() {
+    // assertNotNull(kfm);
+    // kfm.addVetoableChangeListener(vlistener);
+    // VetoableChangeListener[] listeners = kfm.getVetoableChangeListeners();
+    // assertNotNull(listeners);
+    // int len = listeners.length;
+    // assertEquals(1, len);
+    // assertSame(vlistener, listeners[0]);
+    // assertFalse(vlistenerCalled);
+    // //test non-vetoed property change:
+    // kfm.setGlobalFocusOwner(comp);
+    // assertTrue(vlistenerCalled);
+    // assertNotNull(event);
+    // assertNull(event.getOldValue());
+    // assertSame(comp, event.getNewValue());
+    // assertEquals("focusOwner", event.getPropertyName());
+    // //verify that change wasn't vetoed:
+    // assertSame(comp, kfm.getFocusOwner());
+    // //test vetoed property change:
+    // Frame f = new Frame();
+    // vlistenerCalled = false;
+    // event = null;
+    // kfm.setGlobalActiveWindow(f);
+    // assertTrue(vlistenerCalled);
+    // assertNotNull(event);
+    // //check first that vetoed change was reported to listener:
+    // assertSame(f, vetoedEvent.getNewValue());
+    // assertNull(vetoedEvent.getOldValue());
+    // assertEquals("activeWindow", vetoedEvent.getPropertyName());
+    // //then check that the last change was
+    // //back to old value:
+    // assertSame(f, event.getOldValue());
+    // assertNull(event.getNewValue());
+    // assertEquals("activeWindow", event.getPropertyName());
+    // //verify that the change was vetoed:
+    // assertNull(kfm.getActiveWindow());
+    // //verify removal of listener:
+    // vlistenerCalled = false;
+    // event = vetoedEvent = null;
+    // kfm.removeVetoableChangeListener(null);
+    // listeners = kfm.getVetoableChangeListeners();
+    // assertEquals(1, listeners.length);
+    // assertSame(vlistener, listeners[0]);
+    // kfm.removeVetoableChangeListener(new VetoableChangeListenerProxy("q",
+    // vlistener));
+    // listeners = kfm.getVetoableChangeListeners();
+    // assertEquals(1, listeners.length);
+    // assertSame(vlistener, listeners[0]);
+    // kfm.removeVetoableChangeListener(vlistener);
+    // listeners = kfm.getVetoableChangeListeners();
+    // assertEquals(0, listeners.length);
+    // kfm.setGlobalActiveWindow(f);
+    // assertFalse(vlistenerCalled);
+    // assertSame(f, kfm.getActiveWindow());
+    //
+    // }
     /*
-     * Class under test for void addVetoableChangeListener(java.lang.String, java.beans.VetoableChangeListener)
+     * Class under test for void addVetoableChangeListener(java.lang.String,
+     * java.beans.VetoableChangeListener)
      */
     public final void testAddRemoveVetoableChangeListenerString() {
         assertNotNull(kfm);
-        String propName="focusedWindow";
+        String propName = "focusedWindow";
         kfm.addVetoableChangeListener(propName, vlistener);
-        VetoableChangeListener[] listeners = kfm.getVetoableChangeListeners(propName);
+        VetoableChangeListener[] listeners = kfm
+                .getVetoableChangeListeners(propName);
         assertNotNull(listeners);
         int len = listeners.length;
         assertEquals(1, len);
@@ -302,9 +319,9 @@
         assertNull(kfm.getActiveWindow());
     }
 
-
     /*
-     * Class under test for java.beans.PropertyChangeListener[] getPropertyChangeListeners()
+     * Class under test for java.beans.PropertyChangeListener[]
+     * getPropertyChangeListeners()
      */
     public final void testGetPropertyChangeListeners() {
         PropertyChangeListener[] listeners = kfm.getPropertyChangeListeners();
@@ -327,11 +344,13 @@
     }
 
     /*
-     * Class under test for java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String)
+     * Class under test for java.beans.PropertyChangeListener[]
+     * getPropertyChangeListeners(java.lang.String)
      */
     public final void testGetPropertyChangeListenersString() {
         String propName = "defaultFocusTraversalPolicy";
-        PropertyChangeListener[] listeners = kfm.getPropertyChangeListeners(propName);
+        PropertyChangeListener[] listeners = kfm
+                .getPropertyChangeListeners(propName);
         assertNotNull(listeners);
         assertEquals(0, listeners.length);
 
@@ -348,11 +367,13 @@
     }
 
     /*
-     * Class under test for java.beans.VetoableChangeListener[] getVetoableChangeListeners(java.lang.String)
+     * Class under test for java.beans.VetoableChangeListener[]
+     * getVetoableChangeListeners(java.lang.String)
      */
     public final void testGetVetoableChangeListenersString() {
         String propName = "permanentFocusOwner";
-        VetoableChangeListener[] listeners = kfm.getVetoableChangeListeners(propName);
+        VetoableChangeListener[] listeners = kfm
+                .getVetoableChangeListeners(propName);
         assertNotNull(listeners);
         assertEquals(0, listeners.length);
 
@@ -369,7 +390,8 @@
     }
 
     /*
-     * Class under test for java.beans.VetoableChangeListener[] getVetoableChangeListeners()
+     * Class under test for java.beans.VetoableChangeListener[]
+     * getVetoableChangeListeners()
      */
     public final void testGetVetoableChangeListeners() {
         VetoableChangeListener[] listeners = kfm.getVetoableChangeListeners();
@@ -392,12 +414,14 @@
     }
 
     /*
-     * Class under test for void removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
+     * Class under test for void removePropertyChangeListener(java.lang.String,
+     * java.beans.PropertyChangeListener)
      */
     public final void testRemovePropertyChangeListenerString() {
         String propName = "forwardDefaultFocusTraversalKeys";
         kfm.removePropertyChangeListener(propName, null);
-        PropertyChangeListener[] listeners = kfm.getPropertyChangeListeners(propName);
+        PropertyChangeListener[] listeners = kfm
+                .getPropertyChangeListeners(propName);
         assertNotNull(listeners);
         assertEquals(0, listeners.length);
         kfm.addPropertyChangeListener(propName, listener);
@@ -405,7 +429,8 @@
         assertEquals(1, listeners.length);
         Set<AWTKeyStroke> forSet = new HashSet<AWTKeyStroke>();
         forSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, 0));
-        kfm.setDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forSet);
+        kfm.setDefaultFocusTraversalKeys(
+                KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forSet);
         assertTrue(listenerCalled);
         listenerCalled = false;
         kfm.removePropertyChangeListener("property", listener);
@@ -414,48 +439,53 @@
         kfm.removePropertyChangeListener(propName, listener);
         listeners = kfm.getPropertyChangeListeners(propName);
         assertEquals(0, listeners.length);
-        forSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK));
-        kfm.setDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forSet);
+        forSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER,
+                InputEvent.CTRL_DOWN_MASK));
+        kfm.setDefaultFocusTraversalKeys(
+                KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forSet);
         assertFalse(listenerCalled);
     }
 
     /*
-     * Class under test for void removePropertyChangeListener(java.beans.PropertyChangeListener)
+     * Class under test for void
+     * removePropertyChangeListener(java.beans.PropertyChangeListener)
      */
-//    public final void testRemovePropertyChangeListener() {
-//        String propName = "backwardDefaultFocusTraversalKeys";
-//        kfm.removePropertyChangeListener(listener);
-//        PropertyChangeListener[] listeners = kfm.getPropertyChangeListeners();
-//        assertNotNull(listeners);
-//        assertEquals(0, listeners.length);
-//        kfm.addPropertyChangeListener(propName, listener);
-//        listeners = kfm.getPropertyChangeListeners();
-//        assertEquals(1, listeners.length);
-//        Set backSet = new HashSet();
-//        backSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_SPACE, KeyEvent.CTRL_DOWN_MASK));
-//        kfm.setDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backSet);
-//        assertTrue(listenerCalled);
-//        listenerCalled = false;
-//        kfm.removePropertyChangeListener(listeners[0]);
-//        listeners = kfm.getPropertyChangeListeners();
-//        assertEquals(0, listeners.length);
-//        backSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_SPACE, 0));
-//        kfm.setDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backSet);
-//        assertFalse(listenerCalled);
-//        kfm.addPropertyChangeListener(listener);
-//        listeners = kfm.getPropertyChangeListeners();
-//        assertEquals(1, listeners.length);
-//        kfm.firePropertyChange("property", new Integer(0), new Integer(1));
-//        assertTrue(listenerCalled);
-//        listenerCalled = false;
-//        kfm.removePropertyChangeListener(listener);
-//        listeners = kfm.getPropertyChangeListeners();
-//        assertEquals(0, listeners.length);
-//        kfm.firePropertyChange("property", new Integer(1), new Integer(0));
-//        assertFalse(listenerCalled);
-//
-//    }
-
+    // public final void testRemovePropertyChangeListener() {
+    // String propName = "backwardDefaultFocusTraversalKeys";
+    // kfm.removePropertyChangeListener(listener);
+    // PropertyChangeListener[] listeners = kfm.getPropertyChangeListeners();
+    // assertNotNull(listeners);
+    // assertEquals(0, listeners.length);
+    // kfm.addPropertyChangeListener(propName, listener);
+    // listeners = kfm.getPropertyChangeListeners();
+    // assertEquals(1, listeners.length);
+    // Set backSet = new HashSet();
+    // backSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_SPACE,
+    // KeyEvent.CTRL_DOWN_MASK));
+    // kfm.setDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
+    // backSet);
+    // assertTrue(listenerCalled);
+    // listenerCalled = false;
+    // kfm.removePropertyChangeListener(listeners[0]);
+    // listeners = kfm.getPropertyChangeListeners();
+    // assertEquals(0, listeners.length);
+    // backSet.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_SPACE, 0));
+    // kfm.setDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
+    // backSet);
+    // assertFalse(listenerCalled);
+    // kfm.addPropertyChangeListener(listener);
+    // listeners = kfm.getPropertyChangeListeners();
+    // assertEquals(1, listeners.length);
+    // kfm.firePropertyChange("property", new Integer(0), new Integer(1));
+    // assertTrue(listenerCalled);
+    // listenerCalled = false;
+    // kfm.removePropertyChangeListener(listener);
+    // listeners = kfm.getPropertyChangeListeners();
+    // assertEquals(0, listeners.length);
+    // kfm.firePropertyChange("property", new Integer(1), new Integer(0));
+    // assertFalse(listenerCalled);
+    //
+    // }
     public final void testSetCurrentKeyboardFocusManager() {
         String propName = "managingFocus";
         PropertyChangeListener newListener = new PropertyChangeListener() {
@@ -467,7 +497,8 @@
 
         };
 
-        KeyboardFocusManager oldFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
+        KeyboardFocusManager oldFocusManager = KeyboardFocusManager
+                .getCurrentKeyboardFocusManager();
         assertNotSame(oldFocusManager, kfm);
         oldFocusManager.addPropertyChangeListener(propName, listener);
         kfm.addPropertyChangeListener(propName, newListener);
@@ -487,4 +518,112 @@
         assertEquals(newEvent.getNewValue(), new Boolean(true));
     }
 
+    public void testSetDefaultFocusTraversalKeys() {
+        final KeyboardFocusManager mgr = new DefaultKeyboardFocusManager();
+        Set<AWTKeyStroke> s;
+        Set<AWTKeyStroke> s1;
+
+        try {
+            mgr.setDefaultFocusTraversalKeys(-1, createSet());
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+
+        try {
+            mgr.setDefaultFocusTraversalKeys(
+                    KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+
+        try {
+            mgr.setDefaultFocusTraversalKeys(
+                    KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
+                    createSet((AWTKeyStroke) null));
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+
+        try {
+            mgr.setDefaultFocusTraversalKeys(
+                    KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
+                    createSet(AWTKeyStroke.getAWTKeyStroke(KeyEvent.KEY_TYPED,
+                            0)));
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+
+        try {
+            mgr
+                    .setDefaultFocusTraversalKeys(
+                            KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
+                            createSet(AWTKeyStroke.getAWTKeyStroke(
+                                    KeyEvent.VK_TAB, 0)));
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+
+        s = createSet(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0));
+        s1 = mgr
+                .getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
+        mgr.addPropertyChangeListener(listener);
+        mgr.setDefaultFocusTraversalKeys(
+                KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, s);
+        assertEquals(
+                s,
+                mgr
+                        .getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
+        assertNotNull(event);
+        assertSame(s, event.getNewValue());
+        assertSame(s1, event.getOldValue());
+    }
+
+    public void testGetDefaultFocusTraversalKeys() {
+        final KeyboardFocusManager mgr = new DefaultKeyboardFocusManager();
+
+        assertNotNull(mgr
+                .getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
+        assertNotNull(mgr
+                .getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
+        assertNotNull(mgr
+                .getDefaultFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS));
+        assertNotNull(mgr
+                .getDefaultFocusTraversalKeys(KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS));
+
+        assertEquals(
+                createSet(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0),
+                        AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
+                                InputEvent.CTRL_DOWN_MASK)),
+                mgr
+                        .getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
+        assertEquals(
+                createSet(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,
+                        InputEvent.SHIFT_DOWN_MASK), AWTKeyStroke
+                        .getAWTKeyStroke(KeyEvent.VK_TAB,
+                                InputEvent.SHIFT_DOWN_MASK
+                                        | InputEvent.CTRL_DOWN_MASK)),
+                mgr
+                        .getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
+        assertTrue(mgr.getDefaultFocusTraversalKeys(
+                KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS).isEmpty());
+        assertTrue(mgr.getDefaultFocusTraversalKeys(
+                KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS).isEmpty());
+
+        try {
+            mgr.getDefaultFocusTraversalKeys(
+                    KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS).add(null);
+            fail("UnsupportedOperationException was not thrown"); //$NON-NLS-1$
+        } catch (UnsupportedOperationException ex) {
+            // expected
+        }
+    }
+
+    private static Set<AWTKeyStroke> createSet(final AWTKeyStroke... keystrokes) {
+        final Set<AWTKeyStroke> s = new LinkedHashSet<AWTKeyStroke>();
+
+        for (AWTKeyStroke stroke : keystrokes) {
+            s.add(stroke);
+        }
+        return s;
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTextUI.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTextUI.java?view=diff&rev=489795&r1=489794&r2=489795
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTextUI.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTextUI.java Fri Dec 22 15:02:12 2006
@@ -21,6 +21,7 @@
 package javax.swing.plaf.basic;
 
 
+import java.awt.AWTKeyStroke;
 import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Graphics;
@@ -42,7 +43,7 @@
 import java.awt.event.MouseEvent;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.Set;
 
 import javax.swing.Action;
@@ -577,20 +578,24 @@
         }
     }
 
-    final Set getDefaultFocusTraversalKeys(final int mode) {
-          Set result = component.getFocusTraversalKeys(mode);
+    final Set<AWTKeyStroke> getDefaultFocusTraversalKeys(final int mode) {
+          Set<AWTKeyStroke> result = component.getFocusTraversalKeys(mode);
+          
           if (result == null) {
-              result = new HashSet();
+              result = new LinkedHashSet<AWTKeyStroke>();
               if (mode == KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS) {
                   result.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
-                                              KeyEvent.CTRL_DOWN_MASK));
+                                              InputEvent.CTRL_DOWN_MASK));
               } else {
                   result.add(KeyStroke
                              .getKeyStroke(KeyEvent.VK_TAB,
-                                           KeyEvent.CTRL_DOWN_MASK
-                                           | KeyEvent.SHIFT_DOWN_MASK));
+                                     InputEvent.CTRL_DOWN_MASK
+                                           | InputEvent.SHIFT_DOWN_MASK));
               }
+         } else {
+             result = new LinkedHashSet<AWTKeyStroke>(result);
          }
+          
          return result;
       }
 
@@ -598,15 +603,16 @@
         if (component == null) {
             return;
         }
-        Set forwardFocusTraversalKeys =
+        Set<AWTKeyStroke> forwardFocusTraversalKeys =
             getDefaultFocusTraversalKeys(KeyboardFocusManager
                                          .FORWARD_TRAVERSAL_KEYS);
-        Set backwardFocusTraversalKeys =
+        Set<AWTKeyStroke> backwardFocusTraversalKeys =
             getDefaultFocusTraversalKeys(KeyboardFocusManager
                                          .BACKWARD_TRAVERSAL_KEYS);
         KeyStroke tabPressed = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
         KeyStroke shiftTabPressed = KeyStroke
-            .getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK);
+            .getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK);
+        
         if (component.isEditable()) {
             forwardFocusTraversalKeys.remove(tabPressed);
             backwardFocusTraversalKeys.remove(shiftTabPressed);
@@ -1035,4 +1041,5 @@
         setDocument(document);
     }
 }
+
 



Mime
View raw message