⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cell.java

📁 iText是一个能够快速产生PDF文件的java类库。iText的java类对于那些要产生包含文本
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 */
	public boolean isUseBorderPadding() {
	    return useBorderPadding;
	}

	/**
	 * Does this <CODE>Cell</CODE> force a group change?
	 *
	 * @return	a value
	 */
	public boolean getGroupChange() {
		return groupChange;
	}

	/**
	 * Sets group change.
	 *
	 * @param	value	the new value
	 */
	public void setGroupChange(boolean value) {
		groupChange = value;
	}
	
// arraylist stuff

	/**
	 * Gets the number of <CODE>Element</CODE>s in the Cell.
	 *
	 * @return	a <CODE>size</CODE>.
	 */
	public int size() {
		return arrayList.size();
	}

	/**
	 * Gets an iterator of <CODE>Element</CODE>s.
	 *
	 * @return	an <CODE>Iterator</CODE>.
	 */
	public Iterator getElements() {
		return arrayList.iterator();
	}
	
	/**
	 * Clears all the <CODE>Element</CODE>s of this <CODE>Cell</CODE>.
	 */
	public void clear() {
		arrayList.clear();
	}

	/**
	 * Checks if the <CODE>Cell</CODE> is empty.
	 *
	 * @return	<CODE>false</CODE> if there are non-empty <CODE>Element</CODE>s in the <CODE>Cell</CODE>.
	 */
	public boolean isEmpty() {
		switch(size()) {
			case 0:
				return true;
			case 1:
				Element element = (Element) arrayList.get(0);
				switch (element.type()) {
					case Element.CHUNK:
						return ((Chunk) element).isEmpty();
					case Element.ANCHOR:
					case Element.PHRASE:
					case Element.PARAGRAPH:
						return ((Phrase) element).isEmpty();
					case Element.LIST:
						return ((List) element).isEmpty();
				}
			return false;
			default:
				return false;
		}
	}
	
	/**
	 * Makes sure there is at least 1 object in the Cell.
	 *
	 * Otherwise it might not be shown in the table.
	 */
	void fill() {
		if (size() == 0) arrayList.add(new Paragraph(0));
	}

	/**
	 * Checks if this <CODE>Cell</CODE> is a placeholder for a (nested) table.
	 *
	 * @return	true if the only element in this cell is a table
	 */
	public boolean isTable() {
		return (size() == 1)
			&& (((Element)arrayList.get(0)).type() == Element.TABLE);
	}
	
	/**
	 * Adds an element to this <CODE>Cell</CODE>.
	 * <P>
	 * Remark: you can't add <CODE>ListItem</CODE>s, <CODE>Row</CODE>s, <CODE>Cell</CODE>s,
	 * <CODE>JPEG</CODE>s, <CODE>GIF</CODE>s or <CODE>PNG</CODE>s to a <CODE>Cell</CODE>.
	 *
	 * @param element The <CODE>Element</CODE> to add
	 * @throws BadElementException if the method was called with a <CODE>ListItem</CODE>, <CODE>Row</CODE> or <CODE>Cell</CODE>
	 */
	public void addElement(Element element) throws BadElementException {
		if (isTable()) {
			Table table = (Table) arrayList.get(0);
			Cell tmp = new Cell(element);
			tmp.setBorder(NO_BORDER);
			tmp.setColspan(table.getColumns());
			table.addCell(tmp);
			return;
		}
		switch(element.type()) {
			case Element.LISTITEM:
			case Element.ROW:
			case Element.CELL:
				throw new BadElementException("You can't add listitems, rows or cells to a cell.");
			case Element.LIST:
				List list = (List)element;
				if (Float.isNaN(leading)) {
					setLeading(list.getTotalLeading());
				}
				if (list.isEmpty()) return;
				arrayList.add(element);
				return;
			case Element.ANCHOR:
			case Element.PARAGRAPH:
			case Element.PHRASE:
				Phrase p = (Phrase)element;
				if (Float.isNaN(leading)) {
					setLeading(p.getLeading());
				}
				if (p.isEmpty()) return;
				arrayList.add(element);
				return;
			case Element.CHUNK:
				if (((Chunk) element).isEmpty()) return;
				arrayList.add(element);
				return;
			case Element.TABLE:
				Table table = new Table(3);
				float[] widths = new float[3];
				widths[1] = ((Table)element).getWidth();
				switch(((Table)element).getAlignment()) {
					case Element.ALIGN_LEFT:
						widths[0] = 0f;
						widths[2] = 100f - widths[1];
						break;
					case Element.ALIGN_CENTER:
						widths[0] = (100f - widths[1]) / 2f;
						widths[2] = widths[0];
						break;
					case Element.ALIGN_RIGHT:
						widths[0] = 100f - widths[1];
						widths[2] = 0f;
				}
				table.setWidths(widths);
				Cell tmp;
				if (arrayList.isEmpty()) {
					table.addCell(getDummyCell());
				}
				else {
					tmp = new Cell();
					tmp.setBorder(NO_BORDER);
					tmp.setColspan(3);
					for (Iterator i = arrayList.iterator(); i.hasNext(); ) {
						tmp.add(i.next());
					}
					table.addCell(tmp);
				}
				tmp = new Cell();
				tmp.setBorder(NO_BORDER);
				table.addCell(tmp);
				table.insertTable((Table)element);
				tmp = new Cell();
				tmp.setBorder(NO_BORDER);
				table.addCell(tmp);
				table.addCell(getDummyCell());
				clear();
				arrayList.add(table);
				return;
			default:
				arrayList.add(element);
		}
	}

	/**
	 * Add an <CODE>Object</CODE> to this cell.
	 *
	 * @param o the object to add
	 * @return always <CODE>true</CODE>
	 */
	public boolean add(Object o) {
		try {
			this.addElement((Element) o);
			return true;
		}
		catch(ClassCastException cce) {
			throw new ClassCastException("You can only add objects that implement the Element interface.");
		}
		catch(BadElementException bee) {
			throw new ClassCastException(bee.getMessage());
		}
	}

	// helper methods
	
	/**
     * Get dummy cell used when merging inner tables. 
     * @return a cell with colspan 3 and no border
     */
    private static Cell getDummyCell() {
        Cell cell = new Cell(true);
        cell.setColspan(3);
        cell.setBorder(NO_BORDER);
        return cell;
	}

	/**
	 * Creates a PdfPCell based on this Cell object.
	 * @return a PdfPCell
	 * @throws BadElementException
	 */
	public PdfPCell createPdfPCell() throws BadElementException {
		if (rowspan > 1) throw new BadElementException("PdfPCells can't have a rowspan > 1");
		if (isTable()) return new PdfPCell(((Table)arrayList.get(0)).createPdfPTable());
		PdfPCell cell = new PdfPCell();
		cell.setVerticalAlignment(verticalAlignment);
		cell.setHorizontalAlignment(horizontalAlignment);
		cell.setColspan(colspan);
		cell.setUseBorderPadding(useBorderPadding);
		cell.setUseDescender(useDescender);
		cell.setLeading(getLeading(), 0);
		cell.cloneNonPositionParameters(this);
		cell.setNoWrap(getMaxLines() == 1);
		for (Iterator i = getElements(); i.hasNext(); ) {
            Element e = (Element)i.next();
            if (e.type() == Element.PHRASE || e.type() == Element.PARAGRAPH) {
                Paragraph p = new Paragraph((Phrase)e);
                p.setAlignment(horizontalAlignment);
                e = p;
            }
			cell.addElement(e);
		}
		return cell;
	}

	// unsupported Rectangle methods

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @return NA
	 * @deprecated Use {@link #getTop()} instead
	 */
	public float top() {
		return getTop();
	}

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @return NA
	 */
	public float getTop() {
		throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
	}

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @return NA
	 * @deprecated Use {@link #getBottom()} instead
	 */
	public float bottom() {
		return getBottom();
	}

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @return NA
	 */
	public float getBottom() {
		throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
	}

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @return NA
	 * @deprecated Use {@link #getLeft()} instead
	 */
	public float left() {
		return getLeft();
	}

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @return NA
	 */
	public float getLeft() {
		throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
	}

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @return NA
	 * @deprecated Use {@link #getRight()} instead
	 */
	public float right() {
		return getRight();
	}

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @return NA
	 */
	public float getRight() {
		throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
	}

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @param margin
	 * @return NA
	 */
	public float top(int margin) {
		throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
	}

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @param margin
	 * @return NA
	 */
	public float bottom(int margin) {
		throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
	}

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @param margin
	 * @return NA
	 */
	public float left(int margin) {
		throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
	}

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @param margin NA
	 * @return NA
	 */
	public float right(int margin) {
		throw new UnsupportedOperationException("Dimensions of a Cell can't be calculated. See the FAQ.");
	}

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @param value NA
	 */
	public void setTop(int value) {
		throw new UnsupportedOperationException("Dimensions of a Cell are attributed automagically. See the FAQ.");
	}

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @param value NA
	 */
	public void setBottom(int value) {
		throw new UnsupportedOperationException("Dimensions of a Cell are attributed automagically. See the FAQ.");
	}

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @param value NA
	 */
	public void setLeft(int value) {
		throw new UnsupportedOperationException("Dimensions of a Cell are attributed automagically. See the FAQ.");
	}

	/**
	 * This method throws an <CODE>UnsupportedOperationException</CODE>.
	 * @param value NA
	 */
	public void setRight(int value) {
		throw new UnsupportedOperationException("Dimensions of a Cell are attributed automagically. See the FAQ.");
	}
    
// deprecated stuff

	/**
	 * Returns a <CODE>Cell</CODE> that has been constructed taking in account
	 * the value of some <VAR>attributes</VAR>.
	 *
	 * @param	attributes		Some attributes
	 * @deprecated use ElementFactory.getCell(attributes)
	 */
	public Cell(java.util.Properties attributes) {
		this();
		Cell tmp = com.lowagie.text.factories.ElementFactory.getCell(attributes);
		this.cloneNonPositionParameters(tmp);
		this.setHorizontalAlignment(tmp.getHorizontalAlignment());
		this.setVerticalAlignment(tmp.getVerticalAlignment());
		this.setWidth(tmp.getWidth());
		this.setColspan(tmp.getColspan());
		this.setRowspan(tmp.getRowspan());
		this.setLeading(tmp.getLeading());
		this.setHeader(tmp.isHeader());
		this.setMaxLines(tmp.getMaxLines());
	}
    
    /**
	 * Gets the horizontal alignment.
	 * @return	a value
	 * @deprecated Use {@link #getHorizontalAlignment()} instead
	 */
	public int horizontalAlignment() {
		return getHorizontalAlignment();
	}

    /**
	 * Gets the vertical alignment.
	 * @return	a value
	 * @deprecated Use {@link #getVerticalAlignment()} instead
	 */
	public int verticalAlignment() {
		return getVerticalAlignment();
	}

	/**
	 * Gets the width.
	 *
	 * @return	a value
	 * @deprecated Use {@link #getWidthAsString()} instead
	 */
	public String cellWidth() {
		return getWidthAsString();
	}
	
	/**
	 * Gets the colspan.
	 * @return	a value
	 * @deprecated Use {@link #getColspan()} instead
	 */
	public int colspan() {
		return getColspan();
	}

	/**
	 * Gets the rowspan.
	 * @return	a value
	 * @deprecated Use {@link #getRowspan()} instead
	 */
	public int rowspan() {
		return getRowspan();
	}
	
	/**
	 * Gets the leading.
	 *
	 * @return	a value
	 * @deprecated Use {@link #getLeading()} instead
	 */
	public float leading() {
		return getLeading();
	}

	/**
	 * Is this <CODE>Cell</CODE> a header?
	 *
	 * @return	a value
	 * @deprecated Use {@link #isHeader()} instead
	 */
	public boolean header() {
		return isHeader();
	}

	/**
	 * Set nowrap.
	 *
	 * @param	value	the new value
	 * @deprecated Use setMaxLines(1) instead
	 */
	public void setNoWrap(boolean value) {
		if (value)
			maxLines = 1;
		else
			maxLines = Integer.MAX_VALUE;
	}

	/**
	 * Get nowrap.
	 *
	 * @return	a value
	 * @deprecated Use getMaxLines() == 1 instead
	 */
	public boolean noWrap() {
		return maxLines == 1;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -