Package jpicedt.graphic.view
Class AbstractView
- java.lang.Object
-
- jpicedt.graphic.view.AbstractView
-
- All Implemented Interfaces:
View,ViewConstants
- Direct Known Subclasses:
CompositeView,DefaultViewFactory.LeafElementView
public abstract class AbstractView extends java.lang.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
Fields Modifier and Type Field Description protected java.awt.geom.Rectangle2Dboundsthe bounds rectangle used for clipping (as returned by getBounds) ; this should be updated by changedUpdate.protected Elementelementthe graphic element that this View rendersprotected Highlighterhighlighterthe highlighter delegate for this view-
Fields inherited from interface jpicedt.graphic.view.ViewConstants
BARBELL_SIZE, CLICK_DISTANCE
-
-
Constructor Summary
Constructors Constructor Description AbstractView(Element element)construct a new View for the given ElementAbstractView(Element element, Highlighter h)construct a new View for the given Element, delegating highlighting to the given Highlighter.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.awt.geom.Rectangle2DgetBounds()PECanvasgetContainer()Fetches the container hosting the view.DrawinggetDrawing()Fetches the model associated with the view.ElementgetElement()java.awt.GraphicsgetGraphics()Fetch a Graphics for rendering from the hosting container (if not null).HighlightergetHighlighter()Returns the Highlighter responsible for rendering the highlighted part of this view.ViewgetParentView()Returns the parent of the view, as given by the tree-structure the associated graphic element belongs to.ViewFactorygetViewFactory()Fetches the ViewFactory implementation that is feeding the view hierarchy.protected abstract HitInfohitTest(PEMouseEvent e)Returns a HitInfo corresponding to the given mouse-event.HitInfohitTest(PEMouseEvent e, boolean isHighlightVisible)Depending on the value of isHighlighVisible, current implementation first delegates to the hosted Highlighter's hitTest() method, then callshitTest(PEMouseEvent).voidpaintHighlighter(java.awt.Graphics2D g, java.awt.geom.Rectangle2D allocation, double scale)Render the Highlighter to the given graphic context.voidrepaint(java.awt.geom.Rectangle2D clip)ask the hosting container (if it's non-null) to repaint itselfvoidsetElement(Element e)set the element the View is responsible for renderingvoidsetHighlighter(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 java.awt.geom.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:
getElementin interfaceView- 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:
setElementin interfaceView
-
getParentView
public View getParentView()
Returns the parent of the view, as given by the tree-structure the associated graphic element belongs to.- Specified by:
getParentViewin interfaceView- 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:
getContainerin interfaceView- Returns:
- the container, null if none
-
getViewFactory
public ViewFactory getViewFactory()
Fetches the ViewFactory implementation that is feeding the view hierarchy.- Specified by:
getViewFactoryin interfaceView- Returns:
- the factory, null if none
-
getGraphics
public java.awt.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:
getGraphicsin interfaceView- Since:
- 1.3
-
getDrawing
public Drawing getDrawing()
Fetches the model associated with the view.- Specified by:
getDrawingin interfaceView- Returns:
- the view model, null if none
-
repaint
public void repaint(java.awt.geom.Rectangle2D clip)
ask the hosting container (if it's non-null) to repaint itself
-
getBounds
public java.awt.geom.Rectangle2D getBounds()
-
getHighlighter
public Highlighter getHighlighter()
Returns the Highlighter responsible for rendering the highlighted part of this view.- Specified by:
getHighlighterin interfaceView- 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:
setHighlighterin interfaceView- Parameters:
h- the delegate ; null if this View mustn't support highlighting
-
paintHighlighter
public void paintHighlighter(java.awt.Graphics2D g, java.awt.geom.Rectangle2D allocation, double scale)Render the Highlighter to the given graphic context.- Specified by:
paintHighlighterin interfaceView- Parameters:
allocation- current clippingscale- 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 callshitTest(PEMouseEvent).
-
-