/** * Constructs a <CODE>Table</CODE> with a certain number of columns and a certain number of <CODE> * Row</CODE>s. * * @param columns The number of columns in the table * @param rows The number of rows * @throws BadElementException if the creator was called with less than 1 column */ public Table(int columns, int rows) throws BadElementException { // a Rectangle is create with BY DEFAULT a border with a width of 1 super(0, 0, 0, 0); setBorder(BOX); setBorderWidth(1); defaultCell.setBorder(BOX); // a table should have at least 1 column if (columns <= 0) { throw new BadElementException( MessageLocalization.getComposedMessage("a.table.should.have.at.least.1.column")); } this.columns = columns; // a certain number of rows are created for (int i = 0; i < rows; i++) { this.rows.add(new Row(columns)); } curPosition = new Point(0, 0); // the DEFAULT widths are calculated widths = new float[columns]; float width = 100f / columns; for (int i = 0; i < columns; i++) { widths[i] = width; } }
/** * Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE> at a certain location. * * @param aCell The <CODE>Cell</CODE> to add * @param aLocation The location where the <CODE>Cell</CODE> will be added * @throws BadElementException */ public void addCell(Cell aCell, Point aLocation) throws BadElementException { if (aCell == null) throw new NullPointerException( MessageLocalization.getComposedMessage("addcell.cell.has.null.value")); if (aLocation == null) throw new NullPointerException( MessageLocalization.getComposedMessage("addcell.point.has.null.value")); if (aCell.isTable()) insertTable((Table) aCell.getElements().next(), aLocation); if (aLocation.x < 0) throw new BadElementException( MessageLocalization.getComposedMessage("row.coordinate.of.location.must.be.gt.eq.0")); if ((aLocation.y <= 0) && (aLocation.y > columns)) throw new BadElementException( MessageLocalization.getComposedMessage( "column.coordinate.of.location.must.be.gt.eq.0.and.lt.nr.of.columns")); if (!isValidLocation(aCell, aLocation)) throw new BadElementException( MessageLocalization.getComposedMessage( "adding.a.cell.at.the.location.1.2.with.a.colspan.of.3.and.a.rowspan.of.4.is.illegal.beyond.boundaries.overlapping", String.valueOf(aLocation.x), String.valueOf(aLocation.y), String.valueOf(aCell.getColspan()), String.valueOf(aCell.getRowspan()))); if (aCell.getBorder() == UNDEFINED) aCell.setBorder(defaultCell.getBorder()); aCell.fill(); placeCell(rows, aCell, aLocation); setCurrentLocationToNextValidPosition(aLocation); }
/** * Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE>. * * <p>This is a shortcut for <CODE>addCell(Cell cell, Point location)</CODE>. The <CODE>Phrase * </CODE> will be converted to a <CODE>Cell</CODE>. * * @param content a <CODE>Phrase</CODE> * @param location a <CODE>Point</CODE> * @throws BadElementException this should never happen */ public void addCell(Phrase content, Point location) throws BadElementException { Cell cell = new Cell(content); cell.setBorder(defaultCell.getBorder()); cell.setBorderWidth(defaultCell.getBorderWidth()); cell.setBorderColor(defaultCell.getBorderColor()); cell.setBackgroundColor(defaultCell.getBackgroundColor()); cell.setHorizontalAlignment(defaultCell.getHorizontalAlignment()); cell.setVerticalAlignment(defaultCell.getVerticalAlignment()); cell.setColspan(defaultCell.getColspan()); cell.setRowspan(defaultCell.getRowspan()); addCell(cell, location); }
/** * Sets the unset cell properties to be the table defaults. * * @param aCell The cell to set to table defaults as necessary. */ private void assumeTableDefaults(Cell aCell) { if (aCell.getBorder() == Rectangle.UNDEFINED) { aCell.setBorder(defaultCell.getBorder()); } if (aCell.getBorderWidth() == Rectangle.UNDEFINED) { aCell.setBorderWidth(defaultCell.getBorderWidth()); } if (aCell.getBorderColor() == null) { aCell.setBorderColor(defaultCell.getBorderColor()); } if (aCell.getBackgroundColor() == null) { aCell.setBackgroundColor(defaultCell.getBackgroundColor()); } if (aCell.getHorizontalAlignment() == Element.ALIGN_UNDEFINED) { aCell.setHorizontalAlignment(defaultCell.getHorizontalAlignment()); } if (aCell.getVerticalAlignment() == Element.ALIGN_UNDEFINED) { aCell.setVerticalAlignment(defaultCell.getVerticalAlignment()); } }
// utility function to make an item Element. private Table makeItemElement(ShoppingCartItemData pItm) throws DocumentException { Table itmTbl = new PTable(mColumnCount); itmTbl.setWidth(100); itmTbl.setWidths(itmColumnWidth); itmTbl.getDefaultCell().setBorderColor(java.awt.Color.black); itmTbl.getDefaultCell().setVerticalAlignment(Cell.ALIGN_TOP); itmTbl.setOffset(0); itmTbl.setBorder(Table.NO_BORDER); if (!catalogOnly) { String t0 = ""; if (pItm.getIsaInventoryItem()) { t0 = "i"; } if (null != mSiteData && mSiteData.isAnInventoryAutoOrderItem(pItm.getProduct().getProductId())) { t0 += "a"; } Cell tpc0 = new Cell(makePhrase(t0, small, true)); if (!pItm.getIsaInventoryItem()) { tpc0.setBorder(0); } itmTbl.addCell(tpc0); } Cell tpc01 = new Cell(makePhrase("", normal, true)); itmTbl.addCell(tpc01); String t = ""; if (pItm.getProduct().isPackProblemSku()) { t += "*"; } if (t.length() > 0) t += " "; Cell tpc1 = new Cell(makePhrase(t + pItm.getActualSkuNum(), normal, true)); itmTbl.addCell(tpc1); itmTbl.addCell(makePhrase(pItm.getProduct().getCatalogProductShortDesc(), normal, true)); if (mShowSize) { itmTbl.addCell(makePhrase(pItm.getProduct().getSize(), normal, true)); } // itmTbl.addCell(makePhrase(pItm.getProduct().getPack(), normal, true)); // itmTbl.addCell(makePhrase(pItm.getProduct().getUom(), normal, true)); // itmTbl.addCell(makePhrase(pItm.getProduct().getManufacturerName(),normal,true)); if (mShowPrice) { BigDecimal price = new BigDecimal(pItm.getPrice()); String priceStr = ""; try { priceStr = mFormatter.priceFormatWithoutCurrency(price); } catch (Exception exc) { exc.printStackTrace(); } Cell pcell = new Cell(makePhrase(priceStr, normal, true)); pcell.setHorizontalAlignment(Element.ALIGN_RIGHT); itmTbl.addCell(pcell); } if (catalogOnly) { if (pItm.getProduct() != null && pItm.getProduct().getCatalogDistrMapping() != null && Utility.isTrue(pItm.getProduct().getCatalogDistrMapping().getStandardProductList())) { String yStr = ClwI18nUtil.getMessage(mRequest, "shoppingItems.text.y", null); itmTbl.addCell(makePhrase(yStr, normal, true)); } else { String nStr = ClwI18nUtil.getMessage(mRequest, "shoppingItems.text.n", null); itmTbl.addCell(makePhrase(nStr, normal, true)); } } if (!catalogOnly) { // BigDecimal amount = new BigDecimal(pItm.getAmount()); itmTbl.addCell(makePhrase("", normal, true)); } return itmTbl; }