Esempio n. 1
0
  private void updateEntireView() {

    // upadte board view entirely
    boardView.update(board, remainMode.isSelected());

    // redraw combination view
    Group group = board.getGroup(board.getCurrentCell().getGroupId());
    combinationView.update(group);
  }
Esempio n. 2
0
  private void moveFocusTo(int row, int col) {

    // update combination list if new group is selected
    Cell cell = board.getCell(row, col);
    int groupId = cell.getGroupId();
    if (groupId != board.getCurrentCell().getGroupId()) {
      combinationView.update(board.getGroup(groupId));
    }

    // don't update current cell before checking group ID changed
    board.setCurrentCell(row, col);
    boardView.focusOn(row, col);
  }
Esempio n. 3
0
  @Override
  public void handle(KeyEvent event) {
    Cell current = board.getCurrentCell();
    final int row = current.row;
    final int col = current.col;

    int nextRow = row;
    int nextCol = col;

    KeyCode code = event.getCode();
    switch (code) {
        // move using AWSD feature
      case UP:
      case W:
        nextRow = row == Board.MIN_INDEX ? Board.MAX_INDEX : row - 1;
        break;

      case DOWN:
      case S:
        nextRow = row == Board.MAX_INDEX ? Board.MIN_INDEX : row + 1;
        break;

      case LEFT:
      case A:
        nextCol = col == Board.MIN_INDEX ? Board.MAX_INDEX : col - 1;
        break;

      case RIGHT:
      case D:
        nextCol = col == Board.MAX_INDEX ? Board.MIN_INDEX : col + 1;
        break;

        // switch to hint mode feature
      case SHIFT:
        hintMode.setSelected(!hintMode.isSelected());
        break;

        // auto solve
      case SPACE:
        auto();
        break;

        // undo
      case Z:
        if (event.isControlDown()) {
          undo();
        }
        break;

        // delete cell feature
      case DIGIT0:
      case NUMPAD0:
      case DELETE:
      case BACK_SPACE:
        if (hintMode.isSelected()) {
          removeCellHints(row, col);
        } else {
          removeCellValue(row, col);
        }
        break;

        // enter cell value feature
      default:
        if (code.isDigitKey()) {
          String text = event.getText();
          int value = Integer.parseInt(text);

          if (hintMode.isSelected()) {
            toggleCellHint(row, col, value);
          } else {
            updateCellValue(row, col, value);
          }
        }
        break;
    }

    // move to next cell
    event.consume(); // prevent arrow keys automatically change the focus
    if (nextRow != current.row || nextCol != current.col) {
      moveFocusTo(nextRow, nextCol);
    }
  }