org.freehep.graphics2d
Class AbstractVectorGraphics

java.lang.Object
  extended by java.awt.Graphics
      extended by java.awt.Graphics2D
          extended by org.freehep.graphics2d.VectorGraphics
              extended by org.freehep.graphics2d.AbstractVectorGraphics
All Implemented Interfaces:
VectorGraphicsConstants
Direct Known Subclasses:
PixelGraphics2D, VectorGraphicsIO

public abstract class AbstractVectorGraphics
extends VectorGraphics

This class implements all conversions from integer to double as well as a few other convenience functions. It also handles the different drawSymbol and fillSymbol methods and print colors. The drawing of framed strings is broken down to lower level methods.

Version:
$Id: AbstractVectorGraphics.java 10516 2007-02-06 21:11:19Z duns $
Author:
Simon Fischer, Mark Donszelmann, Steffen Greiffenberg

Field Summary
 
Fields inherited from interface org.freehep.graphics2d.VectorGraphicsConstants
NUMBER_OF_HORIZ_ALIGNMENTS, NUMBER_OF_SYMBOLS, NUMBER_OF_VERTICAL_ALIGNMENTS, SYMBOL_BOX, SYMBOL_CIRCLE, SYMBOL_CROSS, SYMBOL_DIAMOND, SYMBOL_DN_TRIANGLE, SYMBOL_HLINE, SYMBOL_PLUS, SYMBOL_STAR, SYMBOL_UP_TRIANGLE, SYMBOL_VLINE, TEXT_BASELINE, TEXT_BOTTOM, TEXT_CENTER, TEXT_LEFT, TEXT_RIGHT, TEXT_TOP
 
Constructor Summary
  AbstractVectorGraphics()
           
protected AbstractVectorGraphics(AbstractVectorGraphics graphics)
           
 
Method Summary
 void clearRect(int x, int y, int width, int height)
           
protected abstract  java.awt.Shape createShape(double[] xPoints, double[] yPoints, int nPoints, boolean close)
          Creates a polyline/polygon shape from a set of points.
protected  java.awt.Shape createShape(int[] xPoints, int[] yPoints, int nPoints, boolean close, boolean biased)
          Creates a polyline/polygon shape from a set of points.
 void drawArc(double x, double y, double width, double height, double startAngle, double arcAngle)
          Draws an arc.
 void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
           
 void drawLine(double x1, double y1, double x2, double y2)
          Draws a straight line.
 void drawLine(int x1, int y1, int x2, int y2)
           
 void drawOval(double x, double y, double width, double height)
          Draws an oval.
 void drawOval(int x, int y, int width, int height)
           
 void drawPolygon(double[] xPoints, double[] yPoints, int nPoints)
          Draws a polygon.
 void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
           
 void drawPolyline(double[] xPoints, double[] yPoints, int nPoints)
          Draws a polyline.
 void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
           
 void drawRect(double x, double y, double width, double height)
          Draws a rectangle.
 void drawRect(int x, int y, int width, int height)
           
 void drawRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)
          Draws a rounded rectangle.
 void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
           
 void drawString(java.text.AttributedCharacterIterator iterator, int x, int y)
           
 void drawString(java.lang.String str, double x, double y, int horizontal, int vertical)
           
 void drawString(java.lang.String str, double x, double y, int horizontal, int vertical, boolean framed, java.awt.Color frameColor, double frameWidth, boolean banner, java.awt.Color bannerColor)
          Draws frame, banner and aligned text inside
 void drawString(java.lang.String s, float x, float y)
           
 void drawString(java.lang.String str, int x, int y)
           
 void drawString(TagString str, double x, double y)
           
 void drawString(TagString str, double x, double y, int horizontal, int vertical)
           
 void drawString(TagString str, double x, double y, int horizontal, int vertical, boolean framed, java.awt.Color frameColor, double frameWidth, boolean banner, java.awt.Color bannerColor)
          Draws the tagged string parsed by a TagHandler and adds a border specified by the parameters
 void drawSymbol(double x, double y, double size, int symbol)
           
 void drawSymbol(int x, int y, int size, int symbol)
           
