http://www.jpicedt.org

jpicedt.graphic.view
Class AbstractView

java.lang.Object
  extended by jpicedt.graphic.view.AbstractView
All Implemented Interfaces:
View
Direct Known Subclasses:
CompositeView, LeafElementView

public abstract class AbstractView
extends Object
implements View

Abstract implementation that provide some basic common behaviours for View's.

Since:
jpicedt 1.3.2
Version:
$Id: AbstractView.java,v 1.24 2013/03/27 06:55:21 vincentb1 Exp $
Author:
Sylvain Reynal

Field Summary
protected  Rectangle2D bounds
          The bounds rectangle used for clipping (as returned by getBounds); this should be updated by changedUpdate.
protected  Element element
          The graphic element that this View renders.
protected  Highlighter highlighter
          The highlighter delegate for this view.
 
Constructor Summary
AbstractView(Element element)
          Construct a new View for the given Element.
AbstractView(Element element, Highlighter h)
          Construct a new View for the given Element, delegating highlighting to the given Highlighter.
 
Method Summary
 Rectangle2D getBounds()
           
 PECanvas getContainer()
          Fetches the container hosting the view.
 Drawing getDrawing()
          Fetches the drawing (aka model) associated with the view.
 Element getElement()
          Returns the element the View is responsible for rendering
 Graphics getGraphics()
          Fetch a Graphics for rendering from the hosting container (if not null).
 Highlighter getHighlighter()
          Returns the Highlighter responsible for rendering the highlighted part of this view.
 View getParentView()
          Returns the parent of the view, as given by the tree-structure the associated graphic element belongs to.
 ViewFactory getViewFactory()
          Fetches the ViewFactory implementation that is feeding the view hierarchy.
protected abstract  HitInfo hitTest(PEMouseEvent e)
          Returns a HitInfo corresponding to the given mouse-event.
 HitInfo hitTest(PEMouseEvent e, boolean isHighlightVisible)
          Depending on the value of isHighlighVisible, current implementation first delegates to the hosted Highlighter's hitTest() method, then calls hitTest(PEMouseEvent).
protected abstract  boolean intersect(Rectangle2D r, ArrayList<Element> list)
          If this view 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 (if non-null), and returns true.
 boolean intersect(Rectangle2D r, boolean isHighlightVisible, ArrayList<Element> list)
          Depending on the value of isHighlighVisible, current implementation first delegates to the hosted Highlighter's intersect() method, then calls intersect(Rectangle2D, ArrayList<Element>).
 void paintHighlighter(Graphics2D g, Rectangle2D allocation, double scale)
          Render the Highlighter to the given graphic context.
 void repaint(Rectangle2D clip)
          Ask the hosting container (if it's non-null) to repaint itself
 void setElement(Element e)
          Set the element the View is responsible for rendering.
 void setHighlighter(Highlighter h)
          Sets the Highlighter responsible for rendering the highlighted part of this view.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jpicedt.graphic.view.View
changedUpdate, paint
 

Field Detail

element

protected Element element
The graphic element that this View renders.


bounds

protected Rectangle2D bounds
The bounds rectangle used for clipping (as returned by getBounds); this should be updated by changedUpdate.


highlighter

protected Highlighter highlighter
The highlighter delegate for this view.

Constructor Detail

AbstractView

public AbstractView(Element element)
Construct a new View for the given Element.


AbstractView

public AbstractView(Element element,
                    Highlighter h)
Construct a new View for the given Element, delegating highlighting to the given Highlighter.

Method Detail

getElement

public Element getElement()
Description copied from interface: View
Returns the element the View is responsible for rendering

Specified by:
getElement in interface View
Returns:
the element the View is responsible for rendering.

setElement

public void setElement(Element e)
Set the element the View is responsible for rendering.

Specified by:
setElement in interface View

getParentView

public View getParentView()
Returns the parent of the view, as given by the tree-structure the associated graphic element belongs to.

Specified by:
getParentView in interface View
Returns:
the parent view, null if none (either because the element has no parent, or because the parent has no View).

getContainer

public PECanvas getContainer()
Fetches the container hosting the view. This is useful for things like scheduling a repaint, finding out the host components font, etc. The default implementation of this is to forward the query to the parent view, if any… (that means that for this method to return non-null, the element attached to this view must have a parent, and this parent, a view, etc…)

Specified by:
getContainer in interface View
Returns:
the container, null if none

getViewFactory

public ViewFactory getViewFactory()
Fetches the ViewFactory implementation that is feeding the view hierarchy.

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

getGraphics

public Graphics getGraphics()
Fetch a Graphics for rendering from the hosting container (if not null). This can be used to determine font characteristics.

Specified by:
getGraphics in interface View
Since:
jPicEdt 1.3

getDrawing

public Drawing getDrawing()
Fetches the drawing (aka model) associated with the view.

Specified by:
getDrawing in interface View
Returns:
the view's model, null if none

repaint

public void repaint(Rectangle2D clip)
Ask the hosting container (if it's non-null) to repaint itself

Specified by:
repaint in interface View
Parameters:
clip - the clip rectangle in model-coordinate; if null, simply call repaint() on the hosting container.

getBounds

public Rectangle2D getBounds()
Specified by:
getBounds in interface View
Returns:
the bounds of this View
This will determine the clipping rectangle passed as a parameter to repaint, and may include the highlighter's bounds as well.
Default implementation return bounds.

getHighlighter

public Highlighter getHighlighter()
Returns the Highlighter responsible for rendering the highlighted part of this view.

Specified by:
getHighlighter in interface View
Returns:
null if this view cannot be highlighted

setHighlighter

public void setHighlighter(Highlighter h)
Sets the Highlighter responsible for rendering the highlighted part of this view.

Specified by:
setHighlighter in interface View
Parameters:
h - the delegate ; null if this View mustn't support highlighting.

paintHighlighter

public void paintHighlighter(Graphics2D g,
                             Rectangle2D allocation,
                             double scale)
Render the Highlighter to the given graphic context.

Specified by:
paintHighlighter in interface View
Parameters:
allocation - current clipping
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 lines/rectangle/… appear with the same lenght on the screen whatever the scale factor that's set to the graphic context.

hitTest

protected abstract HitInfo hitTest(PEMouseEvent e)
Returns a HitInfo corresponding to the given mouse-event. Only the view's shape should be included in this test.


hitTest

public HitInfo hitTest(PEMouseEvent e,
                       boolean isHighlightVisible)
Depending on the value of isHighlighVisible, current implementation first delegates to the hosted Highlighter's hitTest() method, then calls hitTest(PEMouseEvent).

Specified by:
hitTest in interface View
Parameters:
isHighlightVisible - whether the receiver should include the highlighter shapes (e.g. end-points) in the click-sensitive area.
e - the mouse event for which a HitInfo is returned
Returns:
a HitInfo corresponding to the given mouse-event

intersect

public boolean intersect(Rectangle2D r,
                         boolean isHighlightVisible,
                         ArrayList<Element> list)
Depending on the value of isHighlighVisible, current implementation first delegates to the hosted Highlighter's intersect() method, then calls intersect(Rectangle2D, ArrayList<Element>).

Specified by:
intersect in interface View
isHighlightVisible - whether the receiver should include the highlighter shapes (e.g. control-points) in the intersection area.
Returns:
whether the given rectangle intersects this view or its highlighter (that is, whether the given list has been modified or not.

intersect

protected abstract boolean intersect(Rectangle2D r,
                                     ArrayList<Element> list)
If this view 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 (if non-null), and returns true.


http://www.jpicedt.org

Submit a bug : syd@jpicedt.org