net.sf.jcgm.core
Class CGMDisplay

java.lang.Object
  extended by net.sf.jcgm.core.CGMDisplay

public class CGMDisplay
extends java.lang.Object

This class is responsible for displaying the parsed commands of a CGM file into a graphic context.

Version:
$Id: CGMDisplay.java 49 2011-12-14 13:49:38Z phica $
Author:
xphc (Philippe Cadé), BBNT Solutions

Field Summary
protected  CGM Cgm
           
 
Constructor Summary
CGMDisplay(CGM cgm)
           
 
Method Summary
 void addLineType(int lineType, int[] dashElements, double dashCycleRepeatLength)
           
protected  double angle(double x, double y)
           
 boolean drawEdge()
          Returns true if edge should be drawn
 void fill(java.awt.Shape s)
          Checks the interior style and fills the given shape accordingly if necessary
 CGM getCGM()
           
 double getCharacterHeight()
           
 java.awt.geom.Point2D.Double getCharacterOrientationBaselineVector()
           
 java.awt.geom.Point2D.Double getCharacterOrientationUpVector()
           
 double getCharacterSpacing()
           
 boolean getClipFlag()
           
 double getContinuousHorizontalAlignment()
           
 double getContinuousVerticalAlignment()
           
protected  java.awt.geom.AffineTransform getCoordinateSystemTransformation(java.awt.geom.Point2D.Double op, java.awt.geom.Point2D.Double ip, java.awt.geom.Point2D.Double jp)
          Returns a transformation to apply to transform from the given coordinate system
 java.awt.Color getEdgeColor()
           
 java.awt.BasicStroke getEdgeStroke()
           
 java.awt.geom.Point2D.Double[] getExtent()
          Returns the extent of the drawing.
 java.awt.Color getFillColor()
           
 java.awt.Graphics2D getGraphics2D()
           
 net.sf.jcgm.core.TextAlignment.HorizontalAlignment getHorizontalTextAlignment()
           
 java.awt.Color getIndexedColor(int i)
           
 net.sf.jcgm.core.InteriorStyle.Style getInteriorStyle()
           
 java.awt.Color getLineColor()
           
 java.awt.BasicStroke getLineStroke()
           
 java.awt.Color getMarkerColor()
           
 double getMarkerSize()
           
 net.sf.jcgm.core.MarkerType.Type getMarkerType()
           
 java.awt.Color getTextColor()
           
 net.sf.jcgm.core.TextPath.Type getTextPath()
           
 java.awt.geom.AffineTransform getTextTransform()
          AWT always expect increasing X to the right and increasing Y to the bottom.
 net.sf.jcgm.core.TextAlignment.VerticalAlignment getVerticalTextAlignment()
           
 boolean isBeforeBeginPictureBody()
           
 boolean isFilled()
           
 boolean isScaled()
           
 boolean isTransparent()
           
 boolean isViewCleared()
           
protected  double normalizeAngle(double a)
          Normalizes an angle in the range -pi..pi to 0..2pi
 double[] normalizeAngleRange(double startAngle, double endAngle)
           
 void paint(java.awt.Graphics g)
           
 double radiansToDegrees(double angle)
           
 void reachedBeginPictureBody()
           
 void reset()
          Resets the parameters to default settings.
 void scale(java.awt.Graphics g, int w, int h)
           
 void setCharacterHeight(double h)
           
 void setCharacterOrientation(java.awt.geom.Point2D.Double upVector, java.awt.geom.Point2D.Double baselineVector)
           
 void setCharacterSpacing(double additionalInterCharacterSpace)
           
 void setClipFlag(boolean flag)
           
 void setEdge(boolean flag)
           
 void setEdgeCap(LineCapIndicator lineIndicator)
           
 void setEdgeColor(java.awt.Color c)
           
 void setEdgeColorIndex(int colorIndex)
           
 void setEdgeJoin(JoinIndicator type)
           
 void setEdgeType(int type)
           
 void setEdgeWidth(double width)
           
 void setFillColor(java.awt.Color c)
           
 void setFillColorIndex(int colorIndex)
           
 void setFilled(boolean flag)
           
 void setFontIndex(int fontIndex)
          Sets the font to use
 void setFonts(FontWrapper[] fontWrappers)
           
 void setHatchStyle(net.sf.jcgm.core.HatchIndex.HatchType type)
           
 void setIndexedColor(int i, java.awt.Color color)
           
 void setInteriorStyle(net.sf.jcgm.core.InteriorStyle.Style interiorStyle)
           
 void setLineCap(LineCapIndicator lineIndicator)
           
 void setLineColor(java.awt.Color c)
           
 void setLineColorIndex(int colorIndex)
           
 void setLineJoin(JoinIndicator type)
           
 void setLineType(int type)
           
 void setLineWidth(double width)
           
 void setMarkerColor(java.awt.Color c)
           
 void setMarkerColorIndex(int colorIndex)
           
 void setMarkerSize(double width)
           
 void setMarkerType(net.sf.jcgm.core.MarkerType.Type type)
           
 void setMaximumColorIndex(int maxColorIndex)
           
 void setTextAlignment(net.sf.jcgm.core.TextAlignment.HorizontalAlignment horizontalAlignment, net.sf.jcgm.core.TextAlignment.VerticalAlignment verticalAlignment, double continuousHorizontalAlignment, double continuousVerticalAlignment)
           
 void setTextColor(java.awt.Color c)
           
 void setTextColorIndex(int colorIndex)
           
 void setTextPath(net.sf.jcgm.core.TextPath.Type path)
           
 void setTransparent(boolean transparent)
           
 void setViewCleared(boolean b)
           
 boolean useSymbolEncoding()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Cgm

