lt.monarch.chart
Class AbstractView<E extends AbstractPaintTags>

java.lang.Object
  extended by lt.monarch.chart.AbstractView<E>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, StyleEditorEntity, View
Direct Known Subclasses:
AbstractChart, AbstractLegend, CompositeView, LabelView

public abstract class AbstractView<E extends AbstractPaintTags>
extends java.lang.Object
implements View, StyleEditorEntity, java.io.Serializable

Default implementation of most utility methods of View

See Also:
Serialized Form

Field Summary
Modifier and Type Field and Description
protected  boolean layoutInvalid
          Specifies whether view layout is invalid.
protected  PaintStyle<E> paintStyle
          Color style object for getting and setting entityStyle to stylesheet
 Style style
          Local stylesheet.
 
Constructor Summary
Constructor and Description
AbstractView()
           
 
Method Summary
Modifier and Type Method and Description
protected  void activate()
          Prepares the view, when it is added to a view container
 void addViewListener(ViewListener listener)
          Adds the specified view listener to receive notification when the view is invalidated, activated or deactivated.
 java.lang.Object clone()
          Creates and returns a copy of this object.
 ViewContainer container()
          Deprecated. use getContainer()
protected  void deactivate()
          Cleanups the view, when it is removed from the view container
 void dispose()
          Cleans this view.
protected  void finalize()
          Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
 float getAlignmentX()
          Returns the alignment along the x axis.
 float getAlignmentY()
          Returns the alignment along the y axis.
 Rectangle2D getBounds()
          Gets the bounds of this view in the form of a Rectangle object.
 Rectangle2D getChartObjectBounds()
          Gets bounds of chart object
 ViewContainer getContainer()
          Gets the view container.
 GraphicsManager.GraphicsType getGraphicsType()
          Returns graphics type
 double getHeight()
          Return the current height of this view.
 java.awt.Dimension getMaximumSize(AbstractGraphics g)
          Gets the maximum size of this view.
 java.awt.Dimension getMinimumSize(AbstractGraphics g)
          Gets the minimum size of this view.
 PaintMode getPaintMode()
          Gets view painting mode.
 PaintStyle<E> getPaintStyle()
          Gets paint style object
 java.lang.Object getParent()
          Return the parent chart object
 java.awt.Dimension getPreferredSize(AbstractGraphics g)
          Gets the preferred size of this view in the specified Graphics context.
 java.awt.Dimension getSize()
          Returns the size of this view in the form of a Dimension object.
 java.awt.Dimension getSize(java.awt.Dimension rv)
          Store the width/height of this view into "return value" rv and return rv.
 Style getStyle()
          Gets style of this view.
 AbstractStyle<?> getStyle(StyleType styleType)
          Gets style object for the stylesheet attributes specified by style type.
 double getWidth()
          Return the current width of this view.
 double getX()
          Return the current x coordinate of the views origin.
 double getY()
          Return the current y coordinate of the views origin.
 void invalidate()
          Invalidates the view.
protected  boolean isLayoutValid()
          Determines whether view layout is valid.
protected  void layout(AbstractGraphics g)
          Prepares the view by arranging all internal views and calculates required constants.
protected abstract  void paint(AbstractGraphics g)
          Paints the view.
 void removeViewListener(ViewListener listener)
          Removes the specified view listener so that it no longer receives notifications from this view.
 void render(AbstractGraphics g)
          Prepares and renders the view.
 void repaint()
          Repaints entire view.
 void repaint(Rectangle2D r)
          Repaints the specified view region.
 void setAlignmentX(float alignmentX)
          Sets the the vertical alignment.
 void setAlignmentY(float alignmentY)
          Sets the the horizontal alignment.
 void setBounds(double x, double y, double width, double height)
          Moves and resizes this view.
 void setBounds(Rectangle2D r)
          Moves and resizes this view to conform to the new bounding rectangle r.
 void setContainer(ViewContainer container)
          Sets a container for this view.
 void setLocation(double x, double y)
          Moves this view to a new location.
 void setMaximumSize(int width, int height)
          Sets the maximum size of this view to a constant value.
 void setMinimumSize(int width, int height)
          Sets the minimum size of this view to a constant value.
 void setPaintMode(PaintMode paintMode)
          Sets view painting mode.
 void setPreferredSize(int width, int height)
          Sets the preferred size of the receiving view.
 void setSize(double width, double height)
          Resizes this view so that it has width width and height.
 void validate(AbstractGraphics g)
          Validates the view in the specified Graphics context.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface lt.monarch.chart.engine.View
getContainingObjects
 

Field Detail

style

public final Style style
Local stylesheet. All color and font information is stored here


paintStyle

protected PaintStyle<E extends AbstractPaintTags> paintStyle
Color style object for getting and setting entityStyle to stylesheet


layoutInvalid

protected boolean layoutInvalid
Specifies whether view layout is invalid. If true, invalidate does nothing.

Constructor Detail

AbstractView

public AbstractView()
Method Detail

addViewListener

public void addViewListener(ViewListener listener)
Adds the specified view listener to receive notification when the view is invalidated, activated or deactivated. If listener is null, no exception is thrown and no action is performed.

