org.knime.core.data.renderer
Class DefaultDataValueRendererFamily

java.lang.Object
  extended by org.knime.core.data.renderer.DefaultDataValueRendererFamily
All Implemented Interfaces:
ListCellRenderer, TableCellRenderer, DataValueRenderer, DataValueRendererFamily

public class DefaultDataValueRendererFamily
extends Object
implements DataValueRendererFamily

Default container for DataValueRenderer. This implementation only has one renderer type, i.e. DefaultDataValueRenderer.

If you intend to derive this class, you should consider to override the methods getNrAvailableRenderer, getRendererDescription, and getRenderer.

Author:
Bernd Wiswedel, University of Konstanz
See Also:
DefaultDataValueRenderer

Field Summary
 
Fields inherited from interface org.knime.core.data.renderer.DataValueRenderer
PROPERTY_PREFERRED_RENDERER
 
Constructor Summary
DefaultDataValueRendererFamily()
          Constructor that uses a single default renderer with a default description, i.e.
DefaultDataValueRendererFamily(DataValueRenderer... renderers)
          Constructs a renderer family given a set of renders and their description.
 
Method Summary
 boolean accepts(DataColumnSpec spec)
          Is this renderer instance able to render the content of the column given by spec.
 boolean accepts(String desc, DataColumnSpec spec)
          Delegates to renderer.
static DataValueRendererFamily findRendererFamily(Class<?> cellClass)
          Helper method to get the renderer family for a particular DataCell class.
 String getDescription()
          Get a description for this renderer implementation.
 Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
          Render this object in the list using the current renderer.
 Dimension getPreferredSize()
          Get the dimension which the renderer component will preferably occupy.
 Component getRendererComponent(Object val)
          Get a component that visualizes a given object.
 String[] getRendererDescriptions()
          Get a "unique" description for all renderer that are available in this family.
 Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
          Render this object in a table using the current renderer.
 void setActiveRenderer(String description)
          Set the currently active renderer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultDataValueRendererFamily

public DefaultDataValueRendererFamily()
Constructor that uses a single default renderer with a default description, i.e. renderer: DefaultDataValueRenderer, description: "Default Renderer"


DefaultDataValueRendererFamily

public DefaultDataValueRendererFamily(DataValueRenderer... renderers)
Constructs a renderer family given a set of renders and their description. This constructor certainly has the disadvantage that all available renders need to be instantiated in advance (and most of them are not going to be used). If you consider this a problem for your kind of renderes you need to implement an own family that does it on request only.

Parameters:
renderers - Set of all available renderer.
Throws:
NullPointerException - If the argument is null or any entry is null.
IllegalArgumentException - If the array is empty.
Method Detail

findRendererFamily

public static final DataValueRendererFamily findRendererFamily(Class<?> cellClass)
Helper method to get the renderer family for a particular DataCell class. This method uses java reflection to invoke the static getNewRenderer method in the appropriate DataCell.

If this fail, an error message is printed to standard error output and a new DefaultDataValueRendererFamily is returned.

Parameters:
cellClass - The class of the DataCell of interest.
Returns:
The renderer according to the cell's getNewRenderer method. If this method is not defined the super class of the cell is used (at latest DataCell itself should have an renderer)
Throws:
IllegalArgumentException - If the argument is not a subclass of DataCell
NullPointerException - If the argument is null.

getListCellRendererComponent

public Component getListCellRendererComponent(JList list,
                                              Object value,
                                              int index,
                                              boolean isSelected,
                                              boolean cellHasFocus)
Render this object in the list using the current renderer.

Specified by:
getListCellRendererComponent in interface ListCellRenderer
See Also:
ListCellRenderer.getListCellRendererComponent( javax.swing.JList, java.lang.Object, int, boolean, boolean)

getTableCellRendererComponent

public Component getTableCellRendererComponent(JTable table,
                                               Object value,
                                               boolean isSelected,
                                               boolean hasFocus,
                                               int row,
                                               int column)
Render this object in a table using the current renderer.

Specified by:
getTableCellRendererComponent in interface TableCellRenderer
See Also:
TableCellRenderer.getTableCellRendererComponent( javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)

getPreferredSize

public Dimension getPreferredSize()
Get the dimension which the renderer component will preferably occupy.

Specified by:
getPreferredSize in interface DataValueRenderer
Returns:
Size of the component being rendered.

getRendererDescriptions

public String[] getRendererDescriptions()
Get a "unique" description for all renderer that are available in this family.

Specified by:
getRendererDescriptions in interface DataValueRendererFamily
Returns:
The Descriptions of all renderer that can be used here.

setActiveRenderer

public void setActiveRenderer(String description)
Set the currently active renderer. The argument must be an element of whatever is returned in getRendererDescription(). If it is not this method won't do anything.

Specified by:
setActiveRenderer in interface DataValueRendererFamily
Parameters:
description - The ID of the renderer to be used.

getDescription

public String getDescription()
Get a description for this renderer implementation. It will serve to identify this renderer when the user has the choice of different renderer that are available. Make sure that this description is likely to be unique (if not only one of renderer with this ID is shown as available) and this description is short but "expressive" so that it can be shown as label in menus, for instance.

Specified by:
getDescription in interface DataValueRenderer
Returns:
A description for this renderer.

getRendererComponent

public Component getRendererComponent(Object val)
Get a component that visualizes a given object. This object, generally, is a DataCell implementing the underlying DataValue interface. The implementation, however, needs to handle other cases as well, such as null arguments, missing DataCell or generic objects.

Specified by:
getRendererComponent in interface DataValueRenderer
Parameters:
val - The value to render
Returns:
A component displaying the content of val.

accepts

public boolean accepts(String desc,
                       DataColumnSpec spec)
Delegates to renderer.

Specified by:
accepts in interface DataValueRendererFamily
Parameters:
desc - The description of the renderer.
spec - The column spec to check.
Returns:
If the renderer can render the column with the given spec.
See Also:
DataValueRendererFamily.accepts(String, DataColumnSpec)

accepts

public boolean accepts(DataColumnSpec spec)
Is this renderer instance able to render the content of the column given by spec. Most implementations will return true here but some may require some properties to be set, for instance a molecule renderer needs to have 2D coordinates in the column.

Note: This method is not used to test whether arbitrary types can be renderer by this renderer instance but rather if the specific runtime column spec (containing the type) is appropriate, for instance contains domain information or certain properties are set.

Specified by:
accepts in interface DataValueRenderer
Parameters:
spec - The column spec to check.
Returns:
true if this renderer can be chosen to render the content of the column.


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.