Skip to main content

Smooth scrolling in a list - million contact march source available?

6 replies [Last post]
michaelmaguire
Offline
Joined: 2008-08-15

I’m trying to get smooth scrolling through a list in our app working and I’m having trouble getting the focus highlighting to work as nicely as it does in the default LWUIT menus and what is shown in the Million Contact March video:

http://lwuit.blogspot.com/2008/08/model-mvc-million-contacts-march.html

In my own sample code:

<br />
import java.util.*;</p>
<p>import com.sun.lwuit.*;<br />
import com.sun.lwuit.events.*;<br />
import com.sun.lwuit.geom.Dimension;<br />
import com.sun.lwuit.layouts.*;<br />
import com.sun.lwuit.list.*;<br />
import com.sun.lwuit.plaf.Style;</p>
<p>public class ListSmoothScrollForm extends Form implements ListModel, ListCellRenderer<br />
{</p>
<p>    /**<br />
     * We might render models differently depending on the object.<br />
     *<br />
     * In this very simplified sample, ModelRenderer happens to be just<br />
     * a ListCellRenderer.<br />
     */<br />
    private interface ModelRenderer extends ListCellRenderer<br />
    {</p>
<p>    }</p>
<p>    private interface RenderableModel<br />
    {<br />
        /**<br />
         * We might render models differently depending on the object.<br />
         * This method provides a bit of abstraction.<br />
         * @return<br />
         */<br />
        ModelRenderer getModelRenderer();<br />
    }</p>
<p>    /**<br />
     * A concrete ModelRendered for RenderableModelA.<br />
     */<br />
    private static class ModelRendererA extends Container implements ModelRenderer<br />
    {<br />
        public ModelRendererA()<br />
        {<br />
            setLayout( new BorderLayout() );</p>
<p>            Dimension preferredIconDimension = new Dimension( 16, 16 );<br />
            iIcon.setPreferredSize( preferredIconDimension );</p>
<p>            Style iconStyle = iIcon.getStyle();<br />
            iconStyle.setMargin( 0, 0, 2, 2 );<br />
            iconStyle.setPadding( 0, 0, 0, 0 );<br />
            addComponent( BorderLayout.WEST, iIcon );</p>
<p>            Container right = new Container( new BoxLayout( BoxLayout.Y_AXIS ) );<br />
            Style containerStyle = right.getStyle();<br />
            containerStyle.setMargin( 0, 0, 0, 0 );<br />
            containerStyle.setPadding( 0, 0, 0, 0 );</p>
<p>            Style addressStyle = iString1.getStyle();<br />
            addressStyle.setBgTransparency( 0 );<br />
            addressStyle.setMargin( 0, 0, 0, 0 );<br />
            addressStyle.setPadding( 0, 0, 0, 0 );</p>
<p>            Style subjectStyle = iString2.getStyle();<br />
            subjectStyle.setBgTransparency( 0 );<br />
            subjectStyle.setMargin( 0, 0, 0, 0 );<br />
            subjectStyle.setPadding( 0, 0, 0, 0 );</p>
<p>            right.addComponent( iString1 );<br />
            right.addComponent( iString2 );</p>
<p>            addComponent( BorderLayout.CENTER, right );</p>
<p>            getStyle().setMargin( 0, 0, 0, 0 );<br />
        }</p>
<p>        public Component getListCellRendererComponent( List aList, Object aModel, int aIndex, boolean aIsSelected )<br />
        {<br />
            RenderableModelA renderableModel = (RenderableModelA) aModel;<br />
            String string1 = renderableModel.iString1;<br />
            String string2 = renderableModel.iString2;</p>
<p>            if( aIsSelected )<br />
            {<br />
                setFocus( true );<br />
                getStyle().setBgTransparency( 100 );</p>
<p>                // Work-around for wacky LWUIT focus bug see ticket:2794 "LWUIT: Label with setIcon in list doesn't render properly when focused"<br />
                iIcon.getStyle().setBgTransparency( 0 );<br />
            }<br />
            else<br />
            {<br />
                setFocus( false );<br />
                getStyle().setBgTransparency( 0 );</p>
<p>                // Work-around for wacky LWUIT focus bug see ticket:2794 "LWUIT: Label with setIcon in list doesn't render properly when focused"<br />
                iIcon.getStyle().setBgTransparency( 0 );<br />
            }</p>
<p>            iString2.setText( string1 );</p>
<p>            iString1.setText( string2 );</p>
<p>            return this;<br />
        }</p>
<p>        public Component getListFocusComponent( List aList )<br />
        {<br />
            return null;<br />
        }</p>
<p>        private Label   iString1 = new Label( "" );<br />
        private Label   iString2 = new Label( "" );<br />
        protected Label iIcon    = new Label( "" );<br />
    }</p>
<p>    private static class RenderableModelA implements RenderableModel<br />
    {<br />
        RenderableModelA( String aString1, String aString2 )<br />
        {<br />
            iString1 = aString1;<br />
            iString2 = aString2;<br />
        }</p>
<p>        /**<br />
         * We might render models differently depending on the object.<br />
         * This method provides a bit of abstraction.<br />
         * @return<br />
         */<br />
        public ModelRenderer getModelRenderer()<br />
        {<br />
            return iModelRenderer;<br />
        }</p>
<p>        private ModelRenderer iModelRenderer = new ModelRendererA();<br />
        private String        iString1;<br />
        private String        iString2;<br />
    }</p>
<p>    public ListSmoothScrollForm()<br />
    {<br />
        iListModelItems = new Vector();</p>
<p>        for( int i = 0; i < 20; i++ )<br />
        {<br />
            String itemString = "Item " + String.valueOf( i );<br />
            iListModelItems.addElement( new RenderableModelA( "Some item", itemString ) );<br />
        }</p>
<p>        createUserInterface();<br />
    }</p>
<p>    protected void createUserInterface()<br />
    {<br />
        setScrollable( false );<br />
        setLayout( new BorderLayout() );</p>
<p>        iList = new List( this );<br />
        iList.setListCellRenderer( this );<br />
        iList.setFixedSelection( List.FIXED_NONE_CYCLIC );<br />
        iList.setInputOnFocus( true );<br />
        iList.getStyle().setBorder( null );</p>
<p>        addComponent( BorderLayout.CENTER, iList );<br />
    }</p>
<p>    // ListModel    </p>
<p>    public void addDataChangedListener( DataChangedListener l )<br />
    {<br />
        // TODO Auto-generated method stub</p>
<p>    }</p>
<p>    public void addItem( Object item )<br />
    {<br />
        // TODO Auto-generated method stub</p>
<p>    }</p>
<p>    public void addSelectionListener( SelectionListener l )<br />
    {<br />
        // TODO Auto-generated method stub</p>
<p>    }</p>
<p>    public Object getItemAt( int index )<br />
    {<br />
        return iListModelItems.elementAt( index );<br />
    }</p>
<p>    public int getSelectedIndex()<br />
    {<br />
        return iSelectedIndex;<br />
    }</p>
<p>    public int getSize()<br />
    {<br />
        return iListModelItems.size();<br />
    }</p>
<p>    public void removeDataChangedListener( DataChangedListener l )<br />
    {<br />
        // TODO Auto-generated method stub</p>
<p>    }</p>
<p>    public void removeItem( int index )<br />
    {<br />
        // TODO Auto-generated method stub</p>
<p>    }</p>
<p>    public void removeSelectionListener( SelectionListener l )<br />
    {<br />
        // TODO Auto-generated method stub</p>
<p>    }</p>
<p>    public void setSelectedIndex( int index )<br />
    {<br />
        iSelectedIndex = index;<br />
    }</p>
<p>    // ListCellRenderer</p>
<p>    public Component getListCellRendererComponent( List list, Object value, int index, boolean isSelected )<br />
    {<br />
        RenderableModel renderableModel = (RenderableModel) value;<br />
        ModelRenderer modelRenderer = renderableModel.getModelRenderer();<br />
        return modelRenderer.getListCellRendererComponent( list, value, index, isSelected );<br />
    }</p>
<p>    public Component getListFocusComponent( List list )<br />
    {<br />
        // TODO Auto-generated method stub<br />
        return null;<br />
    }</p>
<p>    private List   iList;<br />
    private Vector iListModelItems = new Vector();<br />
    private int    iSelectedIndex;</p>
<p>}<br />

