ilog.views.maps.grids
Class IlvAbstractBaseGrid

java.lang.Object
  extended by ilog.views.IlvIndexedSet
      extended by ilog.views.IlvManagerLayer
          extended by ilog.views.maps.grids.IlvAbstractBaseGrid
All Implemented Interfaces:
IlvManagerViewDecoration, IlvPersistentObject, IlvManagerLightViewDecoration, Serializable
Direct Known Subclasses:
IlvLatLonGrid, IlvMGRSGrid

public abstract class IlvAbstractBaseGrid
extends IlvManagerLayer
implements IlvManagerViewDecoration, IlvManagerLightViewDecoration

The base class to draw grids on top of an IlvManagerView. This class is abstract, but provides many coordinate related utilities and base properties. Subclasses must at least implement the paintGrid(Graphics2D, IlvTransformer)method. For example, the following code can be used to display an automatically scaled longitude/latitude grid.



   IlvManagerView view=new IlvManagerView();
   ...
   IlvLatLonGrid grid = new IlvLatLonGrid();
   grid.setAutoScaled(true);
   grid.setGridColor(Color.lightGray);
   grid.setTextColor(Color.blue);
   view.getManager().addLayer(grid);
 
To have a non printed grid use view.addViewDecoration(grid); If you want the grid to be printed, use instead: view.getManager().addLayer(grid);

Since:
JViews 7.5
See Also:
Serialized Form

Field Summary
protected  Line2D bottomLine
          Current border lines of the visible rectangle - set in the paint(Graphics, IlvManagerView)method.
protected static FontRenderContext FRC
          Font render context used to draw text.
protected  Line2D leftLine
          Current border lines of the visible rectangle - set in the paint(Graphics, IlvManagerView)method.
protected  Line2D rightLine
          Current border lines of the visible rectangle - set in the paint(Graphics, IlvManagerView)method.
protected  IlvPoint tmp1
          Temporary point used to prevent the allocation of new ones for each transformation.
protected  IlvPoint tmp2
          Temporary point used to prevent the allocation of new ones for each transformation.
protected  Line2D topLine
          Current border lines of the visible rectangle - set in the paint(Graphics, IlvManagerView)method.
protected  Rectangle2D visibleRect
          Current visible view rect - set in the paint(Graphics, IlvManagerView)method.
 
Constructor Summary
IlvAbstractBaseGrid()
          Default constructor.
IlvAbstractBaseGrid(IlvInputStream stream)
          Creates a grid by reading parameters from the stream.
 
Method Summary
 void addObject(IlvGraphic obj)
          Overridden method to prevent objects being added on this layer.
protected  boolean checkPointInsideView(double lon, double lat)
          Checks if the lat/lon coordinates passed are inside the view visible rectangle.
 void draw(Graphics dst, IlvManagerView v)
          Paints the grid in the specified view.
protected  void drawImpl(Graphics dst, IlvManagerView v)
          Draws the grid content in the specified view.
protected  void drawLine(Graphics2D dst, IlvTransformer t, IlvPoint p1, IlvPoint p2, Object label, boolean drawLine)
          Utility to draw a grid line and its label.
protected  void drawString(Graphics2D dst, IlvTransformer t, IlvPoint p, String label)
          Utility to draw a label text.
protected  void drawText(Graphics2D g, Point2D point, Object label, boolean horizontal, int alignment)
          Utility to draw a label text.
 Point getAwtCoordinatesFromLatLon(double lon, double lat)
          Computes the awt point on the view from lat/lon coordinates in radians.
protected  IlvCoordinateTransformation getCoordinateTransformation()
          Returns the transformation to use to transform view coordinates to geographic system.
 IlvPoint getGraphicFromLatLonCoordinate(double lon, double lat, IlvPoint rtn)
          Computes an IlvPoint for placing IlvGraphic objects on the view from lat/lon coordinates.
 Color getGridColor()
          Returns the color to use for the grid lines.
