clayer.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 934 行 · 第 1/3 页
JAVA
934 行
/* * * * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */package com.sun.midp.chameleon;import javax.microedition.lcdui.*;import com.sun.midp.chameleon.skins.*;/** * This class represents a "layer". A layer is an element used to comprise * a higher-level "window" (see CWindow.java). A layer has several properties * such as its visibility, whether it accepts input, its size, etc. A layer * also has content, such as its background and its foreground. */public class CLayer { /** Flag indicating this layer is in need of repainting. */ private boolean dirty; /** Array holding a bounding rectangle of an area needing repainting. */ protected int[] dirtyBounds; /** Copy of the layer bounds needed to unlock the layers for painting */ protected int[] boundsCopy; /** Copy of the dirty bounds needed to unlock the layers for painting */ protected int[] dirtyBoundsCopy; /** Flag indicating if this layer has a transparent background or not. */ protected boolean transparent; /** Flag indicating the current visibility state of this layer. */ protected boolean visible; /** Flag indicating the ability of this layer to support key/pen input. */ protected boolean supportsInput; /** * Flag indicating this layer is either completely opaque, or not. * By default, a layer is not opaque, and thus requires the background * and any layers below it to be painted in addition to itself. However, * if a layer is opaque, it does not require anything it is obscuring to * be painted, just itself. All layers are opaque by default. */ protected boolean opaque = true; /** * If this layer has a filled color background, * the 0xrrggbbaa value of that color */ protected int bgColor; /** * The image to use as a background for this layer if this layer * is not transparent and does not use a fill color. */ protected Image[] bgImage; /** * If this layer is not transparent and uses a background image, * a flag indicating if that image should be tiled or otherwise centered. */ protected boolean tileBG; /** * The window which owns this layer. If this layer has not been added * to a window or it has been removed from a window, the owner will be * null. */ protected CWindow owner; /** * An array holding the bounds of this layer. The indices are * as follows: * 0 = layer's 'x' coordinate * 1 = layer's 'y' coordinate * 2 = layer's width * 3 = layer's height * The 'x' and 'y' coordinates are in the coordinate space of the * window which contains this layer. */ public int[] bounds; /** Constant used to reference the '0' index of the bounds array */ public static final int X = 0; /** Constant used to reference the '1' index of the bounds array */ public static final int Y = 1; /** Constant used to reference the '2' index of the bounds array */ public static final int W = 2; /** Constant used to reference the '3' index of the bounds array */ public static final int H = 3; /** * When in the paint() routine, graphicsColor will be set to the * default graphics color. This is a convenience variable for * subclasses to easily modify and then reset the graphics color. */ int graphicsColor; /** * When in the paint() routine, graphicsFont will be set to the * default graphics Font. This is a convenience variable for * subclasses to easily modify and then reset the graphics font. */ Font graphicsFont; /** * Construct a default, transparent layer. As a result, the * 'transparent' value will be set to true. */ public CLayer() { this((Image)null, -1); } /** * Construct a layer with the given background image if it is not null * or with a background fill color. * The color should be in the 0xaarrggbb format. If the bgColor is * invalid and bgImage is null, this layer will be transparent and * equal to the no-argument constructor. * * @param bgImage The background image to use for this layer. * @param bgColor The color (0xaarrggbb) to use as the background fill */ public CLayer(Image bgImage, int bgColor) { if (bgImage != null) { this.bgImage = new Image[] { bgImage }; this.tileBG = true; transparent = false; } else { transparent = (bgColor < 0); } this.bgColor = bgColor; initialize(); } /** * Construct a layer with the given background images (if not null) * or with a background fill color and border. The background images * should be a 9 element array, creating a 9-piece image background. * The color should be in the 0xaarrggbb format. If the bgColor is * invalid and bgImages are null, this layer will be transparent and * equal to the no-argument constructor. * * @param bgImages The background image to use for this layer. * @param bgColor The color (0xaarrggbb) to use as the background fill */ public CLayer(Image[] bgImages, int bgColor) { if (bgImages != null) { this.bgImage = new Image[bgImages.length]; System.arraycopy(bgImages, 0, this.bgImage, 0, bgImages.length); this.tileBG = false; transparent = false; } else { transparent = (bgColor < 0); } this.bgColor = bgColor; initialize(); } /** * Finish initialization of this CLayer. This can * be extended by subclasses. The dimensions of the * CLayer are stored in its bounds[]. The 'x' and 'y' * coordinates are in the coordinate space of the * window which contains this layer. By default, a layer is * located at the origin and is as large as the screen size. * * The X and Y coordinates represent the upper left position * of this CLayer in the containing CWindow's coordinate space. * */ protected void initialize() { bounds = new int[4]; bounds[X] = 0; bounds[Y] = 0; bounds[W] = 0; bounds[H] = 0; dirtyBounds = new int[4]; dirtyBoundsCopy = new int[4]; boundsCopy = new int[4]; cleanDirtyRegions(); // IMPL_NOTE : center the background image by default } /** * Establish a background. This method will evaluate the parameters * and create a background which is appropriate. If the image is non-null, * the image will be used to create the background. If the image is null, * the values for the colors will be used and the background will be * painted in fill color instead. If the image is null, and the background * color is a negative value, this layer will become transparent and no * background will be painted. * * @param bgImage the image to use for the background tile (or null) * @param tileBG If true, then tile the background image as necessary * to fill a larger screen. If false, treat the image * as fullsize. * @param bgColor if the image is null, use this color as a background * fill color */ public void setBackground(Image bgImage, boolean tileBG, int bgColor) { if (bgImage != null) { this.bgImage = new Image[] { bgImage }; this.tileBG = tileBG; transparent = false; } else { this.bgImage = null; transparent = (bgColor < 0); } this.bgColor = bgColor; addDirtyRegion(); } /** * Establish a background. This method will evaluate the parameters * and create a background which is appropriate. If the images are * non-null, the images will be used to create a 9-piece background. * If the images are null, the value for the color will be used and * the background will be painted in fill color instead. If the images * are null, and the background color is a negative value, this layer * will become transparent and no background will be painted. * * @param bgImages an array containing a 9-piece image set to be used * as the background for this layer * @param bgColor if the images are null, use this color as a background * fill color */ public void setBackground(Image[] bgImages, int bgColor) { if (bgImages != null) { this.bgImage = new Image[bgImages.length]; System.arraycopy(bgImages, 0, this.bgImage, 0, bgImages.length); this.tileBG = false; transparent = false; } else { this.bgImage = null; transparent = (bgColor < 0); } this.bgColor = bgColor; addDirtyRegion(); } /** * Establish the bounds of this layer. The coordinate space for * the 'x' and 'y' anchor will be interpreted in that of the window * which contains this layer. * * @param x The 'x' coordinate of this layer's origin * @param y The 'y' coordinate of this layer's origin * @param w The width of this layer * @param h The height of this layer */ public void setBounds(int x, int y, int w, int h) { if (bounds == null) { bounds = new int[4]; } bounds[X] = x; bounds[Y] = y; bounds[W] = w; bounds[H] = h; } /** * Return the bounds of this layer (in the coordinate space of * its parent Window). Returns a 4 element array, containing the * x, y, width, and height representing this layer's bounding * rectangle * * @return this layer's bounding rectangle in the coordinate space * of its parent window */ public int[] getBounds() { return bounds; } /** * Determine the current visibility of this layer. Note that this * state only pertains to the layer's visibility status within its * containing window. The window itself may or may not be actually * visible on the physical display. * * @return true if this layer is currently visible in a window
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?