Graphics Reference
In-Depth Information
In Jasplot, a
PlotModel
object always works with a
Plotter
object. How-
ever, detailed implementations are not defined at the first stage. We then declare
a
createPlotter
method in
PlotModel
and use it in the method
public Plotter getPlotter() {
if (plotter == null) { plotter = createPlotter(); }
return plotter;
}
in
BasicPlotModel
.heconcreteimplementationof
createPlotter
isgiven
in each specific class. For example, in
ScatterPlotModel
,it is defined as
public Plotter createPlotter() {
return new ScatterPlotter(this);
}
hus, when we use the
getPlotter
method of a
ScatterPlotModel
object,
a
ScatterPlotter
object is automatically created. he same things happen with
other
PlotModel
objects and
Plotter
objects, such as
HistogramPlot-
Model
and
HistogramPlotter
. Figure
.
shows some of these relations.
he combination of
PlotModel
and
Plotter
plays the role of the view in the
MVC pattern. Data expressed by a
DataModel
object can be “viewed” by various
graphics that are conceptually described by
PlotModel
objects and are drawn by
methods implemented concretely in
Plotter
objects.
Classes of Panels for Drawing
17.3.6
JasplotPanel
is a base class for displaying graphics defined by a
PlotModel
object.
JasplotPanel
extends the
JLayeredPane
class of Swing components.
We can set a
PlotModel
object by using the
setModel
method of a
Jasplot-
Panel
object.
JasplotPanel
has multilayer functionality, like almost all recent interactive
graphical applications. Multilayering means that the visible graphics display shows
stacksofvirtual transparent layers.Eachlayerdrawssomegraphicsorhandlesmouse
events. his is a useful technology for realizing interactive dynamic graphics.
JasplotPanel
has three layers. he
JasplotPanelPaletteLayer
dis-
plays points, lines and strings to build the main graphics.
JasplotPanelDrag-
Layer
implements mouse event handling.
JasplotPanelPopupLayer
han-
dles pop-up menus. hese classes are accompanied by the user interface classes
JasplotPanelPaletteLayerUI
,
JasplotPanelDragLayerUI
and
JasplotPanelPopupLayerUI
, respectively, and they play a controller role in
the MVC patterns as a whole. hese classes are depicted in Fig.
.
.
It may take considerable time to redraw
JasplotPanelPaletteLayer
in
ordertorealizedynamicgraphicsoranimations onascreenwhenthenumberofdata
points is large. In this case we need to draw slightly different images promptly and
repeatedly. If we draw such images directly to the screen, it probably takes a notable
period of time and we see some flickering.
One technique to eliminate these di
culties is double-buffering. his is a tech-
nique that repeats two steps: create an offscreen image, then draw it to the screen.
Swing uses this technique in many of its components using the
setDouble-