protected  IlvCoordinateTransformation getInverseCoordinateTransformation()
          Returns the transformation to use to transform geographic system to view coordinates.
 IlvCoordinate getLatLonFromAwtCoordinates(int x, int y)
          Computes the longitude/latitude of an awt based point on the view (such as used by MouseEvent).
 IlvCoordinate getLatLonFromGraphicCoordinate(IlvPoint point)
          Computes an IlvCoordinate containing lat/lon in radians, from a set of xy IlvGraphic coordinates.
 int getSmoothness()
          Returns the smoothness factor, that is, the number of intermediary points between each line crossing.
 double getStep()
          Returns the distance between successive grid lines.
 Color getTextColor()
          Returns the color used to draw labels on top of the grid lines.
 Font getTextFont()
          Returns the font used to draw labels on top of the grid lines.
 Color getTextOutlineColor()
          Returns the color used to outline labels on top of the grid lines.
protected  double getViewScale()
          Returns the current view scale.
protected  IlvTransformer getViewTransformer()
          Returns the current view transformer.
 boolean isAutoScaled()
          Returns the autoscaling state (true by default).
protected  boolean isLightPainting()
          This flag indicates grids to try to paint "lightly".
 boolean isTextVisible()
          Returns true if the lines crossing the screen border should display text.
 boolean isVisible(IlvManagerView v)
          Returns true if the layer is visible in the specified view.
 void paint(Graphics dst, IlvManagerView v)
          Paints the grid in the specified view.
abstract  void paintGrid(Graphics2D dst, IlvTransformer t)
          Paints the grid.
 void paintLight(Graphics dst, IlvManagerView v)
          Paints the decoration in the specified view using a "quick" or light rendering.
 void print(Graphics dst, IlvRect area, IlvTransformer t)
          Prints the grid in the specified area.
 void setAutoScaled(boolean autoScaled)
          Activates/Deactivates the autoscaling mechanism.
 void setGridColor(Color gridColor)
          Sets the color used to draw grid lines.
protected  void setScale(double scale)
          Sets the current transformer and scale to use for the view.
 void setSmoothness(int smoothness)
          Sets the smoothness factor (that is, the number of intermediary points between each line crossing) A value above 1 is recommended for better appearance.
 void setStep(double step)
          Sets the distance between successive grid lines (if autoscaling is not activated).
 void setTextColor(Color textColor)
          Sets the color used to draw grid labels.
 void setTextFont(Font textFont)
          Sets the Font used to draw grid labels.
 void setTextOutlineColor(Color textOutlineColor)
          Sets the color used to outline grid labels.
 void setTextVisible(boolean textVisible)
          Indicates whether the lines crossing screen border should display their lat/lon text.
protected  void setTransformer(IlvTransformer t)
          Sets the current transformer to use for the view.
 void setVisibleOnlyOnView(IlvManagerView visibleView)
          Forces the grid to be displayed only on the specified view.
protected  void setVisibleRect(Rectangle2D r)
          Sets the rectangle within which the grid may be drawn.
protected  void updateTransforms(IlvManager m)
          Searches and updates the coordinate transformations to use, according to the coordinate system set on the manager.
 void updateViewParameters(IlvManagerView v)
          Sets grid parameters for next draw.
 void write(IlvOutputStream stream)
          Writes the layer to an output stream.
 
Methods inherited from class ilog.views.IlvManagerLayer
addVisibilityFilter, computeBBox, getAlpha, getIndex, getManager, getName, getNamedProperty, getProperty, getVisibilityFilters, isSelectable, isTemporarilyHidden, isVisible, removeNamedProperty, removeVisibilityFilter, setAlpha, setManager, setName, setNamedProperty, setProperty, writeIt
 
