Java DTV API 1.3
18-Nov-2009

com.sun.dtv.lwuit.list
Interface ListCellRenderer

All Known Implementing Classes:
DefaultListCellRenderer

public interface ListCellRenderer

A "rubber stamp" tool that allows us to extract a component (often the same component instance for all invocations) that is initialized to the value of the current item extracted from the model, this component is drawn on the list and discarded. No state of the component is kept and the component is essentially discarded.

An instance of a renderer can be developed as such:

public class MyYesNoRenderer extends Label implements ListCellRenderer {
    public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
        if( ((Boolean)value).booleanValue() ) {
            setText("Yes");
        } else {
            setText("No");
        }
        return this;
    }
    public Component getListFocusComponent(List list) {
        Label label = new label("");
        label.getStyle().setBgTransparency(100);
        return label;
    }
}
 

It is recommended that the component whose values are manipulated would not support features such as repaint(). This is accomplished by overriding repaint in the subclass with an empty implementation. This is advised for performance reasons, otherwise every change made to the component might trigger a repaint that wouldn't do anything but still cost in terms of processing.


Method Summary
 Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected)
          Returns a component instance that is already set to render "value".
 Component getListFocusComponent(List list)
          Returns a component instance that is painted under the currently focused renderer and is animated to provide smooth scrolling.
 

Method Detail

getListCellRendererComponent

Component getListCellRendererComponent(List list,
                                       Object value,
                                       int index,
                                       boolean isSelected)
Returns a component instance that is already set to render "value". While it is not a requirement many renderers often derive from a component (such as a label) and return "this". Notice that a null value for the value argument might be sent when refreshing the theme of the list.

Parameters:
list - the List object
value - an Object
index - the index
isSelected - indicating whether the Component is selected
Returns:
a Component object

getListFocusComponent

Component getListFocusComponent(List list)
Returns a component instance that is painted under the currently focused renderer and is animated to provide smooth scrolling. When the selection moves, this component is drawn above/bellow the list items - it is recommended to give this component some level of transparency (see above code example). This method is optional an implementation can choose to return null.

Parameters:
list - the list
Returns:
a component instance that is painted under the currently focused renderer and is animated to provide smooth scrolling.
See Also:
Component.setSmoothScrolling(boolean)

Java DTV API 1.3
18-Nov-2009

Copyright © 2008-2009 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved.

U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its supplements. Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.Products covered by and information contained in this service manual are controlled by U.S. Export Control laws and may be subject to the export or import laws in other countries. Nuclear, missile, chemical biological weapons or nuclear maritime end uses or end users, whether direct or indirect, are strictly prohibited. Export or reexport to countries subject to U.S. embargo or to entities identified on U.S. export exclusion lists, including, but not limited to, the denied persons and specially designated nationals lists is strictly prohibited.

DOCUMENTATION IS PROVIDED AS IS AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.

Use of this document is subject to license terms.