http://www.jpicedt.org

jpicedt.graphic.view
Class DefaultViewFactory

java.lang.Object
  extended by jpicedt.graphic.view.DefaultViewFactory
All Implemented Interfaces:
AttributesViewFactory, ViewFactory
Direct Known Subclasses:
DXFViewFactory, EepicViewFactory, PstricksViewFactory, TikzViewFactory

public class DefaultViewFactory
extends Object
implements ViewFactory, AttributesViewFactory

This is the default factory used to:

  1. create a View for a given Element ; it relies on a hashmap that associates View's classes with Element's class, the former being dynamically instanciated (through Reflection) on-the-fly when needed.
  2. create objects for rendering Element's attributes.
This factory should be used when one wants to render all Element's attributes ; otherwise just subclass with your own ViewFactory and override factory methods, e.g. createStroke, createPaintForInterior, createPaintForOutline, …: these methods are called by various View's to extract rendering information from PicAttributeSet's when common behaviour is expected, whatever the particular Element being actually rendered. You may also want to add your own Element/View association by calling the map() method. In this case, your View class MUST have one constructor of the form View(? super your_element, ? super this_factory) for the reflection mechanism to work properly.

Since:
jPicEdt 1.3.2
Version:
$Id: DefaultViewFactory.java,v 1.63 2013/03/27 06:55:01 vincentb1 Exp $
Author:
Sylvain Reynal

Field Summary
protected  HashMap<Class<? extends Element>,Class<? extends View>> factoryMap
          a HashMap that associates View's classes with Element's classes
static String KEY_TEXT_FONT
          key used to fetch the font family value from a Properties object
static Font TEXT_FONT_DEFAULT
          default font used to display text with TextView
protected static float TEXT_FONT_SCALE
          scaling factor to be applied to the default font before rendering, so as to compensate for zoom factor
protected static Font textFont
          font used to display text strings with TextView
 
Constructor Summary
DefaultViewFactory()
           
 
Method Summary
static void configure(Properties preferences)
          Configure static fields using the given Properties object.
 ArrowView createArrow(PicAttributeSet set, PicAttributeName<StyleConstants.ArrowStyle> direction)
          Returns an ArrowView for rendering arrow-related attributes using the given attribute set.
 Paint createPaintForInterior(PicAttributeSet set)
          Returns a Paint object from the given attributes, that is suited for painting the interior of a shape.
 Paint createPaintForOutline(PicAttributeSet set)
          Returns a Paint object from the given attributes, that is suited for painting an outline, or null if LINE_STYLE is NONE.
 Paint createPaintForShadow(PicAttributeSet set)
          Returns a Paint object suited for rendering shadows.
 Shape createShadow(PicAttributeSet set, Shape shape)
          Returns a Shape for rendering the shadow of the given Shape, whose properties are drawn from the SHADOW attribute and rel.
 BasicStroke createStroke(PicAttributeSet set)
          Returns a Stroke built from the given attributes ; null if LINE_STYLE=NONE.
 BasicStroke createStrokeForOverstrike(PicAttributeSet set)
          Returns a Stroke built from the OVER_STRIKE attribute.
 View createView(Element element)
          Create a View for the given Element by looking up the hashmap responsible for creating View's for Element's.
 Class<? extends View> getMappedClass(Class<? extends Element> classElement)
          Returns the View's class associated with the given Element's class in the hashmap responsible for creating View's for Element's.
static void main(String[] arg)
          For debugging purpose.
 void map(Class<? extends Element> classElement, Class<? extends View> classView)
          Associates the given View's class with the given Element's class in the hashmap responsible for creating View's for Element's.
 void paintHatches(Graphics2D g, PicAttributeSet set, Shape shape)
          Paint hatches (vlines,…) depending on the FILL_STYLE attributes of the given set.
 String toString()
           
 void unmap(Class<? extends Element> classElement)
          Remove the element/view mapping for the given Element's class in the hashmap responsible for creating View's for Element's.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TEXT_FONT_DEFAULT

public static Font TEXT_FONT_DEFAULT
default font used to display text with TextView


KEY_TEXT_FONT

public static String KEY_TEXT_FONT
key used to fetch the font family value from a Properties object


TEXT_FONT_SCALE

protected static final float TEXT_FONT_SCALE
scaling factor to be applied to the default font before rendering, so as to compensate for zoom factor

See Also:
Constant Field Values

textFont

protected static Font textFont
font used to display text strings with TextView


factoryMap

protected HashMap<Class<? extends Element>,Class<? extends View>> factoryMap
a HashMap that associates View's classes with Element's classes

Constructor Detail

DefaultViewFactory

