border.java.svn-base

来自「j2me设计的界面包」· SVN-BASE 代码 · 共 726 行 · 第 1/2 页

SVN-BASE
726
字号
package com.sun.lwuit.plaf;import com.sun.lwuit.Component;import com.sun.lwuit.Graphics;import com.sun.lwuit.Image;import com.sun.lwuit.RGBImage;/** * Base class that allows us to render a border for a component, a border is drawn before * the component and is drawn within the padding region of the component. It is the * responsibility of the component not to draw outside of the border line. * <p>This class can be extended to provide additional border types and custom made * border types. * <p>A border can optionally paint the background of the component, this depends on * the border type and is generally required for rounded borders that "know" the area * that should be filled. * * @author Shai Almog */public class Border {    private static Border defaultBorder = Border.createEtchedRaised(0x020202, 0xBBBBBB);        private static final int TYPE_EMPTY = 0;    private static final int TYPE_LINE = 1;    private static final int TYPE_ROUNDED = 2;    private static final int TYPE_ROUNDED_PRESSED = 3;    private static final int TYPE_ETCHED_LOWERED = 4;    private static final int TYPE_ETCHED_RAISED = 5;    private static final int TYPE_BEVEL_RAISED = 6;    private static final int TYPE_BEVEL_LOWERED = 7;    private static final int TYPE_IMAGE = 8;    // variables are package protected for the benefit of the resource editor!    int type;    Image[] images;        /**     * Indicates whether theme colors should be used or whether colors are specified     * in the border     */    boolean themeColors;        int colorA;    int colorB;    int colorC;    int colorD;    int thickness;    int arcWidth;    int arcHeight;    Border pressedBorder;    Border focusBorder;        private static Border empty;        /**     * Returns an empty border, this is mostly useful for overriding components that     * have a border by default     *      * @return a border than draws nothing     */    public static Border getEmpty() {        if(empty == null) {            empty = new Border();        }        return empty;    }        /**     * Creates an empty border, this is useful where we don't want a border for a      * component but want a focus border etc...     *      * @return a border than draws nothing     */    public static Border createEmpty() {        return new Border();    }        /**     * The given images are tiled appropriately across the matching side of the border and placed     * as expected in the four corners. The background image is optional and it will be tiled in     * the background if necessary.     * <p>By default this border does not override background unless a background image is specified     *      * @return new border instance     */    public static Border createImageBorder(Image top, Image bottom, Image left, Image right, Image topLeft, Image topRight,        Image bottomLeft, Image bottomRight, Image background) {        Border b = new Border();        b.type = TYPE_IMAGE;        b.images = new Image[] {top, bottom, left, right, topLeft, topRight, bottomLeft,                         bottomRight, background};        return b;    }        /**     * The given images are tiled appropriately across the matching side of the border, rotated and placed     * as expected in the four corners. The background image is optional and it will be tiled in     * the background if necessary.     * <p>By default this border does not override background unless a background image is specified.     * <p>Notice that this version of the method is potentially much more efficient since images     * are rotated internally and this might save quite a bit of memory!     * <p><b>The top and topLeft images must be square!</b> The width and height of these images     * must be equal otherwise rotation won't work as you expect.     *      * @return new border instance     */    public static Border createImageBorder(Image top, Image topLeft, Image background) {        Border b = new Border();        b.type = TYPE_IMAGE;        b.images = new Image[] {top, top.rotate(180), top.rotate(270), top.rotate(90), topLeft, topLeft.rotate(90),                 topLeft.rotate(270), topLeft.rotate(180), background};        return b;    }    /**     * Creates a line border that uses the color of the component foreground for drawing     *      * @param thickness thickness of the boder in pixels     * @return new border instance     */    public static Border createLineBorder(int thickness) {        Border b = new Border();        b.type = TYPE_LINE;        b.themeColors = true;        b.thickness = thickness;        return b;    }    /**     * Creates a line border that uses the given color for the component     *      * @param thickness thickness of the boder in pixels     * @param color the color for the border     * @return new border instance     */    public static Border createLineBorder(int thickness, int color) {        Border b = new Border();        b.type = TYPE_LINE;        b.themeColors = false;        b.thickness = thickness;        b.colorA = color;        return b;    }        /**     * Creates a rounded corner border that uses the color of the component foreground for drawing.     * Due to technical issues (lack of shaped clipping) performance and memory overhead of round      * borders can be low if used with either a bgImage or translucency!      * <p>This border overrides any painter used on the component and would ignor such a painter.     *      * @param arcWidth the horizontal diameter of the arc at the four corners.     * @param arcHeight the vertical diameter of the arc at the four corners.     * @return new border instance     */    public static Border createRoundBorder(int arcWidth, int arcHeight) {        Border b = new Border();        b.type = TYPE_ROUNDED;        b.themeColors = true;        b.arcHeight = arcHeight;        b.arcWidth = arcWidth;        return b;    }    /**     * Creates a rounded border that uses the given color for the component.     * Due to technical issues (lack of shaped clipping) performance and memory overhead of round      * borders can be low if used with either a bgImage or translucency!      * <p>This border overrides any painter used on the component and would ignor such a painter.     *      * @param arcWidth the horizontal diameter of the arc at the four corners.     * @param arcHeight the vertical diameter of the arc at the four corners.     * @param color the color for the border     * @return new border instance     */    public static Border createRoundBorder(int arcWidth, int arcHeight, int color) {        Border b = new Border();        b.type = TYPE_ROUNDED;        b.themeColors = false;        b.colorA = color;        b.arcHeight = arcHeight;        b.arcWidth = arcWidth;        return b;    }        /**     * Creates a lowered etched border with default colors, highlight is derived     * from the component and shdow is a plain dark color     *      * @return new border instance     */    public static Border createEtchedLowered() {        Border b = new Border();        b.type = TYPE_ETCHED_LOWERED;        b.themeColors = true;        return b;    }    /**     * Creates a raised etched border with the given colors     *      * @param highlight color RGB value     * @param shadow color RGB value     * @return new border instance     */    public static Border createEtchedLowered(int highlight, int shadow) {        Border b = new Border();        b.type = TYPE_ETCHED_LOWERED;        b.themeColors = false;        b.colorA = shadow;        b.colorB = highlight;        return b;    }        /**     * Creates a lowered etched border with default colors, highlight is derived     * from the component and shdow is a plain dark color     *      * @return new border instance     */    public static Border createEtchedRaised() {        Border b = new Border();        b.type = TYPE_ETCHED_RAISED;        b.themeColors = true;        return b;    }    /**     * Creates a raised etched border with the given colors     *      * @param highlight color RGB value     * @param shadow color RGB value     * @return new border instance     */    public static Border createEtchedRaised(int highlight, int shadow) {        Border b = new Border();        b.type = TYPE_ETCHED_RAISED;        b.themeColors = false;        b.colorA = highlight;        b.colorB = shadow;        return b;    }    /**     * Returns true if installing this border will override the painting of the component background     */    public boolean isBackgroundPainter() {        return type == TYPE_ROUNDED || type == TYPE_ROUNDED_PRESSED || (type == TYPE_IMAGE && images[8] != null);    }    /**     * Creates a lowered bevel border with default colors, highlight is derived     * from the component and shdow is a plain dark color     *      * @return new border instance     */    public static Border createBevelLowered() {        Border b = new Border();        b.type = TYPE_BEVEL_LOWERED;        b.themeColors = true;        return b;    }    /**     * Creates a raised bevel border with the given colors     *      * @param highlightOuter  RGB of the outer edge of the highlight area     * @param highlightInner  RGB of the inner edge of the highlight area     * @param shadowOuter     RGB of the outer edge of the shadow area     * @param shadowInner     RGB of the inner edge of the shadow area     * @return new border instance     */    public static Border createBevelLowered(int highlightOuter, int highlightInner,                        int shadowOuter, int shadowInner) {        Border b = new Border();        b.type = TYPE_BEVEL_LOWERED;        b.themeColors = false;        b.colorA = highlightOuter;        b.colorB = highlightInner;        b.colorC = shadowOuter;        b.colorD = shadowInner;        return b;    }        /**     * Creates a lowered bevel border with default colors, highlight is derived     * from the component and shdow is a plain dark color     *      * @return new border instance     */    public static Border createBevelRaised() {        Border b = new Border();        b.type = TYPE_BEVEL_RAISED;        b.themeColors = true;        return b;    }    /**     * Creates a raised bevel border with the given colors     *      * @param highlightOuter  RGB of the outer edge of the highlight area     * @param highlightInner  RGB of the inner edge of the highlight area     * @param shadowOuter     RGB of the outer edge of the shadow area     * @param shadowInner     RGB of the inner edge of the shadow area     * @return new border instance     */    public static Border createBevelRaised(int highlightOuter, int highlightInner,                        int shadowOuter, int shadowInner) {        Border b = new Border();        b.type = TYPE_BEVEL_RAISED;        b.themeColors = false;        b.colorA = highlightOuter;        b.colorB = highlightInner;        b.colorC = shadowOuter;        b.colorD = shadowInner;        return b;    }            /**     * Allows us to define a border that will act as the pressed version of this border     *      * @param pressed a border that will be returned by the pressed version method     */    public void setPressedInstance(Border pressed) {        pressedBorder = pressed;    }        /**     * Allows us to define a border that will act as the focused version of this border     *      * @param focused a border that will be returned by the focused version method     */    public void setFocusedInstance(Border focused) {        focusBorder = focused;    }        /**     * Returns the focused version of the border if one is installed     */    public Border getFocusedInstance() {        if(focusBorder != null) {            return focusBorder;        }        return this;    }    /**     * Returns the pressed version of the border if one is set by the user     */    public Border getPressedInstance() {        if(pressedBorder != null) {            return pressedBorder;        }        return this;    }        /**     * When applied to buttons borders produce a version that reverses the effects      * of the border providing a pressed feel     *      * @return a border that will make the button feel pressed     */    public Border createPressedVersion() {

⌨️ 快捷键说明

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