Methods inherited from class ilog.views.IlvIndexedSet
afterUpdate, beforeUpdate, collectObjects, deleteAll, getCardinal, getElements, getIndex, getManagers, getManagersCount, getObject, getObject, getSubsequentRemoveThreshold, isQuadtreeEnabled, map, mapInside, mapInside, mapIntersects, mapIntersects, removeObject, setIndex, setQuadtreeEnabled, setSubsequentRemoveThreshold
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FRC

protected static final FontRenderContext FRC
Font render context used to draw text.


bottomLine

protected transient Line2D bottomLine
Current border lines of the visible rectangle - set in the paint(Graphics, IlvManagerView)method. Used by drawLine(Graphics2D, IlvTransformer, IlvPoint, IlvPoint, Object, boolean) to detect intersections at which to place labels.


leftLine

protected transient Line2D leftLine
Current border lines of the visible rectangle - set in the paint(Graphics, IlvManagerView)method. Used by drawLine(Graphics2D, IlvTransformer, IlvPoint, IlvPoint, Object, boolean) to detect intersections at which labels can be placed.


rightLine

protected transient Line2D rightLine
Current border lines of the visible rectangle - set in the paint(Graphics, IlvManagerView)method. Used by drawLine(Graphics2D, IlvTransformer, IlvPoint, IlvPoint, Object, boolean) to detect intersections at which labels can be placed.


tmp1

protected final transient IlvPoint tmp1
Temporary point used to prevent the allocation of new ones for each transformation.

See Also:
drawLine(Graphics2D, IlvTransformer, IlvPoint, IlvPoint, Object, boolean), drawString(Graphics2D, IlvTransformer, IlvPoint, String)

tmp2

protected final transient IlvPoint tmp2
Temporary point used to prevent the allocation of new ones for each transformation.

See Also:
tmp1

topLine

protected transient Line2D topLine
Current border lines of the visible rectangle - set in the paint(Graphics, IlvManagerView)method. Used by drawLine(Graphics2D, IlvTransformer, IlvPoint, IlvPoint, Object, boolean) to detect intersections at which labels can be placed.


visibleRect

protected transient Rectangle2D visibleRect
Current visible view rect - set in the paint(Graphics, IlvManagerView)method. Used by drawLine(Graphics2D, IlvTransformer, IlvPoint, IlvPoint, Object, boolean) to detect intersections at which labels can be placed.

Constructor Detail

IlvAbstractBaseGrid

public IlvAbstractBaseGrid()
Default constructor.


IlvAbstractBaseGrid

public IlvAbstractBaseGrid(IlvInputStream stream)
Creates a grid by reading parameters from the stream.

Parameters:
stream - Stream to read from.
Method Detail

addObject

public void addObject(IlvGraphic obj)
Overridden method to prevent objects being added on this layer.

Overrides:
addObject in class IlvIndexedSet
Parameters:
obj - o

draw

public void draw(Graphics dst,
                 IlvManagerView v)
Paints the grid in the specified view. Since JViews 8.1, to take advantage of layer caching, this method calls super.draw(). The actual drawing code is done in drawImpl(Graphics, IlvManagerView).

Overrides:
draw in class IlvManagerLayer
Parameters:
dst - The Graphics to paint to.
v - The manager view.
See Also:
IlvManagerView.setLayerCached(int, boolean)

drawImpl

protected void drawImpl(Graphics dst,
                        IlvManagerView v)
Draws the grid content in the specified view.

Note: as updateViewParameters(IlvManagerView) is called for optimization issues, a grid will only be able to draw one at a time. This is true even if you are using multiple threads.

Overrides:
drawImpl in class IlvManagerLayer
Parameters:
dst - The Graphics object to paint to.
v - The manager view.
Since:
JViews 8.1
See Also:
IlvManagerLayer.draw(Graphics, IlvManagerView)

updateViewParameters

public void updateViewParameters(IlvManagerView v)
Sets grid parameters for next draw. This method computes current drawing parameters for optimization issues. A grid will be able to draw only once at a time - even if using multiple threads.

