|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectewe.fx.Graphics
Graphics draws on a surface.
Surfaces are objects that implement the ISurface interface. Window, Image and PrinterJob are examples of surfaces.
Note the following important points about using Graphics objects:
Always call free() on a Graphics when you are finished drawing on it. Graphics objects use limited system resources and although they are automatically free()'ed when they are garbage collected, the system may run out of graphics resources before this happens. Do not use a Graphics after freeing it.
Call flush() when you absolutely want all previous drawing operations to be written to the surface. Although this is not necessary for most Graphics objects, certain implementations (e.g. RotatedGraphics) may cache all operations in memory before sending them to the destination surface. So if you want to hang on to a Graphics to be used again later, call flush() in between using it to ensure that the operations show up on the screen. Calling free() will automatically flush() the graphics, so if you use free() there is no need to use flush().
Use Control.getGraphics() to get a Graphics to draw on a Control If getGraphics() returns null, it means that no part of the Control is visible and you should not attempt to draw on it.
Note that some Graphics operations require that data be able to be read from the destination surface. This includes drawing images with transparent regions, or using OR/AND/XOR operations. This is always possible on an Image surface, but may not always be possible from a Window surface. It should be considered never possible on a PrinterJob surface.
The static variable canCopy indicates whether copying is possible from a Window surface, or you can call the canCopyFrom() method on an individual Graphics object to determine if it is possible to do these operations on that Graphics object.
However to make things simpler and fully portable it is best to use BufferedGraphics to draw on a Control if the Control is going to display images with transparent areas, or if special draw ops are to be used. A BufferedGraphics will create a temporary Graphics object IF the actual Graphics returned by Control.getGraphics() cannot perform these types of operations.
| Field Summary | |
Color |
background
|
static boolean |
canAlphaBlend
|
static boolean |
canCopy
|
static boolean |
canMove
|
Color |
color
|
static int |
DRAW_ALPHA
This is used for drawing images. |
static int |
DRAW_AND
The constant for a draw operation that AND's the source with the destination. |
static int |
DRAW_OR
The constant for a draw operation that OR's the source with the destination. |
static int |
DRAW_OVER
The constant for a draw operation that draws the source over the destination. |
static int |
DRAW_XOR
The constant for a draw operation that XOR's the source with the destination. |
static Color |
LighterGray
|
static int |
SPECIAL_TICK
|
static int |
SPECIAL_X
|
| Fields inherited from interface ewe.ui.UIConstants |
BDR_DOTTED, BDR_INNER, BDR_NOBORDER, BDR_OUTER, BDR_OUTLINE, BDR_RAISEDINNER, BDR_RAISEDOUTER, BDR_SUNKENINNER, BDR_SUNKENOUTER, BF_BOTTOM, BF_BOTTOMLEFT, BF_BOTTOMRIGHT, BF_BUTTON, BF_DIAGONAL, BF_DIAGONAL_ENDBOTTOMLEFT, BF_DIAGONAL_ENDBOTTOMRIGHT, BF_DIAGONAL_ENDTOPLEFT, BF_DIAGONAL_ENDTOPRIGHT, BF_EXACT, BF_FLAT, BF_LEFT, BF_MIDDLE, BF_MONO, BF_PALM, BF_RECT, BF_RIGHT, BF_SOFT, BF_SQUARE, BF_TOP, BF_TOPLEFT, BF_TOPRIGHT, EDGE_BUMP, EDGE_ETCHED, EDGE_RAISED, EDGE_SUNKEN |
| Fields inherited from interface ewe.ui.CellConstants |
BORDER, BOTTOM, CELLFLAG, CELLMASK, CENTER, CONTROLMASK, DONTCHANGE, DONTFILL, DONTSTRETCH, EAST, FILL, FIXEDSIZE, GROW, HCENTER, HCONTRACT, HEXPAND, HFILL, HGROW, HSHRINK, HSTRETCH, INITIALLY_CLOSED, INITIALLY_MINIMIZED, INITIALLY_PREFERRED_SIZE, INSETS, LEFT, MAXIMUMSIZE, MINIMUMSIZE, NORTH, NORTHEAST, NORTHWEST, PREFERREDSIZE, RECT, RIGHT, SHRINK, SOUTH, SOUTHEAST, SOUTHWEST, SPAN, STRETCH, TEXTSIZE, TOP, VCENTER, VCONTRACT, VEXPAND, VFILL, VGROW, VSHRINK, VSTRETCH, WEST |
| Fields inherited from interface ewe.ui.ControlConstants |
All, AlwaysEnabled, AlwaysRecalculateSizes, ByDeferredMouse, ByDeferredPen, ByFrameChange, ByKeyboard, ByMouse, ByPen, ByRequest, CalculatedSizes, Disabled, DisablePopupMenu, DisplayOnly, Down, DrawFlat, Flag, ForceResize, HasData, Invisible, KeepImage, KeepSIP, Left, MakeMenuAtLeastAsWide, Maximize, Minimize, MouseSensitive, NoFocus, NotAnEditor, NotEditable, PaintDataOnly, PaintOutsideOnly, PenTransparent, PreferredSizeOnly, Right, SendUpKeyEvents, SendUpPenEvents, ShowSIP, ShrinkToNothing, SmallControl, SpecialBackground, TakeControlEvents, TakesKeyFocus, Transparent, Up, WantDrag, WantHoldDown |
| Constructor Summary | |
Graphics(ISurface surface)
Constructs a graphics object which can be used to draw on the given surface. |
|
Graphics(ISurface surface,
boolean forCopying)
|
|
Graphics(Object nativeGraphics)
|
|
| Method Summary | |
void |
anchor(Rect subArea,
Rect largeArea,
int anchor)
Modify subArea so that it is anchored appropriately in largeArea. |
boolean |
canCopyFrom()
This returns true if you can do a bitBlt() using this Graphics object as a source. |
void |
changeBrush(Color c,
int style)
|
void |
changePen(Color c,
int style,
int thickness)
|
void |
clearClip()
Clears the current clipping rectangle. |
boolean |
copyRect(Graphics source,
int x,
int y,
int width,
int height,
int destX,
int destY)
|
boolean |
copyRect(Graphics source,
Rect sourceArea,
Rect destArea,
Mask mask)
Copy and scale an area from another Graphics object to this one, using the optional Mask. |
void |
copyRect(ISurface surface,
int x,
int y,
int width,
int height,
int dstX,
int dstY)
Copies a rectangular area from a surface to the given coordinates on the current surface. |
static Graphics |
createNew(ISurface is)
|
void |
draw3DDiamond(Rect rect,
boolean pressed,
Color back)
|
void |
draw3DDiamond(Rect rect,
boolean pressed,
Color back,
boolean amFlat)
|
void |
draw3DRect(Rect r,
int style,
boolean flat,
Color fill,
Color outlineColor)
|
void |
draw3DRect(Rect r,
int style,
boolean flat,
Color fill,
Color outlineColor,
int labelWidth)
|
void |
drawArc(int x,
int y,
int width,
int height,
float startAngle,
float angle)
Draws the outline of a circular or elliptical arc covering the specified rectangle. |
void |
drawArrow(Rect r,
int which)
|
void |
drawChar(char which,
int x,
int y,
int options)
|
void |
drawClosedArc(int x,
int y,
int width,
int height,
float startAngle,
float angle)
Draws the outline of a circular or elliptical arc covering the specified rectangle, and includes lines that connect the end and start point of the arc to each other (ie the connecting chord). |
void |
drawCursor(int x,
int y,
int width,
int height)
Draws a cursor by XORing the given rectangular area on the surface. |
void |
drawDiamond(Rect r,
int which)
|
void |
drawDots(int x1,
int y1,
int x2,
int y2)
Draws a dotted line at the given coordinates. |
void |
drawEdge(Rect r,
int edge,
int flags,
int labelWidth)
|
void |
drawEllipse(int x,
int y,
int width,
int height)
|
void |
drawFormattedText(char[] s,
int start,
int length,
int x,
int y,
FormattedTextSpecs fts)
|
void |
drawFormattedText(String s,
int x,
int y,
FormattedTextSpecs fts)
|
void |
drawFormattedText(String s,
int start,
int length,
int x,
int y,
FormattedTextSpecs fts)
|
void |
drawHorizontalTriangle(Rect bounds,
boolean left)
|
void |
drawImage(IImage image,
int imageDrawOptions,
Rect dest,
int anchor)
|
void |
drawImage(Image image,
Image mask,
Color transparent,
int x,
int y,
int width,
int height)
|
void |
drawImage(Image image,
Image mask,
Color transparent,
Rect sourceImageArea,
Rect destArea,
int scaleOptions)
This will draw and scale a portion of an image into the destination area. |
void |
drawImage(Image image,
int x,
int y)
Draws an image without transparencies at the given x and y coordinates. |
void |
drawImage(Image image,
int sx,
int sy,
int swidth,
int sheight,
int dx,
int dy,
int dwidth,
int dheight)
|
void |
drawLine(int x1,
int y1,
int x2,
int y2)
Draws a line at the given coordinates. |
void |
drawLineRGB(int x1,
int y1,
int x2,
int y2,
int rgb)
This is a fast way of drawing a solid line of thickness 1 of a particular color. |
void |
drawLines(int[] x,
int[] y,
int count)
|
void |
drawPie(int x,
int y,
int width,
int height,
float startAngle,
float angle)
Draws the outline of a circular or elliptical arc covering the specified rectangle, and includes lines that connect the end and start point of the arc to the center of the ellipse. |
void |
drawPolygon(int[] x,
int[] y,
int count)
Draws the outline of a polygon with the given coordinates. |
void |
drawRect(int x,
int y,
int width,
int height)
Draws a rectangle at the given coordinates. |
void |
drawRect(int x,
int y,
int width,
int height,
int thickness)
|
void |
drawRoundRect(int x,
int y,
int width,
int height,
int radius)
Draw a rectangle with rounded corners. |
void |
drawSpecial(int what,
Rect where,
Color c)
|
protected void |
drawTail(Rect r,
int which)
|
void |
drawText(char[] chars,
int start,
int count,
int x,
int y)
Draws text at the given coordinates. |
void |
drawText(FontMetrics fm,
String[] lines,
Rect where,
int alignment,
int anchor)
|
void |
drawText(FontMetrics fm,
String[] lines,
Rect where,
int alignment,
int anchor,
int startLine,
int endLine)
|
void |
drawText(FontMetrics fm,
String[] lines,
Rect where,
int alignment,
int anchor,
int startLine,
int endLine,
FormattedTextSpecs fts)
|
void |
drawText(String s,
int x,
int y)
Draws text at the given coordinates. |
protected void |
drawTextIn(FontMetrics fm,
String[] lines,
Rect where,
int alignment,
int start,
int end,
FormattedTextSpecs fts)
|
void |
drawVerticalTriangle(Rect bounds,
boolean up)
|
void |
fillClosedArc(int x,
int y,
int width,
int height,
float startAngle,
float angle)
Draws the outline of a circular or elliptical arc covering the specified rectangle, and includes lines that connect the end and start point of the arc to each other (ie the connecting chord). |
void |
fillEllipse(int x,
int y,
int width,
int height)
|
void |
fillPie(int x,
int y,
int width,
int height,
float startAngle,
float angle)
Draws and fills the outline of a circular or elliptical arc covering the specified rectangle, and includes lines that connect the end and start point of the arc to the center of the ellipse. |
void |
fillPolygon(int[] x,
int[] y,
int count)
Draws a filled polygon with the given coordinates. |
void |
fillRect(int x,
int y,
int width,
int height)
Fills a rectangular area with the current color. |
void |
fillRectRGB(int x1,
int y1,
int x2,
int y2,
int rgb)
This is a fast way of setting pixel to a particular color. |
void |
fillRoundRect(int x,
int y,
int width,
int height,
int radius)
Fill a rectangle with rounded corners. |
void |
flush()
On some systems it may be necessary to call this method to have operations made to the Graphics actually be displayed on the screen. |
void |
free()
Frees any system resources (native device contexts) associated with the graphics object. |
protected static Object[] |
getArcPoints(int xc,
int yc,
int rx,
int rw,
float startAngle,
float endAngle,
int flags)
|
Color |
getBackground()
|
Brush |
getBrush()
|
Rect |
getClip(Rect r)
Sets the x, y, width and height coordinates in the rectangle passed to the current clip coordinates. |
Color |
getColor()
|
static Graphics |
getEmptyGraphics()
|
FontMetrics |
getFontMetrics(Font font)
Get a FontMetrics for the font on the ISurface for this Graphics. |
static Image |
getImage(int w,
int h)
|
Pen |
getPen()
|
static void |
getSize(FontMetrics fm,
String[] lines,
int start,
int end,
Dimension dest)
|
static void |
getSize(FontMetrics fm,
String[] lines,
int start,
int end,
Dimension dest,
FormattedTextSpecs fts)
|
static void |
getSize(FontMetrics fm,
String line,
Dimension d)
|
static void |
getSize(FontMetrics fm,
String line,
Dimension d,
FormattedTextSpecs fts)
|
int |
getSurfaceType()
Find out the surface type for the Graphics - which will be one of the XXX_SURFACE values. |
double[] |
getTransform(double[] dest)
|
boolean |
isEmpty()
|
boolean |
isValid()
|
static int |
mapColor(int value)
This is used to map an RGB color from user space into device space. |
void |
moveRect(int x,
int y,
int width,
int height,
int dstX,
int dstY)
This copies a rectangular area in a Graphics to a different location within itself in the most effecient way. |
protected void |
nativeSetBrush(Brush b)
|
protected void |
nativeSetPen(Pen p)
|
Rect |
reduceClip(int x,
int y,
int width,
int height,
Rect oldClip)
This alters the clipping region of the current graphics to be the intersection of the original clipping region and the newly specified region. |
Rect |
reduceClip(Rect newRect)
This alters the clipping region of the current graphics to be the intersection of the original clipping region and the newly specified region. |
void |
reset()
|
void |
restoreClip(Rect r)
Use this with a Rect value returned from reduceClip() |
void |
setBackground(Color c)
|
void |
setBackground(int r,
int g,
int b)
|
Brush |
setBrush(Brush newBrush)
|
void |
setClip(int x,
int y,
int width,
int height)
Sets a clipping rectangle. |
void |
setColor(Color c)
|
void |
setColor(int r,
int g,
int b)
Sets the current color for drawing operations. |
void |
setDrawOp(int drawOp)
Sets the drawing operation. |
void |
setFont(Font font)
Sets the current font for operations that draw text. |
Pen |
setPen(Pen newPen)
|
void |
setPixelRGB(int x,
int y,
int rgb)
This is a fast way of setting pixel to a particular color. |
void |
setTransform(double[] transforms)
|
double[] |
transform(double[] transform,
double[] oldTransform)
|
void |
translate(int x,
int y)
Translates the origin of the current coordinate system by the given x and y values. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, toString |
| Field Detail |
public Color color
public Color background
public static boolean canAlphaBlend
public static boolean canCopy
public static boolean canMove
public static final int DRAW_OVER
public static final int DRAW_AND
public static final int DRAW_OR
public static final int DRAW_XOR
public static final int DRAW_ALPHA
public static Color LighterGray
public static final int SPECIAL_TICK
public static final int SPECIAL_X
| Constructor Detail |
public Graphics(ISurface surface)
If you are trying to create a graphics object for drawing in a subclass of control, use the createGraphics() method in the Control class. It creates a graphics object and translated the origin to the origin of the control.
public Graphics(ISurface surface,
boolean forCopying)
public Graphics(Object nativeGraphics)
| Method Detail |
public static int mapColor(int value)
value - The RGB color to check.
public void setBackground(int r,
int g,
int b)
public void setBackground(Color c)
public int getSurfaceType()
public boolean canCopyFrom()
public void clearClip()
public boolean isValid()
public void moveRect(int x,
int y,
int width,
int height,
int dstX,
int dstY)
x - y - width - height - dstX - dstY -
public void copyRect(ISurface surface,
int x,
int y,
int width,
int height,
int dstX,
int dstY)
Not all combinations of surfaces are supported on all platforms. PalmOS has problems copying from an Window surface to an Image and between two Image surfaces. Java doesn't allow copying from an Window surface to an Image.
surface - the surface to copy fromx - the source x coordinatey - the source y coordinatewidth - the width of the area on the source surfaceheight - the height of the area on the source surfacedstX - the destination x location on the current surfacedstY - the destination y location on the current surfacesetDrawOp(int)
public boolean copyRect(Graphics source,
int x,
int y,
int width,
int height,
int destX,
int destY)
public boolean copyRect(Graphics source,
Rect sourceArea,
Rect destArea,
Mask mask)
public void free()
public void drawText(char[] chars,
int start,
int count,
int x,
int y)
chars - the character array to displaystart - the start position in arraycount - the number of characters to displayx - the left coordinate of the text's bounding boxy - the top coordinate of the text's bounding box
public void drawChar(char which,
int x,
int y,
int options)
public void drawFormattedText(String s,
int x,
int y,
FormattedTextSpecs fts)
public void drawFormattedText(String s,
int start,
int length,
int x,
int y,
FormattedTextSpecs fts)
public void drawFormattedText(char[] s,
int start,
int length,
int x,
int y,
FormattedTextSpecs fts)
public void drawImage(Image image,
int x,
int y)
public void drawImage(Image image,
Image mask,
Color transparent,
int x,
int y,
int width,
int height)
public void drawImage(Image image,
Image mask,
Color transparent,
Rect sourceImageArea,
Rect destArea,
int scaleOptions)
public void drawCursor(int x,
int y,
int width,
int height)
public void drawLine(int x1,
int y1,
int x2,
int y2)
public void drawRoundRect(int x,
int y,
int width,
int height,
int radius)
radius - the radius of the arcs that are at the corners.
public void fillRoundRect(int x,
int y,
int width,
int height,
int radius)
radius - the radius of the arcs that are at the corners.
public void drawRect(int x,
int y,
int width,
int height)
public void drawDots(int x1,
int y1,
int x2,
int y2)
public void drawPolygon(int[] x,
int[] y,
int count)
x - x vertex coordinatesy - y vertex coordinatescount - number of vertices
public void drawLines(int[] x,
int[] y,
int count)
public void drawArc(int x,
int y,
int width,
int height,
float startAngle,
float angle)
public void drawClosedArc(int x,
int y,
int width,
int height,
float startAngle,
float angle)
public void fillClosedArc(int x,
int y,
int width,
int height,
float startAngle,
float angle)
public void drawPie(int x,
int y,
int width,
int height,
float startAngle,
float angle)
public void fillPie(int x,
int y,
int width,
int height,
float startAngle,
float angle)
protected static Object[] getArcPoints(int xc,
int yc,
int rx,
int rw,
float startAngle,
float endAngle,
int flags)
public void fillPolygon(int[] x,
int[] y,
int count)
x - x vertex coordinatesy - y vertex coordinatescount - number of vertices
public void drawText(String s,
int x,
int y)
public void fillRect(int x,
int y,
int width,
int height)
public void setClip(int x,
int y,
int width,
int height)
public Rect getClip(Rect r)
public Rect reduceClip(int x,
int y,
int width,
int height,
Rect oldClip)
public Rect reduceClip(Rect newRect)
public void restoreClip(Rect r)
public void setColor(int r,
int g,
int b)
r - the red value (0..255)g - the green value (0..255)b - the blue value (0..255)public Color getColor()
public Color getBackground()
public void setDrawOp(int drawOp)
Not all operations are supported on all platforms. When used with Java, DRAW_OVER is supported for all types of drawing and DRAW_XOR is supported for drawing lines, rectangles, text and images. However, DRAW_XOR is not supported when copying surface areas and the DRAW_AND and DRAW_OR operations aren't supported at all under Java.
PalmOS platforms supports all the drawing operations when drawing images and copying surface regions. However, only the DRAW_OVER operation is supported when drawing lines, rectangles and text. If you need to use the XOR drawing operation for drawing lines under PalmOS, you can draw the line into an image and then draw the image with an XOR drawing operation.
Win32 and Windows CE platforms support all the drawing operations except when drawing text. Only DRAW_OVER is supported when drawing text. If you need to draw XOR'ed text, you can draw the text into an image and then draw the image with an XOR draw operation.
When calculating the result of XOR, AND and OR drawing, the value of the color black is all 1's (fully set) in binary and white is all 0's (fully unset).
DRAW_OVER,
DRAW_AND,
DRAW_OR,
DRAW_XORpublic void setFont(Font font)
public void translate(int x,
int y)
public Pen getPen()
public Pen setPen(Pen newPen)
protected void nativeSetPen(Pen p)
public Brush getBrush()
public Brush setBrush(Brush newBrush)
protected void nativeSetBrush(Brush b)
public void drawEllipse(int x,
int y,
int width,
int height)
public void fillEllipse(int x,
int y,
int width,
int height)
public static Graphics getEmptyGraphics()
public void setColor(Color c)
public void drawRect(int x,
int y,
int width,
int height,
int thickness)
public void changePen(Color c,
int style,
int thickness)
public void changeBrush(Color c,
int style)
public void draw3DRect(Rect r,
int style,
boolean flat,
Color fill,
Color outlineColor)
public void draw3DRect(Rect r,
int style,
boolean flat,
Color fill,
Color outlineColor,
int labelWidth)
public void drawEdge(Rect r,
int edge,
int flags,
int labelWidth)
public void drawDiamond(Rect r,
int which)
protected void drawTail(Rect r,
int which)
public void drawArrow(Rect r,
int which)
public void reset()
public boolean isEmpty()
public static Graphics createNew(ISurface is)
public static Image getImage(int w,
int h)
public void anchor(Rect subArea,
Rect largeArea,
int anchor)
public void drawImage(IImage image,
int imageDrawOptions,
Rect dest,
int anchor)
public void drawText(FontMetrics fm,
String[] lines,
Rect where,
int alignment,
int anchor)
public void drawText(FontMetrics fm,
String[] lines,
Rect where,
int alignment,
int anchor,
int startLine,
int endLine)
public static void getSize(FontMetrics fm,
String line,
Dimension d)
public static void getSize(FontMetrics fm,
String line,
Dimension d,
FormattedTextSpecs fts)
public static void getSize(FontMetrics fm,
String[] lines,
int start,
int end,
Dimension dest,
FormattedTextSpecs fts)
public static void getSize(FontMetrics fm,
String[] lines,
int start,
int end,
Dimension dest)
public void drawText(FontMetrics fm,
String[] lines,
Rect where,
int alignment,
int anchor,
int startLine,
int endLine,
FormattedTextSpecs fts)
protected void drawTextIn(FontMetrics fm,
String[] lines,
Rect where,
int alignment,
int start,
int end,
FormattedTextSpecs fts)
public void drawVerticalTriangle(Rect bounds,
boolean up)
public void drawHorizontalTriangle(Rect bounds,
boolean left)
public void draw3DDiamond(Rect rect,
boolean pressed,
Color back)
public void draw3DDiamond(Rect rect,
boolean pressed,
Color back,
boolean amFlat)
public void drawSpecial(int what,
Rect where,
Color c)
public FontMetrics getFontMetrics(Font font)
public void drawLineRGB(int x1,
int y1,
int x2,
int y2,
int rgb)
setPixelRGB(),
fillRectRGB()
public void setPixelRGB(int x,
int y,
int rgb)
drawLineRGB(),
fillRectRGB()
public void fillRectRGB(int x1,
int y1,
int x2,
int y2,
int rgb)
drawLineRGB(),
setPixelRGB()public void flush()
public void drawImage(Image image,
int sx,
int sy,
int swidth,
int sheight,
int dx,
int dy,
int dwidth,
int dheight)
public void setTransform(double[] transforms)
public double[] getTransform(double[] dest)
public double[] transform(double[] transform,
double[] oldTransform)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||