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

📄 zcmdclear.java

📁 用Java写的报表.功能如下: 0.内建网络打印,网络预览功能! 1.文件操作。包括url 指定的文件。 2.全功能打印支持。包括打印预览。 3.Undo 和 redo。 4.合并单元格。 5.Cel
💻 JAVA
字号:
/*
 * Copyright 2002 EZCell , Inc. All rights reserved.
 * Version  1.0.
 * Author   W.John
 */
package ezcell;

import java.util.Enumeration;
import java.util.Vector;


/**
 * DOCUMENT ME!
 *
 * @version 1.00
 * @author W.John
 */
class ZCmdClear extends ZCommandX {
    Vector paddedCells = new Vector();

    /**
    * put your documentation comment here
    * @param     ZDefaultSheet sheet
    * @param     ZRect effectCells
    */
    public ZCmdClear(ZDefaultSheet sheet, ZRect effectCells) {
        super(sheet, effectCells);
    }

    /**
    * put your documentation comment here
    */
    public void prepareUndo() {
        for (int i = 0; i < paddedCells.size(); i++)
            sheet.remove((ZBase) paddedCells.get(i));

        paddedCells.clear();
    }

    /**
    */
    public void redo() {
        super.redo();
        sheet.fireObjectsCleared(this, false);
    }

    /**
    * put your documentation comment here
    */
    public void redoForCells() {
        ZDefaultCell cell;
        ZRect inflateEC = (ZRect) effectCells.clone();
        inflateEC.inflate(1, 1);

        for (int r = inflateEC.top; r <= inflateEC.bottom; r++)
            for (int c = inflateEC.left; c <= inflateEC.right; c++) {
                // remove cells in selection
                if (!effectCells.containCell(r, c)) // is padded cell;
                {
                    ZDefaultCell padded = sheet.getExistCell(r, c);

                    if (padded != null) {
                        cells.add(padded);
                    } else {
                        padded = (ZDefaultCell) sheet.getCell(r, c);
                    }

                    boolean cloned = false;
                    ZDefaultCell ec = null;

                    if (effectCells.containCell(r, c + 1)) // locate west
                    {
                        ec = sheet.getExistCell(r, c + 1);

                        if ((ec != null) &&
                                (ec.getBorderZorder(ZBase.PTY_LeftBorder) > padded.getBorderZorder(ZBase.PTY_RightBorder))) {
                            padded = (ZDefaultCell) padded.clone();
                            padded.setRightBorder((ZPen) ec.getLeftBorder().clone());
                            cloned = true;
                        }
                    } else if (effectCells.containCell(r + 1, c)) // locate north
                    {
                        ec = sheet.getExistCell(r + 1, c);

                        if ((ec != null) &&
                                (ec.getBorderZorder(ZBase.PTY_TopBorder) > padded.getBorderZorder(ZBase.PTY_BottomBorder))) {
                            padded = (ZDefaultCell) padded.clone();
                            padded.setBottomBorder((ZPen) ec.getTopBorder().clone());
                            cloned = true;
                        }
                    } else if (effectCells.containCell(r, c - 1)) // locate west
                    {
                        ec = sheet.getExistCell(r, c - 1);

                        if ((ec != null) &&
                                (ec.getBorderZorder(ZBase.PTY_RightBorder) > padded.getBorderZorder(ZBase.PTY_LeftBorder))) {
                            padded = (ZDefaultCell) padded.clone();
                            padded.setLeftBorder((ZPen) ec.getRightBorder0().clone());
                            cloned = true;
                        }
                    } else if (effectCells.containCell(r - 1, c)) // locate right
                    {
                        ec = sheet.getExistCell(r - 1, c);

                        if ((ec != null) &&
                                (ec.getBorderZorder(ZBase.PTY_BottomBorder) > padded.getBorderZorder(ZBase.PTY_TopBorder))) {
                            padded = (ZDefaultCell) padded.clone();
                            padded.setTopBorder((ZPen) ec.getBottomBorder0().clone());
                            cloned = true;
                        }
                    }

                    if (cloned) {
                        sheet.add(padded);
                        paddedCells.add(padded);
                    }
                }
            }

        for (int r = effectCells.top; r <= effectCells.bottom; r++)
            for (int c = effectCells.left; c <= effectCells.right; c++) {
                cell = sheet.getExistCell(r, c);

                if (cell != null) {
                    cells.add(cell);
                    sheet.remove(cell);
                }

                // create blank cell
                boolean createBlank = false;
                ZRow row = sheet.getExistRow(r);

                if ((row != null) && row.hasProperty(~ZBase.PTY_Height)) {
                    createBlank = true;
                } else {
                    ZCol col = sheet.getExistCol(c);

                    if ((col != null) && col.hasProperty(~ZBase.PTY_Width)) {
                        createBlank = true;
                    }
                }

                if (createBlank && effectCells.containCell(r, c)) {
                    cell = new ZDefaultCell(sheet, r, c);
                    cell.setNoPropUnder(ZBase.PTY_All);
                    sheet.add(cell);
                    blankObjs.add(cell);
                }
            }
    }

    /**
    */
    public void undo() {
        super.undo();
        sheet.fireObjectsCleared(this, true);
    }

    /**
    * put your documentation comment here
    */
    public void workOnBlankCols() {
        // fina all rows which has property but PTY_Height, and create all blank cell in those rows
        Enumeration enum = sheet.getRows().elements();

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

            if (row.hasProperty(~ZBase.PTY_Height)) {
                for (int i = effectCells.left; i <= effectCells.right; i++) {
                    ZDefaultCell cell = new ZDefaultCell(sheet, row.getRow(), i);
                    cell.setNoPropUnder(ZBase.PTY_All);
                    sheet.add(cell);
                    blankObjs.add(cell);
                }
            }
        }


        // make new blank rows the same height as before
        enum = cols.elements();

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

            if (col.hasProperty(ZBase.PTY_Width)) {
                sheet.makeCol(col.getCol()).setWidth(col.getWidth());
            }
        }
    }

    /**
    * put your documentation comment here
    */
    public void workOnBlankRows() {
        // create all blank rows
        int rowIndex;

        for (rowIndex = effectCells.top; rowIndex <= effectCells.bottom; rowIndex++) {
            ZRow row = new ZRow(sheet, rowIndex);
            row.setNoPropUnder(ZBase.PTY_All);
            sheet.add(row);
            blankObjs.add(row);
        }

        // make new blank rows the same height as before
        Enumeration enum = rows.elements();

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

            if (row.hasProperty(ZBase.PTY_Height)) {
                // the row must be exist!! so getExistRow!= null, call setHeight() no problem
                sheet.makeRow(row.getRow()).setHeight(row.getHeight());
            }
        }
    }
}

⌨️ 快捷键说明

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