Exemplo n.º 1
0
 public Range(Sheet sheet, Cell cell) {
   this.sheet = sheet;
   fromColumn = cell.getColumn();
   fromRow = cell.getRow();
   toColumn = cell.getColumn();
   toRow = cell.getRow();
 }
Exemplo n.º 2
0
  /**
   * Set the pattern explicitely (rather than waiting for the user to input a pattern).
   *
   * @param displayMode How to display the pattern.
   * @param pattern The pattern.
   */
  public void setPattern(DisplayMode displayMode, List<Cell> pattern) {
    mPattern.clear();
    mPattern.addAll(pattern);
    clearPatternDrawLookup();
    for (Cell cell : pattern) {
      mPatternDrawLookup[cell.getRow()][cell.getColumn()] = true;
    }

    setDisplayMode(displayMode);
  }
Exemplo n.º 3
0
 private boolean hasEmptyColumn(List<Cell> cellList) {
   if (cellList != null && cellList.size() > 0) {
     for (Cell cell : cellList) {
       if (Utilities.isEmpty(cell.getColumn())) {
         return true;
       }
     }
   } else {
     return true;
   }
   return false;
 }
Exemplo n.º 4
0
 /**
  * Set the display mode of the current pattern. This can be useful, for instance, after detecting
  * a pattern to tell this view whether change the in progress result to correct or wrong.
  *
  * @param displayMode The display mode.
  */
 public void setDisplayMode(DisplayMode displayMode) {
   mPatternDisplayMode = displayMode;
   if (displayMode == DisplayMode.Animate) {
     if (mPattern.size() == 0) {
       throw new IllegalStateException(
           "you must have a pattern to "
               + "animate if you want to set the display mode to animate");
     }
     mAnimatingPeriodStart = SystemClock.elapsedRealtime();
     final Cell first = mPattern.get(0);
     mInProgressX = getCenterXForColumn(first.getColumn());
     mInProgressY = getCenterYForRow(first.getRow());
     clearPatternDrawLookup();
   }
   invalidate();
 }
Exemplo n.º 5
0
  @Override
  protected void onDraw(Canvas canvas) {
    final ArrayList<Cell> pattern = mPattern;
    final int count = pattern.size();
    final boolean[][] drawLookup = mPatternDrawLookup;

    if (mPatternDisplayMode == DisplayMode.Animate) {

      // figure out which circles to draw

      // + 1 so we pause on complete pattern
      final int oneCycle = (count + 1) * MILLIS_PER_CIRCLE_ANIMATING;
      final int spotInCycle =
          (int) (SystemClock.elapsedRealtime() - mAnimatingPeriodStart) % oneCycle;
      final int numCircles = spotInCycle / MILLIS_PER_CIRCLE_ANIMATING;

      clearPatternDrawLookup();
      for (int i = 0; i < numCircles; i++) {
        final Cell cell = pattern.get(i);
        drawLookup[cell.getRow()][cell.getColumn()] = true;
      }

      // figure out in progress portion of ghosting line

      final boolean needToUpdateInProgressPoint = numCircles > 0 && numCircles < count;

      if (needToUpdateInProgressPoint) {
        final float percentageOfNextCircle =
            ((float) (spotInCycle % MILLIS_PER_CIRCLE_ANIMATING)) / MILLIS_PER_CIRCLE_ANIMATING;

        final Cell currentCell = pattern.get(numCircles - 1);
        final float centerX = getCenterXForColumn(currentCell.column);
        final float centerY = getCenterYForRow(currentCell.row);

        final Cell nextCell = pattern.get(numCircles);
        final float dx = percentageOfNextCircle * (getCenterXForColumn(nextCell.column) - centerX);
        final float dy = percentageOfNextCircle * (getCenterYForRow(nextCell.row) - centerY);
        mInProgressX = centerX + dx;
        mInProgressY = centerY + dy;
      }
      // TODO: Infinite loop here...
      invalidate();
    }

    final float squareWidth = mSquareWidth;
    final float squareHeight = mSquareHeight;

    float radius = (squareWidth * mDiameterFactor * 0.5f);
    mPathPaint.setStrokeWidth(radius);

    final Path currentPath = mCurrentPath;
    currentPath.rewind();

    // draw the circles
    final int paddingTop = getPaddingTop();
    final int paddingLeft = getPaddingLeft();

    for (int i = 0; i < 3; i++) {
      float topY = paddingTop + i * squareHeight;
      // float centerY = mPaddingTop + i * mSquareHeight + (mSquareHeight / 2);
      for (int j = 0; j < 3; j++) {
        float leftX = paddingLeft + j * squareWidth;
        drawCircle(canvas, (int) leftX, (int) topY, drawLookup[i][j]);
      }
    }

    // TODO: the path should be created and cached every time we hit-detect a cell
    // only the last segment of the path should be computed here
    // draw the path of the pattern (unless the user is in progress, and
    // we are in stealth mode)
    final boolean drawPath = (!mInStealthMode || mPatternDisplayMode == DisplayMode.Wrong);

    // draw the arrows associated with the path (unless the user is in progress, and
    // we are in stealth mode)
    boolean oldFlag = (mPaint.getFlags() & Paint.FILTER_BITMAP_FLAG) != 0;
    mPaint.setFilterBitmap(true); // draw with higher quality since we render with transforms
    if (drawPath) {
      for (int i = 0; i < count - 1; i++) {
        Cell cell = pattern.get(i);
        Cell next = pattern.get(i + 1);

        // only draw the part of the pattern stored in
        // the lookup table (this is only different in the case
        // of animation).
        if (!drawLookup[next.row][next.column]) {
          break;
        }

        float leftX = paddingLeft + cell.column * squareWidth;
        float topY = paddingTop + cell.row * squareHeight;

        drawArrow(canvas, leftX, topY, cell, next);
      }
    }

    if (drawPath) {
      boolean anyCircles = false;
      for (int i = 0; i < count; i++) {
        Cell cell = pattern.get(i);

        // only draw the part of the pattern stored in
        // the lookup table (this is only different in the case
        // of animation).
        if (!drawLookup[cell.row][cell.column]) {
          break;
        }
        anyCircles = true;

        float centerX = getCenterXForColumn(cell.column);
        float centerY = getCenterYForRow(cell.row);
        if (i == 0) {
          currentPath.moveTo(centerX, centerY);
        } else {
          currentPath.lineTo(centerX, centerY);
        }
      }

      // add last in progress section
      if ((mPatternInProgress || mPatternDisplayMode == DisplayMode.Animate) && anyCircles) {
        currentPath.lineTo(mInProgressX, mInProgressY);
      }
      if (mPatternDisplayMode == DisplayMode.Wrong) {
        mPathPaint.setColor(mRedPath);
      } else {
        mPathPaint.setColor(mGreenPath);
      }
      canvas.drawPath(currentPath, mPathPaint);
    }

    mPaint.setFilterBitmap(oldFlag); // restore default flag
  }
Exemplo n.º 6
0
 private void addCellToPattern(Cell newCell) {
   mPatternDrawLookup[newCell.getRow()][newCell.getColumn()] = true;
   mPattern.add(newCell);
   notifyCellAdded();
 }
  /** @see se.idega.idegaweb.commune.school.report.business.ReportModel#calculate() */
  protected float calculate(Cell cell) throws RemoteException {
    float value = 0f;
    int schoolId = -1;
    if (cell.getRowParameter() != null) {
      schoolId = ((Integer) cell.getRowParameter()).intValue();
    }
    String schoolYearName = (String) cell.getColumnParameter();

    if (cell.getColumnMethod() == COLUMN_METHOD_SCHOOL_YEAR) {
      switch (cell.getRowMethod()) {
        case ROW_METHOD_SCHOOL:
          value = getPrivateSchoolOCCPlacementCount(schoolId, schoolYearName);
          break;
        case ROW_METHOD_SUM:
          int rowIndex = cell.getRow() - 1;
          if (rowIndex < 0) {
            break;
          }
          Cell c = getCell(rowIndex, cell.getColumn());
          while (rowIndex >= 0 && c.getCellType() == Cell.CELLTYPE_NORMAL) {
            value += c.getFloatValue();
            rowIndex--;
            if (rowIndex >= 0) {
              c = getCell(rowIndex, cell.getColumn());
            }
          }
          break;
        case ROW_METHOD_TOTAL:
          rowIndex = cell.getRow() - 1;
          while (rowIndex >= 0) {
            c = getCell(rowIndex, cell.getColumn());
            if (c.getCellType() == Cell.CELLTYPE_NORMAL) {
              value += c.getFloatValue();
            }
            rowIndex--;
          }
          break;
      }
    } else {
      switch (cell.getColumnMethod()) {
        case COLUMN_METHOD_SUM_1_3:
          for (int i = 1; i < 4; i++) {
            value += getCell(cell.getRow(), i).getFloatValue();
          }
          break;
        case COLUMN_METHOD_SUM_4_6:
          for (int i = 5; i < 8; i++) {
            value += getCell(cell.getRow(), i).getFloatValue();
          }
          break;
        case COLUMN_METHOD_SUM_7_9:
          for (int i = 9; i < 12; i++) {
            value += getCell(cell.getRow(), i).getFloatValue();
          }
          break;
        case COLUMN_METHOD_TOTAL_1_9:
          value =
              getCell(cell.getRow(), 4).getFloatValue()
                  + getCell(cell.getRow(), 8).getFloatValue()
                  + getCell(cell.getRow(), 12).getFloatValue();
          break;
        case COLUMN_METHOD_TOTAL_F_9:
          value =
              getCell(cell.getRow(), 13).getFloatValue()
                  + getCell(cell.getRow(), 0).getFloatValue();
          break;
      }
    }

    return value;
  }
Exemplo n.º 8
0
 public void testConstructor() {
   Cell newCell = new Cell(10, 5);
   assertEquals(10, newCell.getColumn());
   assertEquals(5, newCell.getRow());
 }