http://www.jpicedt.org

jpicedt.graphic.view
Class DefaultViewFactory.LeafElementView

java.lang.Object
  extended byjpicedt.graphic.view.AbstractView
      extended byjpicedt.graphic.view.DefaultViewFactory.LeafElementView
All Implemented Interfaces:
View, ViewConstants
Direct Known Subclasses:
DefaultViewFactory.AbstractCurveView, DefaultViewFactory.EllipseView, DefaultViewFactory.ParallelogramView, DefaultViewFactory.PicNodeConnectionView, DefaultViewFactory.TextView, DefaultViewFactory.TextViewHybrid
Enclosing class:
DefaultViewFactory

protected abstract class DefaultViewFactory.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  Paint interiorPaint
          paint for interior (cached)
protected  double lineWidth
          line width to be used to compute the view bounds (cached)
protected  Paint outlinePaint
          paint for outline (cached)
protected  Stroke outlineStroke
          stroke for outline (cached)
protected  double overStrikeWidth
          overstrike width
protected  Rectangle2D.Double shadowBounds
          buffer
protected  Shape shape
          shape to be drawn ; subclass must update it properly
 
Fields inherited from class jpicedt.graphic.view.AbstractView
bounds, element, highlighter
 
Fields inherited from interface jpicedt.graphic.view.ViewConstants
BARBELL_SIZE, CLICK_DISTANCE
 
Constructor Summary
DefaultViewFactory.LeafElementView(Element e)
          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.
 ViewFactory getViewFactory()
          Fetches the ViewFactory implementation that is feeding the view hierarchy.
 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).
 void paint(Graphics2D g, Rectangle2D a)
          Render the View to the given graphic context.
protected  void syncAttributes()
          Synchronizes cached attributes values with the model ; lineWidth, from the LINE_WIDTH attribute outlineStroke, from the ViewFactory, using createStroke outinePaint, from the ViewFactory, using createPaintForOutline interiorPaint, from the ViewFactory, using createPaintForInterior overStrikeWidth, from the OVER_STRIKE and OVER_STRIKE_WIDTH attributes
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 the shadow area.
protected  void syncShape()
          Synchronize the "shape" variable with the model ; obviously, this implementation does nothing !
 
Methods inherited from class jpicedt.graphic.view.AbstractView
getBounds, getContainer, getDrawing, getElement, getGraphics, getHighlighter, getParentView, hitTest, paintHighlighter, repaint, setElement, setHighlighter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

shape

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


lineWidth

protected double lineWidth
line width to be used to compute the view bounds (cached)


overStrikeWidth

protected double overStrikeWidth
overstrike width


outlineStroke

protected Stroke outlineStroke
stroke for outline (cached)


interiorPaint

protected Paint interiorPaint
paint for interior (cached)


outlinePaint

protected Paint outlinePaint
paint for outline (cached)


shadowBounds

protected Rectangle2D.Double shadowBounds
buffer

Constructor Detail

DefaultViewFactory.LeafElementView

public DefaultViewFactory.LeafElementView(Element e)
construct a new View for the given Element

Method Detail

getViewFactory

public ViewFactory getViewFactory()
Fetches the ViewFactory implementation that is feeding the view hierarchy. This implementation first try to fetch a ViewFactory from the parent view, in case the root-view was produced from another ViewFactory (which for instance partially delegates to this factory), then, if there's no parent view, return the enclosing class.

Specified by:
getViewFactory in interface View
Overrides:
getViewFactory in class AbstractView
Returns:
the factory, null if none

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" :

  • syncAttributes() if it's an ATTRIBUTE_CHANGE event type or during initialization
  • syncShape() in any case
  • syncBounds() in any case.
  • changedUpdate on the highlighter delegate, if any.
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 ;
  • lineWidth, from the LINE_WIDTH attribute
  • outlineStroke, from the ViewFactory, using createStroke
  • outinePaint, from the ViewFactory, using createPaintForOutline
  • interiorPaint, from the ViewFactory, using createPaintForInterior
  • overStrikeWidth, from the OVER_STRIKE and OVER_STRIKE_WIDTH attributes


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 the shadow area.


syncShape

protected void syncShape()
Synchronize the "shape" variable with the model ; obviously, this implementation does 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

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org