http://www.jpicedt.org

jpicedt.graphic.view
Class LeafElementView

java.lang.Object
  extended by jpicedt.graphic.view.AbstractView
      extended by jpicedt.graphic.view.LeafElementView
All Implemented Interfaces:
View
Direct Known Subclasses:
AbstractCurveView, EllipseView, ParallelogramView, PicNodeConnectionView, TextView, TextViewHybrid

public class LeafElementView
extends AbstractView

A View for rendering leaf-elements; implements attributes caching, and shape rendering. Subclasses might just override the changedUpdate method, and update the shape variable accordingly.


Field Summary
protected  AttributesViewFactory attrFactory
           
protected  Paint interiorPaint
          paint for interior (cached)
protected  ArrowView leftArrow
          arrows to be painted if non-null
protected  Paint outlinePaint
          paint for outline (cached)
protected  BasicStroke outlineStroke
          stroke for outline and arrows (cached)
protected  BasicStroke overstrikeStroke
          stroke for overstrike (cached)
protected  ArrowView rightArrow
          arrows to be painted if non-null
protected  Shape shadow
          shadow to be painted if non-null ; updated using shape
protected  Paint shadowPaint
          paint for shadow (cached)
protected  Shape shape
          shape to be painted ; subclass must update it properly
 
Fields inherited from class jpicedt.graphic.view.AbstractView
bounds, element, highlighter
 
Constructor Summary
LeafElementView(Element e, AttributesViewFactory f)
          construct a new View for the given Element
 
Method Summary
 void changedUpdate(DrawingEvent.EventType eventType)
          Give notification from the model that a change occured for an element this view is responsible for rendering.
 HitInfo hitTest(PEMouseEvent e)
          This implementation returns a HitInfo.Interior if the view is filled and a click occured on the interior, or a HitInfo.Stroke if a click occured on the stroke path (this use a FlatteningPathIterator built from the currentshape).
protected  boolean intersect(Rectangle2D r, ArrayList<Element> list)
          If this view intersects the given rectangle, adds the associated Element to the given list (if non-null) and returns true.
 void paint(Graphics2D g, Rectangle2D a)
          Render the View to the given graphic context.
protected  void syncArrowsAttributes()
          Synchronizes arrows' specific attributes with the model.
protected  void syncArrowsGeometry()
          Sync the geometry of the current "left/rightArrowShape" variables with the model if applicable, that is, if these vars are non-null (means: not Arrow.NONE).
protected  void syncAttributes()
          Synchronizes cached attributes values with the model ; outlineStroke, from the ViewFactory, using createStroke overstrikeStroke, from the ViewFactory, using createStrokeForOverstrike outlinePaint, from the ViewFactory, using createPaintForOutline interiorPaint, from the ViewFactory, using createPaintForInterior shadowPaint, from the ViewFactory, using createPaintForShadow then calls syncArrowAttributes()
protected  void syncBounds()
          Synchronizes the bounding box with the model ; "bounds" is first computed from the current shape's bound, if any, then its size gets increased by BARBELL_SIZE, line-thickness, overstrike width, and possibly shadow and arrows areas.
protected  void syncShadow()
          sync' the shadow with the current shape (which must therefore be valid) AND the current PicAttributeSet; hence must be called either when the geometry's changed, or when attributes have changed.
protected  void syncShape()
          Synchronize the "shape" variable with the model
 
Methods inherited from class jpicedt.graphic.view.AbstractView
getBounds, getContainer, getDrawing, getElement, getGraphics, getHighlighter, getParentView, getViewFactory, hitTest, intersect, paintHighlighter, repaint, setElement, setHighlighter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attrFactory

protected AttributesViewFactory attrFactory

shape

protected Shape shape
shape to be painted ; subclass must update it properly


shadow

protected Shape shadow
shadow to be painted if non-null ; updated using shape


outlineStroke

protected BasicStroke outlineStroke
stroke for outline and arrows (cached)


overstrikeStroke

protected BasicStroke overstrikeStroke
stroke for overstrike (cached)


interiorPaint

protected Paint interiorPaint
paint for interior (cached)


outlinePaint

protected Paint outlinePaint
paint for outline (cached)


shadowPaint

protected Paint shadowPaint
paint for shadow (cached)


leftArrow

protected ArrowView leftArrow
arrows to be painted if non-null


rightArrow

protected ArrowView rightArrow
arrows to be painted if non-null

Constructor Detail

LeafElementView

public LeafElementView(Element e,
                       AttributesViewFactory f)
construct a new View for the given Element

Method Detail

changedUpdate

public void changedUpdate(DrawingEvent.EventType eventType)
Give notification from the model that a change occured for an element this view is responsible for rendering.

To reduce the burden for subclasses, this implemention dispatches to the following methods, in that order, depending on the value of "eventType" :

then call repaint with the union of the old and the new bounds as the argument.
Subclass might simply want to update shape before calling super.changedUpdate(), or override syncAttributes() and syncBounds() if they must implement more specific behaviour.


syncAttributes

protected void syncAttributes()
Synchronizes cached attributes values with the model ;


syncArrowsAttributes

protected void syncArrowsAttributes()
Synchronizes arrows' specific attributes with the model. Called from syncAttributes(). This implementation creates arrows from ViewFactory.createArrow(). View that don't support arrows should override to do nothing. Those that support arrows only when the geometry enables this should override and call superclass when applicable.


syncBounds

protected void syncBounds()
Synchronizes the bounding box with the model ; "bounds" is first computed from the current shape's bound, if any, then its size gets increased by BARBELL_SIZE, line-thickness, overstrike width, and possibly shadow and arrows areas.


syncShape

protected void syncShape()
Synchronize the "shape" variable with the model


syncArrowsGeometry

protected void syncArrowsGeometry()
Sync the geometry of the current "left/rightArrowShape" variables with the model if applicable, that is, if these vars are non-null (means: not Arrow.NONE). This method gets called from changedUpdate() each time a GEOMETRY_CHANGE or ATTRIBUTE_CHANGE event occurs.


syncShadow

protected void syncShadow()
sync' the shadow with the current shape (which must therefore be valid) AND the current PicAttributeSet; hence must be called either when the geometry's changed, or when attributes have changed. Factories that do not support shadowing may override to do nothing.


paint

public void paint(Graphics2D g,
                  Rectangle2D a)
Render the View to the given graphic context. This implementation relies on a bottom-to-top z-ordering policy, ie first renders the shadow, then the interior and hatches, finally the outline (=stroke).

Parameters:
a - the current graphic clip

hitTest

public HitInfo hitTest(PEMouseEvent e)
This implementation returns a HitInfo.Interior if the view is filled and a click occured on the interior, or a HitInfo.Stroke if a click occured on the stroke path (this use a FlatteningPathIterator built from the currentshape).

Specified by:
hitTest in class AbstractView
Returns:
a HitInfo corresponding to the given mouse-event

intersect

protected boolean intersect(Rectangle2D r,
                            ArrayList<Element> list)
If this view intersects the given rectangle, adds the associated Element to the given list (if non-null) and returns true.

Specified by:
intersect in class AbstractView

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org