示例#1
0
  /**
   * Retrieve the footer for this table.
   *
   * @return the definition of footer.
   */
  public TextLine[] getFooter() {
    if (footer == null) {
      List<TextLine> tmp = new ArrayList<>();
      StringBuilder line = new StringBuilder();

      // draw lower border if necessary
      if (isDrawBorder()) {
        line.append(EscpUtil.CP347_LIGHT_UP_RIGHT);
        for (int columnIndex = 0; columnIndex < columns.size(); columnIndex++) {
          TableColumn column = columns.get(columnIndex);
          for (int i = 0; i < column.getWidth() - 1; i++) {
            line.append(EscpUtil.CP347_LIGHT_HORIZONTAL);
          }
          if (columnIndex == (columns.size() - 1)) {
            line.append(EscpUtil.CP347_LIGHT_UP_LEFT);
          } else {
            line.append(EscpUtil.CP347_LIGHT_UP_HORIZONTAL);
          }
        }
        tmp.add(new TextLine(line.toString()));
      }
      footer = tmp.toArray(new TextLine[0]);
    }
    return Arrays.copyOf(footer, footer.length);
  }
示例#2
0
 /**
  * Get width of lines in this table in number of characters.
  *
  * @return width in number of characters.
  */
 public int getWidth() {
   int result = 0;
   for (TableColumn column : columns) {
     result += column.getWidth();
   }
   return result;
 }
示例#3
0
  /**
   * Retrieve the header for this table. If border for this table is disabled, header will only be a
   * row that contains column's caption. If border is enabled, the header is three lines with CP347
   * pseudo-graphic characters to simulate a border.
   *
   * @return the definition of header.
   */
  public TextLine[] getHeader() {
    if (header == null) {
      List<TextLine> tmp = new ArrayList<>();
      StringBuilder line = new StringBuilder();

      // draw header upper border if necessary
      if (isDrawBorder()) {
        line.append(EscpUtil.CP347_LIGHT_DOWN_RIGHT);
        for (int columnIndex = 0; columnIndex < columns.size(); columnIndex++) {
          TableColumn column = columns.get(columnIndex);
          for (int i = 0; i < column.getWidth() - 1; i++) {
            line.append(EscpUtil.CP347_LIGHT_HORIZONTAL);
          }
          if (columnIndex == (columns.size() - 1)) {
            line.append(EscpUtil.CP347_LIGHT_DOWN_LEFT);
          } else {
            line.append(EscpUtil.CP347_LIGHT_DOWN_HORIZONTAL);
          }
        }
        tmp.add(new TextLine(line.toString()));
      }

      // draw column name
      line = new StringBuilder();
      if (isDrawBorder()) {
        line.append(EscpUtil.CP347_LIGHT_VERTICAL);
      }
      for (int columnIndex = 0; columnIndex < columns.size(); columnIndex++) {
        TableColumn column = columns.get(columnIndex);
        int width = column.getWidth() - (isDrawBorder() ? 1 : 0);
        StringUtil.ALIGNMENT alignment = (new BasicPlaceholder(column.getText())).getAlignment();
        if (alignment == null) {
          alignment = StringUtil.ALIGNMENT.LEFT;
        }
        line.append(StringUtil.align(column.getCaption(), width, alignment));
        if (isDrawBorder()) {
          line.append(EscpUtil.CP347_LIGHT_VERTICAL);
        }
      }
      tmp.add(new TextLine(line.toString()));

      // draw lower border if necessary
      line = new StringBuilder();
      if (isDrawBorder()) {
        line.append(EscpUtil.CP347_LIGHT_VERTICAL_RIGHT);
        for (int columnIndex = 0; columnIndex < columns.size(); columnIndex++) {
          TableColumn column = columns.get(columnIndex);
          for (int i = 0; i < column.getWidth() - 1; i++) {
            line.append(EscpUtil.CP347_LIGHT_HORIZONTAL);
          }
          if (columnIndex == (columns.size() - 1)) {
            line.append(EscpUtil.CP347_LIGHT_VERTICAL_LEFT);
          } else {
            line.append(EscpUtil.CP347_LIGHT_VERTICAL_HORIZONTAL);
          }
        }
        tmp.add(new TextLine(line.toString()));
      }
      header = tmp.toArray(new TextLine[0]);
    }
    return Arrays.copyOf(header, header.length);
  }