protected  void drawSymbol(VectorGraphics g, double x, double y, double size, int symbol)
           
 void fillAndDraw(java.awt.Shape s, java.awt.Color fillColor)
           
 void fillAndDrawSymbol(double x, double y, double size, int symbol, java.awt.Color fillColor)
           
 void fillAndDrawSymbol(int x, int y, int size, int symbol, java.awt.Color fillColor)
           
 void fillArc(double x, double y, double width, double height, double startAngle, double arcAngle)
          Fills an arc.
 void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
           
 void fillOval(double x, double y, double width, double height)
          Fills an oval.
 void fillOval(int x, int y, int width, int height)
           
 void fillPolygon(double[] xPoints, double[] yPoints, int nPoints)
          Fills a polygon.
 void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
           
 void fillRect(double x, double y, double width, double height)
          Fills a rectangle.
 void fillRect(int x, int y, int width, int height)
           
 void fillRoundRect(double x, double y, double width, double height, double arcWidth, double arcHeight)
          Fills a rounded rectangle.
 void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
           
 void fillSymbol(double x, double y, double size, int symbol)
           
 void fillSymbol(int x, int y, int size, int symbol)
           
protected  void fillSymbol(VectorGraphics g, double x, double y, double size, int symbol)
           
 java.awt.Color getBackground()
          Gets the background color.
 java.awt.Color getColor()
          Gets the current color.
 int getColorMode()
           
 java.lang.String getCreator()
           
 java.awt.Font getFont()
          Gets the current font.
 java.awt.Paint getPaint()
          Gets the current paint.
protected  java.awt.Color getPrintColor(java.awt.Color color)
          Returns a printColor created from the original printColor, based on the ColorMode.
protected  java.util.Properties getProperties()
           
 java.lang.String getProperty(java.lang.String key)
           
 java.awt.Color getPropertyColor(java.lang.String key)
           
 java.awt.Dimension getPropertyDimension(java.lang.String key)
           
 double getPropertyDouble(java.lang.String key)
           
 java.awt.Insets getPropertyInsets(java.lang.String key)
           
 int getPropertyInt(java.lang.String key)
           
 java.awt.Rectangle getPropertyRectangle(java.lang.String key)
           
 boolean hit(java.awt.Rectangle rect, java.awt.Shape s, boolean onStroke)
          Checks whether or not the specified Shape intersects the specified Rectangle, which is in device space.
protected  void initProperties(java.util.Properties defaults)
           
 boolean isDeviceIndependent()
           
 boolean isProperty(java.lang.String key)
           
 void rotate(double theta, double x, double y)
           
 void setBackground(java.awt.Color color)
          Sets the background color.
 void setColor(java.awt.Color color)
          Sets the current color and the current paint.
 void setColorMode(int colorMode)
           
 void setCreator(java.lang.String creator)
           
 void setDeviceIndependent(boolean isDeviceIndependent)
           
 void setFont(java.awt.Font font)
          Sets the current font.
 void setLineWidth(double width)
           
 void setLineWidth(int width)
           
 void setPaint(java.awt.Paint paint)
          Sets the current paint.
 void setProperties(java.util.Properties newProperties)
           
 void translate(int x, int y)
           
 
Methods inherited from class org.freehep.graphics2d.VectorGraphics
addRenderingHints, clearRect, clip, clipRect, clipRect, copyArea, create, create, create, create, dispose, draw, drawGlyphVector, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawRenderableImage, drawRenderedImage, drawString, drawString, endExport, fill, fill, getClip, getClipBounds, getClipBounds, getComposite, getDeviceConfiguration, getFontMetrics, getFontRenderContext, getRenderingHint, getRenderingHints, getStroke, getSymbol, getTextAlignment, getTransform, getXalignment, getYalignment, printComment, rotate, scale, setClip, setClip, setClip, setComposite, setPaintMode, setRenderingHint, setRenderingHints, setStroke, setTransform, setXORMode, shear, startExport, toString, transform, translate
 
Methods inherited from class java.awt.Graphics2D
draw3DRect, fill3DRect
 
Methods inherited from class java.awt.Graphics
drawBytes, drawChars, drawPolygon, fillPolygon, finalize, getClipRect, getFontMetrics, hitClip
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractVectorGraphics

public AbstractVectorGraphics()

AbstractVectorGraphics

protected AbstractVectorGraphics(AbstractVectorGraphics graphics)
Method Detail

setProperties

public void setProperties(java.util.Properties newProperties)
Specified by:
setProperties in class VectorGraphics

initProperties

protected void initProperties(java.util.Properties defaults)
Specified by:
initProperties in class VectorGraphics

getProperties

protected java.util.Properties getProperties()
Specified by:
getProperties in class VectorGraphics

getProperty

public java.lang.String getProperty(java.lang.String key)
Specified by:
getProperty in class VectorGraphics

getPropertyColor

public java.awt.Color getPropertyColor(java.lang.String key)
Specified by:
getPropertyColor in class VectorGraphics

getPropertyRectangle

public java.awt.Rectangle getPropertyRectangle(java.lang.String key)
Specified by:
getPropertyRectangle in class VectorGraphics

getPropertyInsets

public java.awt.Insets getPropertyInsets(java.lang.String key)

getPropertyDimension

public java.awt.Dimension getPropertyDimension(java.lang.String key)
Specified by:
getPropertyDimension in class VectorGraphics

getPropertyInt

public int getPropertyInt(java.lang.String key)
Specified by:
getPropertyInt in class VectorGraphics

getPropertyDouble

public double getPropertyDouble(java.lang.String key)
Specified by:
getPropertyDouble in class VectorGraphics

isProperty

public boolean isProperty(java.lang.String key)
Specified by:
isProperty in class VectorGraphics

getCreator

public java.lang.String getCreator()
Specified by:
getCreator in class VectorGraphics

setCreator

public void setCreator(java.lang.String creator)
Specified by:
setCreator in class VectorGraphics

isDeviceIndependent

public boolean isDeviceIndependent()
Specified by:
isDeviceIndependent in class VectorGraphics

setDeviceIndependent

public void setDeviceIndependent(boolean isDeviceIndependent)
Specified by:
setDeviceIndependent in class VectorGraphics

getFont

public java.awt.Font getFont()
Gets the current font.

Specified by:
getFont in class VectorGraphics
Returns:
current font

setFont

public void setFont(java.awt.Font font)
Sets the current font.

Specified by:
setFont in class VectorGraphics
Parameters:
font - to be set

drawSymbol

public void drawSymbol(int x,
                       int y,
                       int size,
                       int symbol)
Specified by:
drawSymbol in class VectorGraphics

fillSymbol

public void fillSymbol(int x,
                       int y,
                       int size,
                       int symbol)
Specified by:
fillSymbol in class VectorGraphics

fillAndDrawSymbol

public void fillAndDrawSymbol(int x,
                              int y,
                              int size,
                              int symbol,
                              java.awt.Color fillColor)
Specified by:
fillAndDrawSymbol in class VectorGraphics

drawSymbol

public void drawSymbol(double x,
                       double y,
                       double size,
                       int symbol)
Specified by:
drawSymbol in class VectorGraphics

drawSymbol

protected void drawSymbol(VectorGraphics g,
                          double x,
                          double y,
                          double size,
                          int symbol)

fillSymbol

public void fillSymbol(double x,
                       double y,
                       double size,
                       int symbol)
Specified by:
fillSymbol in class VectorGraphics

fillSymbol

protected void fillSymbol(VectorGraphics g,
                          double x,
                          double y,
                          double size,
                          int symbol)

fillAndDrawSymbol

public void fillAndDrawSymbol(double x,
                              double y,
                              double size,
                              int symbol,
                              java.awt.Color fillColor)
Specified by:
fillAndDrawSymbol in class VectorGraphics

fillAndDraw

public void fillAndDraw(java.awt.Shape s,
                        java.awt.Color fillColor)
Specified by:
fillAndDraw in class VectorGraphics

clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)
Specified by:
clearRect in class VectorGraphics

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Specified by:
drawLine in class VectorGraphics

drawRect

public void drawRect(int x,
                     int y,
                     int width,
                     int height)
Specified by:
drawRect in class VectorGraphics

fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height)
Specified by:
fillRect in class VectorGraphics

drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Specified by:
drawArc in class VectorGraphics

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int startAngle,
                    int arcAngle)
Specified by:
fillArc in class VectorGraphics

drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height)
Specified by:
drawOval in class VectorGraphics

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height)
Specified by:
fillOval in class VectorGraphics

drawRoundRect

public void drawRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Specified by:
drawRoundRect in class VectorGraphics

fillRoundRect

public void fillRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Specified by:
fillRoundRect in class VectorGraphics

translate

public void translate(int x,
                      int y)
Specified by:
translate in class VectorGraphics

setLineWidth

public void setLineWidth(int width)
Specified by:
setLineWidth in class VectorGraphics

setLineWidth

public void setLineWidth(double width)
Specified by:
setLineWidth in class VectorGraphics

