This patch ensures selectAll doesn't affect the lead selection indices for the row or column ListSelectionModel. Since this is fixed, I also replaced some direct code in BasicListUI with a call to selectAll. Also a small touch-up to make the ENTER key press compatible with the JDK.
Patch attached. 2005-07-25 Anthony Balkissoon <[EMAIL PROTECTED]> * javax/swing/JTable.java: (selectAll): Store the lead selection indices and restore them after selecting all cells. * javax/swing/plaf/basic/BasicTableUI.java: (KeyHandler.keyPressed): Changed the criteria for "only one selection" when the ENTER key is pressed to match the behavior of the JDK. Also replaced direct code for CTRL-A with call to JTable.selectAll(). - Tony
Index: javax/swing/JTable.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/JTable.java,v retrieving revision 1.35 diff -u -r1.35 JTable.java --- javax/swing/JTable.java 20 Jul 2005 20:25:08 -0000 1.35 +++ javax/swing/JTable.java 25 Jul 2005 14:46:07 -0000 @@ -2070,8 +2070,17 @@ public void selectAll() { + // rowLead and colLead store the current lead selection indices + int rowLead = selectionModel.getLeadSelectionIndex(); + int colLead = getColumnModel().getSelectionModel().getLeadSelectionIndex(); + // the following calls to setSelectionInterval change the lead selection + // indices setColumnSelectionInterval(0, getColumnCount() - 1); setRowSelectionInterval(0, getRowCount() - 1); + // the following addSelectionInterval calls restore the lead selection + // indices to their previous values + addColumnSelectionInterval(colLead,colLead); + addRowSelectionInterval(rowLead, rowLead); } public Object getValueAt(int row, int column) Index: javax/swing/plaf/basic/BasicTableUI.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTableUI.java,v retrieving revision 1.14 diff -u -r1.14 BasicTableUI.java --- javax/swing/plaf/basic/BasicTableUI.java 22 Jul 2005 19:44:35 -0000 1.14 +++ javax/swing/plaf/basic/BasicTableUI.java 25 Jul 2005 14:46:07 -0000 @@ -265,12 +265,17 @@ return; } - // If there is just one cell selected, select the next row, and wrap + // If there is just one selection, select the next row, and wrap // when you get to the edges of the table. - if ((table.getSelectedRowCount() <= 1 && - table.getSelectedColumnCount() <= 1) - || (table.getRowSelectionAllowed() == false && - table.getColumnSelectionAllowed() == false)) + boolean multRowsSelected, multColsSelected; + multRowsSelected = (table.getSelectedRowCount() > 1) || + (!table.getRowSelectionAllowed() && + table.getSelectedColumnCount() > 0); + multColsSelected = (table.getSelectedColumnCount() > 1) || + (!table.getColumnSelectionAllowed() && + table.getSelectedRowCount() > 0); + + if (!multColsSelected || !multRowsSelected) { rowModel.setSelectionInterval((rowLead + 1)%(rowMax + 1), (rowLead + 1)%(rowMax + 1)); @@ -350,13 +355,7 @@ else if ((evt.getKeyCode() == KeyEvent.VK_A || evt.getKeyCode() == KeyEvent.VK_SLASH) && evt.isControlDown()) { - rowModel.setSelectionInterval(0, rowMax); - colModel.setSelectionInterval(0, colMax); - // the next two lines are to restore the lead selection indices to - // their previous values, because select-all operations shouldn't - // change them - rowModel.addSelectionInterval(rowLead, rowLead); - colModel.addSelectionInterval(colLead, colLead); + table.selectAll(); } else if (evt.getKeyCode() == KeyEvent.VK_BACK_SLASH && evt.isControlDown())
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches