else if (e.getActionCommand().equals("scrollUpExtendSelection"))
else if (command.equals("scrollUpExtendSelection"))
    public void actionPerformed (ActionEvent e)    {      ListSelectionModel rowModel = table.getSelectionModel();      ListSelectionModel colModel = table.getColumnModel().getSelectionModel();      int rowLead = rowModel.getLeadSelectionIndex();      int rowMax = table.getModel().getRowCount() - 1;            int colLead = colModel.getLeadSelectionIndex();      int colMax = table.getModel().getColumnCount() - 1;            if (e.getActionCommand().equals("selectPreviousRowExtendSelection"))        {          rowModel.setLeadSelectionIndex(Math.max(rowLead - 1, 0));          colModel.setLeadSelectionIndex(colLead);        }      else if (e.getActionCommand().equals("selectLastColumn"))        {          table.clearSelection();          rowModel.setSelectionInterval(rowLead, rowLead);          colModel.setSelectionInterval(colMax, colMax);        }      else if (e.getActionCommand().equals("startEditing"))        {          if (table.isCellEditable(rowLead, colLead))            table.editCellAt(rowLead,colLead);        }      else if (e.getActionCommand().equals("selectFirstRowExtendSelection"))        {                        rowModel.setLeadSelectionIndex(0);          colModel.setLeadSelectionIndex(colLead);        }      else if (e.getActionCommand().equals("selectFirstColumn"))        {          rowModel.setSelectionInterval(rowLead, rowLead);          colModel.setSelectionInterval(0, 0);        }      else if (e.getActionCommand().equals("selectFirstColumnExtendSelection"))        {          colModel.setLeadSelectionIndex(0);          rowModel.setLeadSelectionIndex(rowLead);        }      else if (e.getActionCommand().equals("selectLastRow"))        {          rowModel.setSelectionInterval(rowMax,rowMax);          colModel.setSelectionInterval(colLead, colLead);        }      else if (e.getActionCommand().equals("selectNextRowExtendSelection"))        {          rowModel.setLeadSelectionIndex(Math.min(rowLead + 1, rowMax));          colModel.setLeadSelectionIndex(colLead);        }      else if (e.getActionCommand().equals("selectFirstRow"))        {          rowModel.setSelectionInterval(0,0);          colModel.setSelectionInterval(colLead, colLead);        }      else if (e.getActionCommand().equals("selectNextColumnExtendSelection"))        {          colModel.setLeadSelectionIndex(Math.min(colLead + 1, colMax));          rowModel.setLeadSelectionIndex(rowLead);        }      else if (e.getActionCommand().equals("selectLastColumnExtendSelection"))        {          colModel.setLeadSelectionIndex(colMax);          rowModel.setLeadSelectionIndex(rowLead);        }      else if (e.getActionCommand().equals("selectPreviousColumnExtendSelection"))        {          colModel.setLeadSelectionIndex(Math.max(colLead - 1, 0));          rowModel.setLeadSelectionIndex(rowLead);        }      else if (e.getActionCommand().equals("selectNextRow"))        {          rowModel.setSelectionInterval(Math.min(rowLead + 1, rowMax),                                        Math.min(rowLead + 1, rowMax));          colModel.setSelectionInterval(colLead,colLead);        }      else if (e.getActionCommand().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 (e.getActionCommand().equals("selectPreviousRow"))        {          rowModel.setSelectionInterval(Math.max(rowLead - 1, 0),                                        Math.max(rowLead - 1, 0));          colModel.setSelectionInterval(colLead,colLead);        }      else if (e.getActionCommand().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 (e.getActionCommand().equals("selectPreviousColumn"))        {          rowModel.setSelectionInterval(rowLead,rowLead);          colModel.setSelectionInterval(Math.max(colLead - 1, 0),                                        Math.max(colLead - 1, 0));        }      else if (e.getActionCommand().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 (e.getActionCommand().equals("clearSelection"))        {          table.clearSelection();        }      else if (e.getActionCommand().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 (e.getActionCommand().equals("selectNextRowCell")               || e.getActionCommand().equals("selectPreviousRowCell")               || e.getActionCommand().equals("selectNextColumnCell")               || e.getActionCommand().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 (e.getActionCommand().indexOf("Column") != -1)                 advanceSingleSelection(colModel, colMax, rowModel, rowMax,                                        (e.getActionCommand().equals                                        ("selectPreviousColumnCell")));              else                advanceSingleSelection(rowModel, rowMax, colModel, colMax,                                        (e.getActionCommand().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 (e.getActionCommand().indexOf("Column") != -1)             advanceMultipleSelection(colModel, colMinSelected, colMaxSelected,                                      rowModel, rowMinSelected, rowMaxSelected,                                      (e.getActionCommand().equals                                      ("selectPreviousColumnCell")), true);                    else            advanceMultipleSelection(rowModel, rowMinSelected, rowMaxSelected,                                      colModel, colMinSelected, colMaxSelected,                                      (e.getActionCommand().equals                                       ("selectPreviousRowCell")), false);        }      else if (e.getActionCommand().equals("selectNextColumn"))        {          rowModel.setSelectionInterval(rowLead,rowLead);          colModel.setSelectionInterval(Math.min(colLead + 1, colMax),                                        Math.min(colLead + 1, colMax));        }      else if (e.getActionCommand().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 (e.getActionCommand().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 (e.getActionCommand().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 (e.getActionCommand().equals("selectAll"))        {          table.selectAll();        }      else if (e.getActionCommand().equals("selectLastRowExtendSelection"))        {          rowModel.setLeadSelectionIndex(rowMax);          colModel.setLeadSelectionIndex(colLead);        }      else if (e.getActionCommand().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 (e.getActionCommand().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 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.        }      if (table.isEditing() && e.getActionCommand() != "startEditing")        table.editingCanceled(new ChangeEvent("update"));      table.repaint();            table.scrollRectToVisible        (table.getCellRect(rowModel.getLeadSelectionIndex(),                            colModel.getLeadSelectionIndex(), false));    }