Exemplo n.º 1
0
 @Override
 public int compare(Cell o1, Cell o2) {
   if (o1.isEmpty()) {
     return 1;
   } else if (o2.isEmpty()) {
     return -1;
   } else {
     return o1.getItem().compareTo(o2.getItem());
   }
 }
Exemplo n.º 2
0
  public void selectCell(int row, int col) {
    if (!field.cellExists(row, col)) {
      clearSelectedCell();
      return;
    }

    Cell currentCell = field.getCell(row, col);

    if (!currentCell.isEmpty()) {
      selectedCell = currentCell;
    } else if (!noSelectedCell() && currentCell.isEmpty()) {
      moveBallAction.moveBall(selectedCell, currentCell);
      clearSelectedCell();
    }
  }
Exemplo n.º 3
0
 public List<Cell> getNonEmptyCells() {
   List<Cell> cells = new ArrayList<Cell>();
   for (Cell cell : this.cells) {
     if (!cell.isEmpty()) cells.add(cell);
   }
   return cells;
 }
Exemplo n.º 4
0
  private void reorganizeGridAbove(int x, int y, int w) {
    Set<IFormField> fieldsToReorganize = new HashSet<IFormField>();
    Map<MatrixIndex, Cell> occupiedCells = new HashMap<MatrixIndex, Cell>();
    Bounds reorgBounds = new Bounds(x, 0, w, y + 1);

    int minY = y;
    int usedCells = 0;
    boolean continueLoop = true;
    for (int yi = y; yi >= 0 && continueLoop; yi--) {
      for (int xi = x; xi < x + w && continueLoop; xi++) {
        MatrixIndex matrixIndex = new MatrixIndex(xi, yi);
        Cell cell = m_cells.get(matrixIndex);
        if (cell != null && !cell.isEmpty()) {
          GridData gd = cell.fieldGridData;

          if (horizontalMatchesOrOverlaps(reorgBounds, gd)) {
            continueLoop = false;
          } else if (horizontalOverlapsOnSide(reorgBounds, gd)) {
            // freeze the cells for reorganization
            occupiedCells.put(matrixIndex, cell);
            usedCells++;
            minY = Math.min(matrixIndex.y, minY);
          }
          // includes
          else {
            // add field to reorganization
            m_cells.remove(matrixIndex);
            fieldsToReorganize.add(cell.field);
            usedCells++;
            minY = Math.min(matrixIndex.y, minY);
          }
        }
      }
    }
    if (fieldsToReorganize.isEmpty()) {
      return;
    }
    // sort fields
    List<IFormField> sortedFieldsToReorganize = new ArrayList<IFormField>(fieldsToReorganize);
    Collections.sort(
        sortedFieldsToReorganize,
        new Comparator<IFormField>() {
          @Override
          public int compare(IFormField o1, IFormField o2) {
            Integer i1 = m_formFieldIndexes.get(o1);
            Integer i2 = m_formFieldIndexes.get(o2);
            return i1.compareTo(i2);
          }
        });
    reorgBounds.y = minY;

    VerticalGridMatrix reorgMatrix =
        new VerticalGridMatrix(
            reorgBounds.x,
            reorgBounds.y,
            reorgBounds.w,
            (usedCells + reorgBounds.w - 1) / reorgBounds.w);
    reorgMatrix.addCells(occupiedCells);
    while (!reorgMatrix.computeGridData(sortedFieldsToReorganize)) {
      reorgMatrix.resetAll(reorgMatrix.getColumnCount(), reorgMatrix.getRowCount() + 1);
    }
    m_cursor.reset();
    m_cells.putAll(reorgMatrix.getCells());
    m_fieldGridDatas.putAll(reorgMatrix.getFieldGridDatas());
  }
Exemplo n.º 5
0
 public boolean isComplete() {
   for (Cell cell : cells) {
     if (cell.isEmpty()) return false;
   }
   return true;
 }