Delegates almost all work to a state object, that allows us to
hot-swap rendering strategies based on state changes inflicted on
this Graphics object. This class keeps track of properties that are
not affected by the state, (such as clip shape,
foreground/background color, font, etc.).
The far front-end of the rendering pipeline consists of the
Graphics2D API. In the far back-end, lies the native graphics
libraries. In most cases the native graphics libraries only have
direct support for a subset of the properties of Graphics2D. To
make up missing features in the native graphics libraries, the
pipeline between the front-end and the back-end need to translate
drawing request to primitive operations that are supported by the
back-end. E.g. for X11, drawing a straight line will translate to
an XDrawLine, drawing a bezier curve will trigger flattening of the
curve and will result in a call to XDrawLines.
This is the basic strategy for the rendering pipeline: Whenever
a graphics property change occurs, that causes the current pipeline
to be insufficient, amend or replace parts of the pipeline so that
the pipeline will once again be able to translate requests to the
set of primitives supported by the native graphics library.
Most graphics libraries share common subsets of
functionality. To be able to reuse pieces of the rendering pipeline
for several backends, we define interfaces that describe subsets of
characteristics supported by the backends. A wrapper for the native
library can implement several interfaces to describe its range of
functionality.
Typically, most painting is done with a graphics object with
simple properties. Unless one is using a complex Look & Feel, the
painting of Swing components will never require affine transforms,
alpha blending, non-rectangular clipping, etc. When graphics
objects are created, they start off in a state where all the
properties are simple. Most graphics objects experience only
trivial property changes, and never leave this simple state. It is
therefore wise to ensure that the rendering pipeline for this
initial state is lean and as much as possible plugs directly into
the backend.
The initial state for graphics object of most raster displays
would call for two levels of indirection:
Graphics2D object ---> IntegerGraphicsState ---> DirectRasterGraphics
clip
public void clip(Shape shape)
Sets the clip region to the intersection of the current clipping region
and s
.
- clip in interface Graphics2D
clone
public Object clone()
This method may be called to create a new copy of the
Object. The typical behavior is as follows:
o == o.clone()
is falseo.getClass() == o.clone().getClass()
is trueo.equals(o)
is true
However, these are not strict requirements, and may
be violated if necessary. Of the three requirements, the
last is the most commonly violated, particularly if the
subclass does not override
Object.equals(Object)
.
If the Object you call clone() on does not implement
Cloneable
(which is a placeholder interface), then
a CloneNotSupportedException is thrown. Notice that
Object does not implement Cloneable; this method exists
as a convenience for subclasses that do.
Object's implementation of clone allocates space for the
new Object using the correct class, without calling any
constructors, and then fills in all of the new field values
with the old field values. Thus, it is a shallow copy.
However, subclasses are permitted to make a deep copy.
All array types implement Cloneable, and override
this method as follows (it should never fail):
public Object clone()
{
try
{
super.clone();
}
catch (CloneNotSupportedException e)
{
throw new InternalError(e.getMessage());
}
}
- clone in interface Object
draw
public void draw(Shape shape)
Draws an outline around a shape using the current stroke and paint.
- draw in interface Graphics2D
shape
- the shape (null
not permitted).
drawArc
public void drawArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
- drawArc in interface Graphics
drawImage
public boolean drawImage(Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
Color bgcolor,
ImageObserver observer)
- drawImage in interface Graphics
drawPolygon
public void drawPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
drawPolyline
public void drawPolyline(int[] xPoints,
int[] yPoints,
int nPoints)
drawString
public void drawString(String text,
float x,
float y)
Draws a string at the specified location, using the current font.
- drawString in interface Graphics2D
text
- the string to draw.x
- the x-coordinate.y
- the y-coordinate.
drawString
public void drawString(String text,
int x,
int y)
Draws a string at the specified location, using the current font.
- drawString in interface Graphics2D
text
- the string to draw.x
- the x-coordinate.y
- the y-coordinate.
fill
public void fill(Shape shape)
Fills the interior of the specified shape
using the current
paint.
- fill in interface Graphics2D
shape
- the shape to fill (null
not permitted).
fillArc
public void fillArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
- fillArc in interface Graphics
fillPolygon
public void fillPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
setPaint
public void setPaint(Paint paint)
Sets the paint to be used for subsequent drawing operations.
- setPaint in interface Graphics2D
paint
- the paint (null
not permitted).
setStroke
public void setStroke(Stroke stroke)
Sets the stroke to be used for subsequent drawing operations.
- setStroke in interface Graphics2D
stroke
- the stroke (null
not permitted).
Copyright (C) 2000, 2002, 2003 Free Software Foundation
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details.