public void updateTableUiForFoundValue(
      TableSearcherCell cell, int replacementCount, boolean isReplace) {
    // log.debug("updateTableUiForFoundValue()");
    // boolean found = cell.isFound();
    int curRow = -1;
    int curCol = -1;
    if (replacementCount > 0) {
      // log.debug("updateTableUiForFoundValue() - update for found cell");

      curRow = cell.getRow();
      curCol = cell.getColumn();
      // log.debug("updateTableUiForFoundValue() - Cell row[" + curRow + "] ");
      // log.debug("                               Cell col[" + curCol + "] ");
      // log.debug("updateTableUiForFoundValue() - preoapring to set selection model");
      if (curRow != -1 && curCol != -1) {
        ListSelectionModel rsm = table.getSelectionModel();
        ListSelectionModel csm = table.getColumnModel().getSelectionModel();
        Rectangle rect = table.getCellRect(curRow, curCol, false);
        if (!isSearchSelection()) {
          rsm.setSelectionInterval(curRow, curRow);
          csm.setSelectionInterval(curCol, curCol);
        } else {
          table.setEmphasizedCell(curRow, curCol);
          if (rect != null) {
            table.repaint(rect);
          } else {
            table.repaint();
          }
        }
        if (rect != null && table.getAutoscrolls()) {
          // log.debug("updateTableUiForFoundValue() - preparing to scroll");
          table.scrollRectToVisible(rect);
          // log.debug("updateTableUiForFoundValue() - done scrolling");
        }
      }
      if (isSearchDown()) {
        enablePreviousButton();
      } else {
        enableNextButton();
      }
      updateStatusLabel(replacementCount, isReplace);
    } else {
      // log.debug("updateTableUiForFoundValue() found nothing");
      if (isSearchDown()) {
        setFinishedSearchingDown(true);
        if (!getWrapSearchFlag()) {
          disableNextButton();
          enablePreviousButton();
        }
        setStatusLabelWithFailedFind();
      } else {
        setFinishedSearchingUp(true);
        if (!getWrapSearchFlag()) {
          disablePreviousButton();
          enableNextButton();
        }
        setStatusLabelWithFailedFind();
      }
    }
  }
  /**
   * sets up the keystroke mappings for "Ctrl-F" firing the find/replace panel Escape making it
   * disappear, and enter key firing a search
   */
  private void setupKeyStrokeMappings() {
    // table.getActionMap().clear();

    // override the "Ctrl-F" function for launching the find dialog shipped with JXTable
    table
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(
                KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
            UIRegistry.getResourceString(FIND));
    table
        .getInputMap()
        .put(
            KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK),
            UIRegistry.getResourceString(FIND));

    // create action that will display the find/replace dialog
    launchFindAction = new LaunchFindAction();
    table.getActionMap().put(FIND, launchFindAction);

    // Allow ESC buttun to call DisablePanelAction
    String CANCEL_KEY = "CANCELKEY"; // i18n
    // Allow ENTER button to SearchAction
    String ENTER_KEY = "ENTERKEY"; // i18n
    String REPLACE_KEY = "REPLACEKEY"; // i18n

    KeyStroke enterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);
    KeyStroke escapeKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);

    InputMap textFieldInputMap =
        findField.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    textFieldInputMap.put(enterKey, ENTER_KEY);
    textFieldInputMap.put(escapeKey, CANCEL_KEY);

    ActionMap textFieldActionMap = findField.getActionMap();
    textFieldActionMap.put(ENTER_KEY, searchAction);
    textFieldActionMap.put(CANCEL_KEY, hideFindPanelAction);

    if (!table.isReadOnly()) {
      InputMap replaceFieldInputMap =
          replaceField.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
      replaceFieldInputMap.put(enterKey, REPLACE_KEY);
      replaceFieldInputMap.put(escapeKey, CANCEL_KEY);

      ActionMap replaceFieldActionMap = replaceField.getActionMap();
      replaceFieldActionMap.put(REPLACE_KEY, replaceAction);
      replaceFieldActionMap.put(CANCEL_KEY, hideFindPanelAction);
    }
  }
  private void createReplacePanel() {
    if (!table.isReadOnly()) {
      replaceField.setColumns(textFieldLength);
      replaceField.addKeyListener(new FindReplaceTextFieldKeyAdapter());

      replaceButton = createButton(getResourceString("SS_SR_REPLACE"));
      replaceButton.addActionListener(replaceAction);

      replaceAllButton = createButton(getResourceString("SS_SR_REPLACEALL"));
      replaceAllButton.addActionListener(replaceAction);

      // replaceButton.setMnemonic(KeyEvent.VK_N);
      // replaceButton.addActionListener(searchAction);
      // JComponent[] itemSample = { new JMenuItem("Replace"), new JMenuItem("Replace All") };
      // memoryReplaceButton = new MemoryDropDownButton("Replace",
      // IconManager.getIcon("DropDownArrow"),
      // 1, java.util.Arrays.asList(itemSample));
      // memoryReplaceButton.setOverrideBorder(true, memoryReplaceButton.raisedBorder);
      // memoryReplaceButton.setEnabled(false);

      builder.add(replaceField, cc.xy(5, 3));
      builder.add(replaceButton, cc.xy(7, 3));
      builder.add(replaceAllButton, cc.xy(9, 3));
    }
  }
 /** @return true if replace operation can proceed. */
 protected boolean canReplace() {
   TableColumn sortedColumn = table.getSortedColumn();
   if (sortedColumn != null) {
     if (isSearchSelection()) {
       int[] selCols = table.getSelectedColumns();
       int sortCol = table.getColumnModel().getColumnIndex(sortedColumn.getIdentifier());
       for (int c = 0; c < selCols.length; c++) {
         if (selCols[c] == sortCol) {
           return false;
         }
       }
     } else {
       return false;
     }
   }
   return true;
 }
 /**
  * detects when a table changes has been made and changes the next, previous buttons, as well as
  * clears the status label.
  */
 public void handleTableSelections() {
   listSelectionListener =
       new ListSelectionListener() {
         public void valueChanged(ListSelectionEvent e) {
           if (!e.getValueIsAdjusting()) {
             nextButton.setEnabled(true);
             previousButton.setEnabled(true);
             updateStatusLabel(-1, false);
           }
         }
       };
   table.getSelectionModel().addListSelectionListener(listSelectionListener);
 }
  /** Clears the label that tells the user the status of the search/replace */
  public void updateStatusLabel(int count, boolean isReplace) {
    // log.debug("clearing status lable");
    statusInfo.setHorizontalTextPosition(SwingConstants.RIGHT);
    statusInfo.setIcon(null);
    String findFldVal = getFindFieldValue();
    replaceButton.setEnabled(foundCell != null && StringUtils.isNotBlank(findFldVal));

    if (count > 0) {
      if (!isReplace) {
        // Count for find is always 1?? But maybe not when replacing.
        if (!table.isReadOnly() || count > 1) {
          String key =
              count == 1 ? "SearchReplacePanel.FOUND_MATCH" : "SearchReplacePanel.FOUND_MATCHES";
          statusInfo.setText(String.format(UIRegistry.getResourceString(key), count));
        }
      } else {
        String key =
            count == 1 ? "SearchReplacePanel.REPLACED_CELL" : "SearchReplacePanel.REPLACED_CELLS";
        statusInfo.setText(String.format(UIRegistry.getResourceString(key), count));
      }
    } else {
      statusInfo.setText("");
    }
  }
 /** stops editing of the table. */
 private void stopTableEditing() {
   if (table.getCellEditor() != null) {
     table.getCellEditor().stopCellEditing();
   }
 }