Chat Window Design - Blackberry - blackberry

I try to implement a Chat window( Chat functionality work fine & smooth). I am facing problem in designing Middle & Bottom part. In middle part chat messages & bottom i want to add editable field. If i fixed editable field align bottom chat messages not show, & if i add editable field after bottom, then chat messages shown on screen.
I have used NegativeMarginVerticalFieldManager.
I want field attached bottom of screen & messages show middle with scrollbar. Here i also attach code that i used in chat with dummy messages(without Json data). Thanks
package mypackage;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.*;
public class ChatList extends MainScreen
{
Manager _foreground = new NegativeMarginVerticalFieldManager( USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL );
BasicEditField msg;
public ChatList() {
super( NO_VERTICAL_SCROLL );
setTitle( "Chat" );
// Set the linear background.
this.getMainManager().setBackground(
BackgroundFactory.createLinearGradientBackground(0x91e7ff,0x0099CCFF,0x00336699,0x91e7ff)
);
// Add Field Bottom
HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_HEIGHT | USE_ALL_WIDTH);
VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_WIDTH | FIELD_BOTTOM);
msg = new BasicEditField();
msg.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x999999, Border.STYLE_FILLED));
msg.setBackground(BackgroundFactory.createSolidBackground(0xe0e0e0));
msg.setPadding(5,0,5,0);
msg.setMargin(0,10,0,10);
vfm.add(msg);
hfm.add(vfm);
add(hfm);
}
public boolean keyDown(int keycode, int time) {
if (Keypad.KEY_ENTER == Keypad.key(keycode)) {
String message = msg.getText();
if(!message.equals(""))
{
Border rightBorder = BorderFactory.createBitmapBorder( new XYEdges( 16, 23, 27, 16 ), Bitmap.getBitmapResource( "border_bubble_right.png" ) );
Border leftBorder = BorderFactory.createBitmapBorder( new XYEdges( 16, 16, 27, 23 ), Bitmap.getBitmapResource( "border_bubble_left.png" ) );
addHeading( "Hello Adil!", leftBorder, Field.FIELD_LEFT );
addHeading( "Yeah, I see it", rightBorder, Field.FIELD_RIGHT );
addHeading( "have any update , related to this??", leftBorder, Field.FIELD_LEFT );
addHeading( "No worries, I'll finish it", rightBorder, Field.FIELD_RIGHT );
addHeading( "Middle part Messages", leftBorder, Field.FIELD_LEFT );
addHeading( "Vertically Scroll add in messages", leftBorder, Field.FIELD_LEFT );
addHeading( "have any update!", rightBorder, Field.FIELD_RIGHT );
addHeading( "Better get on that", leftBorder, Field.FIELD_LEFT );
addHeading( "No worries, I'll finish it", rightBorder, Field.FIELD_RIGHT );
addHeading( "Bottom Alignment Basic Editable Field?", leftBorder, Field.FIELD_LEFT );
addHeading( "Probably", rightBorder, Field.FIELD_RIGHT );
addHeading( "Better get on that", leftBorder, Field.FIELD_LEFT );
addHeading( "No worries, I'll finish it", rightBorder, Field.FIELD_RIGHT );
msg.setText("");
// ADD ALL FIELDS
add( _foreground );
}// if condition
else{ Dialog.alert("Please insert message");}
return true;
}
//let the system to pass the event to another listener.
return false;
}
private void addHeading( String label, Border border, long style )
{
LabelField header = new LabelField( label, Field.FOCUSABLE | style );
header.setBorder( border );
header.setMargin( 5, 5, -15, 5 );
_foreground.add( header );
}
}