public DefaultViewFactory()
Method Detail

main

public static void main(String[] arg)
For debugging purpose.


toString

public String toString()
Overrides:
toString in class Object

configure

public static void configure(Properties preferences)
Configure static fields using the given Properties object.

Parameters:
preferences - properties used to read shared parameters If null, default values are used.

map

public void map(Class<? extends Element> classElement,
                Class<? extends View> classView)
Associates the given View's class with the given Element's class in the hashmap responsible for creating View's for Element's.

Since:
jpicedt 1.5

unmap

public void unmap(Class<? extends Element> classElement)
Remove the element/view mapping for the given Element's class in the hashmap responsible for creating View's for Element's.

Since:
jpicedt 1.5

getMappedClass

public Class<? extends View> getMappedClass(Class<? extends Element> classElement)
Returns the View's class associated with the given Element's class in the hashmap responsible for creating View's for Element's.

Since:
jpicedt 1.5

createView

public View createView(Element element)
Create a View for the given Element by looking up the hashmap responsible for creating View's for Element's.

Specified by:
createView in interface ViewFactory
Returns:
a View for the given Element
Since:
jpicedt 1.5

createStroke

public BasicStroke createStroke(PicAttributeSet set)
Returns a Stroke built from the given attributes ; null if LINE_STYLE=NONE. All currently supported attributes for stroke are rendered.

Specified by:
createStroke in interface AttributesViewFactory
Parameters:
set - used to fetch the LINE_STYLE attributes

createStrokeForOverstrike

public BasicStroke createStrokeForOverstrike(PicAttributeSet set)
Returns a Stroke built from the OVER_STRIKE attribute. Factory that don't overstrike should override to return null.

Specified by:
createStrokeForOverstrike in interface AttributesViewFactory
Parameters:
set - used to fetch the overstrike attributes

createPaintForOutline

public Paint createPaintForOutline(PicAttributeSet set)
Returns a Paint object from the given attributes, that is suited for painting an outline, or null if LINE_STYLE is NONE.

All currently supported attributes for painting an outline are rendered. It's up to subclassers to adapt this behavior to their need (probably by restricting it).

Specified by:
createPaintForOutline in interface AttributesViewFactory
Parameters:
set - used to fetch the LINE_COLOR attributes

createPaintForShadow

public Paint createPaintForShadow(PicAttributeSet set)
Returns a Paint object suited for rendering shadows. Guaranteed to return a non-null object, even if shadowing is not supported (although a subclass may return null as well).

All currently supported attributes for painting a shadow are rendered. It's up to subclassers to adapt this behavior to their need (probably by restricting it, e.g., to gray-levels).

Specified by:
createPaintForShadow in interface AttributesViewFactory
Parameters:
set - used to fetch the SHADOW and related attributes

createPaintForInterior

public Paint createPaintForInterior(PicAttributeSet set)
Returns a Paint object from the given attributes, that is suited for painting the interior of a shape.

The returned object depends on the FILL_STYLE and FILL_COLOR attributes of the given set:

To sum up, all currently supported attributes (as defined in jpicedt.graphic.model.PicObjectConstants) for painting the interior of shapes are rendered. [pending] gradient (need to add some attributes).

Specified by:
createPaintForInterior in interface AttributesViewFactory
Parameters:
set - used to fetch the SHADOW and related attributes

paintHatches

public void paintHatches(Graphics2D g,
                         PicAttributeSet set,
                         Shape shape)
Paint hatches (vlines,…) depending on the FILL_STYLE attributes of the given set. Factories that don't paint hatches should override this method to do nothing.

Specified by:
paintHatches in interface AttributesViewFactory
Parameters:
shape - used to clip the hatch (i.e. the shape the calling view must render)

createShadow

public Shape createShadow(PicAttributeSet set,
                          Shape shape)
Returns a Shape for rendering the shadow of the given Shape, whose properties are drawn from the SHADOW attribute and rel. Factory that don't paint shadow should override to return null.

Specified by:
createShadow in interface AttributesViewFactory
Parameters:
shape - the Shape under which to drop a shadow
set - used to fetch the shadow attributes
Returns:
null if no shadow should be painted.

createArrow

public ArrowView createArrow(PicAttributeSet set,
                             PicAttributeName<StyleConstants.ArrowStyle> direction)
Description copied from interface: AttributesViewFactory
Returns an ArrowView for rendering arrow-related attributes using the given attribute set.

Specified by:
createArrow in interface AttributesViewFactory
Parameters:
direction - LEFT_ARROW or RIGHT_ARROW
Returns:
an ArrowView from the given attribute set, or null if ArrowStyle.NONE.

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org