Class FxGraphics
public abstract class FxGraphics extends Graphics implements
IFxGraphicsConstants, IFxTextConstants,
PeerConstants
{
// Methods
public void draw3DRect(int x, int y, int width, int height,
boolean raised);
public abstract void drawBezier(int xOrig, int yOrig,
int values[], int nPoints);
public boolean drawBorder(Rectangle rect, int edge, int flags);
public void drawChars(char data[], int offset, int length, int x,
int y);
public void drawChars(char data[], int offset, int length, int x,
int y, Rectangle optionRect, int options, int dx[], int
dy[]);
protected abstract void drawCharsWithoutFxFont(char data[],
int offset, int length, int x, int y,
Rectangle optionRect, int options, int dx[], int dy[]);
public boolean drawEdge(Rectangle inRect, int edge, int flags);
public abstract boolean drawImage(Image img, int dx1, int dy1,
int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
ImageObserver observer);
public abstract boolean drawImage(Image img, int dx1, int dy1,
int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
Color bgcolor, ImageObserver observer);
public void drawOutlineChar(int xOrig, int yOrig,
GlyphOutline go);
public abstract void drawOutlinePolygon(int xOrig, int yOrig,
OutlinePolygon op);
public abstract void drawPixels(int pels[], int len);
public abstract void drawPolyline(int xPoints[], int yPoints[],
int nPoints);
public abstract void drawScanLines(boolean xChanging,
int points[], int offset, int nPoints);
public void drawString(String str, int x, int y,
Rectangle optionRect, int options, int dx[], int dy[]);
public void drawString(String str, int x, int y);
public void drawString(String str, int x, int y, int a);
public FxFormattedText drawStringFormatted(String s, Rectangle r,
int hta, int vta, int ww, boolean bordered, int
tabOrigin, int tabs[], IFxShape outline, boolean mnem);
protected abstract void drawStringWithoutFxFont(String str,int x,
int y, Rectangle optionRect, int options, int[] dx,int[]
dy);
public void drawT2Curve(FloatPoint pta, FloatPoint ptb,
FloatPoint ptc, int xOrig, int yOrig);
public abstract void excludeClip(int x, int y, int w, int h);
public void fill3DRect(int x, int y, int width, int height,
boolean raised);
public Shape getClip();
public abstract Rectangle getClipBounds();
public abstract Region getClipRegion();
public static FxGraphics getExtendedGraphics(Graphics g);
public static FxGraphics getExtendedGraphics(Component c,
Image img);
public abstract GlyphOutline getGlyphOutline(char ch);
public Color getTextBackgroundColor();
public abstract Point getTranslation();
public abstract void intersectClip(int x, int y, int w, int h);
public abstract void setClip(Region r);
public abstract void setClip(int x, int y, int width, int height);
public abstract void setClip(Shape clip);
public abstract void setColor( FxColor c );
public void setTextBackgroundColor( FxColor c);
public void setTextBackgroundColor( Color c);
}
This class encapsulates an extended graphics object.
The FxGraphics class is one of the core classes of the com.ms.fx package. It provides both an extended graphics object implementation and abstract methods for full cross-platform compatibility. (These methods are implemented either in a graphic object's peer or native windowing system.)
Any graphics object, whether AWT or AFC, performs operations with the same basic premise: You can assign a color and font style to the object, and then draw text and shapes with that color and font. The following example shows how you create an instance of the FxGraphics class with the getExtendedGraphics method. The object is created with default font and color.
// Create an extended graphics object.
FxGraphics fxg = FxGraphics.getExtendedGraphics(Graphics gOriginal);
You can use either the default color and font that the graphics object was created with for drawing operations, or you can call the setColor and setFont methods to set these attributes independently.
// Set the color and font of the graphics object.
fxg.setColor(Color.red);
fxg.setFont("Helvetica");
The graphics object is used to draw both text and various shapes. Generally, the shapes that may be drawn are either an outline shape or a shape that is filled with a specified color. With the com.ms.fx package, you are provided with classes that extend the flexibility of drawing operations. These classes enable you to use images for background and foreground drawing (FxTexture), pens that may be several pixels wide (FxPen), and pens that enable users to select different background fill colors and foreground drawing colors (FxBrushPen).
In the following example, the graphics object is used to perform several drawing operations, using some standard drawing methods.
// Draw a line from the top-left corner of the canvas object to a point 100
// pixels down and 100 pixels across. A red diagonal line, 1 pixel wide, results.
fxg.drawLine(0, 0, 100, 100);
// Draw a filled red circle with the fillOval method.
fxg.fillOval(0, 0, 50, 50);
These are very simple examples, but by using the extended objects in the fx package, you can draw more complex and compelling graphics. An instance of the FxTexture class may be selected into a graphics context in the same way a color is selected, and then used as a background or foreground color. Similarly, you can create an FxPen using the same FxTexture, and draw lines and shapes of varying thickness. The following example demonstrates how to link the attributes of these objects together and use them to draw.
// Create an FxTexture based on an Image object. The fifth and sixth
// parameters indicate that the image should be drawn over a surface dimension
// that is 200 pixels wide and 300 high. The color (255, 0, 0) is used as a
// default color should the image fail to be drawn.
FxTexture myTex = new FxTexture(anImage, FxTexture.STRETCH_ALL,
0, 0, 200, 300, false, 255, 0, 0);
// An FxPen object can now be created based on the FxTexture object.
FxPen myWidePen = new FxPen(10, myTex);
// The FxPen object, in turn, may be selected into the graphics object
// the same way a Color is selected in the previous example.
fxg.setColor(myWidePen);
Now any drawing operation with the current graphics object are performed by drawing the Image (stretched across the surface) with a pen that is 10 pixels wide. The drawing method calls are the same as before, as all the objects described use internal callback methods to perform their operations. As a result, you can draw the same line and circle, with very different results, without altering the graphics' method calls.
The FxGraphics class provides a drawing API inherited from the java.awt.Graphics class. The drawImage methods draw images either within a given bounding rectangle, or a full image at a specified screen location. Scaling options and transparent pixel drawing may be specified by the user. The shape and line drawing methods (drawLine, fillOval) are simple and intuitive, yet powerful when used with extended pen and texture objects. The text drawing methods (drawChars, drawString) draw graphical representations of String objects and character arrays.
The FxGraphics class supports the following drawing primitives:
The FxGraphics class supports the JDK 1.0.2 and JDK 1.1 clipping methods, as well as new methods for setting clip regions:
Graphics
|
+--FxGraphics
public void draw3DRect(int x, int y, int width, int height, boolean raised);
Draws a three-dimensional rectangle with a specified edge style.
Return Value:
No return value.
Parameter | Description |
x
| The x coordinate of the rectangle's upper-left corner.
|
y
| The y coordinate of the rectangle's upper-left corner.
|
width
| The width of the rectangle (in pixels).
|
height
| The height of the rectangle (in pixels).
|
raised
| Determines either a raised or sunken edge.
|
public abstract void drawBezier(int xOrig, int yOrig, int values[],
int nPoints);
Draws a Bezier curve.
Return Value:
No return value.
Parameter | Description |
xOrig
| The x coordinate of the origin for the curve.
|
yOrig
| The y coordinate of the origin for the curve.
|
values
| An array of (x,y) pairs of coordinates used to draw the curve.
|
nPoints
| The number of points in the curve.
|
public boolean drawBorder(Rectangle rect, int edge, int flags);
Draws the border of a three-dimensional rectangle.
Return Value:
Returns true if successful; otherwise, returns false.
Parameter | Description |
rect
| The rectangle to use.
|
edge
| The edge to use. This may be one of the following edge styles.
|
flags
| The specified border flags. For a complete listing of all border flags, see IFxGraphicsConstants.
|
public void drawChars(char data[], int offset, int length, int x, int y);
Draws a given character array in the current graphics context.
Return Value:
No return value.
Parameter | Description |
data
| The array of characters to be drawn.
|
offset
| The offset to use.
|
length
| The length of the array used.
|
x
| The x coordinate of the point where the characters are drawn.
|
y
| The y coordinate of the point where the characters are drawn.
|
public void drawChars(char data[], int offset, int length, int x, int y,
Rectangle optionRect, int options, int dx[], int dy[]);
Draws a given character array with the given clipping rectangle or opaquing rectangle. Clipping or opaquing are only performed for the current operation.
Return Value:
No return value.
Parameter | Description |
data
| The array of characters to be drawn.
|
offset
| The offset to use.
|
length
| The length of the array used.
|
x
| The x coordinate of the point where the characters are drawn.
|
y
| The y coordinate of the point where the characters are drawn.
|
optionRect
| The optional rectangle used for clipping or opaquing.
|
options
| The options for this method.
|
dx
| An array of destination x coordinates.
|
dy
| An array of destination y coordinates.
|
protected abstract void drawCharsWithoutFxFont(char data[], int offset, int
length, int x, int y, Rectangle optionRect, int options, int dx[],
int dy[]);
Uses a native peer graphics object to draw the given character array using the supplied advancement lists. This method is used by an FxFont object if it needs to be able to draw and then process. This method is implemented for the Microsoft Virtual Machine in the com.ms.awt.GraphicsX class.
Return Value:
No return value.
Parameter | Description |
str
| The string to draw.
|
x
| The x coordinate of the point where the string is drawn.
|
y
| The y coordinate of the point where the string is drawn.
|
optionRect
| The optional rectangle used for clipping and opaquing.
|
options
| The options for this method.
|
dx
| An array of destination x-values.
|
dy
| An array of destination y-values.
|
See Also: com.ms.fx.FxGraphics
public boolean drawEdge(Rectangle inRect, int edge, int flags);
Draws the edges of a three-dimensional rectangle.
Return Value:
Returns true if successful; otherwise, returns false.
Parameter | Description |
inRect
| The rectangle to use.
|
edge
| The edge to use. For a complete listing of all edge styles, see IFxGraphicsConstants.
|
flags
| The specified edge style.
|
public abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int
dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer);
Draws as much of the specified area in the image as is currently available. For more information on this abstract method, see the appropriate Graphics.drawImage method.
Return Value:
Returns immediately in all cases, even if the entire area of the image has not yet been scaled, dithered, and converted for the output device.
Parameter | Description |
img
| The Image object to draw.
|
dx1
| The x coordinate of the first corner of the destination rectangle.
|
dy1
| The y coordinate of the first corner of the destination rectangle.
|
dx2
| The x coordinate of the second corner of the destination rectangle.
|
dy2
| The y coordinate of the second corner of the destination rectangle.
|
sx1
| The x coordinate of the first corner of the source rectangle.
|
sy1
| The y coordinate of the first corner of the source rectangle.
|
sx2
| The x coordinate of the second corner of the source rectangle.
|
sy2
| The y coordinate of the second corner of the source rectangle.
|
observer
| The object to be notified as more of the image is scaled and converted.
|
public abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int
dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor,
ImageObserver observer);
Draws as much of the specified area in the image as is currently available. Transparent pixels are drawn in the specified background color. For more information on this abstract method, see the appropriate Graphics.drawImage method.
Return Value:
Returns immediately in all cases, even if the entire area of the image has not yet been scaled, dithered, and converted for the output device.
Parameter | Description |
img
| The Image object to draw.
|
dx1
| The x coordinate of the first corner of the destination rectangle.
|
dy1
| The y coordinate of the first corner of the destination rectangle.
|
dx2
| The x coordinate of the second corner of the destination rectangle.
|
dy2
| The y coordinate of the second corner of the destination rectangle.
|
sx1
| The x coordinate of the first corner of the source rectangle.
|
sy1
| The y coordinate of the first corner of the source rectangle.
|
sx2
| The x coordinate of the second corner of the source rectangle.
|
sy2
| The y coordinate of the second corner of the source rectangle.
|
bgcolor
| The background color to use.
|
observer
| The object to be notified as more of the image is scaled and converted.
|
public void drawOutlineChar(int xOrig, int yOrig, GlyphOutline go);
Draws an outline character.
Return Value:
No return value.
Parameter | Description |
xOrig
| The x coordinate of the character.
|
yOrig
| The y coordinate of the character.
|
go
| The GlyphOutline to use.
|
public abstract void drawOutlinePolygon(int xOrig, int yOrig,
OutlinePolygon op);
Draws an outline polygon of a character.
Return Value:
No return value.
Parameter | Description |
xOrig
| The horizontal starting point for the shape.
|
yOrig
| The vertical starting point for the shape.
|
op
| The OutlinePolygon to draw.
|
See Also: com.ms.fx.OutlinePolygon
public abstract void drawPixels(int pels[], int len);
Draws a given list of pixels.
Return Value:
No return value.
Parameter | Description |
pels
| An array of pixels.
|
len
| The length of the array.
|
public abstract void drawPolyline(int xPoints[], int yPoints[],
int nPoints);
Draws multiple lines at one time.
Return Value:
No return value.
Parameter | Description |
xPoints
| An array of x coordinates.
|
yPoints
| An array of y coordinates.
|
nPoints
| The number of points used to draw the lines.
|
public abstract void drawScanLines(boolean xChanging, int points[],
int offset, int nPoints);
Draws fast lines, either horizontally or vertically.
Return Value:
No return value.
Parameter | Description |
xChanging
| The direction that the line is drawn, either vertically or horizontally.
|
points
| An array of points.
|
offset
| The offset to use.
|
nPoints
| The number of points in the array.
|
public void drawString(String str, int x, int y, Rectangle optionRect,
int options, int dx[], int dy[]);
Draws the given string using the supplied advancement lists.
Return Value:
No return value.
Parameter | Description |
str
| The string to draw.
|
x
| The x coordinate of the point where the string is drawn.
|
y
| The y coordinate of the point where the string is drawn.
|
optionRect
| The optional rectangle used for clipping and opaquing.
|
options
| The options for this method.
|
dx
| An array of destination x-values.
|
dy
| An array of destination y-values.
|
public void drawString(String str, int x, int y);
Draws the given string.
Return Value:
No return value.
Parameter | Description |
str
| The string to draw.
|
x
| The x coordinate of the point where the string is drawn.
|
y
| The y coordinate of the point where the string is drawn.
|
public void drawString(String str, int x, int y, int a);
Rotates and draws a string at the specified angle of rotation.
Return Value:
No return value.
Parameter | Description |
str
| The string to draw.
|
x
| The x coordinate of the point where the string is drawn.
|
y
| The y coordinate of the point where the string is drawn.
|
a
| The angle at which the text is drawn. An angle of 0 degrees draws standard tdLatinNormal text normally, while an angle of 180 degrees would rotate and draw this same string upside down. The range for this field is 0 to 359.
|
public FxFormattedText drawStringFormatted(String s, Rectangle r, int hta,
int vta, int ww, boolean bordered, int tabOrigin, int tabs[],
IFxShape outline, boolean mnem);
Draws a formatted text string.
Return Value:
Returns an FxFormattedText object, which is a formatted text string.
Parameter | Description |
s
| The string to draw.
|
r
| The bounding rectangle.
|
hta
| The horizontal text alignment. This may be one of the following hta values.
htaLeft
|
htaCenter
|
htaRight
|
htaStretch
|
htaJustified
|
htaScriptDefault
|
|
vta
| The vertical text alignment. This may be one of the following vta values.
vtaTop
|
vtaCenter
|
vtaBaseline
|
vtaBottom
|
vtaStretch
|
vtaScriptDefault
|
|
ww
| A word wrap value. This may be one of the following word wrap values.
wwCleanEdges
|
wwKeepWordIntact
|
wwNone
|
wwVirtualRectEnd
|
wwVirtualRectSide
|
wwWrap
|
|
bordered
| Determines whether the string is bordered.
|
tabOrigin
| Set tabs are relative to this position in the text string.
|
tabs
| The tab stops.
|
outline
| The outline for the formatted text. (The value may be null.)
|
mnem
| Set this value to true if mnemonic drawing is used.
|
See Also: getMnemonicDrawing, setMnemonicDrawing
protected abstract void drawStringWithoutFxFont(String str,int x, int y,
Rectangle optionRect, int options, int[] dx,int[] dy);
Uses a native peer graphics object to draw the given string using the supplied advancement lists. This method is implemented for the Microsoft Virtual Machine in the com.ms.awt.GraphicsX class.
Return Value:
No return value.
Parameter | Description |
str
| The string to draw.
|
x
| The x coordinate of the point where the string is drawn.
|
y
| The y coordinate of the point where the string is drawn.
|
optionRect
| The optional rectangle used for clipping and opaquing.
|
options
| The options for this method.
|
dx
| An array of destination x-values.
|
dy
| An array of destination y-values.
|
See Also: com.ms.awt.GraphicsX
public void drawT2Curve(FloatPoint pta, FloatPoint ptb, FloatPoint ptc, int
xOrig, int yOrig);
Draws a true type (T2, TT) curve, which is a three-point Bezier curve that uses TrueType fonts, for part of a glyph outline.
Return Value:
No return value.
Parameter | Description |
pta
| Point a on the T2 curve.
|
ptb
| Point b on the T2 curve.
|
ptc
| Point c on the T2 curve.
|
xOrig
| The x coordinate of the origin for the curve.
|
yOrig
| The y coordinate of the origin for the curve.
|
See Also: com.ms.fx.GlyphOutline
public abstract void excludeClip(int x, int y, int w, int h);
Excludes the clipping area from the specified rectangle.
Return Value:
No return value.
Parameter | Description |
x
| The upper-left x coordinate of the rectangle to exclude from the clipping area.
|
y
| The upper-left y coordinate of the rectangle to exclude from the clipping area.
|
w
| The width of the rectangle (in pixels).
|
h
| The height of the rectangle (in pixels).
|
public void fill3DRect(int x, int y, int width, int height, boolean raised);
Draws a filled three-dimensional rectangle with the specified edge style and current color.
Return Value:
No return value.
Parameter | Description |
x
| The x coordinate of the rectangle upper-left corner.
|
y
| The y coordinate of the rectangle upper-left corner.
|
width
| The width of the rectangle (in pixels).
|
height
| The height of the rectangle (in pixels).
|
raised
| Determines either a raised or sunken edge.
|
public Shape getClip();
Retrieves the current clipping area.
Return Value:
Returns a Shape that defines the clipping area.
public abstract Rectangle getClipBounds();
Retrieves the bounds of the current clipping area.
Return Value:
Returns a Rectangle describing the current clipping area.
public abstract Region getClipRegion();
Retrieves the clipping area as a Region.
Return Value:
Returns the region that defines the clipping area.
public static FxGraphics getExtendedGraphics(Graphics g);
Retrieves an extended graphics object based on a java.awt.Graphics object. This allows the extended object to be used with any set of class libraries.
Return Value:
Returns an extended graphics object.
Parameter | Description |
g
| A base graphics object.
|
public static FxGraphics getExtendedGraphics(Component c, Image img);
Retrieves an extended graphics object, using a Component and an optional image as a base. This method enables the extended objects to be used with any set of class libraries.
Return Value:
Returns an extended graphics object.
Parameter | Description |
c
| The component that the graphics object is based on.
|
img
| The image that the graphics object is based on. The parameter value may be null, and if so, an image is created based on the Component c.
|
public abstract GlyphOutline getGlyphOutline(char ch);
Retrieves the outline of the character in the currently selected font.
Return Value:
Returns an OutlinePolygon object. If however, the font is not an outline font, null is returned.
Parameter | Description |
ch
| The character outline that is requested.
|
public Color getTextBackgroundColor();
Retrieves the text background color.
Return Value:
Returns the background color. If no background color is currently set, null is returned.
Remarks:
This method is used for opaquing text.
public abstract Point getTranslation();
Retrieves the origin Point used in a translate operation on a graphics context after the translation is complete.
Return Value:
Returns the origin for the translation.
public abstract void intersectClip(int x, int y, int w, int h);
Sets the current clipping area to the intersection of the current clipping area and the given rectangle.
Return Value:
No return value.
Parameter | Description |
x
| The upper-left x coordinate of the rectangle that specifies the area that may overlap the current clipping area.
|
y
| The upper-left y coordinate of the rectangle that specifies the area that may overlap the current clipping area.
|
w
| The width of the rectangle (in pixels).
|
h
| The height of the rectangle (in pixels).
|
public abstract void setClip(Region r);
Sets the clipping area to the specified region.
Return Value:
No return value.
Parameter | Description |
r
| The Region to set the clipping area to.
|
public abstract void setClip(int x, int y, int width, int height);
Sets the clipping area to the specified rectangle.
Return Value:
No return value.
Parameter | Description |
x
| The x coordinate of the upper-left corner of the clipping rectangle.
|
y
| The y coordinate of the upper-left corner of the clipping rectangle.
|
width
| The width of the clipping rectangle (in pixels).
|
height
| The height of the clipping rectangle (in pixels).
|
public abstract void setClip(Shape clip);
Sets the clipping area to the specified Shape.
Return Value:
No return value.
Parameter | Description |
clip
| The shape of the clipping area.
|
public abstract void setColor( FxColor c );
Sets the current graphics context's color for drawing operations. This method is included for JDK 1.0.2 compatibility.
Return Value:
No return value.
Parameter | Description |
c
| The FxColor that is used in drawing operations.
|
public void setTextBackgroundColor( FxColor c);
Sets the text background color. This method is included for JDK 1.0.2 compatibility.
Return Value:
No return value.
Parameter | Description |
c
| The color to set the background to.
|
Remarks:
This method is used for opaquing text.
public void setTextBackgroundColor( Color c);
Sets the text background color.
Return Value:
No return value.
Parameter | Description |
c
| The color to set the background to.
|
Remarks:
This method is used for opaquing text.