try this - (i modified your code little bit.)
public class ChatList extends MainScreen
{
Manager _foreground = new NegativeMarginVerticalFieldManager( USE_ALL_WIDTH | USE_ALL_HEIGHT | VERTICAL_SCROLL );
BasicEditField msg;
public ChatList() {
super( NO_VERTICAL_SCROLL );
setTitle( "Chat" );
// Set the linear background.
this.getMainManager().setBackground(
BackgroundFactory.createLinearGradientBackground(0x91e7ff,0x0099CCFF,0x00336699,0x91e7ff)
);
// Add Field Bottom
HorizontalFieldManager hfm = new HorizontalFieldManager(){
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Display.getWidth()/2+60,20); setExtent(Display.getWidth()/2+60,20);
}
};
msg = new BasicEditField(){
};
msg.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x999999, Border.STYLE_FILLED));
msg.setBackground(BackgroundFactory.createSolidBackground(0xe0e0e0));
// msg.setPadding(5,0,5,0);
msg.setPadding(5,0,5,0);
msg.setMargin(0,10,0,10);
hfm.add(msg);
final ButtonField b=new ButtonField("send");
JustifiedHorizontalFieldManager jfm=new JustifiedHorizontalFieldManager(hfm, b,true);
setStatus(jfm);
FieldChangeListener listener=new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
if(field==b){
Border rightBorder = BorderFactory.createBitmapBorder( new XYEdges( 16, 23, 27, 16 ), Bitmap.getBitmapResource( "bubble_right.png" ) );
Border leftBorder = BorderFactory.createBitmapBorder( new XYEdges( 16, 16, 27, 23 ), Bitmap.getBitmapResource( "bubble_left.png" ) );
addHeading( "Hello Adil!", leftBorder, Field.FIELD_LEFT );
addHeading( "Yeah, I see it", rightBorder, Field.FIELD_RIGHT );
addHeading( "have any update , related to this??", leftBorder, Field.FIELD_LEFT );
addHeading( "No worries, I'll finish it", rightBorder, Field.FIELD_RIGHT );
addHeading( "Middle part Messages", leftBorder, Field.FIELD_LEFT );
addHeading( "Vertically Scroll add in messages", leftBorder, Field.FIELD_LEFT );
addHeading( "have any update!", rightBorder, Field.FIELD_RIGHT );
addHeading( "Better get on that", leftBorder, Field.FIELD_LEFT );
addHeading( "No worries, I'll finish it", rightBorder, Field.FIELD_RIGHT );
addHeading( "Bottom Alignment Basic Editable Field?", leftBorder, Field.FIELD_LEFT );
addHeading( "Probably", rightBorder, Field.FIELD_RIGHT );
addHeading( "Better get on that", leftBorder, Field.FIELD_LEFT );
addHeading( "No worries, I'll finish it", rightBorder, Field.FIELD_RIGHT );
msg.setText("");
// ADD ALL FIELDS
add( _foreground );
}
}
};
b.setChangeListener(listener);
}
private void addHeading( String label, Border border, long style )
{
LabelField header = new LabelField( label, Field.FOCUSABLE | style );
header.setBorder( border );
header.setMargin( 5, 5, -15, 5 );
_foreground.add( header );
}
}
JustifiedHorizontalFieldManager.java is given below -
public class JustifiedHorizontalFieldManager extends Manager
{
private static final int SYSTEM_STYLE_SHIFT = 32;
public Field _leftField;
public Field _rightField;
private boolean _giveLeftFieldPriority;
public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority )
{
this( leftField, rightField, giveLeftFieldPriority, Field.USE_ALL_WIDTH );
}
public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority, long style )
{
super( style );
_leftField = leftField;
_rightField = rightField;
add( _leftField );
add( _rightField );
_giveLeftFieldPriority = giveLeftFieldPriority;
}
public JustifiedHorizontalFieldManager( boolean giveLeftFieldPriority, long style )
{
super( style );
_giveLeftFieldPriority = giveLeftFieldPriority;
}
public void addLeftField( Field field )
{
if( _leftField != null ) {
throw new IllegalStateException();
}
_leftField = field;
add( _leftField );
}
public void addRightField( Field field )
{
if( _rightField != null ) {
throw new IllegalStateException();
}
_rightField = field;
add( _rightField );
}
public int getPreferredWidth()
{
return _leftField.getPreferredWidth() + _rightField.getPreferredWidth();
}
public int getPreferredHeight()
{
return Math.max( _leftField.getPreferredHeight(), _rightField.getPreferredHeight() );
}
protected void sublayout( int width, int height )
{
Field firstField;
Field secondField;
if( _giveLeftFieldPriority ) {
firstField = _leftField;
secondField = _rightField;
} else {
firstField = _rightField;
secondField = _leftField;
}
int maxHeight = 0;
int availableWidth = width;
availableWidth -= _leftField.getMarginLeft();
availableWidth -= Math.max( _leftField.getMarginRight(), _rightField.getMarginLeft() );
availableWidth -= _rightField.getMarginRight();
layoutChild( firstField, availableWidth, height - firstField.getMarginTop() - firstField.getMarginBottom() );
maxHeight = Math.max( maxHeight, firstField.getMarginTop() + firstField.getHeight() + firstField.getMarginBottom() );
availableWidth -= firstField.getWidth();
layoutChild( secondField, availableWidth, height - secondField.getMarginTop() - secondField.getMarginBottom() );
maxHeight = Math.max( maxHeight, secondField.getMarginTop() + secondField.getHeight() + secondField.getMarginBottom() );
availableWidth -= secondField.getWidth();
if( !isStyle( Field.USE_ALL_HEIGHT ) ) {
height = maxHeight;
}
if( !isStyle( Field.USE_ALL_WIDTH ) ) {
width -= availableWidth;
}
setPositionChild( _leftField, _leftField.getMarginLeft(), getFieldY( _leftField, height ) );
setPositionChild( _rightField, width - _rightField.getWidth() - _rightField.getMarginRight(), getFieldY( _rightField, height ) );
setExtent( width, height );
}
private int getFieldY( Field field, int height )
{
switch( (int)( ( field.getStyle() & FIELD_VALIGN_MASK ) >> SYSTEM_STYLE_SHIFT ) ) {
case (int)( FIELD_BOTTOM >> SYSTEM_STYLE_SHIFT ):
return height - field.getHeight() - field.getMarginBottom();
case (int)( FIELD_VCENTER >> SYSTEM_STYLE_SHIFT ):
return field.getMarginTop() + ( height - field.getMarginTop() - field.getHeight() - field.getMarginBottom() ) / 2;
default:
return field.getMarginTop();
}
}
public Field getLeftField()
{
return _leftField;
}
public Field getRightField()
{
return _rightField;
}
public void replace( Field oldField, Field newField )
{
if( oldField == newField ) {
// Nothing to do
return;
}
if( oldField == _leftField ) {
_leftField = newField;
} else if( oldField == _rightField ) {
_rightField = newField;
}
add( newField );
delete( oldField );
}
}