Parameters:
v - View for which to retrieve parameters.

getAwtCoordinatesFromLatLon

public Point getAwtCoordinatesFromLatLon(double lon,
                                         double lat)
                                  throws IlvCoordinateTransformationException
Computes the awt point on the view from lat/lon coordinates in radians.

Parameters:
lon - Longitude in radians.
lat - latitude in radians.
Returns:
An IlvCoordinate with latitude and longitude in radians.
Throws:
IlvCoordinateTransformationException
See Also:
getGraphicFromLatLonCoordinate(double, double, IlvPoint)

getGraphicFromLatLonCoordinate

public IlvPoint getGraphicFromLatLonCoordinate(double lon,
                                               double lat,
                                               IlvPoint rtn)
                                        throws IlvCoordinateTransformationException
Computes an IlvPoint for placing IlvGraphic objects on the view from lat/lon coordinates.

Parameters:
lon - Longitude in radians.
lat - Latitude in radians.
rtn - The returned point or null.
Returns:
an IlvPoint of an IlvGraphic inside the view.
Throws:
IlvCoordinateTransformationException
See Also:
IlvCoordinateTransformation.transform(IlvCoordinate, IlvCoordinate)

getGridColor

public Color getGridColor()
Returns the color to use for the grid lines.

Returns:
The color to use for the grid lines.
See Also:
setGridColor(Color)

getLatLonFromAwtCoordinates

public IlvCoordinate getLatLonFromAwtCoordinates(int x,
                                                 int y)
                                          throws IlvCoordinateTransformationException
Computes the longitude/latitude of an awt based point on the view (such as used by MouseEvent).

Parameters:
x - AWT x coordinate.
y - AWT y coordinate.
Returns:
An IlvCoordinate with latitude and longitude in radians.
Throws:
IlvCoordinateTransformationException
See Also:
getLatLonFromGraphicCoordinate(IlvPoint)

getLatLonFromGraphicCoordinate

public IlvCoordinate getLatLonFromGraphicCoordinate(IlvPoint point)
                                             throws IlvCoordinateTransformationException
Computes an IlvCoordinate containing lat/lon in radians, from a set of xy IlvGraphic coordinates.

Parameters:
point - Coordinate of an IlvGraphic inside the view.
Returns:
An IlvCoordinate with latitude and longitude in radians.
Throws:
IlvCoordinateTransformationException
See Also:
getCoordinateTransformation(), IlvCoordinateTransformation.transform(IlvCoordinate, IlvCoordinate)

getSmoothness

public int getSmoothness()
Returns the smoothness factor, that is, the number of intermediary points between each line crossing.

Returns:
The smoothness factor (can be lower than 1).
See Also:
setSmoothness(int)

getStep

public double getStep()
Returns the distance between successive grid lines.

Returns:
The distance in grid class specific units.
See Also:
setStep(double)

getTextColor

public Color getTextColor()
Returns the color used to draw labels on top of the grid lines.

Returns:
The color used to draw labels on top of the grid lines.
See Also:
setTextColor(Color)

getTextOutlineColor

public Color getTextOutlineColor()
Returns the color used to outline labels on top of the grid lines.

Returns:
The color used to outline labels on top of the grid lines.
Since:
JViews 7.5
See Also:
setTextOutlineColor(Color)

getTextFont

public Font getTextFont()
Returns the font used to draw labels on top of the grid lines.

Returns:
The font used to draw labels on top of the grid lines.
See Also:
setTextFont(Font)

isAutoScaled

public boolean isAutoScaled()
Returns the autoscaling state (true by default).

Returns:
true if autoscaling is activated.
See Also:
setAutoScaled(boolean)

isVisible

public boolean isVisible(IlvManagerView v)
Returns true if the layer is visible in the specified view. This method checks the visibility of the layer itself, the visibility of the layer for the specified view, and then calls the visibility filters.