drawString

public void drawString(java.lang.String str,
                       int x,
                       int y)
Specified by:
drawString in class VectorGraphics

drawString

public void drawString(java.lang.String s,
                       float x,
                       float y)
Specified by:
drawString in class VectorGraphics

drawString

public void drawString(java.text.AttributedCharacterIterator iterator,
                       int x,
                       int y)
Specified by:
drawString in class VectorGraphics

drawString

public void drawString(java.lang.String str,
                       double x,
                       double y,
                       int horizontal,
                       int vertical,
                       boolean framed,
                       java.awt.Color frameColor,
                       double frameWidth,
                       boolean banner,
                       java.awt.Color bannerColor)
Draws frame, banner and aligned text inside

Specified by:
drawString in class VectorGraphics
Parameters:
str - text to be drawn
x - coordinate to draw string
y - coordinate to draw string
horizontal - alignment of the text
vertical - alignment of the text
framed - true if text is surrounded by a frame
frameColor - color of the frame
frameWidth - witdh of the frame
banner - true if the frame is filled by a banner
bannerColor - color of the banner

drawString

public void drawString(TagString str,
                       double x,
                       double y,
                       int horizontal,
                       int vertical,
                       boolean framed,
                       java.awt.Color frameColor,
                       double frameWidth,
                       boolean banner,
                       java.awt.Color bannerColor)
Draws the tagged string parsed by a TagHandler and adds a border specified by the parameters

Specified by:
drawString in class VectorGraphics
Parameters:
str - Tagged text to be drawn
x - coordinate to draw string
y - coordinate to draw string
horizontal - alignment of the text
vertical - alignment of the text
framed - true if text is surrounded by a frame
frameColor - color of the frame
frameWidth - witdh of the frame
banner - true if the frame is filled by a banner
bannerColor - color of the banner

drawString

public void drawString(java.lang.String str,
                       double x,
                       double y,
                       int horizontal,
                       int vertical)
Specified by:
drawString in class VectorGraphics

drawString

public void drawString(TagString str,
                       double x,
                       double y)
Specified by:
drawString in class VectorGraphics

drawString

public void drawString(TagString str,
                       double x,
                       double y,
                       int horizontal,
                       int vertical)
Specified by:
drawString in class VectorGraphics

getColorMode

public int getColorMode()
Specified by:
getColorMode in class VectorGraphics

setColorMode

public void setColorMode(int colorMode)
Specified by:
setColorMode in class VectorGraphics

getBackground

public java.awt.Color getBackground()
Gets the background color.

Specified by:
getBackground in class VectorGraphics
Returns:
background color

setBackground

public void setBackground(java.awt.Color color)
Sets the background color.

Specified by:
setBackground in class VectorGraphics
Parameters:
color - background color to be set

setColor

public void setColor(java.awt.Color color)
Sets the current color and the current paint. Calls writePaint(Color).

Specified by:
setColor in class VectorGraphics
Parameters:
color - to be set

getColor

public java.awt.Color getColor()
Gets the current color.

Specified by:
getColor in class VectorGraphics
Returns:
the current color

setPaint

public void setPaint(java.awt.Paint paint)
Sets the current paint.

Specified by:
setPaint in class VectorGraphics
Parameters:
paint - to be set

getPaint

public java.awt.Paint getPaint()
Gets the current paint.

Specified by:
getPaint in class VectorGraphics
Returns:
paint current paint

getPrintColor

protected java.awt.Color getPrintColor(java.awt.Color color)
Returns a printColor created from the original printColor, based on the ColorMode. If you run getPrintColor on it again you still get the same color, so that it does not matter if you convert it more than once.


rotate

public void rotate(double theta,
                   double x,
                   double y)
Specified by:
rotate in class VectorGraphics

drawArc

public void drawArc(double x,
                    double y,
                    double width,
                    double height,
                    double startAngle,
                    double arcAngle)
Description copied from class: VectorGraphics
Draws an arc. Uses Arc2D to call draw(Shape).

Specified by:
drawArc in class VectorGraphics

drawLine

public void drawLine(double x1,
                     double y1,
                     double x2,
                     double y2)
Description copied from class: VectorGraphics
Draws a straight line. Uses Line2D to call draw(Shape).

Specified by:
drawLine in class VectorGraphics

drawOval

public void drawOval(double x,
                     double y,
                     double width,
                     double height)
