changeset 48352:2469e21060a0

8183518: Premature deprecation of Event/InputEvent/KeyEvent in Java 9 Reviewed-by: prr, psadhukhan
author serb
date Fri, 01 Dec 2017 17:44:07 -0800
parents 195b82f9f7d1
children baad9dc0eab1
files src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java src/java.desktop/share/classes/java/awt/MenuBar.java src/java.desktop/share/classes/java/awt/MenuShortcut.java src/java.desktop/share/classes/java/awt/Toolkit.java src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboPopup.java src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java src/java.desktop/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java src/java.desktop/share/classes/sun/awt/HToolkit.java src/java.desktop/share/classes/sun/awt/HeadlessToolkit.java test/jdk/java/awt/Toolkit/Headless/HeadlessToolkit.java
diffstat 10 files changed, 99 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Fri Dec 01 10:35:58 2017 -0800
+++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Fri Dec 01 17:44:07 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -502,30 +502,18 @@
         }
     }
 
-    /**
-     * Determines which modifier key is the appropriate accelerator
-     * key for menu shortcuts.
-     * <p>
-     * Menu shortcuts, which are embodied in the
-     * {@code MenuShortcut} class, are handled by the
-     * {@code MenuBar} class.
-     * <p>
-     * By default, this method returns {@code Event.CTRL_MASK}.
-     * Toolkit implementations should override this method if the
-     * <b>Control</b> key isn't the correct key for accelerators.
-     * @return    the modifier mask on the {@code Event} class
-     *                 that is used for menu shortcuts on this toolkit.
-     * @see       java.awt.MenuBar
-     * @see       java.awt.MenuShortcut
-     * @since     1.1
-     */
     @Override
-    @SuppressWarnings("deprecation")
+    @Deprecated(since = "10")
     public int getMenuShortcutKeyMask() {
         return Event.META_MASK;
     }
 
     @Override
