02-05-2013 06:05 PM
hey all
whilst using the code below in os7 which comes with the eclipse pluggin, everything works fine.
The problem starts when compiling it in jde os5. when choosing an item from the lower choicefields , all the fields move away.
package mypackage; 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.Font; import net.rim.device.api.ui.Graphics; import net.rim.device.api.ui.Manager; import net.rim.device.api.ui.component.ButtonField; import net.rim.device.api.ui.component.LabelField; import net.rim.device.api.ui.component.ObjectChoiceField; import net.rim.device.api.ui.component.SeparatorField; import net.rim.device.api.ui.container.HorizontalFieldManager; import net.rim.device.api.ui.container.MainScreen; import net.rim.device.api.ui.container.VerticalFieldManag er; public class TestScreen extends MainScreen { //Variables storing device screen size for use making app viewable on all devices private int deviceWidth = Display.getWidth(); private int deviceHeight = Display.getHeight(); private Bitmap bmBackground; //================================================ ================================== private ButtonField btnSave = new ButtonField("Save"); private ButtonField btnClose = new ButtonField("Close"); public TestScreen(){ super(NO_VERTICAL_SCROLL); //this manager is used for the static background image VerticalFieldManager mainManager = new VerticalFieldManager( Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR ) { public void paint(Graphics g) { g.clear(); g.drawBitmap(0, 0, deviceWidth, deviceHeight, bmBackground, 0, 0); super.paint(g); } }; //this manger is used for adding the componentes VerticalFieldManager subManager = new VerticalFieldManager( Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR ) { protected void sublayout(int maxWidth, int maxHeight) { int displayWidth = deviceWidth; int displayHeight = deviceHeight; super.sublayout( displayWidth, displayHeight); setExtent( displayWidth, displayHeight); } }; GeneralSubz gs = new GeneralSubz(); bmBackground = gs.getScaledBitmapImage("background2.png",deviceWi dth,deviceHeight); final int intTitleHeight = (Display.getHeight()/8)>>1; final Bitmap titleBk = gs.getScaledBitmapImage("title.png",Display.getWid th(),intTitleHeight); VerticalScrollManager vfmContainer = new VerticalScrollManager(Display.getWidth(),Display.g etHeight()-intTitleHeight); VerticalFieldManager TopVMan = new VerticalFieldManager(); ///* String choices[] = {"Custom","STYLE-1","STYLE-2","Training-1","Traini ng-2","Training-3","Training-4"}; int iSetTo = 0; // ocfLoadSetting.setChangeListener(this); for(int i=0;i<20;i++){ TopVMan.add( new ObjectChoiceField("Test-"+i,choices,iSetTo,0){ public void setDirty( boolean dirty ) { } public void setMuddy( boolean muddy ) { } }); TopVMan.add(new SeparatorField(){ protected void paint(Graphics g){ g.setColor(Color.WHITE); super.paint(g);}}); } HorizontalFieldManager mnBtnz = new HorizontalFieldManager(); mnBtnz.add(btnSave ); mnBtnz.add(btnClose); TopVMan.add(mnBtnz); vfmContainer.add(TopVMan); subManager.add(vfmContainer); mainManager.add(new LabelField("",Field.USE_ALL_WIDTH){ protected void layout(int width, int height){ setExtent(width,intTitleHeight); } protected void paint(Graphics g){ g.drawBitmap(0, 0, getWidth(), getHeight(), titleBk, 0, 0); g.setColor(Color.WHITE); g.setFont(this.getFont().derive(Font.PLAIN, intTitleHeight-2)); g.drawText("Test Screen", (getWidth()>>1)-(g.getFont().getAdvance("Test Screen")>>1), 0); super.paint(g); } }); mainManager.add(subManager); //finally add the mainManager over the screen this.add(mainManager); }// }
package mypackage; import net.rim.device.api.ui.container.VerticalFieldManager; import net.rim.device.api.ui.Graphics; import net.rim.device.api.ui.Manager; import net.rim.device.api.ui.ScrollChangeListener; /** * VerticalScrollManager - a VerticalFieldManager with a nicer-looking scrollbar * and optional width and height limits */ public class VerticalScrollManager extends VerticalFieldManager implements ScrollChangeListener{ /** * Some constants governing the exact look - colors and size - of the scrollbar. * *Our scrollbar is a light grey bar on the right of the manager's visible area * with a darker grey scroll slider. */ private static final int SCROLLBAR_COLOR = 0xCCCCCC; private static final int SLIDER_COLOR = 0x66666666; private static final int TOP_SHADE_COLOR = 0xDDDDDD; private static final int BOTTOM_SHADE_COLOR = 0x333333; private static final int SCROLLBAR_WIDTH = 8; private static final int SCROLLBAR_RIGHT_MARGIN = 0; private static final int SCROLLBAR_LEFT_MARGIN = 0; // The eventual height of the slider in pixels private int sliderHeight; // The eventual horizontal slider position - in this Manager's coordinates private int sliderXPosition; // Height and width limits - useful for creating Managers which should not take // the whole provided area private int maxVisibleHeight; private int maxVisibleWidth; // Actual height and width - set in sublayout() below private int visibleHeight; private int visibleWidth; // Total (a.k.a "virtual") height of the Manager private int totalHeight; // Do we need to display a scrollbar? private boolean isScrolling; // Constructors - please observe the use of width and height limits // Also - you do want to use VERTICAL_SCROLL but definitely not the // default "scrollbar", thus we made that a default public VerticalScrollManager() { this(VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR, Integer.MAX_VALUE, Integer.MAX_VALUE); } public VerticalScrollManager(int w, int h) { this(VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR, w, h); } public VerticalScrollManager(long style) { this(style, Integer.MAX_VALUE, Integer.MAX_VALUE); } public VerticalScrollManager(long style, int w, int h) { super(style); maxVisibleHeight = h; maxVisibleWidth = w; setScrollListener(this); } // This is how we report our desided height and width to the parent manager public int getPreferredHeight() { return visibleHeight; } public int getPreferredWidth() { return visibleWidth; } // This is called by the framework just before displaying this Manager. At this point we are // given the biggest rectangle within the parent Manager that our Manager is allowed to occupy // This is the natural place to make all necessary calculations protected void sublayout(int w, int h) { // Initial value - no scrollbar unless VERTICAL_SCROLL is requested isScrolling = ((getStyle() & VERTICAL_SCROLL) == VERTICAL_SCROLL); // How much room (horizontally) do we need for the scrollbar int scrollbarWidth = isScrolling ? SCROLLBAR_WIDTH + SCROLLBAR_LEFT_MARGIN + SCROLLBAR_RIGHT_MARGIN : 0; // Further limit the given dimensions with the requested size visibleHeight = Math.min(h, maxVisibleHeight); visibleWidth = Math.min(w, maxVisibleWidth); // Before asking the parent class to layout, reserve the necessary room for the scrollbar int myWidth = visibleWidth - scrollbarWidth; super.sublayout(myWidth, visibleHeight); // After the VerticalFieldManager lays out its fields, let's ask it for dimensions and // adjust width back to include the scrollbar visibleHeight = getHeight(); totalHeight = getVirtualHeight(); visibleWidth = getWidth() + scrollbarWidth; // Report our proper dimensions to the parent Manager setExtent(visibleWidth, visibleHeight); // This is necessary for the overall BlackBerry framework to know how far we can scroll // Especially important for touch-screen devices setVirtualExtent(visibleWidth, totalHeight); // Now, let's double check whether any scrollbar is needed // If the visible area is tall enough, let's not bother isScrolling = (visibleHeight < totalHeight); // Finally, determine how big is the slider and where to start painting it horizontally if (isScrolling) { sliderHeight = visibleHeight * visibleHeight / totalHeight; sliderHeight = Math.max(sliderHeight, 1); // show at least one pixel! // Please observe that we reserved the width based on both left and right margin, // but are going to paint based on right margin only - that's how we create // that left margin sliderXPosition = visibleWidth - SCROLLBAR_WIDTH - SCROLLBAR_RIGHT_MARGIN; } } // This is called each time our Manager needs repainting (invalidate(), scrolling, etc.) protected void paint(Graphics g) { // First, paint the fields "normally" super.paint(g); // Now, add the scrollbar if necessary if (isScrolling) { // Determine how far have we scrolled int scrollPosition = getVerticalScroll(); // The slider vertical position on the screen is proportional to the scroll position. // Please observe that we add the scroll position to the calculated result since // everything on the screen starts there. All x and y coordinates for this Graphics // object are within the Manager's FULL (virtual) rectangle. int sliderYPosition = scrollPosition * visibleHeight / totalHeight + scrollPosition; // draw the scrollbar g.setColor(SCROLLBAR_COLOR); // Again, scrollbar starts at scroll position (top of the displayed part) and // is visibleHeight high g.fillRect(sliderXPosition, scrollPosition, SCROLLBAR_WIDTH, visibleHeight); // draw the slider g.setColor(SLIDER_COLOR); g.fillRect(sliderXPosition, sliderYPosition, SCROLLBAR_WIDTH, sliderHeight); // draw the shading - make it "3-D" g.setColor(TOP_SHADE_COLOR); if (sliderHeight > 2) { g.drawLine(sliderXPosition, sliderYPosition, sliderXPosition + SCROLLBAR_WIDTH - 1, sliderYPosition); } g.drawLine(sliderXPosition, sliderYPosition, sliderXPosition, sliderYPosition + sliderHeight - 1); g.setColor(BOTTOM_SHADE_COLOR); if (sliderHeight > 2) { g.drawLine(sliderXPosition, sliderYPosition + sliderHeight - 1, sliderXPosition + SCROLLBAR_WIDTH - 1, sliderYPosition + sliderHeight - 1); } g.drawLine(sliderXPosition + SCROLLBAR_WIDTH - 1, sliderYPosition, sliderXPosition + SCROLLBAR_WIDTH - 1, sliderYPosition + sliderHeight - 1); } } public void scrollChanged(Manager mgr, int newX, int newY) { if (mgr == this) { invalidate(newX + sliderXPosition, newY, SCROLLBAR_WIDTH + SCROLLBAR_RIGHT_MARGIN, getVisibleHeight()); } } }
package mypackage;
import net.rim.device.api.math.Fixed32;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.ui.Color;
import net.rim.device.api.util.MathUtilities;
public class GeneralSubz {
public Bitmap getScaledBitmapImage(String imagename,int width,int height)
{
EncodedImage image = EncodedImage.getEncodedImageResource(imagename);
int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
// int width = image.getWidth() /2;
// int height = image.getHeight() /2;
// int width = deviceWidth;
// int height = deviceHeight;
int requiredWidthFixed32 = Fixed32.toFP(width);
int requiredHeightFixed32 = Fixed32.toFP(height);
int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);
image = image.scaleImage32(scaleXFixed32, scaleYFixed32);
return image.getBitmap();
}//getScaledBitmapImage
}this is what happens with os5


So could someone show me what I'm doing wrong
Thanks