コード例 #1
0
  /**
   * for drawing the Record with its Cell Title and Values
   *
   * @param graphics
   * @param b
   */
  private void drawRecord(Graphics graphics, boolean haveFocus) {
    // graphics.setColor(Color.BLACK);
    // graphics.fillRoundRect(10, 2, Display.getWidth() - 10, height + 5,
    // 10,
    // 10);
    // graphics.drawRoundRect(10, 2, Display.getWidth() - 10, height + 5,
    // 10,
    // 10);

    int color = Color.BLACK;
    int[] colors = drawFousLostColors;
    int[] X_PTS = {getWidth(), getWidth(), getPreferredWidth(), getPreferredWidth()};

    int[] Y_PTS = {height, getPreferredHeight(), getPreferredHeight(), height};
    if (haveFocus) {
      colors = drawFousGainColors;
      color = Color.WHITE;
    }
    graphics.drawShadedFilledPath(X_PTS, Y_PTS, null, colors, null);
    graphics.setColor(color);

    // for placing the arrow icon
    int image_height = (height / 2) - 8;
    int img_x_position = total_Width - 18;
    graphics.drawBitmap(
        img_x_position,
        image_height,
        arrowBitmap.getHeight(),
        arrowBitmap.getWidth(),
        arrowBitmap,
        0,
        0);

    int halfWidth = (getWidth() / 2) - RIGHT_MARGIN;

    int yPosition = 0;
    // Draw each cell

    for (int i = 0; i < record.getCells().size(); i++) {
      Cell cell = (Cell) record.getCells().elementAt(i);

      // Draw the title of the cell
      String text = cell.getTitle().trim();

      // take the value of the cell to draw
      String value = cell.getValue().trim();

      int numberOfRowsForTitle = drawText(text, value, graphics, 0, yPosition);

      int numberOfRowsForValue = drawText(value, value, graphics, halfWidth, yPosition);

      if (numberOfRowsForTitle == 1 && numberOfRowsForValue == 1) {
        yPosition += CELL_HEIGHT - MULTIPLE_CELLS;
      } else {
        yPosition += CELL_HEIGHT - MULTIPLE_CELLS;
        yPosition += SECOND_CELL_HEIGHT;
      }
    }
  }
コード例 #2
0
  /**
   * For calculating the Height of the field based on no.of cells and their text length
   *
   * @return
   */
  private int calculateHeight() {
    Font font = Font.getDefault();
    int height = 0;
    int width = total_Width;
    int halfWidth = (width / 2) - RIGHT_MARGIN;
    boolean hasMultipleCells = false;
    if (record.getCells().size() > 1) {
      hasMultipleCells = true;
      MULTIPLE_CELLS = 10;
    }
    for (int i = 0; i < record.getCells().size(); i++) {
      Cell cell = (Cell) record.getCells().elementAt(i);
      String title = cell.getTitle().trim();
      String value = cell.getValue().trim();

      if (value == null || value.trim().length() == 0) {

        boolean titleFitsInHalfWidth = font.getAdvance(title) <= total_Width - RIGHT_MARGIN;
        // for checking if value did not contain any value
        if (titleFitsInHalfWidth) {
          height += CELL_HEIGHT - MULTIPLE_CELLS;
        } else {
          // We need height for two rows
          height += CELL_HEIGHT - MULTIPLE_CELLS;
          height += SECOND_CELL_HEIGHT;
          // We will ignore anything that does not fit in two rows...
        }

      } else {
        // for checking for both title and value
        // Check if title fits in half width

        boolean titleFitsInHalfWidth = font.getAdvance(title) <= halfWidth;
        boolean valueFitsInHalfWidth = font.getAdvance(value) <= halfWidth;
        if (titleFitsInHalfWidth && valueFitsInHalfWidth) {
          height += CELL_HEIGHT - MULTIPLE_CELLS;
        } else {
          // We need height for two rows
          height += CELL_HEIGHT - MULTIPLE_CELLS;
          height += SECOND_CELL_HEIGHT;
          // We will ignore anything that does not fit in two rows...
        }
      }
    }
    return height;
  }