http://www.jpicedt.org

jpicedt.graphic.view.highlighter
Class DefaultHighlighter

java.lang.Object
  extended by jpicedt.graphic.view.highlighter.DefaultHighlighter
All Implemented Interfaces:
Highlighter
Direct Known Subclasses:
AbstractCurveHighlighter, CircleHighlighter, CompositeHighlighter, EllipseHighlighter, PsCurveHighlighter, SmoothPolygonHighlighter, TextHighlighter

public class DefaultHighlighter
extends Object
implements Highlighter

Default implementation of the Highlighter interface.

Since:
jPicEdt 1.4
Version:
$Id: DefaultHighlighter.java,v 1.7 2013/03/27 06:54:36 vincentb1 Exp $
Author:
Sylvain Reynal

Field Summary
protected  Rectangle2D.Double bounds
          Cache for highlighter bounds.
protected  Element element
          highlighted Element
protected  DefaultHighlighterFactory factory
          factory
protected  PointIndexIterator pointIndexIterator
          iterator over visible control-points
protected  PicPoint ptBuffer
          buffer used by paint only ; may be safely used by subclasses as well
protected  Rectangle2D rectBuffer
          buffer used by paint only ; may be safely used by subclasses as well
protected  Shape shape
          highlighter shape ; should be null if N/A in subclass
 
Constructor Summary
DefaultHighlighter(Element element, DefaultHighlighterFactory f)
           
 
Method Summary
 void changedUpdate(DrawingEvent.EventType eventType, double scale)
          Give notification from the model that a change occured for an element's highlighting this highlighter is responsible for rendering.
 Rectangle2D getBounds()
          Returns the bounds of this Highlighter
This will determine the clipping rectangle passed as a parameter to repaint in the hosting view
 PointIndexIterator getControlPointsIterator()
          Returns an iterator over control-points that should be displayed by the hightligher.
 Element getElement()
          returns the higlighted Element
 HighlighterFactory getHighlighterFactory()
          Fetches the HighlighterFactory implementation that is feeding the view hierarchy.
 HitInfo hitTest(PEMouseEvent e)
          Current implementation returns a HitInfo.Point if a click occured on one of the controlled-point indices returned by getControlPointsIterator(); null otherwise.
 boolean intersect(Rectangle2D r, ArrayList<Element> list)
          If this highligher intersects the given rectangle, add the associated Element (or a child Element if it's more appropriate, for instance for composite views) to the given list, and returns true.
 void paint(Graphics2D g, Rectangle2D allocation, double scale)
          Render the Highlighter to the given graphic context.
protected  void syncBounds(double scale)
          Synchronizes the highlighter's bounding rectangle (aka clip) with the model; "bounds" is first computed from the set of visible control-points, then its size gets increased by BARBELL_SIZE.
protected  void syncShape(double scale)
          Synchronize the shape needed to paint this highlighter, with the model; this could be, for instance, tangents in the case of a Bezier curve, the outline in the case of an ellipse, etc.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

factory

protected DefaultHighlighterFactory factory
factory


element

protected Element element
highlighted Element


pointIndexIterator

protected PointIndexIterator pointIndexIterator
iterator over visible control-points


shape

protected Shape shape
highlighter shape ; should be null if N/A in subclass


bounds

protected Rectangle2D.Double bounds
Cache for highlighter bounds.


rectBuffer

protected Rectangle2D rectBuffer
buffer used by paint only ; may be safely used by subclasses as well


ptBuffer

protected PicPoint ptBuffer
buffer used by paint only ; may be safely used by subclasses as well

Constructor Detail

DefaultHighlighter

public DefaultHighlighter(Element element,
                          DefaultHighlighterFactory f)
Parameters:
element - the Element to be highlighted
Method Detail

getElement

public Element getElement()
Description copied from interface: Highlighter
returns the higlighted Element

Specified by:
getElement in interface Highlighter
Returns:
the higlighted Element.

getHighlighterFactory

public HighlighterFactory getHighlighterFactory()
Fetches the HighlighterFactory implementation that is feeding the view hierarchy.

Specified by:
getHighlighterFactory in interface Highlighter
Returns:
the factory, null if none

changedUpdate

public void changedUpdate(DrawingEvent.EventType eventType,
                          double scale)
Give notification from the model that a change occured for an element's highlighting this highlighter 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" :
  1. syncShape() if it's a DrawingEvent.GEOMETRY_CHANGE
  2. syncBounds() if it's a DrawingEvent.GEOMETRY_CHANGE

Specified by:
changedUpdate in interface Highlighter

syncBounds

protected void syncBounds(double scale)
Synchronizes the highlighter's bounding rectangle (aka clip) with the model; "bounds" is first computed from the set of visible control-points, then its size gets increased by BARBELL_SIZE. Finally, if shape (see syncShape()) is non-null, it gets appended to the bounding rectangle.

Parameters:
scale - The current scale factor from-model-to-screen for the Graphics2D context ; this may be used to scale down line thickess, etc… so that e.g. barbells appear with the same size on the screen whatever the current zoom factor.

syncShape

protected void syncShape(double scale)
Synchronize the shape needed to paint this highlighter, with the model; this could be, for instance, tangents in the case of a Bezier curve, the outline in the case of an ellipse, etc. This implementation does nothing.

Parameters:
scale - The current scale factor from-model-to-screen for the Graphics2D context ; this may be used to scale down line thickess, etc… so that e.g. barbells appear with the same size on the screen whatever the scale factor being set to the graphic context.

paint

public void paint(Graphics2D g,
                  Rectangle2D allocation,
                  double scale)
Render the Highlighter to the given graphic context.
Current implementation first paints the shape member if it's non-null (see the syncShape() method), then control-points by delegating to a DefaultPointIndexIterator, using the highlighter color if the given allocation intersects the bounds of this view,

Specified by:
paint in interface Highlighter
Parameters:
scale - The current scale factor from-model-to-screen for the Graphics2D context ; this may be used to scale down line thickess, etc… so that e.g. barbells appear with the same size on the screen whatever the scale factor being set to the graphic context.
allocation - current clipping

getControlPointsIterator

public PointIndexIterator getControlPointsIterator()
Returns an iterator over control-points that should be displayed by the hightligher. This default implementation iterates over all control-points.


getBounds

public Rectangle2D getBounds()
Description copied from interface: Highlighter
Returns the bounds of this Highlighter
This will determine the clipping rectangle passed as a parameter to repaint in the hosting view

Specified by:
getBounds in interface Highlighter
Returns:
the bounds of this Highlighter
This will determine the clipping rectangle passed as a parameter to repaint in the hosting view

hitTest

public HitInfo hitTest(PEMouseEvent e)
Current implementation returns a HitInfo.Point if a click occured on one of the controlled-point indices returned by getControlPointsIterator(); null otherwise.

Specified by:
hitTest in interface Highlighter
Returns:
a HitInfo corresponding to the given mouse-event

intersect

public boolean intersect(Rectangle2D r,
                         ArrayList<Element> list)
If this highligher intersects the given rectangle, add the associated Element (or a child Element if it's more appropriate, for instance for composite views) to the given list, and returns true.

Specified by:
intersect in interface Highlighter

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org