Related

Vaadin TreeGrid has no expand or collapse icon

I use Vaadin to create a simple Web Application that contains a single TreeGrid.
The TreeGrid shows up, but there is no handle to expand or collapse a root element ("Year 2010" or "Year 2011") although there are children.
When I use expand(..) Method, the tree is expanded (as shown in the screenshot), but there is no icon to collapse it. In the screenshot below "Year 2011" is the expanded root node where "Customer Project1" and "Customer Project 2" are children.
The project is build with Maven, I use vaadin-bom version 13.0.2 with vaadin-grid-flow-3.0.3.jar.
Below the screenshot there is the code I use. I think the problem must be somewhere in method createTreeGrid().
The working example from Vaadin can be found here
Vaadin example
So anyone any ideas on how to solve this? any help appreciated... :-)
Thorsten
package hello;
#Route
public class MainView extends VerticalLayout
{
public MainView()
{
add( createTreeGrid() );
}
private TreeGrid<Project> createTreeGrid()
{
TreeGrid<Project> treeGrid = new TreeGrid<>();
final List<Project> generateProjectsForYears = generateProjectsForYears( 2010, 2016 );
treeGrid.setItems( generateProjectsForYears, Project::getSubProjects );
treeGrid.addColumn( Project::getName ).setHeader( "Project Name" ).setId( "name-column" );
treeGrid.addColumn( Project::getHoursDone ).setHeader( "Hours Done" );
treeGrid.addColumn( Project::getLastModified ).setHeader( "Last Modified" );
treeGrid.expand( generateProjectsForYears.get( 1 ) ); // works!
return treeGrid;
}
private List<Project> generateProjectsForYears( int startYear, int endYear )
{
List<Project> projects = new ArrayList<>();
for ( int year = startYear; year <= endYear; year++ )
{
Project yearProject = new Project( "Year " + year );
Random random = new Random();
for ( int i = 1; i < 2 + random.nextInt( 5 ); i++ )
{
Project customerProject = new Project( "Customer Project " + i );
customerProject.setSubProjects( Arrays.asList(
new LeafProject( "Implementation", random.nextInt( 100 ), year ),
new LeafProject( "Planning", random.nextInt( 10 ), year ),
new LeafProject( "Prototyping", random.nextInt( 20 ), year ) ) );
yearProject.addSubProject( customerProject );
}
projects.add( yearProject );
}
return projects;
}
private class Project
{
private List<Project> subProjects = new ArrayList<>();
private String name;
public Project( String name )
{
this.name = name;
}
public String getName()
{
return name;
}
public List<Project> getSubProjects()
{
return subProjects;
}
public void setSubProjects( List<Project> subProjects )
{
this.subProjects = subProjects;
}
public void addSubProject( Project subProject )
{
subProjects.add( subProject );
}
public int getHoursDone()
{
return getSubProjects().stream()
.map( project -> project.getHoursDone() )
.reduce( 0, Integer::sum );
}
public Date getLastModified()
{
return getSubProjects().stream()
.map( project -> project.getLastModified() )
.max( Date::compareTo ).orElse( null );
}
}
private class LeafProject extends Project
{
private int hoursDone;
private Date lastModified;
public LeafProject( String name, int hoursDone, int year )
{
super( name );
this.hoursDone = hoursDone;
Random random = new Random();
lastModified = new Date( year - 1900, random.nextInt( 12 ),
random.nextInt( 10 ) );
}
#Override
public int getHoursDone()
{
return hoursDone;
}
#Override
public Date getLastModified()
{
return lastModified;
}
}
}
You have to define a hierarchy column.
So simply replace
treeGrid.addColumn( Project::getName ).setHeader( "Project Name" ).setId( "name-column" );
with
treeGrid.addHierarchyColumn( Project::getName ).setHeader( "Project Name" ).setId( "name-column" );

