Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

jpicedt.graphic.view
Class DefaultViewFactory.LeafElementView  view DefaultViewFactory.LeafElementView download DefaultViewFactory.LeafElementView.java

java.lang.Object
  extended byjpicedt.graphic.view.AbstractView
      extended byjpicedt.graphic.view.DefaultViewFactory.LeafElementView
All Implemented Interfaces:
View
Direct Known Subclasses:
DefaultViewFactory.CubicBezierView, DefaultViewFactory.EllipseView, DefaultViewFactory.PolygonView, DefaultViewFactory.QuadBezierView, DefaultViewFactory.RectangleView, DefaultViewFactory.TextView
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  java.awt.Paint interiorPaint
          paint for interior (cached)
protected  double lineWidth
          line width to be used to compute the view bounds (cached)
protected  java.awt.Paint outlinePaint
          paint for outline (cached)
protected  java.awt.Stroke outlineStroke
          stroke for outline (cached)
protected  java.awt.Shape shape
          shape to be drawn ; subclass must update it properly
 
Fields inherited from class jpicedt.graphic.view.AbstractView
bounds, element
 
Fields inherited from interface jpicedt.graphic.view.View
BARBELL_SIZE, CLICK_DISTANCE
 
Constructor Summary
DefaultViewFactory.LeafElementView(jpicedt.graphic.model.Element e)
          construct a new View for the given Element
 
Method Summary
 void changedUpdate(jpicedt.graphic.event.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(jpicedt.graphic.event.PEMouseEvent e, boolean isHighlightVisible)
          This implementation calls super.hitTest and returns the result if non-null (this should be a HitInfo.Point), then returns a HitInfo.Interior if the view is painted filled and a click occured on the interior, or finally a HitInfo.Stroke if a click occured on the stroke path (this use a FlatteningPathIterator built from shape).
 void paint(java.awt.Graphics2D g, java.awt.geom.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
protected  void syncBounds()
          Synchronizes the bounding box with the model ; "bounds" is first computed from element.getBoundingBox(), (which is not necessarily a wise choice, since in a way it ties probably too deeply the view and the model [pending]), then its size gets increased by BARBELL_SIZE, line-thickness, and possibly the shadow area, so as to prevent the outline from sticking out of the bounds if lines are real thick.
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, getParentView, paintHighlighter, repaint, setElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

shape

protected java.awt.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)


outlineStroke

protected java.awt.Stroke outlineStroke
stroke for outline (cached)


interiorPaint

protected java.awt.Paint interiorPaint
paint for interior (cached)


outlinePaint

protected java.awt.Paint outlinePaint
paint for outline (cached)

Constructor Detail

DefaultViewFactory.LeafElementView

public DefaultViewFactory.LeafElementView(jpicedt.graphic.model.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

changedUpdate

public void changedUpdate(jpicedt.graphic.event.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.
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


syncBounds

protected void syncBounds()
Synchronizes the bounding box with the model ; "bounds" is first computed from element.getBoundingBox(), (which is not necessarily a wise choice, since in a way it ties probably too deeply the view and the model [pending]), then its size gets increased by BARBELL_SIZE, line-thickness, and possibly the shadow area, so as to prevent the outline from sticking out of the bounds if lines are real thick.


syncShape

protected void syncShape()
Synchronize the "shape" variable with the model ; obviously, this implementation does nothing !


paint

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

Specified by:
paint in interface View
Overrides:
paint in class AbstractView
Since:
jPicEdt 1.3.2

hitTest

public HitInfo hitTest(jpicedt.graphic.event.PEMouseEvent e,
                       boolean isHighlightVisible)
This implementation calls super.hitTest and returns the result if non-null (this should be a HitInfo.Point), then returns a HitInfo.Interior if the view is painted filled and a click occured on the interior, or finally a HitInfo.Stroke if a click occured on the stroke path (this use a FlatteningPathIterator built from shape).

Specified by:
hitTest in interface View
Overrides:
hitTest in class AbstractView
Since:
jPicEdt 1.3.2