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

📄 zsheetstate.java

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

            break;

        case LEFT:

            do {
                fc.col--;

                if (fc.col < sel.left) {
                    fc.col = sel.right;
                    fc.row--;

                    if (fc.row < sel.top) {
                        fc.row = sel.bottom;
                    }
                }
            } while (sheet.getCell(fc.row, fc.col).isChild());

            break;
        }

        scrollCellIntoView(fc.row, fc.col);
        setFocus(fc);
    }

    /**
     * put your documentation comment here
     * @param direction
     */
    public void moveFocusWithSelection(int direction) {
        ZCellID fs = (ZCellID) focus.clone();
        ZRect fcs;

        if (sheet.getCell(fs.row, fs.col).isParent()) {
            fcs = sheet.getCell(fs.row, fs.col).getSpan();
        } else {
            fcs = new ZRect(fs.col, fs.row, fs.col, fs.row);
        }

        switch (direction) {
        case UP:
            fs.row--;

            if (fs.row == 0) {
                fs.row = 1;
            }

            fs.col = focusFrom.col;

            break;

        case DOWN:
            fcs.bottom++;
            fs.row = (fcs.bottom == sheet.getLastRow()) ? (--fcs.bottom) : fcs.bottom;
            fs.col = focusFrom.col;

            break;

        case LEFT:
            fs.col--;

            if (fs.col == 0) {
                fs.col = 1;
            }

            fs.row = focusFrom.row;

            break;

        case RIGHT:
            fcs.right++;
            fs.col = (fcs.right == sheet.getLastCol()) ? (--fcs.right) : fcs.right;
            fs.row = focusFrom.row;

            break;
        }

        ZCell cell = sheet.getCell(fs.row, fs.col);

        try {
            if (cell.isChild()) {
                cell = cell.getParent();
            }
        } catch (Exception ex) {
        }

        if (cell.isParent()) {
            fcs = cell.getSpan();
        } else {
            fcs = new ZRect(cell.getCol(), cell.getRow(), cell.getCol(), cell.getRow());
        }

        scrollCellIntoView(fs.row, fs.col);
        setSelection(fcs);
        setFocus(new ZCellID(fs.row, fs.col));
        focusFrom = (ZCellID) fs.clone();
    }

    /**
     * put your documentation comment here
     * @param shape
     * @param to
     */
    public void moveShape(ZShape shape, Point to) {
        for (int i = 0; i < listeners.size(); i++) {
            ZSheetStateListener lst = (ZSheetStateListener) listeners.get(i);
            lst.shapeMoving(shape, to);
        }

        shape.moveTo(to.x, to.y);
    }

    /**
     * put your documentation comment here
     * @param shape
     * @param to
     */
    public void moveShape(ZShape shape, ZRect to) {
        for (int i = 0; i < listeners.size(); i++) {
            ZSheetStateListener lst = (ZSheetStateListener) listeners.get(i);
            lst.shapeMoving(shape, to);
        }

        shape.setBound(to.left, to.top, to.right, to.bottom);
    }

    /**
     * put your documentation comment here
     * @param col
     * @return
     */
    public int nextVisibleCol(int col) {
        return (col == 0) ? visibleCells.left : ++col;
    }

    /**
     * put your documentation comment here
     * @param row
     * @return
     */
    public int nextVisibleRow(int row) {
        return (row == 0) ? visibleCells.top : ++row;
    }

    /**
     * put your documentation comment here
     * @param e
     */
    public void objectsAdded(ZSheetEvent e) {
        tableDirty = true;
        fireSheetPropertyChanged();
    }

    /**
     * put your documentation comment here
     * @param e
     */
    public void objectsCleared(ZSheetEvent e) {
        tableDirty = true;
        fireSheetPropertyChanged();
    }

    /**
     * put your documentation comment here
     * @param e
     */
    public void objectsInserted(ZSheetEvent e) {
        tableDirty = true;
        fireSheetPropertyChanged();
    }

    /**
     * put your documentation comment here
     * @param e
     */
    public void objectsRemoved(ZSheetEvent e) {
        tableDirty = true;
        fireSheetPropertyChanged();
    }

    /**
     * put your documentation comment here
     */
    public void paste() {
        try {
            sheet.pasteTextIntoSelection(selection);
        } catch (Exception ex) {
        }
    }

    /**
     * put your documentation comment here
     * @param e
     */
    public void propertyChanged(ZSheetEvent e) {
        if (e.getObject() instanceof ZCmdFormat) {
            ZCmdFormat cmd = (ZCmdFormat) e.getObject();

            if ((cmd.getProperty() & (ZBase.PTY_Height | ZBase.PTY_Width)) != 0) {
                tableDirty = true;
            } else {
                invalidate(cmd.getEffectCells());
            }
        } else if (e.getObject() instanceof ZRect) {
            invalidate((ZRect) e.getObject());
        }

        fireSheetPropertyChanged();
    }

    /**
     * put your documentation comment here
     * @param key
     * @param value
     */
    public void put(String key, Object value) {
        tableDirty = true;
        ui.put(key, value);
        setUI(ui);
    }

    /**
     * put your documentation comment here
     * @param lst
     */
    public void removeListener(ZSheetStateListener lst) {
        listeners.remove(lst);
    }

    /**
     * put your documentation comment here
     * @param lst
     */
    public void removeListener(ZActiveCellListener lst) {
        alisteners.remove(lst);
    }

    /**
     * put your documentation comment here
     */
    public void requestFocus() {
        for (int i = 0; i < listeners.size(); i++) {
            ZSheetStateListener lst = (ZSheetStateListener) listeners.get(i);
            lst.focusGained(this);
        }
    }

    /**
     * put your documentation comment here
     * @param row
     * @param col
     */
    public void scrollCellIntoView(int row, int col) {
        //         A  |   B   |  C
        //         ---+-------+----
        //         D  |   E   |  F
        //         ---+-------+----
        //         G  |   H   |  I
        ZRect cells = null;
        ZCell cell = sheet.getCell(row, col);

        if (cell.isParent()) {
            cells = cell.getSpan();
        } else {
            cells = new ZRect(col, row, col, row);
        }

        if (visibleCells.contain(cells.left, cells.top) && visibleCells.contain(cells.right + 2, cells.bottom + 2)) {
            return;
        }

        Point tl = new Point(visibleCells.left, visibleCells.top);
        Point client = dp2lp(clip.getBottomRight());

        if (cells.left < visibleCells.left) // case A,D,G
        {
            tl.x = cells.left;
        } else if (!(cells.left >= visibleCells.left && // case !(B,E,H) <=> C,F,I
                       (cells.right + 2) <= visibleCells.right)) {
            int ci;
            int w = getLeftHeadWidth();

            for (ci = cells.right; (w <= client.x) && (ci > 0); w += sheet.getColWidth(ci), ci--)
                ;

            ci += 2;

            if ((ci > cells.left) && (ci < cells.bottom)) {
                ci = cells.left;
            }

            tl.x = ci;
        }

        if (cells.top < visibleCells.top) // case A,B ,C
        {
            tl.y = cells.top;
        } else if (!(cells.top >= visibleCells.top && // case !(D,E,F) <=> G,H,I
                       (cells.bottom + 2) <= visibleCells.bottom)) {
            int ri;
            int h = getTopHeadHeight();

            for (ri = cells.bottom; (h <= client.y) && (ri > 0); h += sheet.getRowHeight(ri), ri--)
                ;

            ri += 2;

            if ((ri > cells.top) && (ri < cells.bottom)) {
                ri = cells.top;
            }

            tl.y = ri;
        }

        setVisibleCells(new ZRect(tl.x, tl.y, tl.x, tl.y));
    }

    /**
     * put your documentation comment here
     * @param shape
     */
    public void startAnimation(ZShape shape) {
        for (int i = 0; i < listeners.size(); i++) {
            ZSheetStateListener lst = (ZSheetStateListener) listeners.get(i);
            lst.animationStarted(shape);
        }
    }

    /**
     * put your documentation comment here
     * @param e
     */
    public void stateChanged(ChangeEvent e) {
        fireSheetPropertyChanged();
    }

    /**
     * put your documentation comment here
     * @param shape
     */
    public void stopAnimation(ZShape shape) {
        for (int i = 0; i < listeners.size(); i++) {
            ZSheetStateListener lst = (ZSheetStateListener) listeners.get(i);
            lst.animationStopped(shape);
        }
    }

    /**
     * put your documentation comment here
     * @param ui
     */
    public void updateUI(ZDefaultUI ui) {
        cursors[DEFAULT_CURSOR] = (Cursor) ui.get(ZDefaultUI.CURSOR_DEFAULT);
        cursors[RESIZE_ROW_CURSOR] = (Cursor) ui.get(ZDefaultUI.CURSOR_ROW_RESIZE);
        cursors[RESIZE_COL_CURSOR] = (Cursor) ui.get(ZDefaultUI.CURSOR_COL_RESIZE);
        cursors[MOVE_CURSOR] = (Cursor) ui.get(ZDefaultUI.CURSOR_DRAG_READY);
        resizableBreakSize = ((Integer) ui.get(ZDefaultUI.RESIZE_BREAK)).intValue();
        leftHeadVisible = ((Boolean) ui.get(ZDefaultUI.LEFT_HEAD_VISIBLE)).booleanValue();
        topHeadVisible = ((Boolean) ui.get(ZDefaultUI.TOP_HEAD_VISIBLE)).booleanValue();
    }

    /**
     *
     * @return
     */
    protected ZShape.Rectangle getHorzBreak() {
        if (getLeftHeadWidth() > 0) {
            return new ZShape.Rectangle(0, 0, getLeftHeadWidth(), 0, HIT_LEFT_BREAK);
        } else {
            return null;
        }
    }

    /**
     *
     * @return
     */
    protected ZShape.Rectangle getVertBreak() {
        if (getTopHeadHeight() > 0) {
            return new ZShape.Rectangle(0, 0, 0, getTopHeadHeight(), HIT_TOP_BREAK);
        } else {
            return null;
        }
    }

    /**
     * put your documentation comment here
     * @param sheet
     */
    void init(ZSheet sheet) {
        if ((sheet == null) || (this.sheet == sheet)) {
            return;
        }

        selection = new ZRect(1, 1, 1, 1);
        focus = new ZCellID(1, 1);
        visibleCells = new ZRect(1, 1, 50, 50); // sheet.getLastCol(), sheet.getLastRow());
        canVisibleCells = new ZRect(1, 1, sheet.getLastCol(), sheet.getLastRow());
        buildTransform();
        setUI((ZDefaultUI) ZUIManager.getDefault().clone());
        this.sheet = sheet;
        this.sheet.addListener(this);
        fireUIStateChanged();
    }

    /**
     *
     * @return
     */
    private int getLeftHeadWidth() {
        if (leftHeadVisible) {
            return sheet.getColWidth(0);
        } else {
            return 0;
        }
    }

    /**
     * put your documentation comment here
     * @return
     */
    private int getShape() {
        return lastShape++;
    }

    /**
     * put your documentation comment here
     * @return
     */
    private int getTopHeadHeight() {
        if (topHeadVisible) {
            return sheet.getRowHeight(0);
        } else {
            return 0;
        }
    }

    /**
     * put your documentation comment here
     */
    private void buildTransform() {
        af = new AffineTransform();


        // af.rotate(50,1,50); //:) fun!!!
        af.scale(scale, scale);
        af.translate(offset.x, offset.y);
        tableDirty = true;
        dirtyArea = null;
    }

    /**
     * put your documentation comment here
     */
    private void fireActiveCellChanged() {
        for (int i = 0; i < alisteners.size(); i++) {
            ZActiveCellListener lst = (ZActiveCellListener) alisteners.get(i);
            lst.activeCellChanged(this);
        }
    }

    /**
     * put your documentation comment here
     */
    private void fireSheetPropertyChanged() {
        for (int i = 0; i < listeners.size(); i++) {
            ZSheetStateListener lst = (ZSheetStateListener) listeners.get(i);
            lst.sheetPropertyChanged(this);
        }

        fireActiveCellChanged();
    }

    /**
     * put your documentation comment here
     */
    private void fireUIChnaged() {
        for (int i = 0; i < listeners.size(); i++) {
            ZSheetStateListener lst = (ZSheetStateListener) listeners.get(i);
            lst.uiChanged(this);
        }
    }

    /**
     * put your documentation comment here
     */
    private void fireUIStateChanged() {
        for (int i = 0; i < listeners.size(); i++) {
            ZSheetStateListener lst = (ZSheetStateListener) listeners.get(i);
            lst.uiStateChanged(this);
        }
    }

    /**
     * put your documentation comment here
     * @param rect
     */
    private void invalidate(ZRect rect) {
        if (dirtyArea != null) {
            dirtyArea.union(rect);
        } else {
            dirtyArea = (ZRect) rect.clone();
        }
    }
} // end ZSheetState

⌨️ 快捷键说明

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