how to show couple of data in blackberry on single screen

Hi Friend's how can i show couple of data in blackberry on a single screen.
for example:
current Date------------value.
Name------------------- value.
roll--------------------value.
email-id----------------value.
phone-no----------------value.
pass--------------------value.
class-------------------value.
sex---------------------value.
college-----------------value.
city--------------------value.
state-------------------value.
pin code----------------value.
country-----------------value.
public LabelField lbSr, lbDate, lbAllo, lbMob, lbDetail, lbRemark, lbSlaDate, lbEmail, lbStatus, lbspace;
public LabelField lb1Sr, lb1Date, lb1Allo, lb1Mob, lb1Detail, lb1Remark, lb1SlaDate, lb1Email, lb1Status;
public JustifiedHorizontalFieldManager jhfm1,jhfm2,jhfm3,jhfm4,jhfm5,jhfm6,jhfm7,jhfm8,jhfm9;
VerticalFieldManager vfm=new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL);
lb1Sr = new LabelField("SRNo :");
lb1Sr.setColor(Color.BLACK);
lbSr = new LabelField(strSerno);
lbSr.setColor(Color.BLACK);
lb1Date = new LabelField("SRDate :");
lb1Date.setColor(Color.BLACK);
lbDate = new LabelField(strDate);
lbDate.setColor(Color.BLACK);
lb1Allo = new LabelField("AllocDate :");
lb1Allo.setColor(Color.BLACK);
lbAllo = new LabelField(strAllo);
lbAllo.setColor(Color.BLACK);
lb1Mob = new LabelField("MobNo :");
lb1Mob.setColor(Color.BLACK);
lbMob = new LabelField(strMob);
lbMob.setColor(Color.BLACK);
lb1Detail = new LabelField("SRDetails :");
lb1Detail.setColor(Color.BLACK);
lbDetail = new LabelField(strDetail);
lbDetail.setColor(Color.BLACK);
lb1Remark = new LabelField("Remarks :");
lb1Remark.setColor(Color.BLACK);
lbRemark = new LabelField(strRemark);
lbRemark.setColor(Color.BLACK);
lb1SlaDate = new LabelField("SLADate :");
lb1SlaDate.setColor(Color.BLACK);
lbSlaDate = new LabelField(strSldate);
lbSlaDate.setColor(Color.BLACK);
lb1Email = new LabelField("Email :");
lb1Email.setColor(Color.BLACK);
lbEmail = new LabelField(strEmail);
lbEmail.setColor(Color.BLACK);
lb1Status = new LabelField("Status :");
lb1Status.setColor(Color.BLACK);
lbStatus = new LabelField(strStatus);
lbStatus.setColor(Color.BLACK);
jhfm1=new JustifiedHorizontalFieldManager(lb1Sr, lbSr, true);
vfm.add(jhfm1);
jhfm2=new JustifiedHorizontalFieldManager(lb1Date, lbDate, true);
vfm.add(jhfm2);
jhfm3=new JustifiedHorizontalFieldManager(lb1Allo, lbAllo, true);
vfm.add(jhfm3);
jhfm4=new JustifiedHorizontalFieldManager(lb1Mob, lbMob, true);
vfm.add(jhfm4);
hfm5=new JustifiedHorizontalFieldManager(lb1Detail, lbDetail, true);
vfm.add(jhfm5);
jhfm6=new JustifiedHorizontalFieldManager(lb1Remark, lbRemark, true);
vfm.add(jhfm6);
jhfm7=new JustifiedHorizontalFieldManager(lb1SlaDate, lbSlaDate, true);
vfm.add(jhfm7);
jhfm8=new JustifiedHorizontalFieldManager(lb1Email, lbEmail, true);
vfm.add(jhfm8);
jhfm9=new JustifiedHorizontalFieldManager(lb1Status, lbStatus, true);
vfm.add(jhfm9);
add(vfm);
I want to show all data with both side scroll option.
try this code -
VerticalFieldManager vfm=new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL);
LabelField date=new LabelField("Date :");
LabelField date_value=new LabelField(value);
JustifiedHorizontalFieldManager jfm_date=new JustifiedHorizontalFieldManager(date,date_value, true);
vfm.add(jfm_date);
LabelField name=new LabelField("Name:");
LabelField name_value=new LabelField(value);
JustifiedHorizontalFieldManager jfm_name=new JustifiedHorizontalFieldManager(name,name_value, true);
vfm.add(jfm_name);
add(vfm);
And so on....add all the fields like this.
JustifiedHorizontalFieldManager class is given below-
public class JustifiedHorizontalFieldManager extends Manager
{
private static final int SYSTEM_STYLE_SHIFT = 32;
public Field _leftField;
public Field _rightField;
private boolean _giveLeftFieldPriority;
public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority )
{
this( leftField, rightField, giveLeftFieldPriority, Field.USE_ALL_WIDTH );
}
public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority, long style )
{
super( style );
_leftField = leftField;
_rightField = rightField;
add( _leftField );
add( _rightField );
_giveLeftFieldPriority = giveLeftFieldPriority;
}
public JustifiedHorizontalFieldManager( boolean giveLeftFieldPriority, long style )
{
super( style );
_giveLeftFieldPriority = giveLeftFieldPriority;
}
public void addLeftField( Field field )
{
if( _leftField != null ) {
throw new IllegalStateException();
}
_leftField = field;
add( _leftField );
}
public void addRightField( Field field )
{
if( _rightField != null ) {
throw new IllegalStateException();
}
_rightField = field;
add( _rightField );
}
public int getPreferredWidth()
{
return _leftField.getPreferredWidth() + _rightField.getPreferredWidth();
}
public int getPreferredHeight()
{
return Math.max( _leftField.getPreferredHeight(), _rightField.getPreferredHeight() );
}
protected void sublayout( int width, int height )
{
Field firstField;
Field secondField;
if( _giveLeftFieldPriority ) {
firstField = _leftField;
secondField = _rightField;
} else {
firstField = _rightField;
secondField = _leftField;
}
int maxHeight = 0;
int availableWidth = width;
availableWidth -= _leftField.getMarginLeft();
availableWidth -= Math.max( _leftField.getMarginRight(), _rightField.getMarginLeft() );
availableWidth -= _rightField.getMarginRight();
layoutChild( firstField, availableWidth, height - firstField.getMarginTop() - firstField.getMarginBottom() );
maxHeight = Math.max( maxHeight, firstField.getMarginTop() + firstField.getHeight() + firstField.getMarginBottom() );
availableWidth -= firstField.getWidth();
layoutChild( secondField, availableWidth, height - secondField.getMarginTop() - secondField.getMarginBottom() );
maxHeight = Math.max( maxHeight, secondField.getMarginTop() + secondField.getHeight() + secondField.getMarginBottom() );
availableWidth -= secondField.getWidth();
if( !isStyle( Field.USE_ALL_HEIGHT ) ) {
height = maxHeight;
}
if( !isStyle( Field.USE_ALL_WIDTH ) ) {
width -= availableWidth;
}
setPositionChild( _leftField, _leftField.getMarginLeft(), getFieldY( _leftField, height ) );
setPositionChild( _rightField, width - _rightField.getWidth() - _rightField.getMarginRight(), getFieldY( _rightField, height ) );
setExtent( width, height );
}
private int getFieldY( Field field, int height )
{
switch( (int)( ( field.getStyle() & FIELD_VALIGN_MASK ) >> SYSTEM_STYLE_SHIFT ) ) {
case (int)( FIELD_BOTTOM >> SYSTEM_STYLE_SHIFT ):
return height - field.getHeight() - field.getMarginBottom();
case (int)( FIELD_VCENTER >> SYSTEM_STYLE_SHIFT ):
return field.getMarginTop() + ( height - field.getMarginTop() - field.getHeight() - field.getMarginBottom() ) / 2;
default:
return field.getMarginTop();
}
}
public Field getLeftField()
{
return _leftField;
}
public Field getRightField()
{
return _rightField;
}
public void replace( Field oldField, Field newField )
{
if( oldField == newField ) {
// Nothing to do
return;
}
if( oldField == _leftField ) {
_leftField = newField;
} else if( oldField == _rightField ) {
_rightField = newField;
}
add( newField );
delete( oldField );
}
}

