net.sourceforge.swtlayeredgraph
Class GraphGridLayer

java.lang.Object
  extended by net.sourceforge.swtlayeredgraph.GraphGridLayer
All Implemented Interfaces:
IGraphGridLayer

public class GraphGridLayer
extends java.lang.Object
implements IGraphGridLayer

Author:
davija

Constructor Summary
GraphGridLayer()
          Default constructor
GraphGridLayer(java.lang.Double xInterval, java.lang.Double yInterval, LineStyle xLineStyle, LineStyle yLineStyle, int xWidth, int yWidth, int xMultiplier, int yMultiplier, int xMultWidth, int yMultWidth, java.lang.Boolean visible, CoordinateType type, org.eclipse.swt.graphics.Color color)
          Builds a graph grid layer object.
 
Method Summary
 void addChangeListener(ChangeListener listener)
          Subscribes to change events.
 void draw(GCTransformer transformer)
          Draws the grid.
protected  org.eclipse.swt.graphics.Color drawInit(SwtGC gc)
          Initializes drawing.
protected  void drawLines(SwtGC gc, int incX, int incY, org.eclipse.swt.graphics.Point startPoint, org.eclipse.swt.graphics.Point endPoint, org.eclipse.swt.graphics.Point multipule, org.eclipse.swt.graphics.Point origin)
          Draws the grid using lines.
protected  void drawPoints(SwtGC gc, int incX, int incY, int radius, org.eclipse.swt.graphics.Point startPoint, org.eclipse.swt.graphics.Point endPoint, org.eclipse.swt.graphics.Point multipule, org.eclipse.swt.graphics.Point origin)
          Draws the grid using points.
 org.eclipse.swt.graphics.Color getColor()
          Gets the line color for the grid.
 CoordinateType getCoordinateType()
          Gets the coordinate type for x/y increments.
protected  org.eclipse.swt.graphics.Point getStartingMultiplierValues(GCTransformer transformer, int incX, int incY)
           
protected  org.eclipse.swt.graphics.Point getStartingPoint(GCTransformer transformer, int incX, int incY)
          Calculates the point to start drawing grid.
 java.lang.Double getXInterval()
          Gets the X interval.
 int getXLineMultiplier()
          Gets the x line multiplier.
 int getXLineMultiplierWidth()
          Gets the with of lines that match the x multiplier.
 LineStyle getXLineStyle()
          Gets the line style for horizontal lines.
 int getXLineWidth()
          Gets the horizontal line width in pixels.
 java.lang.Double getYInterval()
          Gets the Y interval.
 int getYLineMultiplier()
          Gets the y line multiplier.
 int getYLineMultiplierWidth()
          Gets the with of lines that match the x multiplier.
 LineStyle getYLineStyle()
          Gets the line style for vertical lines.
 int getYLineWidth()
          Gets the vertical line width in pixels.
 java.lang.Boolean isVisible()
          Checks if the grid is visible.
 void removeChangeListener(ChangeListener listener)
          Removes subscription to change events.
 void setColor(org.eclipse.swt.graphics.Color color)
          Sets the line color.
 void setCoordinateType(CoordinateType type)
          Sets the coordinate type of the x/y intervals.
 void setVisible(java.lang.Boolean visible)
          Sets the visibility flag for the grid.
 void setXInterval(java.lang.Double interval)
          Sets the X interval (vertical line spacing).
 void setXLineMultiplier(int multiplier)
          Sets the new x line multiplier.
 void setXLineMultiplierWidth(int width)
          Sets the width of lines that match the y multiplier.
 void setXLineStyle(LineStyle lineStyle)
          Sets the line style for horizontal lines.
 void setXLineWidth(int width)
          Sets the width (in pixels) of horizontal lines.
 void setYInterval(java.lang.Double interval)
          Sets the Y interval (horizontal line spacing).
 void setYLineMultiplier(int multiplier)
          Sets the new y line multiplier.
 void setYLineMultiplierWidth(int width)
          Sets the width of lines that match the y multiplier.
 void setYLineStyle(LineStyle lineStyle)
          Sets the line style for vertical lines.
 void setYLineWidth(int width)
          Sets the width (in pixels) of vertical lines.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphGridLayer

public GraphGridLayer()
Default constructor


GraphGridLayer

public GraphGridLayer(java.lang.Double xInterval,
                      java.lang.Double yInterval,
                      LineStyle xLineStyle,
                      LineStyle yLineStyle,
                      int xWidth,
                      int yWidth,
                      int xMultiplier,
                      int yMultiplier,
                      int xMultWidth,
                      int yMultWidth,
                      java.lang.Boolean visible,
                      CoordinateType type,
                      org.eclipse.swt.graphics.Color color)
Builds a graph grid layer object.

Parameters:
xInterval - Interval between vertical lines.
yInterval - Interval between horizontal lines.
xLineStyle - Line style for horizontal lines.
yLineStyle - Line style for vertical lines.
xWidth - Width (in pixels) of horizontal lines.
yWidth - Width (in pixels) of vertical lines.
visible - Flag to indicate if grid is visible.
xMultiplier - X multiplier interval. Zero disables usage of multiplier interval.
yMultiplier - Y multiplier interval. Zero disables usage of multiplier interval.
xMultWidth - Width of x multiple lines (in pixels).
yMultWidth - Width of y multiple lines (in pixels).
type - Coordinate system interval is in.
color - Color of grid.
Throws:
IllegalArgumentExcetpion - If xInterval, yInterval, xLineStyle, yLineStyle, visible, type or color are null. Also thrown if xWidth or yWidth <= 0.
Method Detail

getStartingPoint

protected org.eclipse.swt.graphics.Point getStartingPoint(GCTransformer transformer,
                                                          int incX,
                                                          int incY)
Calculates the point to start drawing grid. This is the first intersection that is just outside of the drawing region.

Parameters:
transformer - GC Transformer that contains gc to draw on.
incX - Number of pixels between vertical lines.
incY - Number of pixels between horizontal lines.
Returns:
Returns the point to start drawing the grid from.

getStartingMultiplierValues

protected org.eclipse.swt.graphics.Point getStartingMultiplierValues(GCTransformer transformer,
                                                                     int incX,
                                                                     int incY)

drawInit

protected org.eclipse.swt.graphics.Color drawInit(SwtGC gc)
Initializes drawing. It will also return the current line color so it can be restored when drawing is completed.

Parameters:
gc - The GC object to draw on.
Returns:
The original foreground color that needs to be restored when completed.

drawLines

protected void drawLines(SwtGC gc,
                         int incX,
                         int incY,
                         org.eclipse.swt.graphics.Point startPoint,
                         org.eclipse.swt.graphics.Point endPoint,
                         org.eclipse.swt.graphics.Point multipule,
                         org.eclipse.swt.graphics.Point origin)
Draws the grid using lines.

Parameters:
gc - The GC to draw to.
incX - Number of pixels between vertical lines.
incY - Number of pixels between horizontal lines.
startPoint - Point to start drawing from.
endPoint - Point to end drawing at.
multipule - Point that specifies the multiplier value.
origin - Point that specifies 0, 0 on the graph.

drawPoints

protected void drawPoints(SwtGC gc,
                          int incX,
                          int incY,
                          int radius,
                          org.eclipse.swt.graphics.Point startPoint,
                          org.eclipse.swt.graphics.Point endPoint,
                          org.eclipse.swt.graphics.Point multipule,
                          org.eclipse.swt.graphics.Point origin)
Draws the grid using points.

Parameters:
gc - The GC to draw to.
incX - Number of pixels between vertical lines.
incY - Number of pixels between horizontal lines.
radius - Number of pixels for diameter of the point. If < 1, 1 is used.
startPoint - Point to start drawing from.
endPoint - Point to end drawing at.
multipule - Point that specifies the multiplier value.
origin - Point that specifies 0, 0 on the graph.