the focus shows up, but focus does not smoothly animate from one item to the next the way it does in menus or the blog video. Instead, it just jumps from one item to the next:

http://www.youtube.com/watch?v=u2n9ulVfpIs

Unfortunately, when I try compiling the Million Contact March source myself from the blog post, what I get doesn't show any focus at all (also at end of video above, sorry it's almost impossible to see absence of blue focus in that video):

<br />
import com.sun.lwuit.*;<br />
import com.sun.lwuit.events.*;<br />
import com.sun.lwuit.layouts.*;<br />
import com.sun.lwuit.list.*;</p>
<p>/**<br />
 * Originally from <a href="http://lwuit.blogspot.com/2008/08/model-mvc-million-contacts-march.html" title="http://lwuit.blogspot.com/2008/08/model-mvc-million-contacts-march.html">http://lwuit.blogspot.com/2008/08/model-mvc-million-contacts-march.html</a><br />
 *<br />
 * With slight simplifications by Michael Maguire, Blue Whale Systems Ltd<br />
 *<br />
 */<br />
public class MillionContactsMarchListForm extends Form<br />
{<br />
    class Contact<br />
    {<br />
        private String name;<br />
        private String email;<br />
        private Image  pic;</p>
<p>        public Contact( String name, String email, Image pic )<br />
        {<br />
            this.name = name;<br />
            this.email = email;<br />
            this.pic = pic;<br />
        }</p>
<p>        public String getName()<br />
        {<br />
            return name;<br />
        }</p>
<p>        public String getEmail()<br />
        {<br />
            return email;<br />
        }</p>
<p>        public Image getPic()<br />
        {<br />
            return pic;<br />
        }<br />
    }</p>
<p>    class ContactsRenderer extends Container implements ListCellRenderer<br />
    {</p>
<p>        private Label name  = new Label( "" );<br />
        private Label email = new Label( "" );<br />
        private Label pic   = new Label( "" );</p>
<p>        private Label focus = new Label( "" );</p>
<p>        public ContactsRenderer()<br />
        {<br />
            setLayout( new BorderLayout() );<br />
            addComponent( BorderLayout.WEST, pic );<br />
            Container cnt = new Container( new BoxLayout( BoxLayout.Y_AXIS ) );<br />
            name.getStyle().setBgTransparency( 0 );<br />
            email.getStyle().setBgTransparency( 0 );<br />
            cnt.addComponent( name );<br />
            cnt.addComponent( email );<br />
            addComponent( BorderLayout.CENTER, cnt );<br />
        }</p>
<p>        public Component getListCellRendererComponent( List list, Object value, int index, boolean isSelected )<br />
        {<br />
            Contact person = (Contact) value;<br />
            name.setText( index + ": " + person.getName() );<br />
            email.setText( person.getEmail() );</p>
<p>            // Maguire: We commented out the image business for this sample so check for null here.<br />
            if( null != pic )<br />
            {<br />
                pic.setIcon( person.getPic() );<br />
            }<br />
            return this;<br />
        }</p>
<p>        public Component getListFocusComponent( List list )<br />
        {<br />
            return focus;<br />
        }<br />
    }</p>
<p>    String[][] CONTACTS_INFO = { { "Nir V.", "Nir.Vazana@Sun.COM" }, { "Tidhar G.", "Tidhar.Gilor@Sun.COM" }, { "Iddo A.", "Iddo.Arie@Sun.COM" }, { "Ari S.", "Ari.Shapiro@Sun.COM" },<br />
            { "Chen F.", "Chen.Fishbein@Sun.COM" }, { "Yoav B.", "Yoav.Barel@Sun.COM" }, { "Moshe S.", "Moshe.Sambol@Sun.COM" }, { "Keren S.", "Keren.Strul@Sun.COM" },<br />
            { "Amit H.", "Amit.Harel@Sun.COM" }, { "Arkady N.", "Arcadi.Novosiolok@Sun.COM" }, { "Shai A.", "Shai.Almog@Sun.COM" }, { "Elina K.", "Elina.Kleyman@Sun.COM" },<br />
            { "Yaniv V.", "Yaniv.Vakrat@Sun.COM" }, { "Nadav B.", "Nadav.Benedek@Sun.COM" }, { "Martin L.", "Martin.Lichtbrun@Sun.COM" }, { "Tamir S.", "Tamir.Shabat@Sun.COM" },<br />
            { "Nir S.", "Nir.Shabi@Sun.COM" }, { "Eran K.", "Eran.Katz@Sun.COM" } };</p>
<p>    MillionContactsMarchListForm()<br />
    {<br />
        super( "Million" );</p>
<p>        // Maguire: Comment out the image business for this sample -- we're interested in scrolling.<br />
        //int contactWidth = 36;<br />
        //int contactHeight = 48;<br />
        //int cols = 4;<br />
        //Resources images = Resources.open("/images.res");<br />
        //Image contacts = images.getImage("people.jpg");<br />
        //Image[] persons = new Image[CONTACTS_INFO.length];<br />
        //for( int i = 0; i < persons.length; i++ )<br />
        //{<br />
        //    persons[i] = contacts.subImage( ( i % cols ) * contactWidth, ( i / cols ) * contactHeight, contactWidth, contactHeight, true );<br />
        //}</p>
<p>        final Contact[] contactArray = new Contact[CONTACTS_INFO.length];<br />
        for( int i = 0; i < contactArray.length; i++ )<br />
        {<br />
            int pos = i % CONTACTS_INFO.length;<br />
            contactArray[i] = new Contact( CONTACTS_INFO[pos][0], CONTACTS_INFO[pos][1], /* persons[pos]*/null );<br />
        }</p>
<p>        setScrollable( false );<br />
        List l = new List( new ListModel()<br />
        {<br />
            private int selection;</p>
<p>            public Object getItemAt( int index )<br />
            {<br />
                return contactArray[index % contactArray.length];<br />
            }</p>
<p>            public int getSize()<br />
            {<br />
                return 1000000;<br />
            }</p>
<p>            public int getSelectedIndex()<br />
            {<br />
                return selection;<br />
            }</p>
<p>            public void setSelectedIndex( int index )<br />
            {<br />
                selection = index;<br />
            }</p>
<p>            public void addDataChangedListener( DataChangedListener l )<br />
            {<br />
            }</p>
<p>            public void removeDataChangedListener( DataChangedListener l )<br />
            {<br />
            }</p>
<p>            public void addSelectionListener( SelectionListener l )<br />
            {<br />
            }</p>
<p>            public void removeSelectionListener( SelectionListener l )<br />
            {<br />
            }</p>
<p>            public void addItem( Object item )<br />
            {<br />
            }</p>
<p>            public void removeItem( int index )<br />
            {<br />
            }<br />
        } );<br />
        l.setListCellRenderer( new ContactsRenderer() );<br />
        l.setFixedSelection( List.FIXED_NONE_CYCLIC );<br />
        setLayout( new BorderLayout() );<br />
        addComponent( BorderLayout.CENTER, l );</p>
<p>    }</p>
<p>}<br />

I thought this might be because in my sample I'm not setting up theming or something the way it might be in the source compiled to make the video, but in that case I'm a bit stumped why I wouldn't at least get the default light blue focus drawn for menus and in my sample.

Can someone point out what I’m doing wrong? Is the Million Contact March source up somewhere that I’ve missed?

Thanks,
Michael

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Shai Almog

You are returning null for your focus component which is what we use
to draw the animation. Your focus should be drawn by that widget and
it would animate as you would expect.

> I’m trying to get smooth scrolling through a list in our app
> working and I’m having trouble getting the focus highlighting to
> work as nicely as it does in the default LWUIT menus and what is
> shown in the Million Contact March video:
>
> http://lwuit.blogspot.com/2008/08/model-mvc-million-contacts-
> march.html
>
> In my own sample code:
>
>
> [code]
> import java.util.*;
>
> import com.sun.lwuit.*;
> import com.sun.lwuit.events.*;
> import com.sun.lwuit.geom.Dimension;
> import com.sun.lwuit.layouts.*;
> import com.sun.lwuit.list.*;
> import com.sun.lwuit.plaf.Style;
>
> public class ListSmoothScrollForm extends Form implements
> ListModel, ListCellRenderer
> {
>
> /**
> * We might render models differently depending on the object.
> *
> * In this very simplified sample, ModelRenderer happens to be
> just
> * a ListCellRenderer.
> */
> private interface ModelRenderer extends ListCellRenderer
> {
>
> }
>
> private interface RenderableModel
> {
> /**
> * We might render models differently depending on the object.
> * This method provides a bit of abstraction.
> * @return
> */
> ModelRenderer getModelRenderer();
> }
>
> /**
> * A concrete ModelRendered for RenderableModelA.
> */
> private static class ModelRendererA extends Container
> implements ModelRenderer
> {
> public ModelRendererA()
> {
> setLayout( new BorderLayout() );
>
> Dimension preferredIconDimension = new Dimension( 16,
> 16 );
> iIcon.setPreferredSize( preferredIconDimension );
>
> Style iconStyle = iIcon.getStyle();
> iconStyle.setMargin( 0, 0, 2, 2 );
> iconStyle.setPadding( 0, 0, 0, 0 );
> addComponent( BorderLayout.WEST, iIcon );
>
> Container right = new Container( new BoxLayout
> ( BoxLayout.Y_AXIS ) );
> Style containerStyle = right.getStyle();
> containerStyle.setMargin( 0, 0, 0, 0 );
> containerStyle.setPadding( 0, 0, 0, 0 );
>
> Style addressStyle = iString1.getStyle();
> addressStyle.setBgTransparency( 0 );
> addressStyle.setMargin( 0, 0, 0, 0 );
> addressStyle.setPadding( 0, 0, 0, 0 );
>
> Style subjectStyle = iString2.getStyle();
> subjectStyle.setBgTransparency( 0 );
> subjectStyle.setMargin( 0, 0, 0, 0 );
> subjectStyle.setPadding( 0, 0, 0, 0 );
>
> right.addComponent( iString1 );
> right.addComponent( iString2 );
>
> addComponent( BorderLayout.CENTER, right );
>
> getStyle().setMargin( 0, 0, 0, 0 );
> }
>
> public Component getListCellRendererComponent( List aList,
> Object aModel, int aIndex, boolean aIsSelected )
> {
> RenderableModelA renderableModel = (RenderableModelA)
> aModel;
> String string1 = renderableModel.iString1;
> String string2 = renderableModel.iString2;
>
> if( aIsSelected )
> {
> setFocus( true );
> getStyle().setBgTransparency( 100 );
>
> // Work-around for wacky LWUIT focus bug see ticket:
> 2794 "LWUIT: Label with setIcon in list doesn't render properly
> when focused"
> iIcon.getStyle().setBgTransparency( 0 );
> }
> else
> {
> setFocus( false );
> getStyle().setBgTransparency( 0 );
>
> // Work-around for wacky LWUIT focus bug see ticket:
> 2794 "LWUIT: Label with setIcon in list doesn't render properly
> when focused"
> iIcon.getStyle().setBgTransparency( 0 );
> }
>
> iString2.setText( string1 );
>
> iString1.setText( string2 );
>
> return this;
> }
>
> public Component getListFocusComponent( List aList )
> {
> return null;
> }
>
> private Label iString1 = new Label( "" );
> private Label iString2 = new Label( "" );
> protected Label iIcon = new Label( "" );
> }
>
> private static class RenderableModelA implements RenderableModel
> {
> RenderableModelA( String aString1, String aString2 )
> {
> iString1 = aString1;
> iString2 = aString2;
> }
>
> /**
> * We might render models differently depending on the object.
> * This method provides a bit of abstraction.
> * @return
> */
> public ModelRenderer getModelRenderer()
> {
> return iModelRenderer;
> }
>
> private ModelRenderer iModelRenderer = new ModelRendererA();
> private String iString1;
> private String iString2;
> }
>
> public ListSmoothScrollForm()
> {
> iListModelItems = new Vector();
>
> for( int i = 0; i < 20; i++ )
> {
> String itemString = "Item " + String.valueOf( i );
> iListModelItems.addElement( new RenderableModelA( "Some
> item", itemString ) );
> }
>
> createUserInterface();
> }
>
> protected void createUserInterface()
> {
> setScrollable( false );
> setLayout( new BorderLayout() );
>
> iList = new List( this );
> iList.setListCellRenderer( this );
> iList.setFixedSelection( List.FIXED_NONE_CYCLIC );
> iList.setInputOnFocus( true );
> iList.getStyle().setBorder( null );
>
> addComponent( BorderLayout.CENTER, iList );
> }
>
>
> // ListModel
>
> public void addDataChangedListener( DataChangedListener l )
> {
> // TODO Auto-generated method stub
>
> }
>
> public void addItem( Object item )
> {
> // TODO Auto-generated method stub
>
> }
>
> public void addSelectionListener( SelectionListener l )
> {
> // TODO Auto-generated method stub
>
> }
>
> public Object getItemAt( int index )
> {
> return iListModelItems.elementAt( index );
> }
>
> public int getSelectedIndex()
> {
> return iSelectedIndex;
> }
>
> public int getSize()
> {
> return iListModelItems.size();
> }
>
> public void removeDataChangedListener( DataChangedListener l )
> {
> // TODO Auto-generated method stub
>
> }
>
> public void removeItem( int index )
> {
> // TODO Auto-generated method stub
>
> }
>
> public void removeSelectionListener( SelectionListener l )
> {
> // TODO Auto-generated method stub
>
> }
>
> public void setSelectedIndex( int index )
> {
> iSelectedIndex = index;
> }
>
> // ListCellRenderer
>
> public Component getListCellRendererComponent( List list,
> Object value, int index, boolean isSelected )
> {
> RenderableModel renderableModel = (RenderableModel) value;
> ModelRenderer modelRenderer =
> renderableModel.getModelRenderer();
> return modelRenderer.getListCellRendererComponent( list,
> value, index, isSelected );
> }
>
> public Component getListFocusComponent( List list )
> {
> // TODO Auto-generated method stub
> return null;
> }
>
> private List iList;
> private Vector iListModelItems = new Vector();
> private int iSelectedIndex;
>
> }
> [/code]
>
> the focus shows up, but focus does not smoothly animate from one
> item to the next the way it does in menus or the blog video.
> Instead, it just jumps from one item to the next:
>
>
> http://www.youtube.com/watch?v=u2n9ulVfpIs
>
> Unfortunately, when I try compiling the Million Contact March
> source myself from the blog post, what I get doesn't show any focus
> at all (also at end of video above, sorry it's almost impossible to
> see absence of blue focus in that video):
>
> [code]
> import com.sun.lwuit.*;
> import com.sun.lwuit.events.*;
> import com.sun.lwuit.layouts.*;
> import com.sun.lwuit.list.*;
>
> /**
> * Originally from http://lwuit.blogspot.com/2008/08/model-mvc-
> million-contacts-march.html
> *
> * With slight simplifications by Michael Maguire, Blue Whale
> Systems Ltd
> *
> */
> public class MillionContactsMarchListForm extends Form
> {
> class Contact
> {
> private String name;
> private String email;
> private Image pic;
>
> public Contact( String name, String email, Image pic )
> {
> this.name = name;
> this.email = email;
> this.pic = pic;
> }
>
> public String getName()
> {
> return name;
> }
>
> public String getEmail()
> {
> return email;
> }
>
> public Image getPic()
> {
> return pic;
> }
> }
>
> class ContactsRenderer extends Container implements
> ListCellRenderer
> {
>
> private Label name = new Label( "" );
> private Label email = new Label( "" );
> private Label pic = new Label( "" );
>
> private Label focus = new Label( "" );
>
> public ContactsRenderer()
> {
> setLayout( new BorderLayout() );
> addComponent( BorderLayout.WEST, pic );
> Container cnt = new Container( new BoxLayout
> ( BoxLayout.Y_AXIS ) );
> name.getStyle().setBgTransparency( 0 );
> email.getStyle().setBgTransparency( 0 );
> cnt.addComponent( name );
> cnt.addComponent( email );
> addComponent( BorderLayout.CENTER, cnt );
> }
>
> public Component getListCellRendererComponent( List list,
> Object value, int index, boolean isSelected )
> {
> Contact person = (Contact) value;
> name.setText( index + ": " + person.getName() );
> email.setText( person.getEmail() );
>
> // Maguire: We commented out the image business for
> this sample so check for null here.
> if( null != pic )
> {
> pic.setIcon( person.getPic() );
> }
> return this;
> }
>
> public Component getListFocusComponent( List list )
> {
> return focus;
> }
> }
>
> String[][] CONTACTS_INFO = { { "Nir V.",
> "Nir.Vazana@Sun.COM" }, { "Tidhar G.", "Tidhar.Gilor@Sun.COM" },
> { "Iddo A.", "Iddo.Arie@Sun.COM" }, { "Ari S.",
> "Ari.Shapiro@Sun.COM" },
> { "Chen F.", "Chen.Fishbein@Sun.COM" }, { "Yoav B.",
> "Yoav.Barel@Sun.COM" }, { "Moshe S.", "Moshe.Sambol@Sun.COM" },
> { "Keren S.", "Keren.Strul@Sun.COM" },
> { "Amit H.", "Amit.Harel@Sun.COM" }, { "Arkady N.",
> "Arcadi.Novosiolok@Sun.COM" }, { "Shai A.", "Shai.Almog@Sun.COM" },
> { "Elina K.", "Elina.Kleyman@Sun.COM" },
> { "Yaniv V.", "Yaniv.Vakrat@Sun.COM" }, { "Nadav B.",
> "Nadav.Benedek@Sun.COM" }, { "Martin L.",
> "Martin.Lichtbrun@Sun.COM" }, { "Tamir S.", "Tamir.Shabat@Sun.COM" },
> { "Nir S.", "Nir.Shabi@Sun.COM" }, { "Eran K.",
> "Eran.Katz@Sun.COM" } };
>
> MillionContactsMarchListForm()
> {
> super( "Million" );
>
> // Maguire: Comment out the image business for this sample
> -- we're interested in scrolling.
> //int contactWidth = 36;
> //int contactHeight = 48;
> //int cols = 4;
> //Resources images = Resources.open("/images.res");
> //Image contacts = images.getImage("people.jpg");
> //Image[] persons = new Image[CONTACTS_INFO.length];
> //for( int i = 0; i < persons.length; i++ )
> //{
> // persons[i] = contacts.subImage( ( i % cols ) *
> contactWidth, ( i / cols ) * contactHeight, contactWidth,
> contactHeight, true );
> //}
>
> final Contact[] contactArray = new Contact
> [CONTACTS_INFO.length];
> for( int i = 0; i < contactArray.length; i++ )
> {
> int pos = i % CONTACTS_INFO.length;
> contactArray[i] = new Contact( CONTACTS_INFO[pos][0],
> CONTACTS_INFO[pos][1], /* persons[pos]*/null );
> }
>
> setScrollable( false );
> List l = new List( new ListModel()
> {
> private int selection;
>
> public Object getItemAt( int index )
> {
> return contactArray[index % contactArray.length];
> }
>
> public int getSize()
> {
> return 1000000;
> }
>
> public int getSelectedIndex()
> {
> return selection;
> }
>
> public void setSelectedIndex( int index )
> {
> selection = index;
> }
>
> public void addDataChangedListener( DataChangedListener
> l )
> {
> }
>
> public void removeDataChangedListener
> ( DataChangedListener l )
> {
> }
>
> public void addSelectionListener( SelectionListener l )
> {
> }
>
> public void removeSelectionListener( SelectionListener l )
> {
> }
>
> public void addItem( Object item )
> {
> }
>
> public void removeItem( int index )
> {
> }
> } );
> l.setListCellRenderer( new ContactsRenderer() );
> l.setFixedSelection( List.FIXED_NONE_CYCLIC );
> setLayout( new BorderLayout() );
> addComponent( BorderLayout.CENTER, l );
>
>
> }
>
> }
> [/code]
>
> I thought this might be because in my sample I'm not setting up
> theming or something the way it might be in the source compiled to
> make the video, but in that case I'm a bit stumped why I wouldn't
> at least get the default light blue focus drawn for menus and in my
> sample.
>
> Can someone point out what I’m doing wrong? Is the Million Contact
> March source up somewhere that I’ve missed?
>
> Thanks,
> Michael
> [Message sent by forum member 'michaelmaguire' (michaelmaguire)]
>
> http://forums.java.net/jive/thread.jspa?messageID=337272
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/
https://lwuit.dev.java.net/faq.html

[att1.html]

michaelmaguire
Offline
Joined: 2008-08-15

I have tried returning a focus Label before, but with mixed results:

[code]
public Component getListFocusComponent( List list )
{
return iFocus;
}

//private Label iFocus = null; // Not smooth.
//private Label iFocus = new Label( "" ); // Not smooth.
private Label iFocus = new Label( "Bob" ); // Smooth -- but can't have Bob showing up!
//private Label iFocus = new Label( " " ); // Not smooth
[/code]

Is it possible to have a look at the complete million contact march source?

michaelmaguire
Offline
Joined: 2008-08-15

Actually, what I think I see happening in the:

[code]
iFocus = new Label( "Bob" );
[/code]

case is that only the text 'Bob' is being smoothly moved from one item to the next, but the light green highlight is still jumping from one to the next.

michaelmaguire
Offline
Joined: 2008-08-15

Thanks to everyone for their suggestions. In the end what got it to work was:

[code]
public Component getListFocusComponent( List list )
{
iFocus.setFocus( true );
iFocus.getStyle().setBgTransparency( 100 );
iFocus.getStyle().setMargin( 0, 0, 0, 0 ); // To fix margin issue with item.
return iFocus;
}

private Label iFocus = new Label( "" );
[/code]

dmitry_belov
Offline
Joined: 2009-03-16

I don't see this, setSmoothScrolling(true);, anywhere in your code.

Using it works here with smooth focus transition.

michaelmaguire
Offline
Joined: 2008-08-15

Neither:

[code]
protected void createUserInterface()
{
setScrollable( false );
setLayout( new BorderLayout() );

iList = new List( this );
iList.setListCellRenderer( this );
iList.setFixedSelection( List.FIXED_NONE_CYCLIC );
iList.setInputOnFocus( true );
iList.getStyle().setBorder( null );

iList.setSmoothScrolling(true);

addComponent( BorderLayout.CENTER, iList );
}
[/code]

nor:

[code]
protected void createUserInterface()
{
setScrollable( false );
setLayout( new BorderLayout() );

iList = new List( this );
iList.setListCellRenderer( this );
iList.setFixedSelection( List.FIXED_NONE_CYCLIC );
iList.setInputOnFocus( true );
iList.getStyle().setBorder( null );

setSmoothScrolling(true);

addComponent( BorderLayout.CENTER, iList );
}
[/code]

nor (trying both):

[code]
protected void createUserInterface()
{
setScrollable( false );
setLayout( new BorderLayout() );

iList = new List( this );
iList.setListCellRenderer( this );
iList.setFixedSelection( List.FIXED_NONE_CYCLIC );
iList.setInputOnFocus( true );
iList.getStyle().setBorder( null );

iList.setSmoothScrolling(true);
setSmoothScrolling(true);

addComponent( BorderLayout.CENTER, iList );
}
[/code]

helps -- focus still block moves from one to the next.