protected CGM Cgm
Constructor Detail

CGMDisplay

public CGMDisplay(CGM cgm)
Method Detail

getCGM

public CGM getCGM()

paint

public void paint(java.awt.Graphics g)

getGraphics2D

public java.awt.Graphics2D getGraphics2D()

setTransparent

public void setTransparent(boolean transparent)

isTransparent

public boolean isTransparent()

setFillColor

public void setFillColor(java.awt.Color c)

setFillColorIndex

public void setFillColorIndex(int colorIndex)

getFillColor

public java.awt.Color getFillColor()

setFilled

public void setFilled(boolean flag)

isFilled

public boolean isFilled()

setEdgeColor

public void setEdgeColor(java.awt.Color c)

setEdgeColorIndex

public void setEdgeColorIndex(int colorIndex)

getEdgeColor

public java.awt.Color getEdgeColor()

setEdge

public void setEdge(boolean flag)

drawEdge

public boolean drawEdge()
Returns true if edge should be drawn

Returns:
true/false

setLineColor

public void setLineColor(java.awt.Color c)

setLineColorIndex

public void setLineColorIndex(int colorIndex)

getLineColor

public java.awt.Color getLineColor()

setMarkerColor

public void setMarkerColor(java.awt.Color c)

setMarkerColorIndex

public void setMarkerColorIndex(int colorIndex)

getMarkerColor

public java.awt.Color getMarkerColor()

setTextColor

public void setTextColor(java.awt.Color c)

setTextColorIndex

public void setTextColorIndex(int colorIndex)

getTextColor

public java.awt.Color getTextColor()

setCharacterHeight

public void setCharacterHeight(double h)

getCharacterHeight

public double getCharacterHeight()

scale

public void scale(java.awt.Graphics g,
                  int w,
                  int h)

isScaled

public boolean isScaled()

getExtent

public java.awt.geom.Point2D.Double[] getExtent()
Returns the extent of the drawing.
       extent[1].x,[1].y
        ----------*
        |         |
        |         |
        * ---------
   [0].x,[0].y
 

Returns:
An array of 2 points, each with two coordinates (x, y). extent[0] always represents the lower left corner, extent[1] always represents the upper right corner

angle

protected final double angle(double x,
                             double y)

normalizeAngle

protected final double normalizeAngle(double a)
Normalizes an angle in the range -pi..pi to 0..2pi

Parameters:
a -
Returns:

getCoordinateSystemTransformation

protected final java.awt.geom.AffineTransform getCoordinateSystemTransformation(java.awt.geom.Point2D.Double op,
                                                                                java.awt.geom.Point2D.Double ip,
                                                                                java.awt.geom.Point2D.Double jp)
Returns a transformation to apply to transform from the given coordinate system

Parameters:
op - The origin of the coordinate system
ip - The first axis vector
jp - The second axis vector
Returns:
The transformation to apply

setFonts

public void setFonts(FontWrapper[] fontWrappers)

setFontIndex

public void setFontIndex(int fontIndex)
Sets the font to use

Parameters:
fontIndex - Font index starts from one

useSymbolEncoding

public boolean useSymbolEncoding()
Returns:
True if the current font is using the symbol encoding, false otherwise

getHorizontalTextAlignment

