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

📄 zdefaultsheet.java

📁 用Java写的报表.功能如下: 0.内建网络打印,网络预览功能! 1.文件操作。包括url 指定的文件。 2.全功能打印支持。包括打印预览。 3.Undo 和 redo。 4.合并单元格。 5.Cel
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            cell = (ZDefaultCell) enum.nextElement();
            cell = (ZDefaultCell) cell.clone();
            oc = getExistCol(cell.getCol());

            if (oc != null) {
                or = getExistRow(cell.getRow());

                if (or != null) {
                    cell.copyFrom(oc, ~(cell.getProperty2() | or.getProperty2()));
                } else {
                    cell.copyFrom(oc);
                }
            }

            toCells.add(cell);
        }

        enum = getCols().elements();

        while (enum.hasMoreElements()) {
            oc = (ZCol) enum.nextElement();

            // if the col has olny property of width ,then loop again;
            if (!oc.hasProperty2(~ZBase.PTY_Width)) {
                continue;
            }

            for (row = from; row <= to; row++) {
                cell = (ZDefaultCell) getCell(row, oc.getCol());

                if (cell != null) // this cell has been done above
                {
                    continue;
                }

                cell = new ZDefaultCell(this, row, oc.getCol());
                or = getRow(row);

                // if the row has not exist ,build from the col;
                if (or == null) {
                    cell.copyFrom(oc);
                } else {
                    cell.copyFrom(oc, ~or.getProperty2());
                }

                toCells.add(cell);
            }
        }
    }

    /**
     * put your documentation comment here
     * @param rect
     */
    public void copySelection(ZRect rect) throws ZSelectionNoSupported {
        validateSelection(rect);
        ZClipboard.getSystem().setContents(getSelectionTransferable(rect, null), null);
    }

    /**
     * put your documentation comment here
     * @return
     */
    public ZSheet create() {
        try {
            return (ZDefaultSheet) clone();
        } catch (Exception e) {
        }

        return null;
    }

    /**
     * put your documentation comment here
     * @param rect
     */
    public void cutSelection(ZRect rect) throws ZSelectionNoSupported {
        validateSelection(rect);
        copySelection(rect);
        clearSelectionText(rect);
    }

    /**
     *
     * @param source
     * @param undo
     */
    public void fireObjectesInserted(Object source, boolean undo) {
        if (listeners.isEmpty()) {
            return;
        }

        ZSheetEvent e = new ZSheetEvent(this, source, undo);

        for (int i = 0; i < listeners.size(); i++) {
            ZSheetListener lst = (ZSheetListener) listeners.get(i);
            lst.objectsInserted(e);
        }
    }

    /**
     *
     * @param source
     * @param undo
     */
    public void fireObjectsAdded(Object source, boolean undo) {
        if (listeners.isEmpty()) {
            return;
        }

        ZSheetEvent e = new ZSheetEvent(this, source, undo);

        for (int i = 0; i < listeners.size(); i++) {
            ZSheetListener lst = (ZSheetListener) listeners.get(i);
            lst.objectsAdded(e);
        }
    }

    /**
     *
     * @param source
     * @param undo
     */
    public void fireObjectsCleared(Object source, boolean undo) {
        if (listeners.isEmpty()) {
            return;
        }

        ZSheetEvent e = new ZSheetEvent(this, source, undo);

        for (int i = 0; i < listeners.size(); i++) {
            ZSheetListener lst = (ZSheetListener) listeners.get(i);
            lst.objectsCleared(e);
        }
    }

    /**
     *
     * @param source
     * @param undo
     */
    public void fireObjectsInserted(Object source, boolean undo) {
        if (listeners.isEmpty()) {
            return;
        }

        ZSheetEvent e = new ZSheetEvent(this, source, undo);

        for (int i = 0; i < listeners.size(); i++) {
            ZSheetListener lst = (ZSheetListener) listeners.get(i);
            lst.objectsInserted(e);
        }
    }

    /**
     *
     * @param source
     * @param undo
     */
    public void fireObjectsRemoved(Object source, boolean undo) {
        if (listeners.isEmpty()) {
            return;
        }

        ZSheetEvent e = new ZSheetEvent(this, source, undo);

        for (int i = 0; i < listeners.size(); i++) {
            ZSheetListener lst = (ZSheetListener) listeners.get(i);
            lst.objectsRemoved(e);
        }
    }

    /**
     *
     * @param source
     * @param undo
     */
    public void firePropertyChanged(Object source, boolean undo) {
        if (listeners.isEmpty()) {
            return;
        }

        ZSheetEvent e = new ZSheetEvent(this, source, undo);

        for (int i = 0; i < listeners.size(); i++) {
            ZSheetListener lst = (ZSheetListener) listeners.get(i);
            lst.propertyChanged(e);
        }
    }

    /**
     * put your documentation comment here
     * @param rect
     */
    public void insertSelection(ZRect rect) throws ZSelectionNoSupported {
        if (rect == null) {
            return;
        }

        validateSelection(rect, ZRect.COLUMNS | ZRect.ROWS);

        ZCmdInsert cmd = new ZCmdInsert(this, (ZRect) rect.clone());
        cmd.commit();
    }

    /**
     * put your documentation comment here
     * @param row
     * @param col
     * @return
     */
    public ZDefaultCell makeCell(int row, int col) {
        ZDefaultCell cell = getExistCell(row, col);

        if (cell != null) {
            return cell;
        }

        cell = new ZDefaultCell(this, row, col);
        add(cell);

        return cell;
    }

    /**
     * put your documentation comment here
     * @param col
     * @return
     */
    public ZCol makeCol(int col) {
        ZCol oc = getExistCol(col);

        if (oc != null) {
            return oc;
        }

        oc = new ZCol(this, col);
        add(oc);

        return oc;
    }

    /**
     * put your documentation comment here
     * @param row
     * @return
     */
    public ZRow makeRow(int row) {
        ZRow or = getExistRow(row);

        if (or != null) {
            return or;
        }

        or = new ZRow(this, row);
        add(or);

        return or;
    }

    /**
     * put your documentation comment here
     * @param rect
     * @param merge
     */
    public void mergeSelection(ZRect rect, boolean merge)
                        throws ZSelectionNoSupported {
        //
        // make sure selection type is rows
        validateSelection(rect, ZRect.CELLS);

        ZCmdFormat cmd = new ZCmdFormat(this, (ZRect) rect.clone(), ZBase.PTY_MergeAsParent | ZBase.PTY_MergeAsChild,
                                        new Boolean(merge),
                                        new ZCmdWorker(ZCmdWorker.ACCEPT_CELL) {
            /**
             * put your documentation comment here
             * @param cmd
             * @param obj
             */
            public void workOnObject(ZCmdFormat cmd, ZBase obj) {
                Boolean merging = (Boolean) cmd.getValueObject();
                ZDefaultCell cell = (ZDefaultCell) obj;
                ZRect effectCells = cmd.getEffectCells();

                if (merging.booleanValue()) {
                    // if is merging and the cell is a left upper one , please as a parent
                    if ((cell.row == effectCells.top) && (cell.col == effectCells.left)) {
                        cell.setMergeAsParent(effectCells.right - effectCells.left + 1,
                                              effectCells.bottom - effectCells.top + 1);
                    } else {
                        cell.setMergeAsChild(cell.col - effectCells.left, cell.row - effectCells.top);
                    }
                } else // if now is unmerging all cells ,then clear all
                {
                    if (cell.hasProperty(ZBase.PTY_MergeAsParent)) {
                        cell.sheet.removeParentCell(cell);
                    }

                    cell.clearProperty(ZBase.PTY_MergeAsParent | ZBase.PTY_MergeAsChild);
                }
            }

            public void prepareUndo(ZCmdFormat cmd) {
                ZRect effectCells = cmd.getEffectCells();
                ZDefaultSheet sheet = (ZDefaultSheet) cmd.getSheet();
                sheet.removeParentCell((ZDefaultCell) sheet.getCell(effectCells.top, effectCells.left));
            }
        });
        cmd.commit();
    }

    /**
     * put your documentation comment here
     * @param cell
     * @param row
     * @param col
     */
    public void moveCell(ZDefaultCell cell, int row, int col) {
        remove(cell);
        cell.row = row;
        cell.col = col;
        add(cell);
    }

    /**
     * put your documentation comment here
     * @param col
     * @param pos
     */
    public void moveCol(ZCol col, int pos) {
        remove(col);
        col.col = pos;
        add(col);
    }

    /**
     * put your documentation comment here
     * @param from
     * @param to
     * @param offset
     */
    public void moveObjcetsDown(int from, int to, int offset) {
        ZBase.compareReverse = true;

        Vector obs = (Vector) getRows().clone();
        Collections.sort(obs);

        // if cell in the row ,and its property exists ,then change it
        Enumeration enum = obs.elements();

        while (enum.hasMoreElements()) {
            ZRow row = (ZRow) enum.nextElement();

            if (row.getRow() <= to) {
                while (row.getRow() >= from) {
                    moveRow(row, row.getRow() + offset);

                    if (enum.hasMoreElements()) {
                        row = (ZRow) enum.nextElement();
                    } else {
                        break;
                    }
                }

                break;
            }
        }

        obs = getSortedCells(true);
        enum = obs.elements();

        while (enum.hasMoreElements()) {
            ZDefaultCell cell = (ZDefaultCell) enum.nextElement();

            if (cell.getRow() <= to) {
                while (cell.getRow() >= from) {
                    moveCell(cell, cell.getRow() + offset, cell.getCol());

                    if (enum.hasMoreElements()) {
                        cell = (ZDefaultCell) enum.nextElement();
                    } else {
                        break;
                    }
                }

                break;
            }
        }
    }

    /**
     * put your documentation comment here
     * @param from
     * @param to
     * @param offset
     */
    public void moveObjcetsRight(int from, int to, int offset) {
        ZBase.compareReverse = true;

        Vector obs = (Vector) getCols().clone();
        Collections.sort(obs);

        // if cell in the row ,and its property exists ,then change it
        Enumeration enum = obs.elements();

        while (enum.hasMoreElements()) {
            ZCol col = (ZCol) enum.nextElement();

            if (col.getRow() <= to) {
                while (col.getCol() >= from) {
                    moveCol(col, col.getCol() + offset);

                    if (enum.hasMoreElements()) {
                        col = (ZCol) enum.nextElement();
                    } else {
                        break;
                    }
                }

                break;
            }
        }

        obs = (Vector) getCells().clone();
        ZDefaultCell.compareByRow = true;
        Collections.sort(obs);
        enum = obs.elements();

        while (enum.hasMoreElements()) {
            ZDefaultCell cell = (ZDefaultCell) enum.nextElement();

            if (cell.getCol() <= to) {
                while (cell.getCol() >= from) {
                    moveCell(cell, cell.getRow(), cell.getCol() + offset);

                    if (enum.hasMoreElements()) {
                        cell = (ZDefaultCell) enum.nextElement();
                    } else {
                        break;
                    }
                }

                break;
            }
        }
    }

    /**
     * put your documentation comment here
     * @param from
     * @param to
     * @param offset
     */
    public void moveObjectsLeft(int from, int to, int offset) {
        ZBase.compareReverse = false;

        Vector obs = (Vector) getCols().clone();
        Collections.sort(obs);

        // if cell in the row ,and its property exists ,then change it
        Enumeration enum = obs.elements();

        while (enum.hasMoreElements()) {
            ZCol col = (ZCol) enum.nextElement();

            if (col.getCol() >= from) {
                while (col.getCol() <= to) {
                    moveCol(col, col.getCol() - offset);

⌨️ 快捷键说明

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