draw

public void draw(GCTransformer transformer)
Description copied from interface: IGraphGridLayer
Draws the grid.

Specified by:
draw in interface IGraphGridLayer
Parameters:
transformer - Transformer that contains the GC to draw on.

getColor

public org.eclipse.swt.graphics.Color getColor()
Description copied from interface: IGraphGridLayer
Gets the line color for the grid.

Specified by:
getColor in interface IGraphGridLayer
Returns:
Returns line color.

getCoordinateType

public CoordinateType getCoordinateType()
Description copied from interface: IGraphGridLayer
Gets the coordinate type for x/y increments.

Specified by:
getCoordinateType in interface IGraphGridLayer
Returns:

isVisible

public java.lang.Boolean isVisible()
Description copied from interface: IGraphGridLayer
Checks if the grid is visible.

Specified by:
isVisible in interface IGraphGridLayer
Returns:
Returns true if visible, false otherwise.

getXInterval

public java.lang.Double getXInterval()
Description copied from interface: IGraphGridLayer
Gets the X interval.

Specified by:
getXInterval in interface IGraphGridLayer
Returns:
Returns the X interval.

getXLineStyle

public LineStyle getXLineStyle()
Description copied from interface: IGraphGridLayer
Gets the line style for horizontal lines.

Specified by:
getXLineStyle in interface IGraphGridLayer
Returns:
Returns the line style for horizontal lines.

getXLineWidth

public int getXLineWidth()
Description copied from interface: IGraphGridLayer
Gets the horizontal line width in pixels.

Specified by:
getXLineWidth in interface IGraphGridLayer
Returns:
Returns the horizontal line width in pixels.

getXLineMultiplier

public int getXLineMultiplier()
Description copied from interface: IGraphGridLayer
Gets the x line multiplier. Lines that match this interval are drawn with the multiplier width.

Specified by:
getXLineMultiplier in interface IGraphGridLayer
Returns:
Returns the x line multiplier.

setXLineMultiplier

public void setXLineMultiplier(int multiplier)
Description copied from interface: IGraphGridLayer
Sets the new x line multiplier. Lines that match this interval are drawn with the multiplier width. Multiplier of zero disables multiplier.

Specified by:
setXLineMultiplier in interface IGraphGridLayer
Parameters:
multiplier - New multiplier.

getXLineMultiplierWidth

public int getXLineMultiplierWidth()
Description copied from interface: IGraphGridLayer
Gets the with of lines that match the x multiplier.

Specified by:
getXLineMultiplierWidth in interface IGraphGridLayer
Returns:
Returns the width of lines that match the x multiplier.

setXLineMultiplierWidth

public void setXLineMultiplierWidth(int width)
Description copied from interface: IGraphGridLayer
Sets the width of lines that match the y multiplier.

Specified by:
setXLineMultiplierWidth in interface IGraphGridLayer
Parameters:
width - New multiplier.

getYLineMultiplier

public int getYLineMultiplier()
Description copied from interface: IGraphGridLayer
Gets the y line multiplier. Lines that match this interval are drawn with the multiplier width.

Specified by:
getYLineMultiplier in interface IGraphGridLayer
Returns:
Returns the y line multiplier.

setYLineMultiplier

public void setYLineMultiplier(int multiplier)
Description copied from interface: IGraphGridLayer
Sets the new y line multiplier. Lines that match this interval are drawn with the multiplier width. Multiplier of zero disables multiplier.

Specified by:
setYLineMultiplier in interface IGraphGridLayer
Parameters:
multiplier - New multiplier.

getYLineMultiplierWidth

public int getYLineMultiplierWidth()
Description copied from interface: IGraphGridLayer
Gets the with of lines that match the x multiplier.

Specified by:
getYLineMultiplierWidth in interface IGraphGridLayer
Returns:
Returns the width of lines that match the y multiplier.

setYLineMultiplierWidth

public void setYLineMultiplierWidth(int width)
Description copied from interface: IGraphGridLayer
Sets the width of lines that match the y multiplier.