Specified by:
addViewListener in interface View
Parameters:
listener - the view listener
See Also:
ViewListener

removeViewListener

public void removeViewListener(ViewListener listener)
Removes the specified view listener so that it no longer receives notifications from this view. If listener is null, no exception is thrown and no action is performed.

Specified by:
removeViewListener in interface View
Parameters:
listener - the view listener
See Also:
ViewListener

getStyle

public Style getStyle()
Gets style of this view.

Specified by:
getStyle in interface View
Returns:
style of this view
See Also:
Style

repaint

public void repaint()
Repaints entire view.

Specified by:
repaint in interface View

repaint

public void repaint(Rectangle2D r)
Repaints the specified view region.

Specified by:
repaint in interface View
Parameters:
r - the view region to repaint

invalidate

public void invalidate()
Invalidates the view.

Specified by:
invalidate in interface View

setContainer

public void setContainer(ViewContainer container)
Sets a container for this view. If container is null, view container is set to NullViewContainer.instance.

Specified by:
setContainer in interface View
Parameters:
container - the view container
See Also:
ViewContainer

container

@Deprecated
public ViewContainer container()
Deprecated. use getContainer()

Gets the view container.

Specified by:
container in interface View
Returns:
the view container
See Also:
ViewContainer

getContainer

public ViewContainer getContainer()
Gets the view container.

Returns:
the view container
See Also:
ViewContainer

setBounds

public void setBounds(Rectangle2D r)
Moves and resizes this view to conform to the new bounding rectangle r. This view's new position is specified by r.x and r.y, and its new size is specified by r.width and r.height

Specified by:
setBounds in interface View
Parameters:
r - the new bounding rectangle for this view

getBounds

public Rectangle2D getBounds()
Gets the bounds of this view in the form of a Rectangle object. The bounds specify this view's width, height, and location relative to its parent.

Specified by:
getBounds in interface View
Returns:
a rectangle indicating this component's bounds.

getPreferredSize

public java.awt.Dimension getPreferredSize(AbstractGraphics g)
Gets the preferred size of this view in the specified Graphics context.

Specified by:
getPreferredSize in interface View
Parameters:
g - the Graphics context in which view will be painted
Returns:
a dimension object indicating this view's preferred size.

render

public final void render(AbstractGraphics g)
Prepares and renders the view.

Specified by:
render in interface View
Parameters:
g - graphics context

isLayoutValid

protected boolean isLayoutValid()
Determines whether view layout is valid.

Returns:
true if view layout is valid, false otherwise

validate

public void validate(AbstractGraphics g)
Validates the view in the specified Graphics context. If layout of the view is invalid the view bounds are intersected with current graphics context clipping area and view is layouted.

Specified by:
validate in interface View
Parameters:
g - the Graphics context in which view will be painted

layout

protected void layout(AbstractGraphics g)
Prepares the view by arranging all internal views and calculates required constants.

Parameters:
g - graphics context

activate

protected void activate()
Prepares the view, when it is added to a view container


deactivate

protected void deactivate()
Cleanups the view, when it is removed from the view container


paint

protected abstract void paint(AbstractGraphics g)
Paints the view.

Parameters:
g - graphics context

setLocation

public void setLocation(double x,
                        double y)
Moves this view to a new location. The top-left corner of the new location is specified by the x and y.

Specified by:
setLocation in interface View
Parameters:
x - The x-coordinate of the new location'stop-left corner.
y - The y-coordinate of the new location's top-left corner.

getX

public double getX()
Return the current x coordinate of the views origin.

Specified by:
getX in interface View
Returns:
the current x coordinate of the views origin.

getY

public double getY()
Return the current y coordinate of the views origin.

Specified by:
getY in interface View
Returns:
the current y coordinate of the views origin.

getMaximumSize

public java.awt.Dimension getMaximumSize(AbstractGraphics g)
Gets the maximum size of this view.

Specified by:
getMaximumSize in interface View
Parameters:
g - the Graphics context in which view will be painted
Returns:
A dimension object indicating this view's maximum size.

getMinimumSize

public java.awt.Dimension getMinimumSize(AbstractGraphics g)
Gets the minimum size of this view.

Specified by:
getMinimumSize in interface View
Parameters:
g - the Graphics context in which view will be painted
Returns:
A dimension object indicating this view's minimum size.

setSize

public void setSize(double width,
                    double height)
Resizes this view so that it has width width and height.

Specified by:
setSize in interface View
Parameters:
width - The new width of this view in pixels.
height - The new height of this view in pixels.

getSize

public java.awt.Dimension getSize()
Returns the size of this view in the form of a Dimension object. The height field of the Dimension object contains this view's height, and the width field of the Dimension object contains this view's width.

Specified by:
getSize in interface View
Returns:
A Dimension object that indicates the size of this view.

getSize

public java.awt.Dimension getSize(java.awt.Dimension rv)
Store the width/height of this view into "return value" rv and return rv. If rv is null a new Dimension object is allocated. This version of getSize() is useful if the caller wants to avoid allocating a new Dimension object on the heap.

