2011-02-17 14 views
0

如何修改下面的類以便按鈕字段不可選(從不具有焦點),因此永不突出顯示?修改類以便ButtonField不可選(從不具有焦點)

感謝

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 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;   
     } 
} 

回答

相關問題