Specified by:
setYLineMultiplierWidth in interface IGraphGridLayer
Parameters:
width - New multiplier.

getYInterval

public java.lang.Double getYInterval()
Description copied from interface: IGraphGridLayer
Gets the Y interval.

Specified by:
getYInterval in interface IGraphGridLayer
Returns:
Returns the Y interval.

getYLineStyle

public LineStyle getYLineStyle()
Description copied from interface: IGraphGridLayer
Gets the line style for vertical lines.

Specified by:
getYLineStyle in interface IGraphGridLayer
Returns:
Returns the line style for horizontal lines.

getYLineWidth

public int getYLineWidth()
Description copied from interface: IGraphGridLayer
Gets the vertical line width in pixels.

Specified by:
getYLineWidth in interface IGraphGridLayer
Returns:
Returns the vertical line width in pixels.

setColor

public void setColor(org.eclipse.swt.graphics.Color color)
Description copied from interface: IGraphGridLayer
Sets the line color. Note that grid will not assume ownership of the color object. Proper disposal is the responsibility of the caller.

Specified by:
setColor in interface IGraphGridLayer
Parameters:
color - New color to use for grid.

setCoordinateType

public void setCoordinateType(CoordinateType type)
Description copied from interface: IGraphGridLayer
Sets the coordinate type of the x/y intervals. This will also convert the x/y intervals to the specified type.

Specified by:
setCoordinateType in interface IGraphGridLayer
Parameters:
type - New coordinate system type.

setVisible

public void setVisible(java.lang.Boolean visible)
Description copied from interface: IGraphGridLayer
Sets the visibility flag for the grid.

Specified by:
setVisible in interface IGraphGridLayer
Parameters:
visible - Flag to indicate if grid is visible.

setXInterval

public void setXInterval(java.lang.Double interval)
Description copied from interface: IGraphGridLayer
Sets the X interval (vertical line spacing).

Specified by:
setXInterval in interface IGraphGridLayer
Parameters:
interval - Distance between vertical lines.

setXLineStyle

public void setXLineStyle(LineStyle lineStyle)
Description copied from interface: IGraphGridLayer
Sets the line style for horizontal lines.

Specified by:
setXLineStyle in interface IGraphGridLayer
Parameters:
lineStyle - Line style for horizontal lines.

setXLineWidth

public void setXLineWidth(int width)
Description copied from interface: IGraphGridLayer
Sets the width (in pixels) of horizontal lines.

Specified by:
setXLineWidth in interface IGraphGridLayer
Parameters:
width - Width (in pixels) of horizontal lines.

setYInterval

public void setYInterval(java.lang.Double interval)
Description copied from interface: IGraphGridLayer
Sets the Y interval (horizontal line spacing).

Specified by:
setYInterval in interface IGraphGridLayer
Parameters:
interval - Distance between horizontal lines.

setYLineStyle

public void setYLineStyle(LineStyle lineStyle)
Description copied from interface: IGraphGridLayer
Sets the line style for vertical lines.

Specified by:
setYLineStyle in interface IGraphGridLayer
Parameters:
lineStyle - Line style for vertical lines.

setYLineWidth

public void setYLineWidth(int width)
Description copied from interface: IGraphGridLayer
Sets the width (in pixels) of vertical lines.

Specified by:
setYLineWidth in interface IGraphGridLayer
Parameters:
width - Width (in pixels) of vertical lines.

addChangeListener

public void addChangeListener(ChangeListener listener)
Description copied from interface: IGraphGridLayer
Subscribes to change events.

Specified by:
addChangeListener in interface IGraphGridLayer
Parameters:
listener - Listener to call when a change occurs.

removeChangeListener

public void removeChangeListener(ChangeListener listener)
Description copied from interface: IGraphGridLayer
Removes subscription to change events.

Specified by:
removeChangeListener in interface IGraphGridLayer
Parameters:
listener - Listener to unregister.


Copyright © 2009. All Rights Reserved.