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

📄 table.java

📁 iText可以制作中文PDF文件的JAVA源程序
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
 * 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.border() == Rectangle.UNDEFINED) {            aCell.setBorder(defaultLayout.border());        }        if (aCell.borderWidth() == Rectangle.UNDEFINED) {            aCell.setBorderWidth(defaultLayout.borderWidth());        }        if (aCell.borderColor() == null) {            aCell.setBorderColor(defaultLayout.borderColor());        }        if (aCell.backgroundColor() == null) {            aCell.setBackgroundColor(defaultLayout.backgroundColor());        }        if (aCell.grayFill() == Rectangle.UNDEFINED) {            aCell.setGrayFill(defaultLayout.grayFill());        }        if (aCell.horizontalAlignment() == Element.ALIGN_UNDEFINED) {            aCell.setHorizontalAlignment(defaultLayout.horizontalAlignment());        }        if (aCell.verticalAlignment() == Element.ALIGN_UNDEFINED) {            aCell.setVerticalAlignment(defaultLayout.verticalAlignment());        }    }/** * Deletes a column in this table. * * @param       column  the number of the column that has to be deleted */    public void deleteColumn(int column) throws BadElementException {        float newWidths[] = new float[--columns];        for (int i = 0; i < column; i++) {            newWidths[i] = widths[i];        }        for (int i = column; i < columns; i++) {            newWidths[i] = widths[i + 1];        }        setWidths(newWidths);        for (int i = 0; i < columns; i++) {            newWidths[i] = widths[i];        }        widths = newWidths;        Row row;        int size = rows.size();        for (int i = 0; i < size; i++) {            row = (Row) rows.get(i);            row.deleteColumn(column);            rows.set(i, row);        }        if (column == columns) {            curPosition.setLocation(curPosition.x+1, 0);        }    }/** * Deletes a row. * * @param       row             the number of the row to delete * @return      boolean <CODE>true</CODE> if the row was deleted; <CODE>false</CODE> if not */    public boolean deleteRow(int row) {        if (row < 0 || row >= rows.size()) {            return false;        }        rows.remove(row);        curPosition.setLocation(curPosition.x-1, curPosition.y);        return true;    }/** * Deletes the last row in this table. * * @return      boolean <CODE>true</CODE> if the row was deleted; <CODE>false</CODE> if not */    public boolean deleteLastRow() {        return deleteRow(rows.size() - 1);    }/** * Marks the last row of the table headers. * * @return      the number of the last row of the table headers */    public int endHeaders() {        /* patch sep 8 2001 Francesco De Milato */        lastHeaderRow = curPosition.x - 1;        return lastHeaderRow;    }    // methods to set the membervariables/** * Sets the horizontal alignment. * * @param       value   the new value */    public void setLastHeaderRow(int value) {        lastHeaderRow = value;    }/** * Sets the horizontal alignment. * * @param       value   the new value */    public void setAlignment(int value) {        alignment = value;    }/** * Sets the alignment of this paragraph. * * @param    alignment        the new alignment as a <CODE>String</CODE> */    public void setAlignment(String alignment) {        if (ElementTags.ALIGN_LEFT.equalsIgnoreCase(alignment)) {            this.alignment = Element.ALIGN_LEFT;            return;        }        if (ElementTags.RIGHT.equalsIgnoreCase(alignment)) {            this.alignment = Element.ALIGN_RIGHT;            return;        }        this.alignment = Element.ALIGN_CENTER;    }/** * Sets the cellpadding. * * @param       value   the new value */    public void setSpaceInsideCell(float value) {        cellpadding = value;    }/** * Sets the cellspacing. * * @param       value   the new value */    public void setSpaceBetweenCells(float value) {        cellspacing = value;    }/** * Sets the cellpadding. * * @param       value   the new value */    public void setPadding(float value) {        cellpadding = value;    }/** * Sets the cellspacing. * * @param       value   the new value */    public void setSpacing(float value) {        cellspacing = value;    }/** * Sets the cellspacing (the meaning of cellpadding and cellspacing was inverted by mistake). * * @param       value   the new value * @deprecated  use setSpacing instead */    public void setCellpadding(float value) {        cellspacing = value;    }/** * Sets the cellpadding (the meaning of cellpadding and cellspacing was inverted by mistake). * * @param       value   the new value * @deprecated  use setPadding instead */    public void setCellspacing(float value) {        cellpadding = value;    }/** * Sets the width of this table (in percentage of the available space). * * @param       width           the width */    public void setWidth(float width) {        this.widthPercentage = width;    }/** * Sets the width of this table (in percentage of the available space). * * @param   width           the width */    public void setAbsWidth(String width) {        this.absWidth = width;    }/** * Sets the widths of the different columns (percentages). * <P> * You can give up relative values of borderwidths. * The sum of these values will be considered 100%. * The values will be recalculated as percentages of this sum. * <P> * example: * <BLOCKQUOTE><PRE> * float[] widths = {2, 1, 1}; * <STRONG>table.setWidths(widths)</STRONG> * </PRE></BLOCKQUOTE> * The widths will be: a width of 50% for the first column, * 25% for the second and third column. * * @param       widths  an array with values */    public void setWidths(float[] widths) throws BadElementException {        if (widths.length != columns) {            throw new BadElementException("Wrong number of columns.");        }        // The sum of all values is 100%        float hundredPercent = 0;        for (int i = 0; i < columns; i++) {            hundredPercent += widths[i];        }        // The different percentages are calculated        float width;        this.widths[columns - 1] = 100;        for (int i = 0; i < columns - 1; i++) {            width = (100.0f * widths[i]) / hundredPercent;            this.widths[i] = width;            this.widths[columns - 1] -= width;        }    }/** * Sets the widths of the different columns (percentages). * <P> * You can give up relative values of borderwidths. * The sum of these values will be considered 100%. * The values will be recalculated as percentages of this sum. * * @param       widths  an array with values */    public void setWidths(int[] widths) throws DocumentException {        float tb[] = new float[widths.length];        for (int k = 0; k < widths.length; ++k)            tb[k] = widths[k];        setWidths(tb);    }    // methods to retrieve the membervariables/** * Gets the number of columns. * * @return    a value */    public int columns() {        return columns;    }/** * Gets the number of rows in this <CODE>Table</CODE>. * * @return      the number of rows in this <CODE>Table</CODE> */    public int size() {        return rows.size();    }/** * Gets the proportional widths of the columns in this <CODE>Table</CODE>. * * @return      the proportional widths of the columns in this <CODE>Table</CODE> */    public float[] getProportionalWidths() {        return widths;    }/** * Gets an <CODE>Iterator</CODE> of all the <CODE>Row</CODE>s. * * @return      an <CODE>Iterator</CODE> */    public Iterator iterator() {        return rows.iterator();    }/** * Gets the horizontal alignment. * * @return  a value */    public int alignment() {        return alignment;    }/** * Gets the cellpadding. * * @return  a value */    public float cellpadding() {        return cellpadding;    }/** * Gets the cellspacing. * * @return  a value */    public float cellspacing() {        return cellspacing;    }/** * Gets the table width (a percentage). * * @return      the table width */    public float widthPercentage() {        return widthPercentage;    }/** * Gets the table width (in pixels). * * @return  the table width */    public String absWidth() {        return absWidth;    }/** * Gets the first number of the row that doesn't contain headers. * * @return      a rownumber */    public int firstDataRow() {        return lastHeaderRow + 1;    }/** * Gets the dimension of this table * * @return  dimension */    public Dimension getDimension() {        return new Dimension(columns, rows.size());    }/** * returns the element at the position row, column *          (Cast to Cell or Table) * * @return  dimension */    public Object getElement(int row, int column) {        return ((Row) rows.get(row)).getCell(column);    }/** * Integrates all added tables and recalculates column widths. */    private void mergeInsertedTables() {        int i=0, j=0;        float [] lNewWidths = null;        int [] lDummyWidths = new int[columns];     // to keep track in how many new cols this one will be split        float[][] lDummyColumnWidths = new float[columns][]; // bugfix Tony Copping        int [] lDummyHeights = new int[rows.size()]; // to keep track in how many new rows this one will be split        ArrayList newRows = null;        int lTotalRows  = 0, lTotalColumns      = 0;        int lNewMaxRows = 0, lNewMaxColumns     = 0;        Table lDummyTable = null;        // first we'll add new columns when needed

⌨️ 快捷键说明

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