http://www.jpicedt.org

jpicedt.graphic.view
Class AbstractView

java.lang.Object
  extended byjpicedt.graphic.view.AbstractView
All Implemented Interfaces:
View, ViewConstants
Direct Known Subclasses:
CompositeView, DefaultViewFactory.LeafElementView

public abstract class AbstractView
extends Object
implements View, ViewConstants

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

Since:
jpicedt 1.3.2
Version:
$Id: AbstractView.java,v 1.11.2.1 2007/09/02 11:56:29 reynal 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
 
Fields inherited from interface jpicedt.graphic.view.ViewConstants
BARBELL_SIZE, CLICK_DISTANCE
 
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 model associated with the view.
 Element getElement()
           
 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).
 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()
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, and will be different for a print view than a component view.

Specified by:
getGraphics in interface View
Since:
1.3

getDrawing

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

Specified by:
getDrawing in interface View
Returns:
the view 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.
Returns:
a HitInfo corresponding to the given mouse-event

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org