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

📄 zrect.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.awt.Point;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;


/**
 * Used for Rectangle area , provide some intersection , union and so on function
 *
 * @version 1.00
 * @author W.John
 */
public class ZRect implements Serializable, Cloneable {
    static final int ROWS = 1;
    static final int COLUMNS = 2;
    static final int CELLS = 4;
    static final int UNKNOWN = 8;
    static final int LEFT = 0;
    static final int XCENTER = 1;
    static final int RIGHT = 2;
    static final int TOP = 3;
    static final int YCENTER = 4;
    static final int BOTTOM = 5;
    public int left;
    public int top;
    public int right;
    public int bottom;

    /**
     * put your documentation comment here
     */
    public ZRect() {
        // System.out.print("hello in ezrect constructor!\n");
    }

    /**
     * put your documentation comment here
     * @param     ZRect rect
     */
    private ZRect(ZRect rect) {
        left = rect.left;
        top = rect.top;
        right = rect.right;
        bottom = rect.bottom;
    }

    /**
     * put your documentation comment here
     * @param     int left
     * @param     int top
     * @param     int right
     * @param     int bottom
     */
    public ZRect(int left, int top, int right, int bottom) {
        this.left = left;
        this.top = top;
        this.right = right;
        this.bottom = bottom;
    }

    /**
     *
     * @return
     */
    public Point getBottomRight() {
        return new Point(right, bottom);
    }

    /**
     * put your documentation comment here
     * @return
     */
    public boolean isEmpty() {
        return (left == -1) && (top == -1) && (right == -1) && (bottom == -1);
    }

    /**
     * put your documentation comment here
     * @return
     */
    public int getHeight() {
        return bottom - top;
    }

    /**
     * put your documentation comment here
     * @param x
     * @param y
     * @return
     */
    public Point getLocation(int x, int y) {
        int xl;
        int yl;

        if (x == left) {
            xl = LEFT;
        }
        //        else if (x == right)
        //          xl = RIGHT;
        else if ((x > left) && (x <= right)) {
            xl = XCENTER;
        } else {
            xl = UNKNOWN;
        }

        if (y == top) {
            yl = TOP;
        }
        //        else if (y == bottom)
        //            yl = BOTTOM;
        else if ((y > top) && (y <= bottom)) {
            yl = YCENTER;
        } else {
            yl = UNKNOWN;
        }

        return new Point(xl, yl);
    }

    /**
     * put your documentation comment here
     * @param left
     * @param top
     * @param right
     * @param bottom
     */
    public void setRect(int left, int top, int right, int bottom) {
        this.left = left;
        this.top = top;
        this.right = right;
        this.bottom = bottom;
    }

    /**
     *
     * @return
     */
    public Point getTopLeft() {
        return new Point(left, top);
    }

    /**
     * put your documentation comment here
     * @return
     */
    public int getWidth() {
        return right - left;
    }

    /**
     * put your documentation comment here
     * @return
     */
    public Object clone() {
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }

        return null;
    }

    /**
     *
     * @param x
     * @param y
     *
     * @return
     */
    public boolean contain(int x, int y) {
        return (top <= y) && (left <= x) && (bottom >= y) && (right >= x);
    }

    /**
     *
     * @param cid
     *
     * @return
     */
    public boolean contain(ZCellID cid) {
        return contain(cid.col, cid.row);
    }

    /**
     * put your documentation comment here
     * @param row
     * @param col
     * @return
     */
    public boolean containCell(int row, int col) {
        return contain(col, row);
    }

    /**
     *
     * @param rect
     *
     * @return
     */
    public boolean equals(ZRect rect) {
        return (left == rect.left) && ((right == rect.right) & (top == rect.top)) && (bottom == rect.bottom);
    }

    /**
     * put your documentation comment here
     * @param x
     * @param y
     */
    public void grow(int x, int y) {
        left = left - x;
        right = right + x;
        top = top - y;
        bottom = bottom + y;
    }

    /**
     * put your documentation comment here
     */
    public void normalize() {
        int tmpInt;

        if (left > right) {
            tmpInt = left;
            left = right;
            right = tmpInt;
        }

        if (top > bottom) {
            tmpInt = top;
            top = bottom;
            bottom = tmpInt;
        }
    }

    /**
     *
     * @return
     */
    public String toString() {
        return "ZRect(" + left + "," + top + "," + right + "," + bottom + ")";
    }

    /**
     * put your documentation comment here
     * @return
     */
    public int type(ZSheet sheet) {
        int maxRow = sheet.getLastRow();
        int maxCol = sheet.getLastCol();

        if ((right != maxCol) && (bottom != maxCol) && (left > 0) && (top > 0)) {
            return CELLS;
        } else if ((bottom == maxRow) && (top == 0)) {
            return COLUMNS;
        } else if ((right == maxRow) && (left == 0)) {
            return ROWS;
        } else {
            return UNKNOWN;
        }
    }

    /**
     * put your documentation comment here
     * @param rect
     */
    public void union(ZRect rect) {
        left = Math.min(left, rect.left);
        top = Math.min(top, rect.top);
        right = Math.max(right, rect.right);
        bottom = Math.max(bottom, rect.bottom);
    }

    /**
     * put your documentation comment here
     */
    void setEmpty() {
        top = -1;
        left = -1;
        right = -1;
        bottom = -1;
    }

    /**
     * put your documentation comment here
     * @param src
     * @return
     */
    boolean isIntersects(ZRect src) {
        return (Math.max(top, src.top) <= Math.min(bottom, src.bottom) &&
               Math.max(left, src.left) <= Math.min(right, src.right));
    }

    /**
     *
     * @param rect
     *
     * @return
     */
    boolean contain(ZRect rect) {
        return contain(rect.left, rect.top) && contain(rect.right, rect.bottom);
    }

    /**
     *
     * @param x
     * @param y
     *
     * @return
     */
    ZRect inflate(int x, int y) {
        right += x;
        bottom += y;
        left -= x;
        top -= y;

        return this;
    }

    /**
     * put your documentation comment here
     * @param src
     * @return
     */
    void intersection(ZRect src) {
        left = Math.max(left, src.left);
        top = Math.max(top, src.top);
        right = Math.min(right, src.right);
        bottom = Math.min(bottom, src.bottom);
    }

    /**
     *
     * @param x
     * @param y
     */
    void moveTo(int x, int y) {
        right = x + getWidth();
        bottom = y + getHeight();
        left = x;
        right = y;
    }

    /**
     * put your documentation comment here
     * @param ois
     * @exception ClassNotFoundException, IOException
     */
    private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
        //        ois.defaultReadObject();
        left = ois.readInt();
        top = ois.readInt();
        right = ois.readInt();
        bottom = ois.readInt();
    }

    /**
     * put your documentation comment here
     * @param oos
     * @exception IOException
     */
    private void writeObject(ObjectOutputStream oos) throws IOException {
        oos.writeInt(left);
        oos.writeInt(top);
        oos.writeInt(right);
        oos.writeInt(bottom);

        //   oos.defaultWriteObject();
    }
}

⌨️ 快捷键说明

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