public net.sf.jcgm.core.TextAlignment.HorizontalAlignment getHorizontalTextAlignment()

getVerticalTextAlignment

public net.sf.jcgm.core.TextAlignment.VerticalAlignment getVerticalTextAlignment()

getContinuousHorizontalAlignment

public double getContinuousHorizontalAlignment()

getContinuousVerticalAlignment

public double getContinuousVerticalAlignment()

setTextAlignment

public void setTextAlignment(net.sf.jcgm.core.TextAlignment.HorizontalAlignment horizontalAlignment,
                             net.sf.jcgm.core.TextAlignment.VerticalAlignment verticalAlignment,
                             double continuousHorizontalAlignment,
                             double continuousVerticalAlignment)

reset

public void reset()
Resets the parameters to default settings. This is called before the picture is scaled.


addLineType

public void addLineType(int lineType,
                        int[] dashElements,
                        double dashCycleRepeatLength)

setLineType

public void setLineType(int type)

getLineStroke

public java.awt.BasicStroke getLineStroke()

setEdgeType

public void setEdgeType(int type)

getEdgeStroke

public java.awt.BasicStroke getEdgeStroke()

setMaximumColorIndex

public void setMaximumColorIndex(int maxColorIndex)

setIndexedColor

public void setIndexedColor(int i,
                            java.awt.Color color)

getIndexedColor

public java.awt.Color getIndexedColor(int i)

getInteriorStyle

public net.sf.jcgm.core.InteriorStyle.Style getInteriorStyle()

setInteriorStyle

public void setInteriorStyle(net.sf.jcgm.core.InteriorStyle.Style interiorStyle)

isBeforeBeginPictureBody

public boolean isBeforeBeginPictureBody()

reachedBeginPictureBody

public void reachedBeginPictureBody()

normalizeAngleRange

public double[] normalizeAngleRange(double startAngle,
                                    double endAngle)
Parameters:
startAngle -
endAngle -
normalizedStartAngle -
normalizedEndAngle -

radiansToDegrees

public double radiansToDegrees(double angle)
Parameters:
d -
Returns:

getTextTransform

public java.awt.geom.AffineTransform getTextTransform()
AWT always expect increasing X to the right and increasing Y to the bottom. If our user coordinate system is oriented differently, the returned matrix will convert the user space to AWT space and be applied on the drawn string.

Returns:
The matrix to apply to the string before drawing

setCharacterSpacing

public void setCharacterSpacing(double additionalInterCharacterSpace)
Parameters:
additionalInterCharacterSpace -

getCharacterSpacing

public double getCharacterSpacing()
Returns:
the additionalInterCharacterSpace

setCharacterOrientation

public void setCharacterOrientation(java.awt.geom.Point2D.Double upVector,
                                    java.awt.geom.Point2D.Double baselineVector)
Parameters:
upVector -
baselineVector -

getCharacterOrientationUpVector

public java.awt.geom.Point2D.Double getCharacterOrientationUpVector()

getCharacterOrientationBaselineVector

public java.awt.geom.Point2D.Double getCharacterOrientationBaselineVector()

setLineWidth

public void setLineWidth(double width)

setEdgeWidth

public void setEdgeWidth(double width)

setLineCap

public void setLineCap(LineCapIndicator lineIndicator)

setEdgeCap

public void setEdgeCap(LineCapIndicator lineIndicator)

setLineJoin

public void setLineJoin(JoinIndicator type)

setEdgeJoin

public void setEdgeJoin(JoinIndicator type)

setMarkerType

public void setMarkerType(net.sf.jcgm.core.MarkerType.Type type)

getMarkerType

public net.sf.jcgm.core.MarkerType.Type getMarkerType()

setMarkerSize

public void setMarkerSize(double width)

getMarkerSize

public double getMarkerSize()

setTextPath

public void setTextPath(net.sf.jcgm.core.TextPath.Type path)

getTextPath

public net.sf.jcgm.core.TextPath.Type getTextPath()

fill

public void fill(java.awt.Shape s)
Checks the interior style and fills the given shape accordingly if necessary

Parameters:
s - The shape to fill

setHatchStyle

public void setHatchStyle(net.sf.jcgm.core.HatchIndex.HatchType type)
Parameters:
type -

setClipFlag

public void setClipFlag(boolean flag)
Parameters:
flag -

getClipFlag

public boolean getClipFlag()

isViewCleared

public boolean isViewCleared()

setViewCleared

public void setViewCleared(boolean b)


Part of the jcgm library http://jcgm.sourceforge.net/