In BlackBerry UI Right Align Issue

In BlackBerry UI I am trying to align some LabelFields Right aligned and left aligned:
For this I have created one VertiFieldManager at top level then Adding a HorizontalFieldmanager to it and all lalbelFields are added to horizontalFieldManager,
Horizontal field Manager is forcing content to Left aligned.
How can I align the fields in Right side?
I tried spacing but it does not looks good in BB devices having different Pixcels resolution.
Please advise.
i'm still new on BB, but have you tried to change Long style for the HorizontalField ?
try this code -
JustifiedHorizontalFieldManager j=new JustifiedHorizontalFieldManager(new NullField(),your_field, true);
add(j);
//JustifiedHorizontalFieldManager class is given below.
public class JustifiedHorizontalFieldManager extends Manager
{
private static final int SYSTEM_STYLE_SHIFT = 32;
public Field _leftField;
public Field _rightField;
private boolean _giveLeftFieldPriority;
public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority )
{
this( leftField, rightField, giveLeftFieldPriority, Field.USE_ALL_WIDTH );
}
public JustifiedHorizontalFieldManager( Field leftField, Field rightField, boolean giveLeftFieldPriority, long style )
{
super( style );
_leftField = leftField;
_rightField = rightField;
add( _leftField );
add( _rightField );
_giveLeftFieldPriority = giveLeftFieldPriority;
}
public JustifiedHorizontalFieldManager( boolean giveLeftFieldPriority, long style )
{
super( style );
_giveLeftFieldPriority = giveLeftFieldPriority;
}
public void addLeftField( Field field )
{
if( _leftField != null ) {
throw new IllegalStateException();
}
_leftField = field;
add( _leftField );
}
public void addRightField( Field field )
{
if( _rightField != null ) {
throw new IllegalStateException();
}
_rightField = field;
add( _rightField );
}
public int getPreferredWidth()
{
return _leftField.getPreferredWidth() + _rightField.getPreferredWidth();
}
public int getPreferredHeight()
{
return Math.max( _leftField.getPreferredHeight(), _rightField.getPreferredHeight() );
}
protected void sublayout( int width, int height )
{
Field firstField;
Field secondField;
if( _giveLeftFieldPriority ) {
firstField = _leftField;
secondField = _rightField;
} else {
firstField = _rightField;
secondField = _leftField;
}
int maxHeight = 0;
int availableWidth = width;
availableWidth -= _leftField.getMarginLeft();
availableWidth -= Math.max( _leftField.getMarginRight(), _rightField.getMarginLeft() );
availableWidth -= _rightField.getMarginRight();
layoutChild( firstField, availableWidth, height - firstField.getMarginTop() - firstField.getMarginBottom() );
maxHeight = Math.max( maxHeight, firstField.getMarginTop() + firstField.getHeight() + firstField.getMarginBottom() );
availableWidth -= firstField.getWidth();
layoutChild( secondField, availableWidth, height - secondField.getMarginTop() - secondField.getMarginBottom() );
maxHeight = Math.max( maxHeight, secondField.getMarginTop() + secondField.getHeight() + secondField.getMarginBottom() );
availableWidth -= secondField.getWidth();
if( !isStyle( Field.USE_ALL_HEIGHT ) ) {
height = maxHeight;
}
if( !isStyle( Field.USE_ALL_WIDTH ) ) {
width -= availableWidth;
}
setPositionChild( _leftField, _leftField.getMarginLeft(), getFieldY( _leftField, height ) );
setPositionChild( _rightField, width - _rightField.getWidth() - _rightField.getMarginRight(), getFieldY( _rightField, height ) );
setExtent( width, height );
}
private int getFieldY( Field field, int height )
{
switch( (int)( ( field.getStyle() & FIELD_VALIGN_MASK ) >> SYSTEM_STYLE_SHIFT ) ) {
case (int)( FIELD_BOTTOM >> SYSTEM_STYLE_SHIFT ):
return height - field.getHeight() - field.getMarginBottom();
case (int)( FIELD_VCENTER >> SYSTEM_STYLE_SHIFT ):
return field.getMarginTop() + ( height - field.getMarginTop() - field.getHeight() - field.getMarginBottom() ) / 2;
default:
return field.getMarginTop();
}
}
public Field getLeftField()
{
return _leftField;
}
public Field getRightField()
{
return _rightField;
}
public void replace( Field oldField, Field newField )
{
if( oldField == newField ) {
// Nothing to do
return;
}
if( oldField == _leftField ) {
_leftField = newField;
} else if( oldField == _rightField ) {
_rightField = newField;
}
add( newField );
delete( oldField );
}
}
There are no nice solution unfortunately. The smaller than previous I think this:
HorizontalFieldManager hfm = new HorizontalFieldManager();
LabelField leftField = new LabelField("One");
hfm.add(leftField);
LabelField rightField = new LabelField("Two", LabelField.USE_ALL_WIDTH | DrawStyle.RIGHT);
hfm.add(rightField);
Basically we use all available width area for second field and ask it to draw text as right aligned.
This solution is Ok because LabeLField is not focusable. As soon as you have to deal with focusable fields use solution from #Signare.

