BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 03-12-2010, 07:36 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2008
Model: 9000
PIN: N/A
Carrier: rogers
Posts: 26
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Variable height ObjectListField items PLEASE HELP

Please Login to Remove!

I'm trying to do what the SMS mail client does where the mail messages are one height and the day names are another (about half the height).

I also need to use the elipsis... function so I uses a Manager class to put the rows into the ObjectListField.

I CAN'T seem to vary the heights of the fields. I've tried everything and I hope someone can point me in the right direction.

THANK YOU to anyone who responds. !!!




package ca.itpartners.components;

import java.util.Vector;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.DrawStyle;
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.Keypad;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
import net.rim.device.api.ui.component.ObjectListField;
import net.rim.device.api.ui.container.HorizontalFieldMan ager;
import net.rim.device.api.ui.container.VerticalFieldManag er;

public class FriendsListField extends ObjectListField implements ListFieldCallback {
private Friend[] friends;
private Vector rows;



private class TableRowManager extends Manager {

public TableRowManager(int style,int h){
super(style);
setRowHeight(h) ;

}


public void drawRow(Graphics g, int x, int y, int width, int height)
{
layout(width, height);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x00CACACA);
g.drawLine(0, 0, getPreferredWidth(), 0);
g.popContext();
}

protected void sublayout(int width, int height) {
Field field ;
int numberOfFields = getFieldCount();

for (int i = 0; i < numberOfFields; i++)
{
field = getField(i);
setPositionChild(field,0, 0+i*20);
layoutChild(field, width, height);
}
setExtent(width, getPreferredHeight());
}
public int getPreferredWidth()
{
return Display.getWidth();
}

// The preferred height of a row is the "row height" as defined in the
// enclosing list.
public int getPreferredHeight()
{
return getRowHeight();
}
}



public FriendsListField(Friend[] friends) {

setEmptyString("Empty", DrawStyle.HCENTER);
setCallback(this);

this.friends = friends;
rows = new Vector();

for(int x = 0; x < friends.length; ++x)
{
TableRowManager row = new TableRowManager( LabelField.ELLIPSIS,friends[x].getHeight());
if( friends[x].isLabel ) {
LabelField friend = new LabelField(friends[x].getName(), LabelField.ELLIPSIS | LabelField.NON_FOCUSABLE);
int height = Font.getDefault().getHeight()*2;
friend.setFont( Font.getDefault().derive(Font.ITALIC, height));
row.add(friend);
}else {
LabelField friend = new LabelField(friends[x].getName(), DrawStyle.ELLIPSIS | LabelField.FOCUSABLE);
int height = Font.getDefault().getHeight() ;
friend.setFont( Font.getDefault().derive(Font.ITALIC, height));
row.add(friend);
LabelField dateLoc = new LabelField(friends[x].getLocationTime(), DrawStyle.ELLIPSIS);
int height1 = Font.getDefault().getHeight();
dateLoc.setFont( Font.getDefault().derive(Font.ITALIC, height));
row.add(dateLoc);
}
rows.addElement(row);
}

setSize(rows.size());
this.setSelectedIndex(1) ;
}




public void drawListRow(ListField listField, Graphics graphics, int index,
int y, int width) {
FriendsListField list = (FriendsListField) listField;
TableRowManager rowManager = (TableRowManager)list.rows.elementAt(index);
rowManager.drawRow(graphics, 0, y, width,friends[index].getHeight());

}

public Object get(ListField listField, int index) {
return friends[index];
}

public int getPreferredWidth(ListField listField) {
return Display.getWidth();
}

public int indexOfList(ListField listField, String prefix, int start) {
return -1;
}

}
Offline  
Old 03-12-2010, 09:59 AM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2010
Model: N/A
PIN: N/A
Carrier: Fledge
Posts: 43
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

ronaldg,

In any class that extends Field, you can override the layout() method to set the extent of your field.

The width and height parameters in the layout(int width, int height) method correspond to the width and height parameters in the manager's layoutChild(Field field, int width, int height) method that is called within the manager's sublayout method.

As a result, that width and height is only a guideline for the field, but the field can layout itself if you choose to have it do so (but it may not be the best idea). If you set your field's extent to be larger than the area that the manager has allowed it, then the field will be clipped.