Specified by:
getSize in interface View
Parameters:
rv - the return value, modified to the view size
Returns:
rv

getHeight

public double getHeight()
Return the current height of this view. This method is preferable to writing view.getBounds().height, or view.getSize().height because it doesn't cause any heap allocations.

Specified by:
getHeight in interface View
Returns:
the current height of this view.

getWidth

public double getWidth()
Return the current width of this view. This method is preferable to writing view.getBounds().width, or view.getSize().width because it doesn't cause any heap allocations.

Specified by:
getWidth in interface View
Returns:
the current width of this view.

setBounds

public void setBounds(double x,
                      double y,
                      double width,
                      double height)
Moves and resizes this view. The new location of the top-left corner is specified by x and y, and the new size is specified by width and height.

Specified by:
setBounds in interface View
Parameters:
x - The new x-coordinate of this view.
y - The new y-coordinate of this view.
width - The new width of this view.
height - The new height of this view.

setMinimumSize

public void setMinimumSize(int width,
                           int height)
Sets the minimum size of this view to a constant value. Subsequent calls to getMinimumSize will always return this value.

Specified by:
setMinimumSize in interface View
Parameters:
width - the minimum width of the view
height - the minimum height of the view

setMaximumSize

public void setMaximumSize(int width,
                           int height)
Sets the maximum size of this view to a constant value. Subsequent calls to getMaximumSize will always return this value.

Specified by:
setMaximumSize in interface View
Parameters:
width - the maximum width of the view
height - the maximum height of the view

setPreferredSize

public void setPreferredSize(int width,
                             int height)
Sets the preferred size of the receiving view.

Specified by:
setPreferredSize in interface View
Parameters:
width - the preferred width of the receiving view
height - the preferred height of the receiving view

getAlignmentX

public float getAlignmentX()
Returns the alignment along the x axis. This specifies how the view would like to be aligned relative to other views. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the farthest away from the origin, 0.5 is centered, etc.

Specified by:
getAlignmentX in interface View
Returns:
the alignment along the x axis

getAlignmentY

public float getAlignmentY()
Returns the alignment along the y axis. This specifies how the view would like to be aligned relative to other views. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the farthest away from the origin, 0.5 is centered, etc.

Specified by:
getAlignmentY in interface View
Returns:
the alignment along the y axis

setAlignmentX

public void setAlignmentX(float alignmentX)
Sets the the vertical alignment.

Specified by:
setAlignmentX in interface View
Parameters:
alignmentX - the alignment along the x axis

setAlignmentY

public void setAlignmentY(float alignmentY)
Sets the the horizontal alignment.

Specified by:
setAlignmentY in interface View
Parameters:
alignmentY - the alignment along the y axis

dispose

public void dispose()
Cleans this view.

Specified by:
dispose in interface View

clone

public java.lang.Object clone()
Creates and returns a copy of this object.

Specified by:
clone in interface View
Overrides:
clone in class java.lang.Object
Returns:
clone of this view

finalize

protected void finalize()
                 throws java.lang.Throwable
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. Calls cleanup method if it isn't called yet.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - the Exception raised by this method

setPaintMode

public void setPaintMode(PaintMode paintMode)
Sets view painting mode. Possible values are: FILL_PAINT, HATCH_PAINT and GRADIENT_PAINT. FILL_PAINT for single color toFill-painting. GRADIENT_PAINT for cyclic (from start color to center color and from center color to start color) or acyclic (from start color to end color) gradient panel painting. By default the paint mode is set to FILL_PAINT.

Parameters:
paintMode - paint mode constant.

getPaintMode

public PaintMode getPaintMode()
Gets view painting mode. Possible values are: FILL_PAINT, HATCH_PAINT and GRADIENT_PAINT. FILL_PAINT for single color toFill-painting. GRADIENT_PAINT for cyclic (from start color to center color and from center color to start color) or acyclic (from start color to end color) gradient panel painting. By default the paint mode is set to FILL_PAINT.

Returns:
paintMode paint mode constant.

getPaintStyle

public PaintStyle<E> getPaintStyle()
Gets paint style object

Returns:
the paintStyle object

getGraphicsType

public GraphicsManager.GraphicsType getGraphicsType()
Returns graphics type

Specified by:
getGraphicsType in interface View
Returns:
graphicsType graphics type for view

getStyle

public AbstractStyle<?> getStyle(StyleType styleType)
Description copied from interface: StyleEditorEntity
Gets style object for the stylesheet attributes specified by style type.

Specified by:
getStyle in interface StyleEditorEntity
Parameters:
styleType - style type attributes
Returns:
the style object

getChartObjectBounds

public Rectangle2D getChartObjectBounds()
Description copied from interface: StyleEditorEntity
Gets bounds of chart object

Specified by:
getChartObjectBounds in interface StyleEditorEntity
Returns:
A rectangle indicating this chart object bounds

getParent

public java.lang.Object getParent()
Description copied from interface: StyleEditorEntity
Return the parent chart object

Specified by:
getParent in interface StyleEditorEntity
Returns:
the parent