clayer.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 934 行 · 第 1/3 页

JAVA
934
字号
     */    public boolean isVisible() {        return visible;    }    /**     * Toggle the visibility state of this layer within its containing     * window.     *     * @param visible If true, this layer will be painted as part of its     *                containing window, as well as receive events if it     *                supports input.     */    public void setVisible(boolean visible) {        this.visible = visible;        addDirtyRegion();    }    /**     * Determine if this layer is opaque     *     * @return true if this layer does not have any transparent     *         or translucent areas     */    public boolean isOpaque() {        return opaque;    }        /**     * Set the opacity flag for this layer. True means that this     * layer does not have any transparent or translucent areas     *     * @param opaque a flag indicating the layer's opacity     */    public void setOpaque(boolean opaque) {        this.opaque = opaque;    }        /**     * Returns true if this layer is in need of repainting.     *     * @return true if this layer is marked as 'dirty' and needs repainting.     */    public boolean isDirty() {        return this.dirty;    }        /**     * Mark this layer as being dirty.     * By default, this will also mark the containing window (if there is one)     * as being dirty as well.     */        protected void setDirty() {        setDirtyButNotNotifyOwner();        if (owner != null) {            owner.setDirty();        }    }    /**     * Mark this layer as being dirty     * but don't mark the containing window.     */    protected void setDirtyButNotNotifyOwner() {        this.dirty = true;    }    /** Clean any dirty regions of the layer. */    protected void cleanDirtyRegions() {        dirtyBounds[X] = dirtyBounds[Y]            = dirtyBounds[W] = dirtyBounds[H] = -1;    }    /**     * Determines whether dirty regions are empty.     *     * @return true if dirty regions are not set,     *         false otherwise     */    protected boolean isEmptyDirtyRegions() {        return dirtyBounds[X] == -1;    }    /** Clean any dirty regions of the layer and mark layer as not dirty. */    protected void cleanDirty() {        dirty = false;        cleanDirtyRegions();    }    /**     * Determine if this layer supports input, such as key and pen events.     *     * @return true if this layer supports handling input events     */    public boolean supportsInput() {        return supportsInput;    }    /**     * Toggle the ability of this layer to receive input.     *     * @param support If true, this layer will receive user input events     *                (as long as the layer is also visible)     */    public void setSupportsInput(boolean support) {        this.supportsInput = support;    }    /**     * Handle input from a pen tap.     *     * Parameters describe the type of pen event and the x,y location in the     * layer at which the event occurred.     *     * Important: the x,y location of the pen tap will already be translated     * into the coordinate space of the layer.     *     * @param type the type of pen event     * @param x the x coordinate of the event     * @param y the y coordinate of the event     * @return     */    public boolean pointerInput(int type, int x, int y) {        return false;    }    /**     * Handle key input from a keypad. Parameters describe     * the type of key event and the platform-specific     * code for the key. (Codes are translated using the     * lcdui.Canvas)     *     * @param type the type of key event     * @param code the numeric code assigned to the key     * @return     */    public boolean keyInput(int type, int code) {        return false;    }    /**     * Handle input from some type of device-dependent     * input method. This could be input from something     * such as T9, or a phonebook lookup, etc.     *     * @param str the text to handle as direct input     * @return     */    public boolean methodInput(String str) {        return false;    }    /**     * Utility method to determine if the given point lies within     * the bounds of this layer. The point should be in the coordinate     * space of this layer's containing CWindow.     *     * @param x the "x" coordinate of the point     * @param y the "y" coordinate of the point     * @return true if the coordinate lies in the bounds of this layer     */    public boolean containsPoint(int x, int y) {        return (visible &&                x >= bounds[X] && x <= (bounds[X] + bounds[W]) &&                y >= bounds[Y] && y <= (bounds[Y] + bounds[H]));    }    /**     * Utility method to determine if this layer wanna handle     * the given point. By default the layer handles the point if it     * lies within the bounds of this layer.  The point should be in     * the coordinate space of this layer's containing CWindow.     *     * @param x the "x" coordinate of the point     * @param y the "y" coordinate of the point     * @return true if the coordinate lies in the bounds of this layer     */    public boolean handlePoint(int x, int y) {        return containsPoint(x, y);    }        /**     * Add this layer's entire area to be marked for repaint. Any pending     * dirty regions will be cleared and the entire layer will be painted     * on the next repaint.     */    public void addDirtyRegion() {        if (CGraphicsQ.DEBUG) {            System.err.println("Layer " + layerID() + ":");            System.err.println("\tMarking entire layer dirty");        }        cleanDirtyRegions();        setDirty();    }    /**     * Check whether the layer is intersected with another one.     * @param l the layer to check intersection with     * @return true when the layers are intersected, false otherwise     */    public boolean intersects(CLayer l) {        int x = bounds[X];        int y = bounds[Y];        int lx = l.bounds[X];        int ly = l.bounds[Y];        return !(lx >= x + bounds[W] || lx + l.bounds[W] <= x ||            ly >= y + bounds[H] || ly + l.bounds[H] <= y);    }    /**     * Add an area to be marked for repaint to this layer. This could     * be needed for a variety of reasons, such as this layer being     * obscured by another layer or window element. The new region should     * be in the coordinate space of this layer.     *     * @param x the x coordinate of the region     * @param y the y coordinate of the region     * @param w the width of the region     * @param h the height of the region     * @return true if dirty region of the layer was changed,     *         false otherwise     */    public boolean addDirtyRegion(int x, int y, int w, int h) {        if (CGraphicsQ.DEBUG) {            System.err.println("Layer " + this + ":");            System.err.println("\tAdd dirty: " + x + ", "                + y + ", " + w + ", " + h);        }        // The whole layer is dirty already        if (isDirty() && isEmptyDirtyRegions()) {            if (CGraphicsQ.DEBUG) {                System.err.println(                    "\tWhole layer is dirty already");            }            return false;        }        // Cache layer bounds        int bw = bounds[W];        int bh = bounds[H];        int x2 = x + w;        int y2 = y + h;        // Dirty region can be outside of the layer        if (x >= bw || y >= bh || x2 <= 0 || y2 <=0) {            if (CGraphicsQ.DEBUG) {                System.err.println(                    "\tAdded region is outside of the layer");            }            return false;        }        boolean res = false;        int dx, dy, dx2, dy2;        if (isEmptyDirtyRegions()) {            dx = x; dy = y;            dx2 = x2; dy2 = y2;        } else {            dx = dirtyBounds[X];            dy = dirtyBounds[Y];            dx2 = dx + dirtyBounds[W];            dy2 = dy + dirtyBounds[H];            if (dx2 < x2) dx2 = x2;            if (dy2 < y2) dy2 = y2;            if (x < dx) dx = x;            if (y < dy) dy = y;        }        // Lastly, we carefully restrict the dirty region        // to be within the bounds of this layer        if (dx < 0) dx = 0;        if (dy < 0) dy = 0;        if (dx2 > bw) dx2 = bw;        if (dy2 > bh) dy2 = bh;        // Update changed dirty region        int dw = dx2 - dx;        int dh = dy2 - dy;        if (dirtyBounds[W] != dw || dirtyBounds[H] != dh) {            if (dw == bw && dh == bh) {                // The entire layer is dirty now                cleanDirtyRegions();                if (CGraphicsQ.DEBUG) {                    System.err.println(                        "\tThe entire layer became dirty");                }            } else {                dirtyBounds[X] = dx;                dirtyBounds[Y] = dy;                dirtyBounds[W] = dw;                dirtyBounds[H] = dh;                if (CGraphicsQ.DEBUG) {                    System.err.println(                        "\tCurrent dirty: " + dirtyBounds[X] + ", "                        + dirtyBounds[Y] + ", " + dirtyBounds[W] + ", "                        + dirtyBounds[H]);                }            }            res = true;            setDirty();        }        return res;    }    /**     * Subtract a layer area not needed for repaint of this layer.     * It could be needed for a variety of reasons, such as layer being

⌨️ 快捷键说明

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