The PolyDraw Applet -- S. Tanimoto
What this applet does: Lets the user draw polygons.
Features: Any number of polygons at a time; Line color can be set prior
to drawing a polygon; Vertices can be constrained to grid points if desired;
Grid spacing is adjustable; Vertices can be moved after they have been
drawn; Vertices can be deleted after they have been drawn; Double-clicking
while drawing closes the current polygon.
User instructions:
To create a new polygon, first click on Poly, and then click to
create each vertex in the red drawing area.
A polygon can be closed by double-clicking when creating the
last vertex.
A polygon that has not be closed when created will remain an
open polygon (sometimes called a "polyline").
To move any vertex, click on Edit, then drag a selection rectangle
around the vertex, then pick up and drag the vertex.
To delete a selected vertex, click on Delete.
Limitations:
The color of a polygon cannot be changed after the Poly button has
been clicked for the new polygon.
Any one polygon has only one color.
There is no Undo facility.
Polygons with no vertices are invisible but take up a position
in the internal list of objects.
The sources:
PolyDraw.java
-- the main applet/application class.
DrawCanvas.java
-- most of the drawing functionality is here.
Controls.java
-- sets up the control panel for the grid and for color selection.
Valuator.java
-- used to encapsulate scrollbar + textfield combinations.
Toolbar.java
-- subclasses Canvas to create an array of button-like tools.
Polygon.java
-- defines the polygon objects, including their paint method.
DrawnObject.java
-- a superclass of Polygon, included to allow later incorporation
of other kinds of objects than polygons.
PDPoint.java
-- subclasses Point, adding facilities for being selected and displaying
themselves
in selected mode.
S. Tanimoto, February 1, 2000.