blackberry - Modify class so that ButtonField is unselectable (never has focus) -
how can modify below class button field unselectable (never has focus), , 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 bitmap 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 new bitmap button field. * * @param bitmap bitmap use 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 bitmaphighlight, 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 constructor.
Comments
Post a Comment