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

📄 table.java

📁 iText可以制作中文PDF文件的JAVA源程序
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    }/** * Enables/disables automatic insertion of empty cells before table is rendered. (default = false) * As some people may want to create a table, fill only a couple of the cells and don't bother with * investigating which empty ones need to be added, this default behaviour may be very welcome. * Disabling is recommended to increase speed. (empty cells should be added through extra code then) * * @param       aDoAutoFill   enable/disable autofill */    public void setAutoFillEmptyCells(boolean aDoAutoFill) {        mAutoFillEmptyCells = aDoAutoFill;    }/** * Allows you to control when a page break occurs. * <P> * When a table doesn't fit a page, it is split in two parts. * If you want to avoid this, you should set the <VAR>tableFitsPage</VAR> value to true. * * @param   fitPage    enter true if you don't want to split cells */    public void setTableFitsPage(boolean fitPage) {        this.tableFitsPage = fitPage;        if (fitPage) setCellsFitPage(true);    }/** * Allows you to control when a page break occurs. * <P> * When a cell doesn't fit a page, it is split in two parts. * If you want to avoid this, you should set the <VAR>cellsFitPage</VAR> value to true. * * @param   fitPage    enter true if you don't want to split cells */    public void setCellsFitPage(boolean fitPage) {        this.cellsFitPage = fitPage;    }/** * Checks if this <CODE>Table</CODE> has to fit a page. * * @return  true if the table may not be split */    public boolean hasToFitPageTable() {        return tableFitsPage;    }/** * Checks if the cells of this <CODE>Table</CODE> have to fit a page. * * @return  true if the cells may not be split */    public boolean hasToFitPageCells() {        return cellsFitPage;    }/** * Sets the offset of this table. * * Normally a newline is added before you add a Table object. * This newline uses the current leading. * If you want to control the space between the table and the previous * element yourself, you have to set the offset of this table. * * @param   offset  the space between this table and the previous object. */    public void setOffset(float offset) {        this.offset = offset;    }/** * Gets the offset of this table. * * @return  the space between this table and the previous element. */    public float getOffset() {        return offset;    }/** * Gets the type of the text element. * * @return  a type */    public int type() {        return Element.TABLE;    }/** * Gets all the chunks in this element. * * @return  an <CODE>ArrayList</CODE> */    public ArrayList getChunks() {        return new ArrayList();    }    // methods to add content to the table/** * Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE> at a certain row and column. * * @param       aCell    The <CODE>Cell</CODE> to add * @param       row     The row where the <CODE>Cell</CODE> will be added * @param       column  The column where the <CODE>Cell</CODE> will be added */    public void addCell(Cell aCell, int row, int column) throws BadElementException {        addCell(aCell, new Point(row,column));    }/** * 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 */    public void addCell(Cell aCell, Point aLocation) throws BadElementException {        if (aCell == null) throw new NullPointerException("addCell - cell has null-value");        if (aLocation == null) throw new NullPointerException("addCell - point has null-value");        if (aCell.isTable()) insertTable((Table)aCell.getElements().next(), aLocation);        if (mDebug == true) {            if (aLocation.x < 0) throw new BadElementException("row coordinate of location must be >= 0");            if ((aLocation.y <= 0) && (aLocation.y > columns)) throw new BadElementException("column coordinate of location must be >= 0 and < nr of columns");            if (!isValidLocation(aCell, aLocation)) throw new BadElementException("Adding a cell at the location (" + aLocation.x + "," + aLocation.y + ") with a colspan of " + aCell.colspan() + " and a rowspan of " + aCell.rowspan() + " is illegal (beyond boundaries/overlapping).");        }        if (aCell.border() == UNDEFINED) aCell.setBorder(defaultLayout.border());        aCell.fill();        placeCell(rows, aCell, aLocation);        setCurrentLocationToNextValidPosition(aLocation);    }/** * Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE>. * * @param       cell         a <CODE>Cell</CODE> */    public void addCell(Cell cell) {        try {            addCell(cell, curPosition);        }        catch(BadElementException bee) {            // don't add the cell        }    }/** * Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE>. * <P> * This is a shortcut for <CODE>addCell(Cell cell)</CODE>. * The <CODE>Phrase</CODE> will be converted to a <CODE>Cell</CODE>. * * @param       content         a <CODE>Phrase</CODE> * @throws      BadElementException this should never happen */    public void addCell(Phrase content) throws BadElementException {        addCell(content, curPosition);    }/** * 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(defaultLayout.border());        cell.setBorderWidth(defaultLayout.borderWidth());        cell.setBorderColor(defaultLayout.borderColor());        cell.setBackgroundColor(defaultLayout.backgroundColor());        cell.setGrayFill(defaultLayout.grayFill());        cell.setHorizontalAlignment(defaultLayout.horizontalAlignment());        cell.setVerticalAlignment(defaultLayout.verticalAlignment());        cell.setColspan(defaultLayout.colspan());        cell.setRowspan(defaultLayout.rowspan());        addCell(cell, location);    }/** * Adds a <CODE>Cell</CODE> to the <CODE>Table</CODE>. * <P> * This is a shortcut for <CODE>addCell(Cell cell)</CODE>. * The <CODE>String</CODE> will be converted to a <CODE>Cell</CODE>. * * @param       content         a <CODE>String</CODE> * @throws      BadElementException this should never happen */    public void addCell(String content) throws BadElementException {        addCell(new Phrase(content), curPosition);    }/** * 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>String</CODE> will be converted to a <CODE>Cell</CODE>. * * @param       content         a <CODE>String</CODE> * @param       location        a <CODE>Point</CODE> * @throws      BadElementException this should never happen */    public void addCell(String content, Point location) throws BadElementException {        addCell(new Phrase(content), location);    }/** * To put a table within the existing table at the current position * generateTable will of course re-arrange the widths of the columns. * * @param   aTable      the table you want to insert */    public void insertTable(Table aTable) {        if (aTable == null) throw new NullPointerException("insertTable - table has null-value");        insertTable(aTable, curPosition);    }/** * To put a table within the existing table at the given position * generateTable will of course re-arrange the widths of the columns. * * @param       aTable  The <CODE>Table</CODE> to add * @param       row     The row where the <CODE>Cell</CODE> will be added * @param       column  The column where the <CODE>Cell</CODE> will be added */    public void insertTable(Table aTable, int row, int column) {        if (aTable == null) throw new NullPointerException("insertTable - table has null-value");        insertTable(aTable, new Point(row, column));    }/** * To put a table within the existing table at the given position * generateTable will of course re-arrange the widths of the columns. * * @param   aTable      the table you want to insert * @param   aLocation   a <CODE>Point</CODE> */    public void insertTable(Table aTable, Point aLocation) {        if (aTable == null) throw new NullPointerException("insertTable - table has null-value");        if (aLocation == null) throw new NullPointerException("insertTable - point has null-value");        mTableInserted = true;        aTable.complete();        if (mDebug == true) {            if (aLocation.y > columns) System.err.println("insertTable -- wrong columnposition("+ aLocation.y + ") of location; max =" + columns);        }        int rowCount = aLocation.x + 1 - rows.size();        int i = 0;        if ( rowCount > 0 ) {   //create new rows ?            for (; i < rowCount; i++) {                rows.add(new Row(columns));            }        }        ((Row) rows.get(aLocation.x)).setElement(aTable,aLocation.y);        setCurrentLocationToNextValidPosition(aLocation);    }/* * Will fill empty cells with valid blank <CODE>Cell</CODE>s */    public void complete() {        if (mTableInserted == true) {            mergeInsertedTables();  // integrate tables in the table            mTableInserted = false;        }        if (mAutoFillEmptyCells == true) {            fillEmptyMatrixCells();        }        if (alternatingRowAttributes != null) {            Properties even = new Properties();            Properties odd = new Properties();            String name;            String[] value;            for (Iterator iterator = alternatingRowAttributes.keySet().iterator(); iterator.hasNext(); ) {                name = String.valueOf(iterator.next());                value = (String[])alternatingRowAttributes.get(name);                even.setProperty(name, value[0]);                odd.setProperty(name, value[1]);            }            Row row;            for (int i = lastHeaderRow + 1; i < rows.size(); i++) {                row = (Row)rows.get(i);                row.setMarkupAttributes(i % 2 == 0 ? even : odd);            }        }    }/** * Changes the border in the default layout of the <CODE>Cell</CODE>s * added with method <CODE>addCell(String content)</CODE>. * * @param       value   the new border value */    public void setDefaultCellBorder(int value) {        defaultLayout.setBorder(value);    }/** * Changes the width of the borders in the default layout of the <CODE>Cell</CODE>s * added with method <CODE>addCell(String content)</CODE>. * * @param       value   the new width */    public void setDefaultCellBorderWidth(float value) {        defaultLayout.setBorderWidth(value);    }/** * Changes the bordercolor in the default layout of the <CODE>Cell</CODE>s * added with method <CODE>addCell(String content)</CODE>. * * @param       color   the new color */    public void setDefaultCellBorderColor(Color color) {        defaultLayout.setBorderColor(color);    }/** * Changes the backgroundcolor in the default layout of the <CODE>Cell</CODE>s * added with method <CODE>addCell(String content)</CODE>. * * @param       color   the new color */    public void setDefaultCellBackgroundColor(Color color) {        defaultLayout.setBackgroundColor(color);    }/** * Changes the grayfill in the default layout of the <CODE>Cell</CODE>s * added with method <CODE>addCell(String content)</CODE>. * * @param       value   the new value */    public void setDefaultCellGrayFill(float value) {        if (value >= 0 && value <= 1) {            defaultLayout.setGrayFill(value);        }    }/** * Changes the horizontalAlignment in the default layout of the <CODE>Cell</CODE>s * added with method <CODE>addCell(String content)</CODE>. * * @param       value   the new alignment value */    public void setDefaultHorizontalAlignment(int value) {        defaultLayout.setHorizontalAlignment(value);    }/** * Changes the verticalAlignment in the default layout of the <CODE>Cell</CODE>s * added with method <CODE>addCell(String content)</CODE>. * * @param       value   the new alignment value */    public void setDefaultVerticalAlignment(int value) {        defaultLayout.setVerticalAlignment(value);    }/** * Changes the rowspan in the default layout of the <CODE>Cell</CODE>s * added with method <CODE>addCell(String content)</CODE>. * * @param       value   the new rowspan value */    public void setDefaultRowspan(int value) {        defaultLayout.setRowspan(value);    }/** * Changes the colspan in the default layout of the <CODE>Cell</CODE>s * added with method <CODE>addCell(String content)</CODE>. * * @param       value   the new colspan value */    public void setDefaultColspan(int value) {        defaultLayout.setColspan(value);    }    // methods/**

⌨️ 快捷键说明

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