Advertisement
warodri

BlackBerry Tooltips

Nov 3rd, 2011
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.81 KB | None | 0 0
  1. import net.rim.device.api.system.Bitmap;
  2. import net.rim.device.api.system.Display;
  3. import net.rim.device.api.ui.Color;
  4. import net.rim.device.api.ui.Field;
  5. import net.rim.device.api.ui.Graphics;
  6. import net.rim.device.api.ui.Manager;
  7. import net.rim.device.api.ui.UiApplication;
  8. import net.rim.device.api.ui.XYEdges;
  9. import net.rim.device.api.ui.component.*;
  10. import net.rim.device.api.ui.container.*;
  11.  
  12. public class StartApp extends UiApplication
  13. {
  14.     public StartApp()
  15.     {
  16.         pushScreen( new ScreenTest() );
  17.     }
  18.     public static void main(String[] args) {
  19.         StartApp fanwards = new StartApp();
  20.         fanwards.enterEventDispatcher();
  21.     }
  22.  
  23. }
  24.  
  25. class ScreenTest extends MainScreen
  26. {
  27.     // ** need to access these from everywhere
  28.     VerticalFieldManager scroll;
  29.     Bitmap bitmapTooltip1 = Bitmap.getBitmapResource("tooltip1.png");
  30.     Bitmap bitmapTooltip2 = Bitmap.getBitmapResource("tooltip2.png");
  31.     boolean paintTooltip1 = false;
  32.     boolean paintTooltip2 = false;
  33.    
  34.     public ScreenTest()
  35.     {
  36.         // ** this is the container manager
  37.         VerticalFieldManager container = new VerticalFieldManager(
  38.                 Manager.NO_VERTICAL_SCROLL )
  39.         {
  40.             protected void sublayout(int maxWidth, int maxHeight) {
  41.                 maxHeight = Display.getHeight() - 10;
  42.                 super.sublayout(maxWidth, maxHeight);
  43.                 setExtent(maxWidth, maxHeight);
  44.             }
  45.         };
  46.         add( container );
  47.        
  48.         // ** fixed manager for not-moving title bar
  49.         VerticalFieldManager fixed = new VerticalFieldManager(
  50.                 Manager.NO_VERTICAL_SCROLL )
  51.         {
  52.             protected void paintBackground(Graphics g) {
  53.                 g.setBackgroundColor( Color.RED );
  54.                 g.clear();
  55.                 super.paintBackground(g);
  56.             }
  57.             protected void sublayout(int maxWidth, int maxHeight) {
  58.                 maxHeight = 40;
  59.                 super.sublayout(maxWidth, maxHeight);
  60.                 setExtent(maxWidth, maxHeight);
  61.             }
  62.         };
  63.         container.add( fixed );
  64.        
  65.         // ** this manager will hold some menu buttons
  66.         HorizontalFieldManager hButtons= new HorizontalFieldManager();
  67.         fixed.add( hButtons );
  68.        
  69.         // ** buttons on the fixed manager
  70.         ButtonField button1 = new ButtonField("Menu 1", Field.FOCUSABLE )
  71.         {
  72.             protected void onFocus(int direction) {
  73.                 paintTooltip1 = true;
  74.                 scroll.invalidate();
  75.                 super.onFocus(direction);
  76.             }
  77.             protected void onUnfocus() {
  78.                 paintTooltip1 = false;
  79.                 scroll.invalidate();
  80.                 super.onUnfocus();
  81.             }
  82.         };
  83.         button1.setPadding( new XYEdges(5, 5, 5, 5) );
  84.         hButtons.add( button1 );
  85.  
  86.         ButtonField button2 = new ButtonField("Menu 2", Field.FOCUSABLE )
  87.         {
  88.             protected void onFocus(int direction) {
  89.                 paintTooltip2 = true;
  90.                 scroll.invalidate();
  91.                 super.onFocus(direction);
  92.             }
  93.             protected void onUnfocus() {
  94.                 paintTooltip2 = false;
  95.                 scroll.invalidate();
  96.                 super.onUnfocus();
  97.             }
  98.         };
  99.         button2.setPadding( new XYEdges(5, 5, 5, 5) );
  100.         hButtons.add( button2 );
  101.        
  102.         ButtonField button3 = new ButtonField("No menu", Field.FOCUSABLE )
  103.         {
  104.             protected void onFocus(int direction) {
  105.                 paintTooltip1 = false;
  106.                 paintTooltip2 = false;
  107.                 scroll.invalidate();
  108.                 super.onFocus(direction);
  109.             }
  110.         };
  111.         hButtons.add( button3 );
  112.        
  113.        
  114.         // ** scroll manager (with anything inside) and some negative top margin
  115.         scroll = new VerticalFieldManager(
  116.                 Manager.USE_ALL_WIDTH | Manager.VERTICAL_SCROLL )
  117.         {
  118.             protected void paint(Graphics g) {
  119.                
  120.                 super.paint(g);
  121.                
  122.                 if ( paintTooltip1 )
  123.                     g.drawBitmap(5, 5, bitmapTooltip1.getWidth(),
  124.                         bitmapTooltip1.getHeight(), bitmapTooltip1, 0, 0);
  125.                
  126.                 if ( paintTooltip2 )
  127.                     g.drawBitmap(90, 5, bitmapTooltip2.getWidth(),
  128.                         bitmapTooltip2.getHeight(), bitmapTooltip2, 0, 0);
  129.             }
  130.         };
  131.         container.add( scroll );
  132.        
  133.         // ** add some buttons just for showing something
  134.         for ( int i=0; i<10; i++ ) {
  135.             ButtonField button = new ButtonField("Button: " + i );
  136.             scroll.add( button );
  137.         }
  138.                
  139.        
  140.     }
  141. }
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement