org.embl.ebi.escience.scuflui.spi
Interface RendererSPI

All Known Implementing Classes:
AbstractRenderer, AbstractRenderer.ByJavaClass, AbstractRenderer.ByMimeType, AbstractRenderer.ByPattern, AbstractRenderer.BySemanticType, AWTComponentRenderer, CollectionAsTable, Image, JMolRenderer, LabelRenderer, SeqVistaRenderer, SVGRenderer, Text, TextHtml, TextRtf, TextTavernaWebUrl, TextTavernaWebUrlFetcher, TextXGraphviz, TextXml

public interface RendererSPI

SPI for rendering a data thing.

Users

Instances of this interface will normaly be obtained from methods on RendererRegistry. You can then use methods on a particular instance to get its icon and name, a Component for rendering data, and query if it is capable of rendering particular data. It is a good idea to wrap calls to these methods in a try/catch block for common runtime exceptions like NullPointerException, as each SPI is implemented independantly of the main library, and may fail in exciting and unpredictable ways.

Implementors

Each jar providing implementations of this SPI should list them in META-INF/services/org.embl.ebi.escience.scuflui.renderers.RendererSPI.

If a particular SPI needs extra information, it should be in a resource in the same location as the .class file, and prefixed by the local class name, so that it could be retrieved as:

 getClass().getClassLoader().getResourceAsStream(
     getClass().getName().replace('.', '/') + postFix );
 
or alternatively
 getClass().getResourceAsStream(getClass().getName().substring(
     getClass().getPackage().toString() + 1) + postFix );
 

Author:
Matthew Pocock

Method Summary
 boolean canHandle(RendererRegistry renderers, DataThing dataThing)
          Return true if this SPI can handle the given object with the given mime type, false otherwise.
 javax.swing.JComponent getComponent(RendererRegistry renderers, DataThing dataThing)
          Return a JComponent that renders this object that proports to have a particular mime type.
 javax.swing.Icon getIcon(RendererRegistry renderers, DataThing dataThing)
          An icon that can be used to identify this SPI.
 java.lang.String getName()
          A human-readable name for this SPI.
 boolean isTerminal()
          Discover if this is a terminal renderer.
 

Method Detail

isTerminal

boolean isTerminal()
Discover if this is a terminal renderer. A renderer is terminal if it renders the given DataThing. It is not terminal if it first calculates some property of that DataThing that may potentially lead to some other non-terminal Renderer being used.

Returns:
true if this is a terminal renderer, false otherwise

canHandle

boolean canHandle(RendererRegistry renderers,
                  DataThing dataThing)
Return true if this SPI can handle the given object with the given mime type, false otherwise.

Parameters:
renderers - the MimeTypeRendereRegistry to look up sibling renderers
dataThing - the object to render
Returns:
true if we can handle the mime type

getComponent

javax.swing.JComponent getComponent(RendererRegistry renderers,
                                    DataThing dataThing)
                                    throws RendererException
Return a JComponent that renders this object that proports to have a particular mime type. If canHandle() returns true, then getComponent() must not return null.

Parameters:
renderers - the MimeTypeRendereRegistry to look up sibling renderers
dataThing - the object to render
Returns:
a JComponent for displaying the object, or null
Throws:
RendererException

getName

java.lang.String getName()
A human-readable name for this SPI.

Returns:
the name

getIcon

javax.swing.Icon getIcon(RendererRegistry renderers,
                         DataThing dataThing)
An icon that can be used to identify this SPI.

Parameters:
renderers - the MimeTypeRendereRegistry to look up sibling renderers
dataThing - the object to render
Returns:
an appropreate icon, or null if this SPI doesn't have an icon