Repository: nvaccess/nvda

Issue:
Needless state announcement on JMenu and JMenuItem (Java Access Bridge)
<!-- Please read the text in this edit field before filling it in.
Please thoroughly read NVDA's wiki article on how to fill in this template, including how to provide the required files.
Issues may be closed if the required information is not present.
https://github.com/nvaccess/nvda/blob/master/devDocs/githubIssueTemplateExplanationAndExamples.md
Please also note that the NVDA project has a Citizen and Contributor Code of Conduct which can be found at https://github.com/nvaccess/nvda/blob/master/CODE_OF_CONDUCT.md. NV Access expects that all contributors and other community members read and abide by the rules set out in this document while participating or contributing to this project. This includes creating or commenting on issues and pull requests. 

Each of the questions and sections below start with multiple hash symbols (#). Place your answers and information on the blank line below each question.
-->
When opening a JMenu and selecting a JMenuItem (or a subclass of JMenuItem), NVDA announces the AccessibleState "selected" or "enabled". These state announcements are needless on menu and menu items and time-consuming when exploring menus.

### Steps to reproduce:
Prerequisites:
You have installed a Java Runtime Environment, e.g. JDK/JRE version 17 or 18.
You have downloaded the SwingSet2 Demonstration Program from: https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html#swingset2

1. Launch SwingSet2.jar with the Java JRE.
The SwingSet2 application window appears.
2. Open the File menu with keystroke Alt+F.
3. Use arrow down key to navigate to the menu items About and Exit.

### Actual behavior:
<!--
Use "Speak command keys" (NVDA+4) and speech viewer to copy and paste here. 
Use braille viewer to copy and paste here.
You may additionally include an explanation.
-->
(I got a German speech output and translated it to English. Maybe the English speech output is different.)

File  Menu  selected enabled  Alt+F
About  selected  B
Exit  selected  X

### Expected behavior:
<!--
Use "Speak command keys" (NVDA+4) and speech viewer to copy and paste here. 
Use braille viewer to copy and paste here.
You may additionally include an explanation.
-->
File  Menu  Alt+F
About  B
Exit  X

### NVDA logs, crash dumps and other attachments:

### System configuration
#### NVDA installed/portable/running from source:
instlled

#### NVDA version:
Version 2022.3.1

#### Windows version:
Microsoft Windows 10 Enterprise
Version 10.0.19044 Build 1904

#### Name and version of other software in use when reproducing the issue:
java version "17.0.4" 2022-07-19 LTS
Java(TM) SE Runtime Environment (build 17.0.4+11-LTS-179)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.4+11-LTS-179, mixed mode, sharing)

#### Other information about your system:
Java Access Bridge is enabled.

### Other questions
#### Does the issue still occur after restarting your computer?
Yes.

#### Have you tried any other versions of NVDA? If so, please report their behaviors.
Same behavior in previous versions of NVDA.

#### If NVDA add-ons are disabled, is your problem still occurring?
Not applicable.

#### Does the issue still occur after you run the COM Registration Fixing Tool in NVDA's tools menu?
Not applicable.


Discussion:
I have mixed feelings over this issue. I understand where it comes from, other applications do not give the selected state for menus and so why should it be so for Java applications. However Java Access Bridge is supplying this state, it does signify something as menu items without the focus do not have the selected state and the item with selected state changes as you move around the menu. This use of the selected state can be observed when using object navigation in the menus rather than focus navigation. Thus it serves the purpose should someone be exploring the menu with object navigation to tell them which menu item has been selected/focused. Has a sufficient case been made for NVDA to have special handling to provide a non-accurate representation of the accessibility information been made here?
What about announcing the exceptional or none-expected state when a menu is not selected or is not enabled? This is similar to a JButton where NVDA does not announce that it is enabled, but announces the state when it is not enabled ("unavailable").
That would seem a reasonable solution to make it more user friendly whilst maintaining an accurate representation. The comparison with enabled/unavailable state though, it is not that simple. NVDA has a state unavailable but no state enabled (ie. the state is present for the exceptional case). For selection, NVDA has the state selected, I guess in many cases selected is the exception. So in the code mapping JAB objects to NVDA objects we are mapping correctly. However in some applications I have observed NVDA announce not-selected, so may be I can use that as a guide as to how to achieve this.

Resolving patch:
diff --git a/source/NVDAObjects/JAB/__init__.py b/source/NVDAObjects/JAB/__init__.py
--- a/source/NVDAObjects/JAB/__init__.py
+++ b/source/NVDAObjects/JAB/__init__.py
@@ -98,6 +98,7 @@
 	"multi_line":controlTypes.State.MULTILINE,
 	"focusable":controlTypes.State.FOCUSABLE,
 	"editable":controlTypes.State.EDITABLE,
+	"selectable": controlTypes.State.SELECTABLE,
 }
 
 


Test patch: