public class GenericListCellRenderer<T>
- Object
- GenericListCellRenderer
ImplementsCellRenderer<T>, ListCellRenderer<T>
The generic list cell renderer can display containers or arbitrary Codename One components
as items in a list, notice that
we strongly discourage usage of lists.. It relies on the source data being a Map object. It extracts values from
the Map using the component name as an indication to the Map key lookup.
This renderer supports label tickering, check boxes/radio buttons etc. seamlessly.
Please notice that you must use at least two distinct instances of the component when passing them to the constructor, reusing the same instance WILL NOT WORK!
Furthermore, the renderer instance cannot be reused for multiple lists, each list will need a new instance of this renderer!
Sample usage for this renderer follows:
public void showForm() {
com.codename1.ui.List list = new com.codename1.ui.List(createGenericListCellRendererModelData());
list.setRenderer(new GenericListCellRenderer(createGenericRendererContainer(), createGenericRendererContainer()));
Form hi = new Form("GenericListCellRenderer", new BorderLayout());
hi.add(BorderLayout.CENTER, list);
hi.show();
}
private Container createGenericRendererContainer() {
Label name = new Label();
name.setFocusable(true);
name.setName("Name");
Label surname = new Label();
surname.setFocusable(true);
surname.setName("Surname");
CheckBox selected = new CheckBox();
selected.setName("Selected");
selected.setFocusable(true);
Container c = BorderLayout.center(name).
add(BorderLayout.SOUTH, surname).
add(BorderLayout.WEST, selected);
c.setUIID("ListRenderer");
return c;
}
private Object[] createGenericListCellRendererModelData() {
Map[] data = new HashMap[5];
data[0] = new HashMap<>();
data[0].put("Name", "Shai");
data[0].put("Surname", "Almog");
data[0].put("Selected", Boolean.TRUE);
data[1] = new HashMap<>();
data[1].put("Name", "Chen");
data[1].put("Surname", "Fishbein");
data[1].put("Selected", Boolean.TRUE);
data[2] = new HashMap<>();
data[2].put("Name", "Ofir");
data[2].put("Surname", "Leitner");
data[3] = new HashMap<>();
data[3].put("Name", "Yaniv");
data[3].put("Surname", "Vakarat");
data[4] = new HashMap<>();
data[4].put("Name", "Meirav");
data[4].put("Surname", "Nachmanovitch");
return data;
}
public void showForm() {
com.codename1.ui.List list = new com.codename1.ui.List(createGenericListCellRendererModelData());
list.setRenderer(new GenericListCellRenderer(createGenericRendererContainer(), createGenericRendererContainer()));
Form hi = new Form("GenericListCellRenderer", new BorderLayout());
hi.add(BorderLayout.CENTER, list);
hi.show();
}
private Container createGenericRendererContainer() {
Label name = new Label();
name.setFocusable(true);
name.setName("Name");
Label surname = new Label();
surname.setFocusable(true);
surname.setName("Surname");
CheckBox selected = new CheckBox();
selected.setName("Selected");
selected.setFocusable(true);
Container c = BorderLayout.center(name).
add(BorderLayout.SOUTH, surname).
add(BorderLayout.WEST, selected);
c.setUIID("ListRenderer");
return c;
}
private Object[] createGenericListCellRendererModelData() {
Map[] data = new HashMap[5];
data[0] = new HashMap<>();
data[0].put("Name", "Shai");
data[0].put("Surname", "Almog");
data[0].put("Selected", Boolean.TRUE);
data[1] = new HashMap<>();
data[1].put("Name", "Chen");
data[1].put("Surname", "Fishbein");
data[1].put("Selected", Boolean.TRUE);
data[2] = new HashMap<>();
data[2].put("Name", "Ofir");
data[2].put("Surname", "Leitner");
data[3] = new HashMap<>();
data[3].put("Name", "Yaniv");
data[3].put("Surname", "Vakarat");
data[4] = new HashMap<>();
data[4].put("Name", "Meirav");
data[4].put("Surname", "Nachmanovitch");
return data;
}
Fields
public static final String ENABLED = "$$ENABLED$$" | If this flag exists in a Map of data the renderer will enable/disable the entries, the flag assumes either Boolean.TRUE or Boolean.FALSE. |
public static final String SELECT_ALL_FLAG = "$$SELECTALL$$" | Put this flag as a Map key to indicate that a checkbox entry rendered by this renderer should act as a “select all” entry and toggle all other entries. |
Constructors
public GenericListCellRenderer(Component selected, Component unselected) | Constructs a generic renderer with the given selected/unselected components |
public GenericListCellRenderer(Component odd, Component oddUnselected, Component even, Component evenUnselected) | Constructs a generic renderer with the given selected/unselected components for odd/even values allowing a “pinstripe” effect |
Methods
Inherited methods
Field details
ENABLED
public static final String ENABLED = "$$ENABLED$$"SELECT_ALL_FLAG
public static final String SELECT_ALL_FLAG = "$$SELECTALL$$"Constructor details
GenericListCellRenderer
public GenericListCellRenderer(Component selected, Component unselected)Parameters
selectedComponent- indicates the selected value for the renderer
unselectedComponent- indicates the unselected value for the renderer
GenericListCellRenderer
public GenericListCellRenderer(Component odd, Component oddUnselected, Component even, Component evenUnselected)Parameters
oddComponent- indicates the selected value for the renderer
oddUnselectedComponent- indicates the unselected value for the renderer
evenComponent- indicates the selected value for the renderer
evenUnselectedComponent- indicates the unselected value for the renderer
Method details
getDefaultAdapter
public static URLImage.ImageAdapter getDefaultAdapter()Returns
setDefaultAdapter
public static void setDefaultAdapter(URLImage.ImageAdapter aDefaultAdapter)Parameters
aDefaultAdapterURLImage.ImageAdapter- the defaultAdapter to set
updateIconPlaceholders
public void updateIconPlaceholders()extractLastClickedComponent
public Button extractLastClickedComponent()Returns
getCellRendererComponent
public Component getCellRendererComponent(Component list, Object model, T value, int index, boolean isSelected)Parameters
listComponent- the list component
modelObject- the model behind the render
valueT- the value to render
indexint- the index in the list
isSelectedboolean- whether the entry is selected
Returns
getListCellRendererComponent
public Component getListCellRendererComponent(List list, T value, int index, boolean isSelected)Parameters
listList- the list component
valueT- the value to render
indexint- the index in the list
isSelectedboolean- whether the entry is selected
Returns
getListFocusComponent
public Component getListFocusComponent(List list)Parameters
listList- the parent list
Returns
getFocusComponent
public Component getFocusComponent(Component list)Parameters
listComponent- the parent list
Returns
isSelectionListener
public boolean isSelectionListener()Returns
setSelectionListener
public void setSelectionListener(boolean selectionListener)Parameters
selectionListenerboolean- the selectionListener to set
getSelected
public Component getSelected()Returns
getUnselected
public Component getUnselected()Returns
getSelectedEven
public Component getSelectedEven()Returns
getUnselectedEven
public Component getUnselectedEven()Returns
isFisheye
public boolean isFisheye()Returns
setFisheye
public void setFisheye(boolean fisheye)Parameters
fisheyeboolean- the fisheye to set
getAdapter
public URLImage.ImageAdapter getAdapter()Returns
setAdapter
public void setAdapter(URLImage.ImageAdapter adapter)Parameters
adapterURLImage.ImageAdapter- the adapter to set