From a9993d6f3616ddeb68e65d5905abce0aecc829f2 Mon Sep 17 00:00:00 2001 From: asaha Date: Thu, 17 Apr 2014 12:47:49 -0700 Subject: [PATCH] 8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event Reviewed-by: pchelko, alexsch Contributed-by: vivi.an@oracle.com --- src/share/classes/javax/swing/JTable.java | 35 ++++++++------- src/share/classes/javax/swing/JTree.java | 52 +++++++++++++++-------- 2 files changed, 54 insertions(+), 33 deletions(-) diff --git a/src/share/classes/javax/swing/JTable.java b/src/share/classes/javax/swing/JTable.java index bc91b504f..3b021da96 100644 --- a/src/share/classes/javax/swing/JTable.java +++ b/src/share/classes/javax/swing/JTable.java @@ -6588,8 +6588,8 @@ public class JTable extends JComponent implements TableModelListener, Scrollable TableColumnModelListener, CellEditorListener, PropertyChangeListener, AccessibleExtendedTable { - int lastSelectedRow; - int lastSelectedCol; + int previousFocusedRow; + int previousFocusedCol; /** * AccessibleJTable constructor @@ -6604,8 +6604,10 @@ public class JTable extends JComponent implements TableModelListener, Scrollable tcm.addColumnModelListener(this); tcm.getSelectionModel().addListSelectionListener(this); JTable.this.getModel().addTableModelListener(this); - lastSelectedRow = JTable.this.getSelectedRow(); - lastSelectedCol = JTable.this.getSelectedColumn(); + previousFocusedRow = JTable.this.getSelectionModel(). + getLeadSelectionIndex(); + previousFocusedCol = JTable.this.getColumnModel(). + getSelectionModel().getLeadSelectionIndex(); } // Listeners to track model, etc. changes to as to re-place the other @@ -6933,18 +6935,21 @@ public class JTable extends JComponent implements TableModelListener, Scrollable firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY, Boolean.valueOf(false), Boolean.valueOf(true)); - int selectedRow = JTable.this.getSelectedRow(); - int selectedCol = JTable.this.getSelectedColumn(); - if (selectedRow != lastSelectedRow || - selectedCol != lastSelectedCol) { - Accessible oldA = getAccessibleAt(lastSelectedRow, - lastSelectedCol); - Accessible newA = getAccessibleAt(selectedRow, selectedCol); + // Using lead selection index to cover both cases: node selected and node + // is focused but not selected (Ctrl+up/down) + int focusedRow = JTable.this.getSelectionModel().getLeadSelectionIndex(); + int focusedCol = JTable.this.getColumnModel().getSelectionModel(). + getLeadSelectionIndex(); + + if (focusedRow != previousFocusedRow || + focusedCol != previousFocusedCol) { + Accessible oldA = getAccessibleAt(previousFocusedRow, previousFocusedCol); + Accessible newA = getAccessibleAt(focusedRow, focusedCol); firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY, - oldA, newA); - lastSelectedRow = selectedRow; - lastSelectedCol = selectedCol; - } + oldA, newA); + previousFocusedRow = focusedRow; + previousFocusedCol = focusedCol; + } } diff --git a/src/share/classes/javax/swing/JTree.java b/src/share/classes/javax/swing/JTree.java index 35603c5b1..707305312 100644 --- a/src/share/classes/javax/swing/JTree.java +++ b/src/share/classes/javax/swing/JTree.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, 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 @@ -1664,6 +1664,11 @@ public class JTree extends JComponent implements Scrollable, Accessible leadPath = newPath; firePropertyChange(LEAD_SELECTION_PATH_PROPERTY, oldValue, newPath); + + if (accessibleContext != null){ + ((AccessibleJTree)accessibleContext). + fireActiveDescendantPropertyChange(oldValue, newPath); + } } /** @@ -4129,23 +4134,6 @@ public class JTree extends JComponent implements Scrollable, Accessible * */ public void valueChanged(TreeSelectionEvent e) { - // Fixes 4546503 - JTree is sending incorrect active - // descendant events - TreePath oldLeadSelectionPath = e.getOldLeadSelectionPath(); - leadSelectionPath = e.getNewLeadSelectionPath(); - - if (oldLeadSelectionPath != leadSelectionPath) { - // Set parent to null so AccessibleJTreeNode computes - // its parent. - Accessible oldLSA = leadSelectionAccessible; - leadSelectionAccessible = (leadSelectionPath != null) - ? new AccessibleJTreeNode(JTree.this, - leadSelectionPath, - null) // parent - : null; - firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY, - oldLSA, leadSelectionAccessible); - } firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY, Boolean.valueOf(false), Boolean.valueOf(true)); } @@ -4249,6 +4237,34 @@ public class JTree extends JComponent implements Scrollable, Accessible } } + /** + * Fire an active descendant property change notification. + * The active descendant is used for objects such as list, + * tree, and table, which may have transient children. + * It notifies screen readers the active child of the component + * has been changed so user can be notified from there. + * + * @param oldPath - lead path of previous active child + * @param newPath - lead path of current active child + * + */ + void fireActiveDescendantPropertyChange(TreePath oldPath, TreePath newPath){ + if(oldPath != newPath){ + Accessible oldLSA = (oldPath != null) + ? new AccessibleJTreeNode(JTree.this, + oldPath, + null) + : null; + + Accessible newLSA = (newPath != null) + ? new AccessibleJTreeNode(JTree.this, + newPath, + null) + : null; + firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY, + oldLSA, newLSA); + } + } private AccessibleContext getCurrentAccessibleContext() { Component c = getCurrentComponent(); -- GitLab