Usage of vertical field manager with eyelid field manager in blackberry

I have created 3 tabs in my blackberry application.I now want to add an eyelid field manager that allows for an eye lid component only on the third tab.
With the current code, i am able to create an eyelid but it doesnt show me any of the tabs.
// setup the tab model with 3 tabs
final PaneManagerModel model = new PaneManagerModel();
model.enableLooping( true );
// setup the first tab
VerticalFieldManager vfm = new VerticalFieldManager(
Field.USE_ALL_HEIGHT | Field.USE_ALL_WIDTH |
Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL );
LabelField lbl = new LabelField( "Content for tab 1", Field.FOCUSABLE );
vfm.add( lbl );
ButtonField _btnGoBack = new ButtonField(" Tab 3 ",ButtonField.FIELD_HCENTER | ButtonField.CONSUME_CLICK);
_btnGoBack.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field,int context)
{
System.out.println("Inside button");
jumpTo(2,PaneManagerView.DIRECTION_NONE);
}
});
vfm.add(_btnGoBack);
MyLabelField myLbl = new MyLabelField( "Tab 1" );
NullField nullFld = new NullField( Field.FOCUSABLE );
HorizontalFieldManager hfm = new HorizontalFieldManager();
hfm.add( nullFld );
hfm.add( myLbl );
Pane pane = new Pane( hfm, vfm );
model.addPane( pane );
// setup the second tab
vfm = new VerticalFieldManager(
Field.USE_ALL_HEIGHT | Field.USE_ALL_WIDTH |
Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL );
lbl = new LabelField( "Content for tab 2", Field.FOCUSABLE );
vfm.add( lbl );
myLbl = new MyLabelField( "Tab 2" );
nullFld = new NullField( Field.FOCUSABLE );
hfm = new HorizontalFieldManager();
hfm.add( nullFld );
hfm.add( myLbl );
pane = new Pane( hfm, vfm );
model.addPane( pane );
//Setup the third tab
vfm = new VerticalFieldManager(
Field.USE_ALL_HEIGHT | Field.USE_ALL_WIDTH |
Manager.NO_VERTICAL_SCROLL | Manager.NO_HORIZONTAL_SCROLL );
lbl = new LabelField( "Content for tab 3", Field.FOCUSABLE );
vfm.add( lbl );
myLbl = new MyLabelField( "Tab 3" );
nullFld = new NullField( Field.FOCUSABLE );
hfm = new HorizontalFieldManager();
hfm.add( nullFld );
hfm.add( myLbl );
((LabelField)myLbl).setEnabled(false);
((NullField)nullFld).setEnabled(false);
Here i start the implemenatation for eyelid field manager
_eyelidFieldManager = new EyelidFieldManager();
// Change the display time from the default 1.2s
_eyelidFieldManager.setEyelidDisplayTime(2000);
// Add components to the north eye-lid of the blinker
_eyelidFieldManager.vfm.addTop(new LabelField(" Do you wish to send report to client?",LabelField.FIELD_HCENTER | LabelField.NON_FOCUSABLE));
_eyelidFieldManager.addTop(new LabelField(" ",LabelField.FIELD_HCENTER | LabelField.NON_FOCUSABLE));
// Add components to the south eye-lid of the blinker
_eyelidFieldManager.addBottom(new LabelField(" Send Report as: ",LabelField.FIELD_HCENTER | LabelField.NON_FOCUSABLE));
HorizontalFieldManager buttonPanel = new HorizontalFieldManager(Field.FIELD_HCENTER | Field.USE_ALL_WIDTH);
buttonPanel.add(new ButtonField("SMS"));
buttonPanel.add(new ButtonField("Email"));
_eyelidFieldManager.addBottom(buttonPanel);
// Add checkbox in non-eyelid region for showing eyelids on user input
_showOnInputCheckbox = new CheckboxField("Show eyelids on user input", true, Field.FIELD_HCENTER);
_showOnInputCheckbox.setChangeListener(this);
add(_eyelidFieldManager);
// Disable virtual keyboard so it doesn't obscure bottom eyelid
VirtualKeyboard keyboard = getVirtualKeyboard();
if( keyboard != null )
{
keyboard.setVisibility(VirtualKeyboard.IGNORE);
}
pane = new Pane( hfm, vfm );
model.addPane( pane );
// select the tab to be displayed
model.setCurrentlySelectedIndex( 0 );
Now set up the rest of the tab components
// setup the rest of the components
HorizontalTabTitleView titleView = new HorizontalTabTitleView( Field.FOCUSABLE );
titleView.setNumberOfDisplayedTabs( 3 );
titleView.setModel( model );
PaneView paneView = new PaneView( Field.FOCUSABLE );
paneView.setModel( model );
PaneManagerView view = new PaneManagerView(
Field.FOCUSABLE | Manager.NO_VERTICAL_SCROLL |
Manager.NO_HORIZONTAL_SCROLL | Manager.USE_ALL_HEIGHT |
Manager.USE_ALL_WIDTH,
titleView, paneView );
view.setModel( model );
model.setView( view );
// configure the Controller
HorizontalTabController controller = new HorizontalTabController();
controller.setModel( model );
controller.setView( view );
model.setController( controller );
view.setController( controller );
// add the tab manager to the MainScreen
this.add( view );
}
Anyone aware on a solution please guide.Thanks

