Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import net.rim.device.api.system.Bitmap;
- import net.rim.device.api.system.Display;
- import net.rim.device.api.ui.Color;
- import net.rim.device.api.ui.Field;
- import net.rim.device.api.ui.Graphics;
- import net.rim.device.api.ui.Manager;
- import net.rim.device.api.ui.UiApplication;
- import net.rim.device.api.ui.XYEdges;
- import net.rim.device.api.ui.component.*;
- import net.rim.device.api.ui.container.*;
- public class StartApp extends UiApplication
- {
- public StartApp()
- {
- pushScreen( new ScreenTest() );
- }
- public static void main(String[] args) {
- StartApp fanwards = new StartApp();
- fanwards.enterEventDispatcher();
- }
- }
- class ScreenTest extends MainScreen
- {
- // ** need to access these from everywhere
- VerticalFieldManager scroll;
- Bitmap bitmapTooltip1 = Bitmap.getBitmapResource("tooltip1.png");
- Bitmap bitmapTooltip2 = Bitmap.getBitmapResource("tooltip2.png");
- boolean paintTooltip1 = false;
- boolean paintTooltip2 = false;
- public ScreenTest()
- {
- // ** this is the container manager
- VerticalFieldManager container = new VerticalFieldManager(
- Manager.NO_VERTICAL_SCROLL )
- {
- protected void sublayout(int maxWidth, int maxHeight) {
- maxHeight = Display.getHeight() - 10;
- super.sublayout(maxWidth, maxHeight);
- setExtent(maxWidth, maxHeight);
- }
- };
- add( container );
- // ** fixed manager for not-moving title bar
- VerticalFieldManager fixed = new VerticalFieldManager(
- Manager.NO_VERTICAL_SCROLL )
- {
- protected void paintBackground(Graphics g) {
- g.setBackgroundColor( Color.RED );
- g.clear();
- super.paintBackground(g);
- }
- protected void sublayout(int maxWidth, int maxHeight) {
- maxHeight = 40;
- super.sublayout(maxWidth, maxHeight);
- setExtent(maxWidth, maxHeight);
- }
- };
- container.add( fixed );
- // ** this manager will hold some menu buttons
- HorizontalFieldManager hButtons= new HorizontalFieldManager();
- fixed.add( hButtons );
- // ** buttons on the fixed manager
- ButtonField button1 = new ButtonField("Menu 1", Field.FOCUSABLE )
- {
- protected void onFocus(int direction) {
- paintTooltip1 = true;
- scroll.invalidate();
- super.onFocus(direction);
- }
- protected void onUnfocus() {
- paintTooltip1 = false;
- scroll.invalidate();
- super.onUnfocus();
- }
- };
- button1.setPadding( new XYEdges(5, 5, 5, 5) );
- hButtons.add( button1 );
- ButtonField button2 = new ButtonField("Menu 2", Field.FOCUSABLE )
- {
- protected void onFocus(int direction) {
- paintTooltip2 = true;
- scroll.invalidate();
- super.onFocus(direction);
- }
- protected void onUnfocus() {
- paintTooltip2 = false;
- scroll.invalidate();
- super.onUnfocus();
- }
- };
- button2.setPadding( new XYEdges(5, 5, 5, 5) );
- hButtons.add( button2 );
- ButtonField button3 = new ButtonField("No menu", Field.FOCUSABLE )
- {
- protected void onFocus(int direction) {
- paintTooltip1 = false;
- paintTooltip2 = false;
- scroll.invalidate();
- super.onFocus(direction);
- }
- };
- hButtons.add( button3 );
- // ** scroll manager (with anything inside) and some negative top margin
- scroll = new VerticalFieldManager(
- Manager.USE_ALL_WIDTH | Manager.VERTICAL_SCROLL )
- {
- protected void paint(Graphics g) {
- super.paint(g);
- if ( paintTooltip1 )
- g.drawBitmap(5, 5, bitmapTooltip1.getWidth(),
- bitmapTooltip1.getHeight(), bitmapTooltip1, 0, 0);
- if ( paintTooltip2 )
- g.drawBitmap(90, 5, bitmapTooltip2.getWidth(),
- bitmapTooltip2.getHeight(), bitmapTooltip2, 0, 0);
- }
- };
- container.add( scroll );
- // ** add some buttons just for showing something
- for ( int i=0; i<10; i++ ) {
- ButtonField button = new ButtonField("Button: " + i );
- scroll.add( button );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement