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

📄 zsheetstate.java

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

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

    /**
     * put your documentation comment here
     * @param shape
     */
    public void addShape(ZShape shape) {
        //fire
        shape.setModal(this);
        shapes.add(shape);

        for (int i = 0; i < listeners.size(); i++) {
            ZSheetStateListener lst = (ZSheetStateListener) listeners.get(i);
            lst.shapeAdded(shape);
        }
    }

    /**
     * put your documentation comment here
     */
    public void buildTable() {
        if (!tableDirty) {
            return;
        }


        // for create a new breaks table
        breaks.clear();

        int ri;
        int ci;
        int left;
        int top;
        int right;
        int bottom;
        Point end = dp2lp(new Point(clip.right, clip.bottom));
        rows.clear();
        cols.clear();
        top = 0;
        bottom = getTopHeadHeight();
        rows.add(new ZShape.Row(top, bottom, 0));

        ZShape.Rectangle bk = getHorzBreak();

        for (ri = visibleCells.top; (bottom <= end.y) && (ri <= sheet.getLastRow()); ri++) {
            top = bottom;
            bottom = top + sheet.getRowHeight(ri);

            ZShape.Row row = new ZShape.Row(top, bottom, ri);
            rows.add(row);

            if (bk != null) {
                bk = (ZShape.Rectangle) bk.clone();
                bk.top = bottom - (resizableBreakSize / 2);
                bk.bottom = bottom + (resizableBreakSize / 2);
                bk.object = row;
                breaks.add(bk);
            }
        }

        visibleCells.bottom = ri - 1;
        bk = getVertBreak();

        left = 0;
        right = getLeftHeadWidth();
        cols.add(new ZShape.Col(left, right, 0));

        for (ci = visibleCells.left; (right <= end.x) && (ci <= sheet.getLastCol()); ci++) {
            left = right;
            right = left + sheet.getColWidth(ci);

            ZShape.Col col = new ZShape.Col(left, right, ci);
            cols.add(col);

            if (bk != null) {
                bk = (ZShape.Rectangle) bk.clone();
                bk.left = right - (resizableBreakSize / 2);
                bk.right = right + (resizableBreakSize / 2);
                bk.object = col;
                breaks.add(bk);
            }
        }

        visibleCells.right = ci - 1;
        tableDirty = false;
    }

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

    /**
     * put your documentation comment here
     */
    public void clearInvalidate() {
        dirtyArea = null;
    }

    /**
     * put your documentation comment here
     * @param g2
     * @exception Exception
     */
    public void clipClient(Graphics2D g2) throws Exception {
        ZRect rect = getCellRect(sheet.getCell(0, 0));
        Point p = dp2lp(new Point(clip.right, clip.bottom));
        g2.clipRect(rect.right, rect.bottom, p.x, p.y);
    }

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

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

    /**
     * put your documentation comment here
     * @param p
     * @return
     */
    public Point dp2lp(Point p) {
        Point p1 = new Point(p.x, p.y);
        Point p2 = new Point();

        try {
            p2 = (Point) af.inverseTransform(p1, p2);
        } catch (Exception e) {
        }

        return p2;
    }

    /**
     * put your documentation comment here
     * @param rect
     * @return
     */
    public ZRect dr2lr(ZRect rect) {
        Point tl = dp2lp(rect.getTopLeft());
        Point br = dp2lp(rect.getBottomRight());
        rect.setRect(tl.x, tl.y, br.x, br.y);

        return rect;
    }

    /**
     * put your documentation comment here
     * @param direction
     */
    public void expandSelection(int direction) {
        ZRect sel = (ZRect) selection.clone();

        switch (direction) {
        case LEFT:

            if (sel.type(sheet) != ZRect.ROWS) {
                if (sel.right > focus.col) {
                    ZRect merge = sheet.getMerged(new ZRect(sel.right, sel.top, sel.right, sel.bottom));

                    if (!merge.containCell(focus.row, focus.col)) {
                        sel.right -= (merge.getWidth() + 1);
                    } else {
                        sel.left--;
                    }
                } else {
                    sel.left--;
                }

                if (sel.left < 1) {
                    sel.left = 1;
                }
            }

            break;

        case RIGHT:

            if (sel.type(sheet) != ZRect.ROWS) {
                if (sel.left < focus.col) {
                    ZRect merge = sheet.getMerged(new ZRect(sel.left, sel.top, sel.left, sel.bottom));

                    if (!merge.containCell(focus.row, focus.col)) {
                        sel.left += (merge.getWidth() + 1);
                    } else {
                        sel.right++;
                    }
                } else {
                    sel.right++;
                }

                if (sel.right > sheet.getLastCol()) {
                    sel.right = sheet.getLastCol();
                }
            }

            break;

        case UP:

            if (sel.type(sheet) != ZRect.COLUMNS) {
                if (sel.bottom > focus.row) {
                    ZRect merge = sheet.getMerged(new ZRect(sel.left, sel.bottom, sel.right, sel.bottom));

                    if (!merge.containCell(focus.row, focus.col)) {
                        sel.bottom -= (merge.getHeight() + 1);
                    } else {
                        sel.top--;
                    }
                } else {
                    sel.top--;
                }

                if (sel.top < 1) {
                    sel.top = 1;
                }
            }

            break;

        case DOWN:

            if (sel.type(sheet) != ZRect.COLUMNS) {
                if (sel.top < focus.row) {
                    ZRect merge = sheet.getMerged(new ZRect(sel.left, sel.top, sel.right, sel.top));

                    if (!merge.containCell(focus.row, focus.col)) {
                        sel.top += (merge.getHeight() + 1);
                    } else {
                        sel.bottom++;
                    }

                    ;
                } else {
                    sel.bottom++;
                }

                if (sel.bottom > sheet.getLastRow()) {
                    sel.bottom = sheet.getLastRow();
                }
            }

            break;
        }

        setSelection(sel);
    }

    /**
     * put your documentation comment here
     * @param point
     * @return
     * @exception ZException
     */
    public ZShape hit(Point point) throws ZException {
        if (tableDirty) {
            buildTable();
        }

        if (dragTracker.hitBorder(point) != null) {
            return dragTracker;
        }

        int i;

        for (i = 0; i < breaks.size(); i++) {
            ZShape bk = ((ZShape) breaks.get(i)).hit(point);

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

        // look into the rows and cols table
        ZShape.Row row = null;
        i = Collections.binarySearch(rows, point, rowComparator);

        if (i >= 0) {
            row = (ZShape.Row) rows.get(i);
        } else {
            throw new ZException("hit unknown area!");
        }

        // look into the rows and cols table
        ZShape.Col col = null;
        i = Collections.binarySearch(cols, point, colComparator);

        if (i >= 0) {
            col = (ZShape.Col) cols.get(i);
        } else {
            throw new ZException("hit unknown area!");
        }


        ///
        tmpCell.row = row.id;
        tmpCell.col = col.id;
        tmpCell.rect.left = col.left;
        tmpCell.rect.top = row.top;
        tmpCell.rect.right = col.right;
        tmpCell.rect.bottom = row.bottom;

        return tmpCell;
    }

    /**
     * put your documentation comment here
     * @param point
     * @return
     * @exception ZException
     */
    public ZCellID hitCell(Point point) throws ZException {
        if (tableDirty) {
            buildTable();
        }

        // look into the rows and cols table
        int i;
        ZShape.Row row = null;
        i = Collections.binarySearch(rows, point, rowComparator);

        if (i >= 0) {
            row = (ZShape.Row) rows.get(i);
        } else {
            throw new ZException("hit unknown area!");
        }

        // look into the rows and cols table
        ZShape.Col col = null;
        i = Collections.binarySearch(cols, point, colComparator);

        if (i >= 0) {
            col = (ZShape.Col) cols.get(i);
        } else {
            throw new ZException("hit unknown area!");
        }

        return new ZCellID(row.id, col.id);
    }

    /**
     * put your documentation comment here
     * @param editor
     */
    public void killEditor(ZEditor editor) {
        if (!editable) {
            return;
        }

        for (int i = 0; i < listeners.size(); i++) {
            ZSheetStateListener lst = (ZSheetStateListener) listeners.get(i);
            lst.editorKilled(editor);
        }
    }

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

        if (shape.isAnimating()) {
            shape.stopAnimation();
        }

        shapes.remove(shape);
    }

    /**
     * put your documentation comment here
     * @param p
     * @return
     */
    public Point lp2dp(Point p) {
        Point p1 = new Point(p.x, p.y);
        Point p2 = new Point();

        try {
            p2 = (Point) af.transform(p1, p2);
        } catch (Exception e) {
        }

        return p2;
    }

    /**
     * put your documentation comment here
     * @param rect
     * @return
     */
    public ZRect lr2dr(ZRect rect) {
        Point tl = lp2dp(rect.getTopLeft());
        Point br = lp2dp(rect.getBottomRight());
        rect.setRect(tl.x, tl.y, br.x, br.y);

        return rect;
    }

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

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

        if (fcs.equals(selection)) {
            moveFocusWithSelection(direction);

            return;
        }

        ZRect sel = (ZRect) selection.clone();

        switch (direction) {
        case DOWN:

            do {
                fc.row++;

                if (fc.row > sel.bottom) {
                    fc.row = sel.top;
                    fc.col++;

                    if (fc.col > sel.right) {
                        fc.col = sel.left;
                    }
                }
            } while (sheet.getCell(fc.row, fc.col).isChild());

            break;

        case RIGHT:

            do {
                fc.col++;

                if (fc.col > sel.right) {
                    fc.col = sel.left;
                    fc.row++;

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

            break;

        case UP:

            do {
                fc.row--;

                if (fc.row < sel.top) {
                    fc.row = sel.bottom;
                    fc.col--;

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

⌨️ 快捷键说明

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