BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/index.php)
-   Developer Forum (http://www.blackberryforums.com/forumdisplay.php?f=15)
-   -   About TreeField (http://www.blackberryforums.com/showthread.php?t=68162)

renuka_anil 03-07-2007 12:07 AM

About TreeField
 
Hi All,

I'm new to Blackberry developement.
I want to develop a application using tree. I already done some implementation regarding this.

i want to add columns in front of each node. The columns may contain any value? And there are any number of columns.

My problem is that I can't able to add them. I tried it, but screen get flickerred when I scroll it.

Is anyone have any idea about what we can do for it?

Also, I want to change Text_color and background color of the node on which current focus is there. I could not able do it properly. So, also need help in this regard too,

Thanks

Chinasaur 03-07-2007 08:00 PM

This would have been better if posted in the Developer forum. Hopefully a nice mod, or other dev, will wander in here and move it for you..or answer the question.

Luck!

NJBlackBerry 03-07-2007 08:05 PM

** Moving to the Developer's Forum **

Skipper_Joe 03-08-2007 09:41 AM

it is not clear what columns do you mean. Can you post short code sample, which shows your problem?

renuka_anil 03-09-2007 07:42 AM

About Treefield
 
Hi all,

I want to display data as tree which is in xml file .

I'll show u for example as follows


Department
|
MSc
|
|- Physics
|
|- First year Sub1 Sub2 sub3
| |- stud1 50 60 58
| |- stud2 60 59 60
|-Second year Sub1 Sub2 Sub3
|

like this so on

Columns I'm talking about are subjects in above case. I haven't done any coding for that. But i need to code. So, I'm sorry to say I cn't give sample of code. here tree may increase.
Also , when I click any parent node AND if it collapses or expands according to that columns should be get hidden or shown. I want to know how can I do so. Plz help me out.

If anybody know plz let me know too.

Thanks

Skipper_Joe 03-09-2007 08:50 AM

please, search "BlackBerry Application Developer Guide, Volume 1" for TreeField and TreeFieldCallback description. There is short chapter about it. You can implement TreeFieldCallback and draw anything you want.

renuka_anil 03-13-2007 07:50 AM

About tree- field
 
Hi All,

i got the way to display tree along with table.

But, there is little problem, I got the tree but not in the order I want. Nodes are not in proper way.
First all parents are displayed then their children are shown. They are in order.
But I want order is that If 1st parent is displayed then after that it's all children should be shown then the parent among that children is shown.
E.g
there is tree with following node where P is parent and C is child
P1 - C1, C2, P2
P2 - C3, C4,P3
P3 - P4
P4 - C5, P5

The tree I want is like

P1
- c1
- c2
- p2
- - c3
- - c4
- - p3
- - - p4
- - - - c5
- - - - p5

But I got

P1
- p2
- - p3
- - - p4
- - - - p5
- - - - c5
- - c3
- - c4
- c1
- c2


Can anybody help me to make tree in correct order.

Thanks

bemshaswing 03-13-2007 08:00 AM

Hi Renuka_anil,
Post your code here, perhaps we can figure out what's wrong.

renuka_anil 03-20-2007 12:04 AM

About Tree field
 
Hi

here is my whole code. I create a class in which tree is dynamically read from XML file generated.


public class CustomChart extends VerticalFieldManager{
// Declaration
private TreeCallback myCallback;
private TreeField myTree;
private boolean hasFocus; //false
private int[] nodeArray;
private int arrLength;
private Util objUtil ;

protected void sublayout(int maxWidth, int maxHeight){
maxWidth = 200 ;
maxHeight = 350;
super.sublayout(maxWidth, maxHeight);
}

//vecParent is vector for all parent node
//vecChild stores childs corresponding to that parent
// sizes is total number of nodes
// strTitle title for tree.

public CustomChart(String strTitle, Vector vecParent, Vector vecChild, int sizes ) {
super(Manager.HORIZONTAL_SCROLL | Manager.VERTICAL_SCROLL);
try{
objUtil = new Util();
//_screen = new MainScreen();
sizes = sizes + 1;
nodeArray = new int[sizes];
myCallback = new TreeCallback();
myTree = new TreeField(myCallback, Field.FOCUSABLE){
//Handles moving the focus within this field.
/* public int moveFocus(int amount, int status, int time)
{
invalidateNode(getCurrentNode());
return super.moveFocus(amount,status,time);
//return true;
}*/

//Invoked when this field receives the focus.
/* public void onFocus(int direction)
{
hasFocus = true;
//super.onFocus(direction);
}

//Invoked when a field loses the focus.
public void onUnfocus()
{
hasFocus = false;
//super.onUnfocus();
invalidate();
}
*/
//Over ride paint to produce the alternating colours.
/* public void paint(Graphics graphics)
{
//Get the current clipping region as it will be the only part that requires repainting
XYRect redrawRect = graphics.getClippingRect();
if(redrawRect.y < 0)
{
throw new IllegalStateException("Clipping rectangle is wrong.");
}

//Determine the start location of the clipping region and end.
int rowHeight = getRowHeight();

int curSelected;

//If the ListeField has focus determine the selected row.
if (hasFocus)
{
curSelected = getCurrentNode();
}
else
{
curSelected = -1;
}

int startLine = redrawRect.y / rowHeight;
int endLine = (redrawRect.y + redrawRect.height - 1) / rowHeight;
endLine = Math.min(endLine, getNodeCount() - 1);
int y = startLine * rowHeight;

//Setup the data used for drawing.
int[] yInds = new int[]{y, y, y + rowHeight, y + rowHeight};
int[] xInds = new int[]{0, getPreferredWidth(), getPreferredWidth(), 0};

//Get the ListFieldCallback.
//This sample assumes that the object returned by the get
//method of the callback is a String or has a toString method.
//If this is not the case you will need to add the required logic
//for your implementation.



//Draw each row
for(; startLine <= endLine; ++startLine)
{
if (startLine % 2 == 0 && startLine != curSelected)
{
//Draw the even and non selected rows.
graphics.setColor(LIGHT_TEXT);
graphics.drawShadedFilledPath(xInds, yInds, null, cols, null);
graphics.drawText((String)getCookie(startLine), 0, yInds[0]);
graphics.setColor(DARK_TEXT);
}
else
{
//Draw the odd or selected rows.
graphics.drawText((String)getCookie(startLine), 0, yInds[0]);
}

//Assign new values to the y axis moving one row down.
y += rowHeight;
yInds[0] = y;
yInds[1] = yInds[0];
yInds[2] = y + rowHeight;
yInds[3] = yInds[2];
}
}*/
};
int c = 0;
int j = 0;

String[] strSplit = null;
boolean flgParent = false;

String strTemp = null;

for(int i = 0; i < vecParent.size(); ){
int tmp = i;
tmp = tmp + 1;
boolean flag = true;
String strParent = (String) vecParent.elementAt(i);
String strChild = (String)vecChild.elementAt(i);
strSplit = objUtil.splitMethod(strChild, ',');
for(int cnt = 0; cnt < strSplit.length; cnt++){
if(strSplit[0].equals("0") && flag == true){
if(j == 0){
//j = j + 1;
nodeArray[j] = myTree.addChildNode(0,strParent);
c = j;
flag = false;
} else {
//j = j + 1;
nodeArray[j] = myTree.addChildNode(0,strParent);
c = j;
flag = false;
}
}else{
if(tmp < vecParent.size()){
strTemp = (String)vecParent.elementAt(tmp);
//System.out.println(" strTemp "+strTemp);
}

if(strSplit[cnt].equalsIgnoreCase(strTemp)){
strParent = strTemp;
nodeArray[j] = myTree.addChildNode(nodeArray[c],strParent);
c = j;
flgParent = true;
i = i + 1;
}else{
nodeArray[j] = myTree.addChildNode(nodeArray[c],strSplit[cnt]);
flgParent = false;
}

}
j = j + 1;
}
if( flgParent == false)
i = i + 1;
flag = true;
}


add(new LabelField (
strTitle , LabelField.NON_FOCUSABLE | LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH
));

add(myTree);

}catch(Exception e){
System.out.println("Exception in buiding chart : "+e.toString());
}// end of try-catch
}// end of constructor.


private class TreeCallback implements TreeFieldCallback {
Util objUtils;

private TreeCallback(){
objUtils = new Util();
}
public void drawTreeItem(TreeField _tree, Graphics g, int node, int y, int width, int indent) {
String text = (String)_tree.getCookie(node);
indent = indent + 5;
int row = _tree.getCurrentNode();
objUtils.setCurrentRow(row);
//System.out.println(" strParent "+text);
g.drawText(text, indent, y);
}
}
}// end of class



Please check this out. And tell me what's wrong with this. Also, can u tell me how to change textcolor and background color for current node having focus on it. Also how to add bitmaps for parent and child. Parent has different bitmaps than child


Thanks
:-( :?


All times are GMT -5. The time now is 03:15 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.