sk.uniba.euromath.editor.imageRenderer
Class ImageRenderer

java.lang.Object
  extended by sk.uniba.euromath.editor.imageRenderer.ImageRenderer
All Implemented Interfaces:
IRenderer

public final class ImageRenderer
extends Object
implements IRenderer

A renderer that is able to render an image. Processes ObjectSource only.

Author:
Martin Vysny

Method Summary
 IInputPreprocessor createPreprocessor()
          Constructs new instance of preprocessor.
 org.eclipse.draw2d.geometry.Dimension getCanvasSize()
          Retrieves size of area where the rendering occurs.
 IEMFigure getFigure(Object o)
          Retrieves figure that displays given data object.
protected  EMImageFigure getImageFigure()
           
 RendererInfo getInfo()
          Returns instance of RendererInfo able to create this renderer.
 org.eclipse.draw2d.geometry.Point getPlacement(String id)
          Returns point, relative to renderer's canvas, where canvas of child renderer will be positioned.
 IEMFigure getRootFigure()
          Retrieves the root figure, where all figures will be placed.
 void init(Source transformedDoc, RendererContext context)
           Initializes the renderer.
 Object offerObject()
           When the renderer accepts the ObjectSource but wants to provide an object as a result (for example it wants the document producer to draw something in a certain instance of Graphics), then return non-null value.
 void reinit(sk.baka.ikslibs.modify.IChangeCollector changes)
           Reinitialize the renderer when a partial change of the rendered document occurs.
 void render(org.eclipse.draw2d.Graphics g)
           Paint rendered view to Graphics.
protected  void setImageFigure(EMImageFigure imageFigure)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

init

public void init(Source transformedDoc,
                 RendererContext context)
          throws EditorException
Description copied from interface: IRenderer

Initializes the renderer. Called as the first method (only the IRenderer.offerObject() and IRenderer.getInfo() methods may be called before this method). Renderer should prepare IFigure instances for future rendering.

If an element from another namespace occurs (generef processing instruction in case of DOMSource - you can retrieve id using SplittedDocHolder.getRef(org.w3c.dom.Node) function, or a custom object type in case of ObjectSource), the following steps are to be taken:

  1. Renderer must query the context instance using this ID. It then receives the child renderer's canvas size.
  2. Renderer must leave place for each child renderer canvas somewhere on its canvas, during the rendering process. It is not recommended to paint anything into that area - it gets covered by a Composite widget.
  3. After the init ends, the renderer can be queried at any time for the child renderer placement using the IRenderer.getPlacement(String) method.

Specified by:
init in interface IRenderer
Parameters:
transformedDoc - fragment of document, DOMSource or ObjectSource instance. This nametree is to be rendered by the renderer. Renderer is encouraged to throw any exception including ClassCastException if it encounters illegal objects, to detect invalid objects quickly and cleanly.
context - the context instance, allows you to ask for child renderers output, etc.
Throws:
EditorException - if initialization fails.

getPlacement

public org.eclipse.draw2d.geometry.Point getPlacement(String id)
Description copied from interface: IRenderer
Returns point, relative to renderer's canvas, where canvas of child renderer will be positioned.

Specified by:
getPlacement in interface IRenderer
Parameters:
id - the child nametree's ID.
Returns:
point, may be null if the child renderer's canvas is not visible (not placed anywhere).

reinit

public void reinit(sk.baka.ikslibs.modify.IChangeCollector changes)
            throws EditorException
Description copied from interface: IRenderer

Reinitialize the renderer when a partial change of the rendered document occurs. Renderer should discard IFigures no longer needed, and prepare new IFigures. This changed object is given to an editor when this method finishes, to allow the editor to query for new figures.

Specified by:
reinit in interface IRenderer
Parameters:
changes - defines changed elements. Has appropriate type for transformedDoc parameter, i.e. DOMChangeCollector for DOMSource etc. Contains source with all changes already applied.
Throws:
EditorException - if error occurs.

getCanvasSize

public org.eclipse.draw2d.geometry.Dimension getCanvasSize()
                                                    throws EditorException
Description copied from interface: IRenderer
Retrieves size of area where the rendering occurs.

Specified by:
getCanvasSize in interface IRenderer
Returns:
dimension in pixels, never null.
Throws:
EditorException - if error occurs.

getFigure

public IEMFigure getFigure(Object o)
Description copied from interface: IRenderer
Retrieves figure that displays given data object. The figure may contain child figures when required.

Specified by:
getFigure in interface IRenderer
Parameters:
o - the data object, may be any object instance when transformed document is in form of ObjectSource, or a Node instance otherwise.
Returns:
root of view

getRootFigure

public IEMFigure getRootFigure()
Description copied from interface: IRenderer
Retrieves the root figure, where all figures will be placed.

Specified by:
getRootFigure in interface IRenderer
Returns:
root of rendered view.

render

public void render(org.eclipse.draw2d.Graphics g)
            throws EditorException
Description copied from interface: IRenderer

Paint rendered view to Graphics. Use the context object to let the children renderers to paint.

Specified by:
render in interface IRenderer
Parameters:
g - paint onto this graphics instance.
Throws:
EditorException - if error occurs.

offerObject

public Object offerObject()
Description copied from interface: IRenderer

When the renderer accepts the ObjectSource but wants to provide an object as a result (for example it wants the document producer to draw something in a certain instance of Graphics), then return non-null value. If this functionality is not needed then just return null - if the document producer requires some object then it can create any object as long as it is instance of class that this exporter expects.

The consumer (the one that receives the object, i.e. this) is responsible for freeing the object if necessary (at the end of the export method), even if this function returned null.

If you want producer (the one that creates the object) to create custom instances then provide a factory object. This trick is used with http://www.uniba.sk/euromath/holder/java.awt.Graphics holder - a factory is returned that is able to produce java.awt.Graphics instances.

This method can be called anytime, and is usually called before IRenderer.init(Source, RendererContext).

Specified by:
offerObject in interface IRenderer
Returns:
the object instance, or null.

getImageFigure

protected EMImageFigure getImageFigure()
Returns:
Returns the imageFigure.

setImageFigure

protected void setImageFigure(EMImageFigure imageFigure)
Parameters:
imageFigure - The imageFigure to set.

getInfo

public RendererInfo getInfo()
Description copied from interface: IRenderer
Returns instance of RendererInfo able to create this renderer.

Specified by:
getInfo in interface IRenderer
Returns:
the info object for this renderer.

createPreprocessor

public IInputPreprocessor createPreprocessor()
Description copied from interface: IRenderer
Constructs new instance of preprocessor.

Specified by:
createPreprocessor in interface IRenderer
Returns:
new instance of preprocessor. If null then no preprocessor is needed and will be ignored.


Copyright © 2003-2006 null. All Rights Reserved.