开发者

Modify class so that ButtonField is unselectable (never has focus)

How can I modify below class so that the button field is unselectable (never has focus), and therefore never highlighted ?

Thanks

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.component.ButtonField;

/**
 * Button field with a bitmap as its label.
 */
public class BitmapField extends ButtonField {
        private Bitmap bitmap;
        private Bitmap bitmapHighlight;
        private boolean highlighted = false;
        private int width;
        private String label;
        private Font font;

        /**
         * Instantiates a new bitmap button field.
         * 
         * @param bitmap the bitmap to use as a label
         */
        public BitmapField(Bitmap bitmap, Bitmap bitmapHighlight, String label, int width, Font font) {
            this(bitmap, bitmapHighlight, ButtonField.CONSUME_CLICK|ButtonField.FIELD_HCENTER|ButtonField.FIELD_VCENTER
                    , label, width, font);

        }

        protected void onFocus(int direction) {

            this.setHighlight(true);
            super.onFocus(direction);

            }

            protected void onUnfocus() {
                this.setHighlight(false);
            super.onUnfocus();

            }


        public BitmapField(Bitmap bitmap, Bitmap bitm开发者_运维技巧apHighlight, long style, 
                String label, int width, Font font) {
            super(style);
            this.bitmap = bitmap;
            this.bitmapHighlight = bitmapHighlight;
            this.width = width;
            this.label = label;
            this.font = font;
        }

        /* (non-Javadoc)
         * @see net.rim.device.api.ui.component.ButtonField#layout(int, int)
         */
        protected void layout(int width, int height) {
                setExtent(getPreferredWidth(), getPreferredHeight());
        }

        /* (non-Javadoc)
         * @see net.rim.device.api.ui.component.ButtonField#getPreferredWidth()
         */
        public int getPreferredWidth() {
                return bitmap.getWidth()+this.width;
        }

        /* (non-Javadoc)
         * @see net.rim.device.api.ui.component.ButtonField#getPreferredHeight()
         */
        public int getPreferredHeight() {
                return bitmap.getHeight()+20;
        }

        /* (non-Javadoc)
         * @see net.rim.device.api.ui.component.ButtonField#paint(net.rim.device.api.ui.Graphics)
         */
        protected void paint(Graphics graphics) {
                super.paint(graphics);
                int width = bitmap.getWidth();
                int height = bitmap.getHeight();
                Bitmap b = bitmap;
                if (highlighted)
                    b = bitmapHighlight;

                //graphics.fillRoundRect(0, 0, getWidth(), getHeight(), 10, 10);  
                graphics.drawBitmap(0, 0, width, height, b, 0, 0);
                graphics.setFont(font);
                graphics.drawText(label, 0, bitmap.getHeight());  
        }

        public void setHighlight(boolean highlight)
        {
            this.highlighted = highlight;           
        }
}


Add style bit Field.NON_FOCUSABLE to the constructor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