Overrides:
isVisible in class IlvManagerLayer
Parameters:
v - The view of the manager.
See Also:
IlvManagerLayer.isVisible(ilog.views.IlvManagerView)

paint

public void paint(Graphics dst,
                  IlvManagerView v)
Paints the grid in the specified view. NOTE: due to calling updateViewParameters(IlvManagerView) for optimization issues, a grid will be able to draw only once at a time - even if using multiple threads.

Specified by:
paint in interface IlvManagerViewDecoration
Parameters:
dst - The Graphics to paint to.
v - The manager view.

paintGrid

public abstract void paintGrid(Graphics2D dst,
                               IlvTransformer t)
Paints the grid.

Parameters:
dst - The Graphics to paint the grid onto.
t - The view transformer to use.

paintLight

public void paintLight(Graphics dst,
                       IlvManagerView v)
Paints the decoration in the specified view using a "quick" or light rendering.

Specified by:
paintLight in interface IlvManagerLightViewDecoration
Parameters:
dst - The Graphics to paint to.
v - The manager view.
See Also:
IlvManagerLightViewDecoration.paintLight(java.awt.Graphics,ilog.views.IlvManagerView)

print

public void print(Graphics dst,
                  IlvRect area,
                  IlvTransformer t)
Prints the grid in the specified area. This method uses the geographic system of the last view it has been painted on.

Overrides:
print in class IlvManagerLayer
Parameters:
dst - The Graphics to paint to.
area - The visible area to print.
t - The view transformer.

setAutoScaled

public void setAutoScaled(boolean autoScaled)
Activates/Deactivates the autoscaling mechanism. This mechanism works by guessing the grid extent (based on the visible area of the map view) and making sure at least 10 grid lines will be visible.

Parameters:
autoScaled - Should be true to activate autoscaling.
See Also:
setStep(double)

setGridColor

public void setGridColor(Color gridColor)
Sets the color used to draw grid lines. The default color is dark gray.

Parameters:
gridColor - Color to use to draw grid lines.

setSmoothness

public void setSmoothness(int smoothness)
Sets the smoothness factor (that is, the number of intermediary points between each line crossing) A value above 1 is recommended for better appearance. A high value (such as above 4) may slow down performances.

Parameters:
smoothness - The smoothness factor.

setStep

public void setStep(double step)
Sets the distance between successive grid lines (if autoscaling is not activated). If autoscaling is activated, an heuristic algorithm will automatically change the step value. The distance unit will be different for different types of grids. For Lat/Lon grids, for example, it will be in radians.

Parameters:
step - The distance.

setTextColor

public void setTextColor(Color textColor)
Sets the color used to draw grid labels. The default color is blue.

Parameters:
textColor - Color to use to draw grid labels.

setTextOutlineColor

public void setTextOutlineColor(Color textOutlineColor)
Sets the color used to outline grid labels. The default color is blue.

Parameters:
textOutlineColor - Color to use to outline grid labels.
Since:
JViews 7.5

setTextFont

public void setTextFont(Font textFont)
Sets the Font used to draw grid labels. The default font is Dialog 14.

Parameters:
textFont - Font to use to draw grid labels.

setVisibleOnlyOnView

public void setVisibleOnlyOnView(IlvManagerView visibleView)
Forces the grid to be displayed only on the specified view. If the visibleView parameter is not null, the isVisible(IlvManagerView) method will only return true for this view. Use this method to prevent the grid from painting on an overview, for example.

Parameters:
visibleView - Only view for which the grid will be displayed.
See Also:
isVisible(IlvManagerView)

setScale

protected void setScale(double scale)
Sets the current transformer and scale to use for the view.

Parameters:
scale - Scale of the view.

setTransformer

protected void setTransformer(IlvTransformer t)
Sets the current transformer to use for the view.

Parameters:
t - Transformer to use.

setVisibleRect