So to adjust the area that a field is ALLOWED to use, implement the manager's sublayout method to perform layoutchild(f, w, h) with the area you want to give to that field. Then implement your field's layout method to use the full width and height that it is allowed.

For example:
Code:
Field myField = new Field() {
    protected void layout(int width, int height) {
        setExtent(width, height);
    }
};

Manager myManager = new Manager(0) {
    protected void sublayout(int width, int height) { 
        layoutChild(myField, 200, 200); //give the field 200x200pixels to lay itself out
        setPositionChild(myField, 0, 0);
    }
};

myManager.add(myField);
add(myManager);
Also, to answer your question about Ellipses, you don't need to use a manager or a labelfield to display text with ellipses when it is clipped. In any field's paint method, you can use the Graphics.drawText(String text, int x, int y, int flags, int width). If you specify a width and DrawStyle.ELLIPSIS, if the text is wider than the width, the ellipsis will be inserted where the text gets cut off.

Last edited by jacob.tabak : 03-12-2010 at 10:02 AM.
Offline  
Old 03-12-2010, 11:24 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2008
Model: 9000
PIN: N/A
Carrier: rogers
Posts: 26
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much for replying. Thanks about the elipsis.

I did exactly this. The only thing I changed from below is to add overriding the layout in the Field. It still comes out even sizes.
I'm going nuts with this.

Thanks for the reply.

When I debug I see the size coming into the managers sublayout as the correct size.
I set the extend with that size
for example
i see
20
then
80
then
80
then
20
They all get drawn at 80

any other suggestions?



Quote:
Originally Posted by jacob.tabak View Post
ronaldg,

In any class that extends Field, you can override the layout() method to set the extent of your field.

The width and height parameters in the layout(int width, int height) method correspond to the width and height parameters in the manager's layoutChild(Field field, int width, int height) method that is called within the manager's sublayout method.

As a result, that width and height is only a guideline for the field, but the field can layout itself if you choose to have it do so (but it may not be the best idea). If you set your field's extent to be larger than the area that the manager has allowed it, then the field will be clipped.

So to adjust the area that a field is ALLOWED to use, implement the manager's sublayout method to perform layoutchild(f, w, h) with the area you want to give to that field. Then implement your field's layout method to use the full width and height that it is allowed.

For example:
Code:
Field myField = new Field() {
    protected void layout(int width, int height) {
        setExtent(width, height);
    }
};

Manager myManager = new Manager(0) {
    protected void sublayout(int width, int height) { 
        layoutChild(myField, 200, 200); //give the field 200x200pixels to lay itself out
        setPositionChild(myField, 0, 0);
    }
};

myManager.add(myField);
add(myManager);
Also, to answer your question about Ellipses, you don't need to use a manager or a labelfield to display text with ellipses when it is clipped. In any field's paint method, you can use the Graphics.drawText(String text, int x, int y, int flags, int width). If you specify a width and DrawStyle.ELLIPSIS, if the text is wider than the width, the ellipsis will be inserted where the text gets cut off.
Offline  
Old 03-12-2010, 12:08 PM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Mar 2010
Model: N/A
PIN: N/A
Carrier: Fledge
Posts: 43
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

ronaldg,

I apologize for the hasty answer earlier, I haven't actually used ObjectListField before. I played with your code a bit and read the API for ObjectListField and it says this:

Code:
public void setRowHeight(int rowHeight)
         Sets the height of each row in the list field.
The "each" implies that all rows are the same height. Since ObjectListField is a field and not a manager, you can't override the sublayout() method to manually set the height of each field.

Rather than using an ObjectListField, why don't you just use a custom vertical field manager, and override OnFocus, navigationClick, kehChar, isFocusable, etc and add a FieldChangeListener to listen for events?
Offline  
Old 03-12-2010, 12:42 PM   #5 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2008
Model: 9000
PIN: N/A
Carrier: rogers
Posts: 26
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply again. Yes I am going to re-think the design and do exactly that.
Thanks again.
Offline  
Old 03-12-2010, 06:07 PM   #6 (permalink)
New Member
 
Join Date: Jun 2008
Model: 8700
PIN: N/A
Carrier: AT&T
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

void setRowHeight(int rowHeight,int row) is a method. it exists in 5.0 and it exists in 4.2.1. I don't know if will work in between with standard JDEs.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.