Java Reference
In-Depth Information
A generic graphics
package
21
In this chapter we combine many techniques from the previous parts of the topic
to design a generic graphics package for displaying and manipulating drawings.
The graphical objects to be displayed are specified in an abstract way and the pack-
age may be extended by the user. The package also supports adding and deleting
graphical objects through user interaction.
21.1
Specification of the package
The package provides a panel to display a drawing. The panel can be embedded
into any GUI that needs to display drawings. The drawing can be changed by
an application or by user interaction. The programmer can easily add further
graphical objects to the package according to his or her needs. We describe this
in more detail below.
The drawing is composed of graphical objects . These can be simple shapes
such as lines, circles or triangles but may include much more complex shapes
such as polygons or curves. Some of them are defined in the package.
The programmer can add new graphical objects.
The graphical objects are specified by coordinates that are real numbers. No
knowledge about the display area has to be known.
The drawing is automatically fitted to the display area such that all of it is
visible.
The programmer can choose whether the scaling is proportional (both x - and
y -axes have the same scale) or not (the drawing is extended horizontally and
vertically to fill the panel).
The colour of every graphical object can be set and changed.
The display automatically scales when the panel is re-scaled.
The package provides methods to add or delete graphical objects from the
drawing.
Search WWH ::




Custom Search