style.java

来自「j2me设计的界面包」· Java 代码 · 共 780 行 · 第 1/2 页

JAVA
780
字号
    }

    /**
     * @return true if the image in the background is scalled, false if it is tiled
     */
    public boolean isScaleImage() {
        return scaleImage;
    }

    /**
     * Set to true if the image in the background is scalled, false if it is tiled
     */
    public void setScaleImage(boolean scaleImage) {
        setScaleImage(scaleImage, false);
    }

    /**
     *
     * @return  the transparency level of the Component
     *
     */
    public byte getBgTransparency() {
        if(bgImage != null && (bgImage.isAnimation() || bgImage.isOpaque())) {
            return (byte)0xff;
        }
        return transparency;
    }

    /**
     * Sets the Component transparency level.
     * @param transparency transparency level as byte
     */
    public void setBgTransparency(byte transparency) {
        setBgTransparency(transparency & 0xFF, false);
    }

    /**
     * Sets the Component transparency level. Valid values should be a 
     * number between 0-255
     * @param transparency int value between 0-255
     */
    public void setBgTransparency(int transparency) {
        setBgTransparency(transparency, false);
    }

    /**
     * Sets the Style Padding
     *  
     * @param top number of pixels to padd
     * @param bottom number of pixels to padd
     * @param left number of pixels to padd
     * @param right number of pixels to padd
     */
    public void setPadding(int top, int bottom, int left, int right) {
        if (top < 0 || left < 0 || right < 0 || bottom < 0) {
            throw new IllegalArgumentException("padding cannot be negative");
        }
        padding[Component.TOP] = top;
        padding[Component.BOTTOM] = bottom;
        padding[Component.LEFT] = left;
        padding[Component.RIGHT] = right;

        modifiedFlag |= PADDING_MODIFIED;
        firePropertyChanged(PADDING);
    }

    /**
     * Sets the Style Padding
     * 
     * @param orientation one of: Component.TOP, Component.BOTTOM, Component.LEFT, Component.RIGHT
     * @param gap number of pixels to padd
     */
    public void setPadding(int orientation, int gap) {
        setPadding(orientation, gap, false);
    }

    /**
     * Sets the Style Margin
     *  
     * @param top number of margin pixels
     * @param bottom number of margin pixels
     * @param left number of margin pixels
     * @param right number of margin pixels
     */
    public void setMargin(int top, int bottom, int left, int right) {
        if (top < 0 || left < 0 || right < 0 || bottom < 0) {
            throw new IllegalArgumentException("margin cannot be negative");
        }
        margin[Component.TOP] = top;
        margin[Component.BOTTOM] = bottom;
        margin[Component.LEFT] = left;
        margin[Component.RIGHT] = right;

        modifiedFlag |= MARGIN_MODIFIED;
        firePropertyChanged(MARGIN);
    }

    /**
     * Sets the Style Margin
     * 
     * @param orientation one of: Component.TOP, Component.BOTTOM, Component.LEFT, Component.RIGHT
     * @param gap number of margin pixels
     */
    public void setMargin(int orientation, int gap) {
        setMargin(orientation, gap, false);
    }

    /**
     * Returns the Padding
     * 
     * @param orientation one of: Component.TOP, Component.BOTTOM, Component.LEFT, Component.RIGHT
     * @return number of padding pixels in the givven orientation
     */
    public int getPadding(int orientation) {
        if (orientation < Component.TOP || orientation > Component.RIGHT) {
            throw new IllegalArgumentException("wrong orientation " + orientation);
        }
        return padding[orientation];
    }

    /**
     * Returns the Margin
     * 
     * @param orientation one of: Component.TOP, Component.BOTTOM, Component.LEFT, Component.RIGHT
     * @return number of margin pixels in the givven orientation
     */
    public int getMargin(int orientation) {
        if (orientation < Component.TOP || orientation > Component.RIGHT) {
            throw new IllegalArgumentException("wrong orientation " + orientation);
        }
        return margin[orientation];
    }

    /**
     * Sets the background color for the component
     * 
     * @param bgColor RRGGBB color that ignors the alpha component
     * @param override If set to true allows the look and feel/theme to override 
     * the value in this attribute when changing a theme/look and feel
     */
    public void setBgColor(int bgColor, boolean override) {
        this.bgColor = bgColor;
        if(!override){
            modifiedFlag |= BG_COLOR_MODIFIED;
        }
        firePropertyChanged(BG_COLOR);
    }

    /**
     * Sets the background image for the component
     * 
     * @param override If set to true allows the look and feel/theme to override 
     * the value in this attribute when changing a theme/look and feel
     */
    public void setBgImage(Image bgImage, boolean override) {
        this.bgImage = bgImage;
        if(!override){
            modifiedFlag |= BG_IMAGE_MODIFIED;
        }
        firePropertyChanged(BG_IMAGE);
    }

    /**
     * Sets the foreground color for the component
     * 
     * @param override If set to true allows the look and feel/theme to override 
     * the value in this attribute when changing a theme/look and feel
     */
    public void setFgColor(int fgColor, boolean override) {
        this.fgColor = fgColor;
        if(!override){
            modifiedFlag |= FG_COLOR_MODIFIED;
        }
        firePropertyChanged(FG_COLOR);
    }

    /**
     * Sets the font for the component
     * 
     * @param override If set to true allows the look and feel/theme to override 
     * the value in this attribute when changing a theme/look and feel
     */
    public void setFont(Font font, boolean override) {
        this.font = font;
        if(!override){
            modifiedFlag |= FONT_MODIFIED;
        }
        firePropertyChanged(FONT);
    }


    /**
     * Sets the background selection color for the component
     * 
     * @param override If set to true allows the look and feel/theme to override 
     * the value in this attribute when changing a theme/look and feel
     */
    public void setBgSelectionColor(int bgSelectionColor, boolean override) {
        this.bgSelectionColor = bgSelectionColor;
        if(!override){
            modifiedFlag |= BG_SELECTION_MODIFIED;
        }
        firePropertyChanged(BG_SELECTION_COLOR);
    }

    /**
     * Sets the foreground selection color for the component
     * 
     * @param override If set to true allows the look and feel/theme to override 
     * the value in this attribute when changing a theme/look and feel
     */
    public void setFgSelectionColor(int fgSelectionColor, boolean override) {
        this.fgSelectionColor = fgSelectionColor;
        if(!override){
            modifiedFlag |= FG_SELECTION_MODIFIED;
        }
        firePropertyChanged(FG_SELECTION_COLOR);
    }

    /**
     * Set to true if the image in the background is scalled, false if it is tiled
     * 
     * @param override If set to true allows the look and feel/theme to override 
     * the value in this attribute when changing a theme/look and feel
     */
    public void setScaleImage(boolean scaleImage, boolean override) {
        this.scaleImage = scaleImage;
        if(!override){
            modifiedFlag |= SCALE_IMAGE_MODIFIED;
        }
        firePropertyChanged(SCALED_IMAGE);
    }

    /**
     * Sets the Component transparency level. Valid values should be a 
     * number between 0-255
     * 
     * @param transparency int value between 0-255
     */
    public void setBgTransparency(int transparency, boolean override) {
        if (transparency < 0 || transparency > 255) {
            throw new IllegalArgumentException("valid values are between 0-255");
        }
        this.transparency = (byte) transparency;
        
        if(!override){
            modifiedFlag |= TRANSPARENCY_MODIFIED;
        }
        firePropertyChanged(TRANSPARENCY);
    }


    /**
     * Sets the Style Padding
     * 
     * @param orientation one of: Component.TOP, Component.BOTTOM, Component.LEFT, Component.RIGHT
     * @param gap number of pixels to padd
     * @param override If set to true allows the look and feel/theme to override 
     * the value in this attribute when changing a theme/look and feel
     */
    public void setPadding(int orientation, int gap,boolean override) {
        if (orientation < Component.TOP || orientation > Component.RIGHT) {
            throw new IllegalArgumentException("wrong orientation " + orientation);
        }
        if (gap < 0) {
            throw new IllegalArgumentException("padding cannot be negative");
        }
        padding[orientation] = gap;

        if(!override){
            modifiedFlag |= PADDING_MODIFIED;
        }
        firePropertyChanged(PADDING);
    }


    /**
     * Sets the Style Margin
     * 
     * @param orientation one of: Component.TOP, Component.BOTTOM, Component.LEFT, Component.RIGHT
     * @param gap number of margin pixels
     * @param override If set to true allows the look and feel/theme to override 
     * the value in this attribute when changing a theme/look and feel
     */
    public void setMargin(int orientation, int gap, boolean override) {
        if (orientation < Component.TOP || orientation > Component.RIGHT) {
            throw new IllegalArgumentException("wrong orientation " + orientation);
        }
        if (gap < 0) {
            throw new IllegalArgumentException("margin cannot be negative");
        }
        margin[orientation] = gap;
        if(!override){
            modifiedFlag |= MARGIN_MODIFIED;
        }
        firePropertyChanged(MARGIN);
    }

    
    private void firePropertyChanged(String propertName) {
        if (listeners == null) {
            return;
        }
        Enumeration enums = listeners.elements();
        while (enums.hasMoreElements()) {
            StyleListener l = (StyleListener) enums.nextElement();
            l.styleChanged(propertName, this);
        }
    }

    /**
     * Adds a Style Listener to the Style Object.
     * 
     * @param l a style listener
     */
    public void addStyleListener(StyleListener l) {
        if (listeners == null) {
            listeners = new Vector();
        }
        listeners.addElement(l);
    }

    /**
     * Removes a Style Listener from the Style Object.
     * 
     * @param l a style listener
     */
    public void removeStyleListener(StyleListener l) {
        if (listeners != null) {
            listeners.removeElement(l);
        }
    }

    void resetModifiedFlag() {
        modifiedFlag = 0;
    }

    /**
     * Sets the border for the style
     * 
     * @param border new border object for the component
     */
    public void setBorder(Border border) {
        this.border = border;
        modifiedFlag |= BORDER_MODIFIED;
        firePropertyChanged(BORDER);
    }

    /**
     * Sets the border for the style
     * 
     * @param border new border object for the component
     * @param override If set to true allows the look and feel/theme to override 
     * the value in this attribute when changing a theme/look and feel
     */
    public void setBorder(Border border, boolean override) {
        this.border = border;
        if(!override){
            modifiedFlag |= BORDER_MODIFIED;
        }
        firePropertyChanged(BORDER);
    }
    
    /**
     * Returns the border for the style
     */
    public Border getBorder() {
        return border;
    }
    
    /**
     * Return the background painter for this style, normally this would be 
     * the internal image/color painter but can be user defined 
     */
    public Painter getBgPainter() {
        return bgPainter;
    }

    /**
     * Defines the background painter for this style, normally this would be 
     * the internal image/color painter but can be user defined 
     * 
     * @param bgPainter new painter to install into the style
     */
    public void setBgPainter(Painter bgPainter) {
        this.bgPainter = bgPainter;
    }

}

⌨️ 快捷键说明

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