how to create three edit fileds in horizontal field manager in blackberry

How to create three editfields like this
HorizontalFieldManager hfm_city=new HorizontalFieldManager();
VerticalFieldManager vfm_city = new VerticalFieldManager();
vfm_city.setBorder(
BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), borderBitmap
)
);
vfm_city.setMargin(0, 200, 0, 0);
final EditField city = new EditField("", "", 30, BasicEditField.FILTER_DEFAULT){
String emptyString = "City";
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0xFFFFFF);
g.clear();
}
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x000000);
test = super.getText();
if ( test == null || test.length() < 1 ) {
//g.setColor(Config.hint_colour);
g.drawText(emptyString, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
vfm_city.add(city);
VerticalFieldManager vfm_state = new VerticalFieldManager();
vfm_state.setBorder(
BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), borderBitmap
)
);
vfm_state.setMargin(0, 0, 0, 0);
final EditField state = new EditField("", "", 30, BasicEditField.FILTER_DEFAULT){
String emptyString = "State";
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0xFFFFFF);
g.clear();
}
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x000000);
test = super.getText();
if ( test == null || test.length() < 1 ) {
//g.setColor(Config.hint_colour);
g.drawText(emptyString, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
vfm_state.add(state);
VerticalFieldManager vfm_zip = new VerticalFieldManager();
vfm_zip.setBorder(
BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), borderBitmap
)
);
vfm_zip.setMargin(0, 0, 0, 0);
final EditField zip = new EditField("", "", 30, BasicEditField.FILTER_DEFAULT){
String emptyString = "Zip";
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0xFFFFFF);
g.clear();
}
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x000000);
test = super.getText();
if ( test == null || test.length() < 1 ) {
//g.setColor(Config.hint_colour);
g.drawText(emptyString, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
vfm_zip.add(zip);
hfm_city.add(vfm_city);
hfm_city.add(vfm_state);
hfm_city.add(vfm_zip);
You are going in the right way. but you have to give specific width & height to yourVerticalFieldManager otherwise it will take full width by default.
VerticalFieldManager vfm_city = new VerticalFieldManager() {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getwidth()/3,30);
setExtent(Display.getwidth()/3,30);
}
};
Do this in your State & city vfm and add in your hfm and try.
Check my answer
{
Border bdr = BorderFactory.createRoundedBorder(new XYEdges(4, 4, 4, 4),Border.STYLE_SOLID);
VerticalFieldManager vert=new VerticalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
HorizontalFieldManager hr=new HorizontalFieldManager(USE_ALL_HEIGHT)
{
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),50);
setExtent(Display.getWidth(),50);
}
};
hr.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN));
EditField e1=new EditField(Field.FOCUSABLE|Field.FIELD_VCENTER){
protected void layout(int width, int height) {
super.layout(100,30);
setExtent(100,30);
}
};
EditField e2=new EditField(Field.FOCUSABLE|Field.FIELD_VCENTER){
protected void layout(int width, int height) {
super.layout(60,30);
setExtent(60,30);
}
};
EditField e3=new EditField(Field.FOCUSABLE|Field.FIELD_VCENTER){
protected void layout(int width, int height) {
super.layout(60,30);
setExtent(60,30);
}
};
e1.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
e2.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
e3.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
e1.setPadding(0, 0, 0, 10);
e2.setPadding(0, 0, 0, 20);
e3.setPadding(0, 0, 0, 10);
e1.setBorder(bdr);
e2.setBorder(bdr);
e3.setBorder(bdr);
hr.add(e1);
hr.add(e2);
hr.add(e3);
vert.add(hr);
add(vert);
}

Resources