public interface Painter
Viewer.addPainter(Painter) method. Painter just offers a method that should perform
an arbitrary painting operation. In order to create painters that can
paint specific objects, the ObjectPainter interface may be
used: The SimpleObjectPainter is an implementation of the
Painter interface that allows setting the object that should
be painted, and delegates to an ObjectPainter.| Modifier and Type | Method and Description |
|---|---|
void |
paint(java.awt.Graphics2D g,
java.awt.geom.AffineTransform worldToScreen,
double w,
double h)
Perform the painting operations on the given Graphics.
|
void paint(java.awt.Graphics2D g,
java.awt.geom.AffineTransform worldToScreen,
double w,
double h)
Graphics instance will be passed to
all painters. No painter should make any assumptions about the state of
the Graphics object. Changes in the given Graphics object will affect
painters that are called subsequently. This refers to configuration
settings, like the rendering hints, but also to the
transform of the Graphics.Viewer. If a painter modifies these settings, then it should
either restore the original settings afterwards, or create a local
copy of the Graphics object in order to avoid interferences with
other painters.
public void paint(
Graphics2D g, AffineTransform worldToScreen, double w, double h)
{
// Store the original transform
AffineTransform oldAT = g.getTransform();
// Perform custom transforms and painting
g.translate(100,100);
g.drawLine(10,20,30,40);
...
// Restore the original transform
g.setTransform(oldAT);
}
The AffineTransform that is passed to this method
may also be the same for multiple painters. Usually, the caller
should make sure that modifications of this transform do not
affect painters that are called subsequently, but in general,
it is not recommended to internally store or modify the given
affine transform object. g - The Graphics used for paintingworldToScreen - The world-to-screen transform. This transform
encapsulates the translation, rotation and scaling of the viewer
to which this painter belongs.w - The width of the area, in screen coordinates, in which
this painter operates. This is the screen size of the viewer to
which this painter belongs.h - The height of the area, in screen coordinates, in which
this painter operates. This is the screen size of the viewer to
which this painter belongs.Copyright © 2019. All Rights Reserved.