8183518: Premature deprecation of Event/InputEvent/KeyEvent in Java 9
Reviewed-by: prr, psadhukhan
This commit is contained in:
parent
6a21c771ec
commit
d8efdbc4a2
@ -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,29 +502,17 @@ public final class LWCToolkit extends LWToolkit {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
@ -377,7 +377,6 @@ public class MenuBar extends MenuComponent implements MenuContainer, Accessible
|
||||
* 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 @@ public class MenuBar extends MenuComponent implements MenuContainer, Accessible
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
*/
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
/**
|
||||
@ -51,7 +52,7 @@ import java.awt.event.KeyEvent;
|
||||
* 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 @@ public class MenuShortcut implements java.io.Serializable
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,23 @@ import java.awt.datatransfer.Clipboard;
|
||||
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.beans.PropertyChangeSupport;
|
||||
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.HeadlessToolkit;
|
||||
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,15 +1080,43 @@ public abstract class Toolkit {
|
||||
* @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();
|
||||
|
||||
return Event.CTRL_MASK;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -530,7 +530,6 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup {
|
||||
*/
|
||||
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 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup {
|
||||
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(),
|
||||
|
@ -1134,6 +1134,7 @@ public class BasicFileChooserUI extends FileChooserUI {
|
||||
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);
|
||||
|
||||
|
@ -382,10 +382,9 @@ public class BasicGraphicsUtils
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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,11 +130,18 @@ public final class HToolkit extends SunToolkit implements ComponentFactory {
|
||||
}
|
||||
|
||||
@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 {
|
||||
|
@ -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.DragGestureListener;
|
||||
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,11 +129,18 @@ public final class HeadlessToolkit extends Toolkit
|
||||
}
|
||||
|
||||
@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 {
|
||||
|
@ -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
|
||||
@ -116,6 +116,15 @@ public class HeadlessToolkit {
|
||||
if (!exceptions)
|
||||
throw new RuntimeException("HeadlessException did not occur when expected");
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user