|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jpicedt.graphic.view.DefaultViewFactory
public class DefaultViewFactory
This is the default factory used to:
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.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.
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 |
---|
public static Font TEXT_FONT_DEFAULT
public static String KEY_TEXT_FONT
protected static final float TEXT_FONT_SCALE
protected static Font textFont
protected HashMap<Class<? extends Element>,Class<? extends View>> factoryMap
HashMap
that associates View
's classes with Element
's
classes
Constructor Detail |
---|
public DefaultViewFactory()
Method Detail |
---|
public static void main(String[] arg)
public String toString()
toString
in class Object
public static void configure(Properties preferences)
Properties
object.
preferences
- properties used to read shared parameters
If null, default values are used.public void map(Class<? extends Element> classElement, Class<? extends View> classView)
Element
's class in the hashmap
responsible for creating View's for Element
's.
public void unmap(Class<? extends Element> classElement)
Element
's class in the hashmap responsible
for creating View's for Element
's.
public Class<? extends View> getMappedClass(Class<? extends Element> classElement)
View
's class associated with the given Element
's class in the
hashmap responsible for creating View
's for Element
's.
public View createView(Element element)
Element
by looking up the hashmap responsible for creating
View
's for Element
's.
createView
in interface ViewFactory
public BasicStroke createStroke(PicAttributeSet set)
null
if
LINE_STYLE
=NONE
. All currently supported attributes for stroke are rendered.
createStroke
in interface AttributesViewFactory
set
- used to fetch the LINE_STYLE attributespublic BasicStroke createStrokeForOverstrike(PicAttributeSet set)
OVER_STRIKE
attribute. Factory
that don't
overstrike should override to return null
.
createStrokeForOverstrike
in interface AttributesViewFactory
set
- used to fetch the overstrike attributespublic Paint createPaintForOutline(PicAttributeSet set)
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).
createPaintForOutline
in interface AttributesViewFactory
set
- used to fetch the LINE_COLOR attributespublic Paint createPaintForShadow(PicAttributeSet set)
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).
createPaintForShadow
in interface AttributesViewFactory
set
- used to fetch the SHADOW and related attributespublic Paint createPaintForInterior(PicAttributeSet set)
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:
FILL_STYLE
= NONE
: returns null
FILL_STYLE
= SOLID
, VLINES
, VLINES_FILLED
,
HLINES
, HLINES_FILLED
, CROSSHATCH
and
CROSSHATCH_FILLED
: returns a Color object created from FILL_COLOR
.jpicedt.graphic.model.PicObjectConstants
) for painting the interior of shapes
are rendered. [pending] gradient (need to add some attributes).
createPaintForInterior
in interface AttributesViewFactory
set
- used to fetch the SHADOW and related attributespublic void paintHatches(Graphics2D g, PicAttributeSet set, Shape shape)
FILL_STYLE
attributes of the given set.
Factories that don't paint hatches should override this method to do nothing.
paintHatches
in interface AttributesViewFactory
shape
- used to clip the hatch (i.e. the shape the calling view must render)public Shape createShadow(PicAttributeSet set, Shape shape)
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
.
createShadow
in interface AttributesViewFactory
shape
- the Shape under which to drop a shadowset
- used to fetch the shadow attributes
public ArrowView createArrow(PicAttributeSet set, PicAttributeName<StyleConstants.ArrowStyle> direction)
AttributesViewFactory
createArrow
in interface AttributesViewFactory
direction
- LEFT_ARROW
or RIGHT_ARROW
ArrowView
from the given attribute set, or null
if
ArrowStyle.NONE
.
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |