org.salespointframework.desktop.renderer
Class AbstractListViewRenderer

java.lang.Object
  extended by org.salespointframework.desktop.renderer.AbstractListViewRenderer
All Implemented Interfaces:
javax.swing.ListCellRenderer
Direct Known Subclasses:
CatalogListViewRenderer, UserListViewRenderer

public abstract class AbstractListViewRenderer
extends java.lang.Object
implements javax.swing.ListCellRenderer

this class provides a high performance ListCellRenderer and its intention is the usage with JListView it caches cell components to avoid continual reconstruction of them. Therefore a AbstractListViewRenderer.RenderContext is established and passed to rendering components to whether build the component or update components values. The working component can be obtained from AbstractListViewRenderer.RenderContext.component The AbstractListViewRenderer.RenderComponent is a subclass of JPanel which already is set to its destination size. The renderer differentiates between cells and separators. Renderer also supports mouse over flag ( AbstractListViewRenderer.RenderContext.isMouseOver ) take care of the cache key assignment! cache key should always be the same for each item. otherwise you will face rendering mistakes or large memory leaks.

Since:
4.0
Author:
Thomas Kissinger

Nested Class Summary
static class AbstractListViewRenderer.CategoryItem
          represents a category item. these items have cacheid as unique identification, because Category can occur more than one time if sorting doesn't group
protected static class AbstractListViewRenderer.RenderComponent
          render component is basically a JPanel which has a AbstractListViewRenderer.RenderContext
protected static class AbstractListViewRenderer.RenderContext
          the render context provides information about the current rendering process
 
Field Summary
protected  java.util.Map<java.lang.Object,AbstractListViewRenderer.RenderComponent> cache
          component cache
protected  javax.swing.JPanel categoryLine
          panel for category line
protected  javax.swing.JLabel categoryName
          label for category name
static short RENDER_ELEMENT_TYPE_CELL
          constant for cell type
static short RENDER_ELEMENT_TYPE_SEPERATOR
          constant for separator type
protected  AbstractListViewRenderer.RenderContext renderContext
          current render context
protected  AbstractListViewRenderer.RenderComponent workingComponent
          current component that is being rendered
 
Constructor Summary
AbstractListViewRenderer()
           
 
Method Summary
protected  AbstractListViewRenderer.RenderComponent createWorkingComponent()
          create a new AbstractListViewRenderer.RenderComponent an initializes its size
protected  java.lang.Object getCacheKey(java.lang.Object value)
          used for object to cache key mapping.
protected  AbstractListViewRenderer.CategoryItem getCategoryItem(AbstractListViewRenderer.RenderContext renderContext)
          extracts the category from AbstractListViewRenderer.CategoryItem
 java.awt.Component getListCellRendererComponent(javax.swing.JList list, java.lang.Object value, int index, boolean isSelected, boolean cellHasFocus)
          build an return the component
protected  void initializeSeperatorComponents()
          create components used for seperator
protected  void initializeSeperatorComponentValues()
          initialize or update component values
protected abstract  void render()
          renders the component. use renderContext
protected  void renderComponent(AbstractListViewRenderer.RenderContext renderContext, java.awt.Graphics2D g)
          This is the drawing function of AbstractListViewRenderer.RenderComponent draws the component background.
protected  void renderSeperator()
          renders the separator
protected  void renderSeperatorRack()
          put components on workingComponent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RENDER_ELEMENT_TYPE_CELL

public static final short RENDER_ELEMENT_TYPE_CELL
constant for cell type

See Also:
Constant Field Values

RENDER_ELEMENT_TYPE_SEPERATOR

public static final short RENDER_ELEMENT_TYPE_SEPERATOR
constant for separator type

See Also:
Constant Field Values

renderContext

protected AbstractListViewRenderer.RenderContext renderContext
current render context


workingComponent

protected AbstractListViewRenderer.RenderComponent workingComponent
current component that is being rendered


cache

protected java.util.Map<java.lang.Object,AbstractListViewRenderer.RenderComponent> cache
component cache


categoryName

protected javax.swing.JLabel categoryName
label for category name


categoryLine

protected javax.swing.JPanel categoryLine
panel for category line

Constructor Detail

AbstractListViewRenderer

public AbstractListViewRenderer()
Method Detail

getListCellRendererComponent

public java.awt.Component getListCellRendererComponent(javax.swing.JList list,
                                                       java.lang.Object value,
                                                       int index,
                                                       boolean isSelected,
                                                       boolean cellHasFocus)
build an return the component

Specified by:
getListCellRendererComponent in interface javax.swing.ListCellRenderer

getCacheKey

protected java.lang.Object getCacheKey(java.lang.Object value)
used for object to cache key mapping. Obey the following constrains: 1. each item should the same cache key assigned on multiple calls 2. no cache key twice This must be overridden if the object is always packed into a new component by model. e.g. CountingStocks are facing this issue. or Drag'n Drop shadow objects

Parameters:
value -
Returns:
unique cache key

render

protected abstract void render()
renders the component. use renderContext


renderSeperator

protected void renderSeperator()
renders the separator


getCategoryItem

protected AbstractListViewRenderer.CategoryItem getCategoryItem(AbstractListViewRenderer.RenderContext renderContext)
extracts the category from AbstractListViewRenderer.CategoryItem

Parameters:
renderContext -
Returns:
the category

initializeSeperatorComponents

protected void initializeSeperatorComponents()
create components used for seperator


initializeSeperatorComponentValues

protected void initializeSeperatorComponentValues()
initialize or update component values


renderSeperatorRack

protected void renderSeperatorRack()
put components on workingComponent


renderComponent

protected void renderComponent(AbstractListViewRenderer.RenderContext renderContext,
                               java.awt.Graphics2D g)
This is the drawing function of AbstractListViewRenderer.RenderComponent draws the component background.

Parameters:
renderContext - render context
g - graphics context

createWorkingComponent

protected AbstractListViewRenderer.RenderComponent createWorkingComponent()
create a new AbstractListViewRenderer.RenderComponent an initializes its size

Returns:
a new instance of AbstractListViewRenderer.RenderComponent