?? pdfcell.java
字號:
case Image.MIDDLE: left = left + ((right - left - image.scaledWidth()) / 2f); break; case Image.LEFT: default: } image.setAbsolutePosition(left, height + (lines.size() - 2) * leading + image.scaledHeight() + 0.4f * leading); images.add(image); return height + image.scaledHeight() + 0.4f * leading; } /** * Gets the lines of a cell that can be drawn between certain limits. * <P> * Remark: all the lines that can be drawn are removed from the object! * * @param top the top of the part of the table that can be drawn * @param bottom the bottom of the part of the table that can be drawn * @return an <CODE>ArrayList</CODE> of <CODE>PdfLine</CODE>s */ public ArrayList getLines(float top, float bottom) { // if the bottom of the page is higher than the top of the cell: do nothing if (top() < bottom) { return null; } // initialisations float lineHeight; float currentPosition = Math.min(top(), top); setTop(currentPosition + cellspacing); ArrayList result = new ArrayList(); // we loop over the lines int size = lines.size(); boolean aboveBottom = true; for (int i = 0; i < size && aboveBottom; i++) { line = (PdfLine) lines.get(i); lineHeight = line.height(); currentPosition -= lineHeight; // if the currentPosition is higher than the bottom, we add the line to the result if (currentPosition > (bottom + cellpadding)) { // bugfix by Tom Ring and Veerendra Namineni result.add(line); } else { aboveBottom = false; } } // if the bottom of the cell is higher than the bottom of the page, the cell is written, so we can remove all lines float difference = 0f; if (!header) { if (aboveBottom) { lines = new ArrayList(); } else { size = result.size(); for (int i = 0; i < size; i++) { line = (PdfLine) lines.remove(0); difference += line.height(); } } } if (difference > 0) { Image image; for (Iterator i = images.iterator(); i.hasNext(); ) { image = (Image) i.next(); image.setAbsolutePosition(image.absoluteX(), image.absoluteY() - difference - leading); } } return result; } /** * Gets the images of a cell that can be drawn between certain limits. * <P> * Remark: all the lines that can be drawn are removed from the object! * * @param top the top of the part of the table that can be drawn * @param bottom the bottom of the part of the table that can be drawn * @return an <CODE>ArrayList</CODE> of <CODE>Image</CODE>s */ public ArrayList getImages(float top, float bottom) { // if the bottom of the page is higher than the top of the cell: do nothing if (top() < bottom) { return new ArrayList(); } top = Math.min(top(), top); // initialisations Image image; float height; ArrayList result = new ArrayList(); // we loop over the images for (Iterator i = images.iterator(); i.hasNext() && !header; ) { image = (Image) i.next(); height = image.absoluteY(); // if the currentPosition is higher than the bottom, we add the line to the result if (top - height > (bottom + cellpadding)) { image.setAbsolutePosition(image.absoluteX(), top - height); result.add(image); i.remove(); } } return result; } /** * Checks if this cell belongs to the header of a <CODE>PdfTable</CODE>. * * @return <CODE>void</CODE> */ boolean isHeader() { return header; } /** * Indicates that this cell belongs to the header of a <CODE>PdfTable</CODE>. */ void setHeader() { header = true; } /** * Checks if the cell may be removed. * <P> * Headers may allways be removed, even if they are drawn only partially: * they will be repeated on each following page anyway! * * @return <CODE>true</CODE> if all the lines are allready drawn; <CODE>false</CODE> otherwise. */ boolean mayBeRemoved() { return (header || (lines.size() == 0 && images.size() == 0)); } /** * Returns the number of lines in the cell. * * @return a value */ public int size() { return lines.size(); } /** * Returns the number of lines in the cell that are not empty. * * @return a value */ public int remainingLines() { if (lines.size() == 0) return 0; int result = 0; int size = lines.size(); PdfLine line; for (int i = 0; i < size; i++) { line = (PdfLine) lines.get(i); if (line.size() > 0) result++; } return result; } /** * Returns the height needed to draw the remaining text. * * @return a height */ public float remainingHeight() { float result = 0f; for (Iterator i = images.iterator(); i.hasNext(); ) { Image image = (Image)i.next(); result += image.scaledHeight(); } return remainingLines() * leading + 2 * cellpadding + cellspacing + result + leading / 2.5f; } // methods to retrieve membervariables /** * Gets the leading of a cell. * * @return the leading of the lines is the cell. */ public float leading() { return leading; } /** * Gets the number of the row this cell is in.. * * @return a number */ public int rownumber() { return rownumber; } /** * Gets the rowspan of a cell. * * @return the rowspan of the cell */ public int rowspan() { return rowspan; } /** * Gets the cellspacing of a cell. * * @return a value */ public float cellspacing() { return cellspacing; } /** * Gets the cellpadding of a cell.. * * @return a value */ public float cellpadding() { return cellpadding; } /** * Processes all actions contained in the cell. */ protected void processActions(Element element, PdfAction action, ArrayList allActions) { if (element.type() == Element.ANCHOR) { String url = ((Anchor)element).reference(); if (url != null) { action = new PdfAction(url); } } Iterator i; switch (element.type()) { case Element.PHRASE: case Element.SECTION: case Element.ANCHOR: case Element.CHAPTER: case Element.LISTITEM: case Element.PARAGRAPH: for (i = ((ArrayList)element).iterator(); i.hasNext(); ) { processActions((Element)i.next(), action, allActions); } break; case Element.CHUNK: allActions.add(action); break; case Element.LIST: for (i = ((List)element).getItems().iterator(); i.hasNext(); ) { processActions((Element)i.next(), action, allActions); } break; default: ArrayList tmp = element.getChunks(); int n = element.getChunks().size(); while (n-- > 0) allActions.add(action); break; } } /** This is the number of the group the cell is in. */ private int groupNumber; /** * Gets the number of the group this cell is in.. * * @return a number */ public int getGroupNumber() { return groupNumber; } /** * Sets the group number. */ void setGroupNumber(int number) { groupNumber = number; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -