Merge remote-tracking branch 'origin/GP-6869_fix_improve_accessibilty_for_actions_dialog--SQUASHED'

This commit is contained in:
Ryan Kurtz
2026-06-08 06:36:05 -04:00
3 changed files with 52 additions and 15 deletions

View File

@@ -682,6 +682,9 @@ public class DialogComponentProvider
*/ */
public void setAccessibleDescription(String description) { public void setAccessibleDescription(String description) {
this.accessibleDescription = description; this.accessibleDescription = description;
if (dialog != null) {
dialog.getAccessibleContext().setAccessibleDescription(description);
}
} }
private void doSetStatusText(String text, MessageType type, boolean alert) { private void doSetStatusText(String text, MessageType type, boolean alert) {

View File

@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,6 +24,7 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.function.BiPredicate; import java.util.function.BiPredicate;
import javax.accessibility.AccessibleContext;
import javax.swing.*; import javax.swing.*;
import docking.*; import docking.*;
@@ -59,10 +60,6 @@ public class ActionChooserDialog extends DialogComponentProvider {
addOKButton(); addOKButton();
addCancelButton(); addCancelButton();
updateTitle(); updateTitle();
setAccessibleDescription(
"This dialog initialy shows only locally relevant actions. Repeat initial keybinding " +
"to show More. Use up down arrows to scroll through list of actions and press" +
" enter to invoke selected action. Type text to filter list.");
setOkEnabled(false); setOkEnabled(false);
} }
@@ -115,6 +112,11 @@ public class ActionChooserDialog extends DialogComponentProvider {
public void setActionDisplayLevel(ActionDisplayLevel level) { public void setActionDisplayLevel(ActionDisplayLevel level) {
model.setDisplayLevel(level); model.setDisplayLevel(level);
updateTitle(); updateTitle();
updateAccessibleDescription();
// put the focus to the filter to help the screen reader report the current display level.
// The focus is probably already in the filter or it was moved to the tree, but the tree
// contents is totally changing, so going back to the filter should not be annoying.
searchList.getTextField().requestFocus();
} }
@Override @Override
@@ -137,8 +139,30 @@ public class ActionChooserDialog extends DialogComponentProvider {
setTitle("All Local and Global Actions (" + model.getSize() + ")"); setTitle("All Local and Global Actions (" + model.getSize() + ")");
break; break;
} }
}
setAccessibleDescription(
"This dialog initially shows only locally relevant actions. Repeat initial keybinding " +
"to show more. Use up down arrows to scroll through list of actions and press" +
" enter to invoke selected action. Type text to filter list.");
}
private void updateAccessibleDescription() {
JTextField textField = searchList.getTextField();
String msg = "Type to filter actions by name. List currently contains ";
switch (model.getActionDisplayLevel()) {
case LOCAL:
msg += "only the most relevant actions";
break;
case GLOBAL:
msg += "all valid local and global actions";
break;
case ALL:
msg += "all local and global actions";
break;
}
textField.getAccessibleContext().setAccessibleDescription(msg);
}
private JComponent buildMainPanel() { private JComponent buildMainPanel() {
JPanel panel = new JPanel(new BorderLayout()); JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(BorderFactory.createEmptyBorder(5, 2, 0, 2)); panel.setBorder(BorderFactory.createEmptyBorder(5, 2, 0, 2));
@@ -152,8 +176,15 @@ public class ActionChooserDialog extends DialogComponentProvider {
searchList.setSelectionCallback(this::itemSelected); searchList.setSelectionCallback(this::itemSelected);
searchList.setInitialSelection(); // update selection after adding our listener searchList.setInitialSelection(); // update selection after adding our listener
searchList.setItemRenderer(new ActionRenderer()); searchList.setItemRenderer(new ActionRenderer());
searchList.setDisplayNameFunction( searchList.setDisplayNameFunction((t, c) -> {
(t, c) -> getActionDisplayName(t, c) + " " + getKeyBindingString(t)); String name = getActionDisplayName(t, c) + " " + getKeyBindingString(t);
ActionContext context = model.getContext();
if (context != null && !(t.isValidContext(context) && t.isEnabledForContext(context))) {
name += " (Disabled)";
}
return name;
});
panel.add(searchList); panel.add(searchList);
return panel; return panel;
} }

View File

@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,12 +20,14 @@ import java.awt.event.*;
import java.util.List; import java.util.List;
import java.util.function.*; import java.util.function.*;
import javax.accessibility.AccessibleContext;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.event.*; import javax.swing.event.*;
import docking.event.mouse.GMouseListenerAdapter; import docking.event.mouse.GMouseListenerAdapter;
import docking.widgets.list.GListCellRenderer; import docking.widgets.list.GListCellRenderer;
import ghidra.util.Msg;
import utility.function.Dummy; import utility.function.Dummy;
/** /**
@@ -219,6 +221,8 @@ public class SearchList<T> extends JPanel {
private Component buildFilterField() { private Component buildFilterField() {
JPanel panel = new JPanel(new BorderLayout()); JPanel panel = new JPanel(new BorderLayout());
textField = new JTextField(); textField = new JTextField();
textField.getAccessibleContext().setAccessibleDescription("Enter text to filter list");
textField.getAccessibleContext().setAccessibleName("Filter text field.");
panel.add(textField, BorderLayout.CENTER); panel.add(textField, BorderLayout.CENTER);
textField.addKeyListener(new TextFieldKeyListener()); textField.addKeyListener(new TextFieldKeyListener());
textField.getDocument().addDocumentListener(new SearchListDocumentListener()); textField.getDocument().addDocumentListener(new SearchListDocumentListener());
@@ -272,7 +276,7 @@ public class SearchList<T> extends JPanel {
return new DefaultFilter(text); return new DefaultFilter(text);
} }
JTextField getTextField() { public JTextField getTextField() {
return textField; return textField;
} }
@@ -324,8 +328,8 @@ public class SearchList<T> extends JPanel {
categoryLabel.setOpaque(true); categoryLabel.setOpaque(true);
categoryLabel.setBackground(background); categoryLabel.setBackground(background);
categoryLabel.setForeground(itemRendererComp.getForeground()); categoryLabel.setForeground(itemRendererComp.getForeground());
panel.getAccessibleContext() String txt = getDisplayName(value.value(), value.category());
.setAccessibleName(getDisplayName(value.value(), value.category())); panel.getAccessibleContext().setAccessibleName(txt);
return panel; return panel;
} }
} }
@@ -430,5 +434,4 @@ public class SearchList<T> extends JPanel {
public JTextField getFilterField() { public JTextField getFilterField() {
return textField; return textField;
} }
} }