提交 a9993d6f 编写于 作者: A asaha

8036983: JAB:Multiselection Ctrl+CursorUp/Down and ActivateDescenderPropertyChanged event

Reviewed-by: pchelko, alexsch
Contributed-by: vivi.an@oracle.com
上级 4fc36410
...@@ -6588,8 +6588,8 @@ public class JTable extends JComponent implements TableModelListener, Scrollable ...@@ -6588,8 +6588,8 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
TableColumnModelListener, CellEditorListener, PropertyChangeListener, TableColumnModelListener, CellEditorListener, PropertyChangeListener,
AccessibleExtendedTable { AccessibleExtendedTable {
int lastSelectedRow; int previousFocusedRow;
int lastSelectedCol; int previousFocusedCol;
/** /**
* AccessibleJTable constructor * AccessibleJTable constructor
...@@ -6604,8 +6604,10 @@ public class JTable extends JComponent implements TableModelListener, Scrollable ...@@ -6604,8 +6604,10 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
tcm.addColumnModelListener(this); tcm.addColumnModelListener(this);
tcm.getSelectionModel().addListSelectionListener(this); tcm.getSelectionModel().addListSelectionListener(this);
JTable.this.getModel().addTableModelListener(this); JTable.this.getModel().addTableModelListener(this);
lastSelectedRow = JTable.this.getSelectedRow(); previousFocusedRow = JTable.this.getSelectionModel().
lastSelectedCol = JTable.this.getSelectedColumn(); getLeadSelectionIndex();
previousFocusedCol = JTable.this.getColumnModel().
getSelectionModel().getLeadSelectionIndex();
} }
// Listeners to track model, etc. changes to as to re-place the other // Listeners to track model, etc. changes to as to re-place the other
...@@ -6933,17 +6935,20 @@ public class JTable extends JComponent implements TableModelListener, Scrollable ...@@ -6933,17 +6935,20 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY, firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
Boolean.valueOf(false), Boolean.valueOf(true)); Boolean.valueOf(false), Boolean.valueOf(true));
int selectedRow = JTable.this.getSelectedRow(); // Using lead selection index to cover both cases: node selected and node
int selectedCol = JTable.this.getSelectedColumn(); // is focused but not selected (Ctrl+up/down)
if (selectedRow != lastSelectedRow || int focusedRow = JTable.this.getSelectionModel().getLeadSelectionIndex();
selectedCol != lastSelectedCol) { int focusedCol = JTable.this.getColumnModel().getSelectionModel().
Accessible oldA = getAccessibleAt(lastSelectedRow, getLeadSelectionIndex();
lastSelectedCol);
Accessible newA = getAccessibleAt(selectedRow, selectedCol); if (focusedRow != previousFocusedRow ||
focusedCol != previousFocusedCol) {
Accessible oldA = getAccessibleAt(previousFocusedRow, previousFocusedCol);
Accessible newA = getAccessibleAt(focusedRow, focusedCol);
firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY, firePropertyChange(AccessibleContext.ACCESSIBLE_ACTIVE_DESCENDANT_PROPERTY,
oldA, newA); oldA, newA);
lastSelectedRow = selectedRow; previousFocusedRow = focusedRow;
lastSelectedCol = selectedCol; previousFocusedCol = focusedCol;
} }
} }
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 ...@@ -1664,6 +1664,11 @@ public class JTree extends JComponent implements Scrollable, Accessible
leadPath = newPath; leadPath = newPath;
firePropertyChange(LEAD_SELECTION_PATH_PROPERTY, oldValue, 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 ...@@ -4129,23 +4134,6 @@ public class JTree extends JComponent implements Scrollable, Accessible
* *
*/ */
public void valueChanged(TreeSelectionEvent e) { 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, firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
Boolean.valueOf(false), Boolean.valueOf(true)); Boolean.valueOf(false), Boolean.valueOf(true));
} }
...@@ -4249,6 +4237,34 @@ public class JTree extends JComponent implements Scrollable, Accessible ...@@ -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() { private AccessibleContext getCurrentAccessibleContext() {
Component c = getCurrentComponent(); Component c = getCurrentComponent();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册