1. hellcry's Avatar
    Hi.
    I am new to BB development(have been working on it for 3-4 days) and i am stuck with a problem. Here are the details of my IDE.
    I am using JDE 4.2.1 and running bb 8800 simulator.

    My Project:
    I need to display bitmaps on a text field, be it basicedit, edit, richtext.
    I am extending EditField:

    Code:
    public class CustomTextField extends  EditField implements KeyListener
    {
    and overriding the paint method and here is my main logic of drawing the bitmaps using g.drawBitmap

    Code:
    protected void paint(Graphics g)
    {
    .
    .
         super.paint(g);
    .
    .
       g.drawBitmap(x, y, bitMap.getWidth(), bitMap.getHeight(),bitMap, 0, 0);
    .
    .
    }

    I am creating a VerticalFieldManager and adding an instance of my CustomTextField:
    Code:
    manager = new VerticalFieldManager(Manager.VERTICAL_SCROLL|Manager.VERTICAL_SCROLLBAR);
     CustomTextField c2= new CustomTextField("T2:", "", 100,EditField.FOCUSABLE|EditField.FILTER_DEFAULT|EditField.FIELD_LEFT,30);
    manager.add(c2);
    With this much code only one line of my field is available, meaning when i draw bitmaps and i reach the end of the line, no new line gets inserted and i am still able to draw, or better, insert new bitmaps but they are not visible. But if i override layout:

    Code:
    protected void layout(int width, int height)
    {
            setExtent(100,100);
    }
    I can view more lines but i am not able to scroll past the visible area.

    Any advice/suggestions/hints as to how to view past the visible area will be greatly appreciated.
    Also, the edit fields default behavior is that when the inserted/typed text reaches the end of the line a new line gets inserted, pushing other fields below it down 1 line. I havent been able to provide this feature with my custom field. I would like to know how to do this.

    I hope someone can help me out here.
    Thanks in advance!

    Regards,
    hellcry.
    11-13-09 04:18 AM
  2. QuiteSimple's Avatar
    Hi,

    first at all, why don't you use BitmapField? It seems to do what you are trying to achieve with the CustomTextField

    As for the visible area, if you define your VerticalFieldManager with USE_ALL_HEIGHT style, it may help.
    11-13-09 06:33 AM
  3. hellcry's Avatar
    Thanks for replying back!
    Well i think i should provide a few more details about my project.
    I am creating a transliterator for BB. It functions similar to Google transliterator. The user enters text in english, presses space and the english word is replaced by the appropriate transliterated bitmap image. So i need textfield to accept user input and then i need to display the bitmap. The reason i am displaying the converted word in bitmap is since BB doesnt provide support for regional(Indic in my case) languages.
    I am done coding the transliteration part but now the only hurdle remaining is displaying the obtained bitmap.
    11-13-09 07:00 AM
  4. QuiteSimple's Avatar
    I guess that you are not writing every single char, but whole sentence or a bunch of words together. I think that you have to do the line adding by yourself. So you have to compute the line length (Display.getWidth()) or similar method and when you need to add additional line, you could just start drawing at (y+fontHeight) position.

    Further is maybe a good idea to define the CustomTextField with USE_ALL_HEIGHT so it takes the whole screen
    11-13-09 09:06 AM
  5. hellcry's Avatar
    yep. I am drawing one word at a time. And i dont want to use the complete screen. Well, the app i am writing is generic in nature. It will be used to provide applications in regional languages and hence there will be all sorts of fields on the same screen. Imagine a messaging application but only in a regional language. So using the whole screen just for one field beats the bigger purpose.

    And i have tried what you have suggested, ie drawing at y+fontHeight after exhausting a line but the problem with that is:

    1. If i add the Custom field on to the main/full screen, i am able to write multiple lines but if i have other fields (this might be a difficult to explain..I would have posted some pics if i were in my company but i am not at the moment...)say taking 20pixels height on the screen, then the bitmaps wont be displayed on these 20pixels but when enough number of lines(of bitmaps) are added to out grow the 2nd field, i'll be again able to see the bitmaps. The solution to this will be if i am able to push the 2nd field down one line every time a add a new line to the Custom field. I am not able to find how to do this though.(But the EditField and others do this by default. I wish i knew how!)

    2. If i add the Custom field on to the VerticalFieldManager, i have to use setExtent(height,width) to set the bounds of my Custom field(otherwise only one line will be provided by default). I am able to display my bitmaps within this bound, ie only the visible part. To display the hidden part i need to provide a scroll facility and i have no idea ** to do that either.

    I wish i had some more experience with BB coding but unfortunately i dont and i have never used Swing or Awt.
    11-13-09 11:48 AM
  6. QuiteSimple's Avatar
    Thinking of option 1 - if you put all fields inside the same container (no matter if Screen or VerticalFieldManager) and place all of them in the sublayout() method, then you can set their position dynamically based on the same "y" parameter. So every time you need to add line to your CustomTextField you will change the "y" for all, forcing repaint after that should "push" all fields down.
    11-13-09 03:58 PM
  7. hellcry's Avatar
    Thinking of option 1 - if you put all fields inside the same container (no matter if Screen or VerticalFieldManager) and place all of them in the sublayout() method, then you can set their position dynamically based on the same "y" parameter. So every time you need to add line to your CustomTextField you will change the "y" for all, forcing repaint after that should "push" all fields down.
    That sounds very much like a solution i need! As i have already mentioned i dont have a lot of experience with BB programming.
    This is what i know about sublayout(): It is basically used to position the different fields that are added on to the vertical/horizontal field manager. But i do not know how to invoke/use it dynamically. Could you please provide me with a sample code?
    11-15-09 10:29 AM
  8. hellcry's Avatar
    Code:
                      Screen/Manager
                           |
             -------------------------------
             |             |               |
    CustomTextField      OtherFields      ...
    Above hierarchy describes what i have understood from your prv post.
    You want me to add my custom fields and other fields to a Screen(or its scbclasses) or Manager(or its subclasses) and then depending upon the y value in CustomTextField i need to invoke the subLayout method and use setPositionChild to change the location of other fields dynamically.

    But the problem is: How do i communicate the y value from CustomTextField to the Screen/Manager and cause subLayout to get invoked?
    11-17-09 12:40 AM
  9. QuiteSimple's Avatar
    I'm sorry for not responding lately, too much work to do I will try to create for you a small example, so you can see the idea in action.
    11-17-09 01:33 AM
  10. hellcry's Avatar
    I am so glad to hear back from you! Will be looking forward to your example!
    Thank you so much for helping me out!!!
    11-17-09 01:54 AM
LINK TO POST COPIED TO CLIPBOARD