Description copied from class: VectorGraphics
Draws an oval. Uses Ellipse2D to call draw(Shape).

Specified by:
drawOval in class VectorGraphics

drawPolyline

public void drawPolyline(int[] xPoints,
                         int[] yPoints,
                         int nPoints)
Specified by:
drawPolyline in class VectorGraphics

drawPolyline

public void drawPolyline(double[] xPoints,
                         double[] yPoints,
                         int nPoints)
Description copied from class: VectorGraphics
Draws a polyline. Uses createShape(...) to call draw(Shape).

Specified by:
drawPolyline in class VectorGraphics

drawPolygon

public void drawPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Specified by:
drawPolygon in class VectorGraphics

drawPolygon

public void drawPolygon(double[] xPoints,
                        double[] yPoints,
                        int nPoints)
Description copied from class: VectorGraphics
Draws a polygon. Uses createShape(...) to call draw(Shape).

Specified by:
drawPolygon in class VectorGraphics

drawRect

public void drawRect(double x,
                     double y,
                     double width,
                     double height)
Description copied from class: VectorGraphics
Draws a rectangle. Uses Rectangle2D to call draw(Shape).

Specified by:
drawRect in class VectorGraphics

drawRoundRect

public void drawRoundRect(double x,
                          double y,
                          double width,
                          double height,
                          double arcWidth,
                          double arcHeight)
Description copied from class: VectorGraphics
Draws a rounded rectangle. Uses RoundRectangle2D to call draw(Shape).

Specified by:
drawRoundRect in class VectorGraphics

fillArc

public void fillArc(double x,
                    double y,
                    double width,
                    double height,
                    double startAngle,
                    double arcAngle)
Description copied from class: VectorGraphics
Fills an arc. Uses Arc2D to call fill(Shape).

Specified by:
fillArc in class VectorGraphics

fillOval

public void fillOval(double x,
                     double y,
                     double width,
                     double height)
Description copied from class: VectorGraphics
Fills an oval. Uses Ellipse2D to call fill(Shape).

Specified by:
fillOval in class VectorGraphics

fillPolygon

public void fillPolygon(int[] xPoints,
                        int[] yPoints,
                        int nPoints)
Specified by:
fillPolygon in class VectorGraphics

fillPolygon

public void fillPolygon(double[] xPoints,
                        double[] yPoints,
                        int nPoints)
Description copied from class: VectorGraphics
Fills a polygon. Uses createShape(...) to call fill(Shape).

Specified by:
fillPolygon in class VectorGraphics

fillRect

public void fillRect(double x,
                     double y,
                     double width,
                     double height)
Description copied from class: VectorGraphics
Fills a rectangle. Uses Rectangle2D to call fill(Shape).

Specified by:
fillRect in class VectorGraphics

fillRoundRect

public void fillRoundRect(double x,
                          double y,
                          double width,
                          double height,
                          double arcWidth,
                          double arcHeight)
Description copied from class: VectorGraphics
Fills a rounded rectangle. Uses RoundRectangle2D to call fill(Shape).

Specified by:
fillRoundRect in class VectorGraphics

createShape

protected abstract java.awt.Shape createShape(double[] xPoints,
                                              double[] yPoints,
                                              int nPoints,
                                              boolean close)
Creates a polyline/polygon shape from a set of points. Needs to be defined in subclass because its implementations could be device specific

Parameters:
xPoints - X coordinates of the polyline.
yPoints - Y coordinates of the polyline.
nPoints - number of points of the polyline.
close - is shape closed

createShape

protected java.awt.Shape createShape(int[] xPoints,
                                     int[] yPoints,
                                     int nPoints,
                                     boolean close,
                                     boolean biased)
Creates a polyline/polygon shape from a set of points. Needs a bias!

Parameters:
xPoints - X coordinates of the polyline.
yPoints - Y coordinates of the polyline.
nPoints - number of points of the polyline.
close - is shape closed

hit

public boolean hit(java.awt.Rectangle rect,
                   java.awt.Shape s,
                   boolean onStroke)
Checks whether or not the specified Shape intersects the specified Rectangle, which is in device space.

Specified by:
hit in class VectorGraphics
Parameters:
rect - the area in device space to check for a hit
s - the Shape to check for a hit
onStroke - flag used to choose between testing the stroked or the filled shape.
See Also:
Graphics2D.hit(Rectangle, Shape, boolean)


Copyright © 2000-2007 FreeHEP. All Rights Reserved.