+    public int getMenuShortcutKeyMaskEx() {
+        return InputEvent.META_DOWN_MASK;
+    }
+
+    @Override
     public Image getImage(final String filename) {
         final Image nsImage = checkForNSImage(filename);
         if (nsImage != null) {
--- a/src/java.desktop/share/classes/java/awt/MenuBar.java	Fri Dec 01 10:35:58 2017 -0800
+++ b/src/java.desktop/share/classes/java/awt/MenuBar.java	Fri Dec 01 17:44:07 2017 -0800
@@ -377,7 +377,6 @@
      * keydown).  Returns true if there is an associated
      * keyboard event.
      */
-    @SuppressWarnings("deprecation")
     boolean handleShortcut(KeyEvent e) {
         // Is it a key event?
         int id = e.getID();
@@ -386,8 +385,8 @@
         }
 
         // Is the accelerator modifier key pressed?
-        int accelKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
-        if ((e.getModifiers() & accelKey) == 0) {
+        int accelKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx();
+        if ((e.getModifiersEx() & accelKey) == 0) {
             return false;
         }
 
--- a/src/java.desktop/share/classes/java/awt/MenuShortcut.java	Fri Dec 01 10:35:58 2017 -0800
+++ b/src/java.desktop/share/classes/java/awt/MenuShortcut.java	Fri Dec 01 17:44:07 2017 -0800
@@ -24,6 +24,7 @@
  */
 package java.awt;
 
+import java.awt.event.InputEvent;
 import java.awt.event.KeyEvent;
 
 /**
@@ -51,7 +52,7 @@
  * only work if the current keyboard layout produces a corresponding letter.
  * <p>
  * The accelerator key is platform-dependent and may be obtained
- * via {@link Toolkit#getMenuShortcutKeyMask}.
+ * via {@link Toolkit#getMenuShortcutKeyMaskEx()}.
  *
  * @author Thomas Ball
  * @since 1.1
@@ -180,16 +181,15 @@
      * @return a string representation of this MenuShortcut.
      * @since 1.1
      */
-    @SuppressWarnings("deprecation")
     public String toString() {
         int modifiers = 0;
         if (!GraphicsEnvironment.isHeadless()) {
-            modifiers = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
+            modifiers = Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx();
         }
         if (usesShiftModifier()) {
-            modifiers |= Event.SHIFT_MASK;
+            modifiers |= InputEvent.SHIFT_DOWN_MASK;
         }
-        return KeyEvent.getKeyModifiersText(modifiers) + "+" +
+        return InputEvent.getModifiersExText(modifiers) + "+" +
                KeyEvent.getKeyText(key);
     }
 
--- a/src/java.desktop/share/classes/java/awt/Toolkit.java	Fri Dec 01 10:35:58 2017 -0800
+++ b/src/java.desktop/share/classes/java/awt/Toolkit.java	Fri Dec 01 17:44:07 2017 -0800
@@ -29,7 +29,23 @@
 import java.awt.dnd.DragGestureListener;
 import java.awt.dnd.DragGestureRecognizer;
 import java.awt.dnd.DragSource;
-import java.awt.event.*;
+import java.awt.event.AWTEventListener;
+import java.awt.event.AWTEventListenerProxy;
+import java.awt.event.ActionEvent;
+import java.awt.event.AdjustmentEvent;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ContainerEvent;
+import java.awt.event.FocusEvent;
+import java.awt.event.HierarchyEvent;
+import java.awt.event.InputEvent;
+import java.awt.event.InputMethodEvent;
+import java.awt.event.InvocationEvent;
+import java.awt.event.ItemEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.PaintEvent;
+import java.awt.event.TextEvent;
+import java.awt.event.WindowEvent;
 import java.awt.im.InputMethodHighlight;
 import java.awt.image.ColorModel;
 import java.awt.image.ImageObserver;
@@ -40,15 +56,22 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.EventListener;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.MissingResourceException;
 import java.util.Properties;
 import java.util.ResourceBundle;
-import java.util.StringTokenizer;
+import java.util.ServiceLoader;
+import java.util.Set;
 import java.util.WeakHashMap;
+import java.util.stream.Collectors;
+
+import javax.accessibility.AccessibilityProvider;
 
 import sun.awt.AWTAccessor;
 import sun.awt.AWTPermissions;
@@ -57,14 +80,6 @@
 import sun.awt.PeerEvent;
 import sun.awt.SunToolkit;
 
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Arrays;
-import java.util.ServiceLoader;
-import java.util.Set;
-import java.util.stream.Collectors;
-import javax.accessibility.AccessibilityProvider;
-
 /**
  * This class is the abstract superclass of all actual
  * implementations of the Abstract Window Toolkit. Subclasses of
@@ -1065,9 +1080,11 @@
      * @see       java.awt.GraphicsEnvironment#isHeadless
      * @see       java.awt.MenuBar
      * @see       java.awt.MenuShortcut
+     * @deprecated It is recommended that extended modifier keys and
+     *             {@link #getMenuShortcutKeyMaskEx()} be used instead
      * @since     1.1
      */
-    @SuppressWarnings("deprecation")
+    @Deprecated(since = "10")
     public int getMenuShortcutKeyMask() throws HeadlessException {
         GraphicsEnvironment.checkHeadless();
 
@@ -1075,6 +1092,32 @@
     }
 
     /**
+     * Determines which extended modifier key is the appropriate accelerator
+     * key for menu shortcuts.
+     * <p>
+     * Menu shortcuts, which are embodied in the {@code MenuShortcut} class, are
+     * handled by the {@code MenuBar} class.
+     * <p>
+     * By default, this method returns {@code InputEvent.CTRL_DOWN_MASK}.
+     * Toolkit implementations should override this method if the
+     * <b>Control</b> key isn't the correct key for accelerators.
+     *
+     * @return the modifier mask on the {@code InputEvent} class that is used
+     *         for menu shortcuts on this toolkit
+     * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
+     *         true
+     * @see java.awt.GraphicsEnvironment#isHeadless
+     * @see java.awt.MenuBar
+     * @see java.awt.MenuShortcut
+     * @since 10
+     */
+    public int getMenuShortcutKeyMaskEx() throws HeadlessException {
+        GraphicsEnvironment.checkHeadless();
+
+        return InputEvent.CTRL_DOWN_MASK;
+    }
+
+    /**
      * Returns whether the given locking key on the keyboard is currently in
      * its "on" state.
      * Valid key codes are
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboPopup.java	Fri Dec 01 10:35:58 2017 -0800
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboPopup.java	Fri Dec 01 17:44:07 2017 -0800
@@ -530,7 +530,6 @@
      */
     protected JList<Object> createList() {
         return new JList<Object>( comboBox.getModel() ) {
-            @SuppressWarnings("deprecation")
             public void processMouseEvent(MouseEvent e)  {
                 if (BasicGraphicsUtils.isMenuShortcutKeyDown(e))  {
                     // Fix for 4234053. Filter out the Control Key from the list.
@@ -538,7 +537,7 @@
                     Toolkit toolkit = Toolkit.getDefaultToolkit();
                     MouseEvent newEvent = new MouseEvent(
                                        (Component)e.getSource(), e.getID(), e.getWhen(),
-                                       e.getModifiers() ^ toolkit.getMenuShortcutKeyMask(),
+                                       e.getModifiersEx() ^ toolkit.getMenuShortcutKeyMaskEx(),
                                        e.getX(), e.getY(),
                                        e.getXOnScreen(), e.getYOnScreen(),
                                        e.getClickCount(),
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java	Fri Dec 01 10:35:58 2017 -0800
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java	Fri Dec 01 17:44:07 2017 -0800
@@ -1134,6 +1134,7 @@
                 boolean isTrav = (selectedFile != null && chooser.isTraversable(selectedFile));
                 boolean isDirSelEnabled = chooser.isDirectorySelectionEnabled();
                 boolean isFileSelEnabled = chooser.isFileSelectionEnabled();
+                @SuppressWarnings("deprecation")
                 boolean isCtrl = (e != null && (e.getModifiers() &
                             Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0);
 
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java	Fri Dec 01 10:35:58 2017 -0800
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java	Fri Dec 01 17:44:07 2017 -0800
@@ -382,10 +382,9 @@
         return c.getComponentOrientation().isLeftToRight();
     }
 
-    @SuppressWarnings("deprecation")
     static boolean isMenuShortcutKeyDown(InputEvent event) {
-        return (event.getModifiers() &
-                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0;
+        return (event.getModifiersEx() &
+                Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()) != 0;
     }
 
     /**
--- a/src/java.desktop/share/classes/sun/awt/HToolkit.java	Fri Dec 01 10:35:58 2017 -0800
+++ b/src/java.desktop/share/classes/sun/awt/HToolkit.java	Fri Dec 01 17:44:07 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -130,12 +130,19 @@
     }
 
     @Override
+    @Deprecated(since = "10")
     public int getMenuShortcutKeyMask()
         throws HeadlessException {
         throw new HeadlessException();
     }
 
     @Override
+    public int getMenuShortcutKeyMaskEx()
+        throws HeadlessException {
+        throw new HeadlessException();
+    }
+
+    @Override
     public boolean getLockingKeyState(int keyCode)
         throws UnsupportedOperationException {
         throw new HeadlessException();
--- a/src/java.desktop/share/classes/sun/awt/HeadlessToolkit.java	Fri Dec 01 10:35:58 2017 -0800
+++ b/src/java.desktop/share/classes/sun/awt/HeadlessToolkit.java	Fri Dec 01 17:44:07 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,7 @@
 import java.awt.dnd.DragGestureRecognizer;
 import java.awt.dnd.DragSource;
 import java.awt.event.AWTEventListener;
+import java.awt.event.InputEvent;
 import java.awt.font.TextAttribute;
 import java.awt.im.InputMethodHighlight;
 import java.awt.image.ColorModel;
@@ -128,12 +129,19 @@
     }
 
     @Override
+    @Deprecated(since = "10")
     public int getMenuShortcutKeyMask()
         throws HeadlessException {
         throw new HeadlessException();
     }
 
     @Override
+    public int getMenuShortcutKeyMaskEx()
+        throws HeadlessException {
+        throw new HeadlessException();
+    }
+
+    @Override
     public boolean getLockingKeyState(int keyCode)
         throws UnsupportedOperationException {
         throw new HeadlessException();
--- a/test/jdk/java/awt/Toolkit/Headless/HeadlessToolkit.java	Fri Dec 01 10:35:58 2017 -0800
+++ b/test/jdk/java/awt/Toolkit/Headless/HeadlessToolkit.java	Fri Dec 01 17:44:07 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -118,6 +118,15 @@
 
         exceptions = false;
         try {
+            int km = tk.getMenuShortcutKeyMaskEx();
+        } catch (HeadlessException e) {
+            exceptions = true;
+        }
+        if (!exceptions)
+            throw new RuntimeException("HeadlessException did not occur when expected");
+
+        exceptions = false;
+        try {
             boolean state = tk.getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
         } catch (HeadlessException e) {
             exceptions = true;