(command.equals ("selectPreviousColumnCell")));
command.equals("selectPreviousColumnCell"));
    public void actionPerformed (ActionEvent e)    {      DefaultListSelectionModel rowModel = (DefaultListSelectionModel) table.getSelectionModel();      DefaultListSelectionModel colModel = (DefaultListSelectionModel) table.getColumnModel().getSelectionModel();      int rowLead = rowModel.getLeadSelectionIndex();      int rowMax = table.getModel().getRowCount() - 1;            int colLead = colModel.getLeadSelectionIndex();      int colMax = table.getModel().getColumnCount() - 1;            String command = e.getActionCommand();            if (command.equals("selectPreviousRowExtendSelection"))        {          rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0));        }      else if (command.equals("selectLastColumn"))        {          colModel.setSelectionInterval(colMax, colMax);        }      else if (command.equals("startEditing"))        {          if (table.isCellEditable(rowLead, colLead))            table.editCellAt(rowLead,colLead);        }      else if (command.equals("selectFirstRowExtendSelection"))        {                        rowModel.setLeadSelectionIndex(0);        }      else if (command.equals("selectFirstColumn"))        {          colModel.setSelectionInterval(0, 0);        }      else if (command.equals("selectFirstColumnExtendSelection"))        {          colModel.setLeadSelectionIndex(0);        }      else if (command.equals("selectLastRow"))        {          rowModel.setSelectionInterval(rowMax,rowMax);        }      else if (command.equals("selectNextRowExtendSelection"))        {          rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax));        }      else if (command.equals("selectFirstRow"))        {          rowModel.setSelectionInterval(0,0);        }      else if (command.equals("selectNextColumnExtendSelection"))        {          colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax));        }      else if (command.equals("selectLastColumnExtendSelection"))        {          colModel.setLeadSelectionIndex(colMax);        }      else if (command.equals("selectPreviousColumnExtendSelection"))        {          colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0));        }      else if (command.equals("selectNextRow"))        {          rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax),                                        Math.min(rowLead + 1, rowMax));        }      else if (command.equals("scrollUpExtendSelection"))        {          int target;          if (rowLead == getFirstVisibleRowIndex())            target = Math.max              (0, rowLead - (getLastVisibleRowIndex() -                              getFirstVisibleRowIndex() + 1));          else            target = getFirstVisibleRowIndex();                    rowModel.setLeadSelectionIndex(target);          colModel.setLeadSelectionIndex(colLead);        }      else if (command.equals("selectPreviousRow"))        {          rowModel.setSelectionInterval(Math.max(rowLead - 1, 0),                                        Math.max(rowLead - 1, 0));        }      else if (command.equals("scrollRightChangeSelection"))        {          int target;          if (colLead == getLastVisibleColumnIndex())            target = Math.min              (colMax, colLead + (getLastVisibleColumnIndex() -                                  getFirstVisibleColumnIndex() + 1));          else            target = getLastVisibleColumnIndex();                    colModel.setSelectionInterval(target, target);          rowModel.setSelectionInterval(rowLead, rowLead);        }      else if (command.equals("selectPreviousColumn"))        {          colModel.setSelectionInterval(Math.max(colLead - 1, 0),                                        Math.max(colLead - 1, 0));        }      else if (command.equals("scrollLeftChangeSelection"))        {          int target;          if (colLead == getFirstVisibleColumnIndex())            target = Math.max              (0, colLead - (getLastVisibleColumnIndex() -                             getFirstVisibleColumnIndex() + 1));          else            target = getFirstVisibleColumnIndex();                    colModel.setSelectionInterval(target, target);          rowModel.setSelectionInterval(rowLead, rowLead);        }      else if (command.equals("clearSelection"))        {          table.clearSelection();        }      else if (command.equals("cancel"))        {          // FIXME: implement other parts of "cancel" like undo-ing last          // selection.  Right now it just calls editingCancelled if          // we're currently editing.          if (table.isEditing())            table.editingCanceled(new ChangeEvent("cancel"));        }      else if (command.equals("selectNextRowCell")               || command.equals("selectPreviousRowCell")               || command.equals("selectNextColumnCell")               || command.equals("selectPreviousColumnCell"))        {          // If nothing is selected, select the first cell in the table          if (table.getSelectedRowCount() == 0 &&               table.getSelectedColumnCount() == 0)            {              rowModel.setSelectionInterval(0, 0);              colModel.setSelectionInterval(0, 0);              return;            }                    // If the lead selection index isn't selected (ie a remove operation          // happened, then set the lead to the first selected cell in the          // table          if (!table.isCellSelected(rowLead, colLead))            {              rowModel.addSelectionInterval(rowModel.getMinSelectionIndex(),                                             rowModel.getMinSelectionIndex());              colModel.addSelectionInterval(colModel.getMinSelectionIndex(),                                             colModel.getMinSelectionIndex());              return;            }                    // multRowsSelected and multColsSelected tell us if multiple rows or          // columns are selected, respectively          boolean multRowsSelected, multColsSelected;          multRowsSelected = table.getSelectedRowCount() > 1 &&            table.getRowSelectionAllowed();                    multColsSelected = table.getSelectedColumnCount() > 1 &&            table.getColumnSelectionAllowed();                    // If there is just one selection, select the next cell, and wrap          // when you get to the edges of the table.          if (!multColsSelected && !multRowsSelected)            {              if (command.indexOf("Column") != -1)                 advanceSingleSelection(colModel, colMax, rowModel, rowMax,                                        (command.equals                                        ("selectPreviousColumnCell")));              else                advanceSingleSelection(rowModel, rowMax, colModel, colMax,                                        (command.equals                                         ("selectPreviousRowCell")));              return;            }                              // rowMinSelected and rowMaxSelected are the minimum and maximum          // values respectively of selected cells in the row selection model          // Similarly for colMinSelected and colMaxSelected.          int rowMaxSelected = table.getRowSelectionAllowed() ?             rowModel.getMaxSelectionIndex() : table.getModel().getRowCount() - 1;          int rowMinSelected = table.getRowSelectionAllowed() ?             rowModel.getMinSelectionIndex() : 0;           int colMaxSelected = table.getColumnSelectionAllowed() ?             colModel.getMaxSelectionIndex() :             table.getModel().getColumnCount() - 1;          int colMinSelected = table.getColumnSelectionAllowed() ?             colModel.getMinSelectionIndex() : 0;                    // If there are multiple rows and columns selected, select the next          // cell and wrap at the edges of the selection.            if (command.indexOf("Column") != -1)             advanceMultipleSelection(colModel, colMinSelected, colMaxSelected,                                      rowModel, rowMinSelected, rowMaxSelected,                                      (command.equals                                      ("selectPreviousColumnCell")), true);                    else            advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected,                                      colModel, colMinSelected, colMaxSelected,                                      (command.equals                                       ("selectPreviousRowCell")), false);        }      else if (command.equals("selectNextColumn"))        {          colModel.setSelectionInterval(Math.min(colLead + 1, colMax),                                        Math.min(colLead + 1, colMax));        }      else if (command.equals("scrollLeftExtendSelection"))        {          int target;          if (colLead == getFirstVisibleColumnIndex())            target = Math.max              (0, colLead - (getLastVisibleColumnIndex() -                             getFirstVisibleColumnIndex() + 1));          else            target = getFirstVisibleColumnIndex();                    colModel.setLeadSelectionIndex(target);          rowModel.setLeadSelectionIndex(rowLead);        }      else if (command.equals("scrollDownChangeSelection"))        {          int target;          if (rowLead == getLastVisibleRowIndex())            target = Math.min              (rowMax, rowLead + (getLastVisibleRowIndex() -                                   getFirstVisibleRowIndex() + 1));          else            target = getLastVisibleRowIndex();                    rowModel.setSelectionInterval(target, target);          colModel.setSelectionInterval(colLead, colLead);        }      else if (command.equals("scrollRightExtendSelection"))        {          int target;          if (colLead == getLastVisibleColumnIndex())            target = Math.min              (colMax, colLead + (getLastVisibleColumnIndex() -                                  getFirstVisibleColumnIndex() + 1));          else            target = getLastVisibleColumnIndex();                    colModel.setLeadSelectionIndex(target);          rowModel.setLeadSelectionIndex(rowLead);        }      else if (command.equals("selectAll"))        {          table.selectAll();        }      else if (command.equals("selectLastRowExtendSelection"))        {          rowModel.setLeadSelectionIndex(rowMax);          colModel.setLeadSelectionIndex(colLead);        }      else if (command.equals("scrollDownExtendSelection"))        {          int target;          if (rowLead == getLastVisibleRowIndex())            target = Math.min              (rowMax, rowLead + (getLastVisibleRowIndex() -                                   getFirstVisibleRowIndex() + 1));          else            target = getLastVisibleRowIndex();                    rowModel.setLeadSelectionIndex(target);          colModel.setLeadSelectionIndex(colLead);        }      else if (command.equals("scrollUpChangeSelection"))        {          int target;          if (rowLead == getFirstVisibleRowIndex())            target = Math.max              (0, rowLead - (getLastVisibleRowIndex() -                              getFirstVisibleRowIndex() + 1));          else            target = getFirstVisibleRowIndex();                    rowModel.setSelectionInterval(target, target);          colModel.setSelectionInterval(colLead, colLead);        }      else if (command.equals("selectNextRowChangeLead"))          {            if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION)              {                // just "selectNextRow"                rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax),                                              Math.min(rowLead + 1, rowMax));                colModel.setSelectionInterval(colLead,colLead);              }            else              rowModel.moveLeadSelectionIndex(Math.min(rowLead + 1, rowMax));          }      else if (command.equals("selectPreviousRowChangeLead"))        {          if (rowModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION)            {              // just selectPreviousRow              rowModel.setSelectionInterval(Math.max(rowLead - 1, 0),                                            Math.min(rowLead -1, 0));              colModel.setSelectionInterval(colLead,colLead);            }          else            rowModel.moveLeadSelectionIndex(Math.max(rowLead - 1, 0));        }      else if (command.equals("selectNextColumnChangeLead"))        {          if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION)                        {              // just selectNextColumn              rowModel.setSelectionInterval(rowLead,rowLead);              colModel.setSelectionInterval(Math.min(colLead + 1, colMax),                                            Math.min(colLead + 1, colMax));            }          else            colModel.moveLeadSelectionIndex(Math.min(colLead + 1, colMax));        }      else if (command.equals("selectPreviousColumnChangeLead"))        {          if (colModel.getSelectionMode() != ListSelectionModel.MULTIPLE_INTERVAL_SELECTION)                        {              // just selectPreviousColumn              rowModel.setSelectionInterval(rowLead,rowLead);              colModel.setSelectionInterval(Math.max(colLead - 1, 0),                                            Math.max(colLead - 1, 0));                          }          else            colModel.moveLeadSelectionIndex(Math.max(colLead - 1, 0));        }      else if (command.equals("addToSelection"))          {            if (!table.isEditing())              {                int oldRowAnchor = rowModel.getAnchorSelectionIndex();                int oldColAnchor = colModel.getAnchorSelectionIndex();                rowModel.addSelectionInterval(rowLead, rowLead);                colModel.addSelectionInterval(colLead, colLead);                rowModel.setAnchorSelectionIndex(oldRowAnchor);                colModel.setAnchorSelectionIndex(oldColAnchor);              }          }      else if (command.equals("extendTo"))        {          rowModel.setSelectionInterval(rowModel.getAnchorSelectionIndex(),                                        rowLead);          colModel.setSelectionInterval(colModel.getAnchorSelectionIndex(),                                        colLead);        }      else if (command.equals("toggleAndAnchor"))        {          if (rowModel.isSelectedIndex(rowLead))            rowModel.removeSelectionInterval(rowLead, rowLead);          else            rowModel.addSelectionInterval(rowLead, rowLead);                    if (colModel.isSelectedIndex(colLead))            colModel.removeSelectionInterval(colLead, colLead);          else            colModel.addSelectionInterval(colLead, colLead);                    rowModel.setAnchorSelectionIndex(rowLead);          colModel.setAnchorSelectionIndex(colLead);        }      else if (command.equals("stopEditing"))        {          table.editingStopped(new ChangeEvent(command));        }      else         {          // If we're here that means we bound this TableAction class          // to a keyboard input but we either want to ignore that input          // or we just haven't implemented its action yet.                    // Uncomment the following line to print the names of unused bindings          // when their keys are pressed                    // System.out.println ("not implemented: "+e.getActionCommand());        }      // Any commands whose keyStrokes should be used by the Editor should not      // cause editing to be stopped: ie, the SPACE sends "addToSelection" but       // if the table is in editing mode, the space should not cause us to stop      // editing because it should be used by the Editor.      if (table.isEditing() && command != "startEditing"          && command != "addToSelection")        table.editingStopped(new ChangeEvent("update"));            table.scrollRectToVisible        (table.getCellRect(rowModel.getLeadSelectionIndex(),                            colModel.getLeadSelectionIndex(), false));    }