protected void setVisibleRect(Rectangle2D r)
Sets the rectangle within which the grid may be drawn.

Parameters:
r - Visible rectangle of the view.

checkPointInsideView

protected boolean checkPointInsideView(double lon,
                                       double lat)
Checks if the lat/lon coordinates passed are inside the view visible rectangle.

Parameters:
lon - Longitude in radians.
lat - Latitude in radians.
Returns:
true if the point is inside the visible rect.

drawLine

protected void drawLine(Graphics2D dst,
                        IlvTransformer t,
                        IlvPoint p1,
                        IlvPoint p2,
                        Object label,
                        boolean drawLine)
Utility to draw a grid line and its label. The label will be drawn only if the line intersects the visible rectangle of the view.

Parameters:
dst - The Graphics to paint to.
t - The IlvTransformer to use.
p1 - The view related first point of the line
p2 - The view related second point of the line.
label - The label to draw.
drawLine - If false, this method will only draw the eventual text.
See Also:
drawText(Graphics2D, Point2D, Object, boolean, int)

drawString

protected void drawString(Graphics2D dst,
                          IlvTransformer t,
                          IlvPoint p,
                          String label)
Utility to draw a label text.

Parameters:
dst - The Graphics to paint to.
t - The IlvTransformer to use.
p - The view related reference IlvPoint.
label - The label to draw.
See Also:
drawText(Graphics2D, Point2D, Object, boolean, int)

drawText

protected void drawText(Graphics2D g,
                        Point2D point,
                        Object label,
                        boolean horizontal,
                        int alignment)
Utility to draw a label text.

Parameters:
g - The Graphics to paint to.
point - Swing view coordinates of the text reference point.
label - Can be either an AttributedCharacterIterator or a regular object.
horizontal - true if the string must be horizontal.
alignment - Indicates if the text is centered after or before the reference point. Alignment can be either:

getCoordinateTransformation

protected IlvCoordinateTransformation getCoordinateTransformation()
Returns the transformation to use to transform view coordinates to geographic system.

Returns:
The coordinate transformation associated with the view.

getInverseCoordinateTransformation

protected IlvCoordinateTransformation getInverseCoordinateTransformation()
Returns the transformation to use to transform geographic system to view coordinates.

Returns:
The inverse coordinate transformation associated with the view.

getViewScale

protected double getViewScale()
Returns the current view scale.

Returns:
The scale of the view.

getViewTransformer

protected IlvTransformer getViewTransformer()
Returns the current view transformer.

Returns:
The transformer of the view.

isLightPainting

protected boolean isLightPainting()
This flag indicates grids to try to paint "lightly". This usually means not painting labels, or painting a larger scaled grid.

Returns:
true if painting is light.
See Also:
IlvManagerLightViewDecoration

updateTransforms

protected void updateTransforms(IlvManager m)
Searches and updates the coordinate transformations to use, according to the coordinate system set on the manager.

Parameters:
m - Manager.

write

public void write(IlvOutputStream stream)
           throws IOException
Writes the layer to an output stream. You should not call this method directly, but you may need to override it in a subclass of IlvManagerLayer to store your own information. If you override the method, you may call super.write(stream) after your own saving instructions. Calling the superclass method will dump the graphic objects stored in the layer.

Specified by:
write in interface IlvPersistentObject
Overrides:
write in class IlvManagerLayer
Parameters:
stream - the output stream
Throws:
IOException - thrown when an exception occurs during the write operation for this object.
See Also:
IlvManagerLayer.write(ilog.views.io.IlvOutputStream)

isTextVisible

public boolean isTextVisible()
Returns true if the lines crossing the screen border should display text.

Returns:
Returns true if the lines crossing the screen border should display text.

setTextVisible

public void setTextVisible(boolean textVisible)
Indicates whether the lines crossing screen border should display their lat/lon text.

Parameters:
textVisible - The visibility of text.


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.