Version: 1.1.1

org.biomoby.service.dashboard.renderers
Class Base64Image

java.lang.Object
  extended by org.biomoby.service.dashboard.renderers.AbstractRenderer
      extended by org.biomoby.service.dashboard.renderers.AbstractMobyRenderer
          extended by org.biomoby.service.dashboard.renderers.Base64Image
All Implemented Interfaces:
Renderer

public class Base64Image
extends AbstractMobyRenderer

Decode a byte array from a Base64 encoded Biomoby data types, and convert the resulting byte array to an image.

It can handle several Biomoby data types containing encoded images, but there is no automatic way (at least I do not know about any) how to detect which Biomoby objects have images, and where. Therefore, whenever a new Biomoby image data type appears, somebody must change here canHandle(java.lang.String, java.lang.Object) method. Note, however, that you do not need to add anything here if a new Biomoby data types just inherits from those that are already here - those will be found.

Version:
$Id: Base64Image.java,v 1.3 2006/02/20 05:51:11 senger Exp $
Author:
Martin Senger

Field Summary
 
Fields inherited from interface org.biomoby.service.dashboard.renderers.Renderer
CLASS, CLASS_NAME, DATA, DATA_CONTAINER, MIME_TYPE, MOBY_TYPE
 
Constructor Summary
Base64Image()
           
Base64Image(String name, String iconName)
           
 
Method Summary
 boolean canHandle(String criterion, Object value)
          Return true if this SPI can handle (render) data whose type complies with given value within given criterion.
 JComponent getComponent(DataContainer data)
          Return a JComponent displaying (rendering) given data.
 boolean save2File(DataContainer data, File file)
          Default implementation.
 
Methods inherited from class org.biomoby.service.dashboard.renderers.AbstractRenderer
getIcon, getName
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Base64Image

public Base64Image()

Base64Image

public Base64Image(String name,
                   String iconName)
Method Detail

canHandle

public boolean canHandle(String criterion,
                         Object value)
Description copied from interface: Renderer
Return true if this SPI can handle (render) data whose type complies with given value within given criterion.

Any renderer should handle also a collection of objects that it can handle - see examples in Renderer.getComponent(org.biomoby.service.dashboard.data.DataContainer) and Renderer.save2File(org.biomoby.service.dashboard.data.DataContainer, java.io.File).

Specified by:
canHandle in interface Renderer
Specified by:
canHandle in class AbstractRenderer
Parameters:
criterion - is a category of the value, e.g. "MIME-TYPE"
value - is a value from the category criterion, e.g. "text/xml"

getComponent

public JComponent getComponent(DataContainer data)
                        throws MobyException
Description copied from interface: Renderer
Return a JComponent displaying (rendering) given data.

If it gets an array of data, it can always delegate their accumulation to the CollectionRenderer by saying:

   if (data.getData().getClass().isArray())
      return new BoxCollectionRenderer (this).getComponent (data);

Specified by:
getComponent in interface Renderer
Specified by:
getComponent in class AbstractRenderer
Parameters:
data - to be rendered
Returns:
a component for displaying data, or null if there is a problem with data
Throws:
MobyException - if called with wrong type of data

save2File

public boolean save2File(DataContainer data,
                         File file)
                  throws MobyException
Description copied from class: AbstractRenderer
Default implementation.

If it gets a byte array, it saves it in the given file.

If it gets any other array, it looks at its elements and - if the elements are of type byte array, they all are stored separately, to more files (this is done with the help of the CollectionRenderer). Other types of elements are converted to strings by calling their toString() method, and all of them are store in one file.

It 'data' do not contain an array, they are treated similarly as above: they are converted to string using its toString() method and put in a file.

Specified by:
save2File in interface Renderer
Overrides:
save2File in class AbstractRenderer
Returns:
true on success, return false if you even did nt try to save data (probably because it does not make sense to store such data)
Throws:
MobyException - if saving was tried but failed

Version: 1.1.1

Submit a bug or feature
Generated: Sat May 29 04:26:35 EDT 2010