Introduction to the Figure Package - fEnv
[Introduction to figPac | figPac API ]
The Drawing Environment
Every Figure and each of its fSubFigures comes with a hash table, called env, that stores the drawing environment for that figure or subfigure.
A hash table is just a general structure that contains pairs
consisting of a name (which Figure assumes is a string) and a value (which
is an arbitrary object). When a new figure is created and each time is drawn,
the drawing environment is initialized by a call to Figure.initEnv().
Thereafter, figure element fEnv is used to modify values
in env and to introduce new entries in the table.
Each fSubFigure comes with its own table, env, of drawing environment
variables. Entries in this table override, for the subfigure, corresponding
entries in the parent's env table. Entries in the parent's table which do not
have corresponding entries in the subfigure table are inherited by the
subfigure at the time the drawing of the fSubFigure commences.
A list of the entries that
are currently used is included in the API documentation for the class fEnv.
Any programmer can add entries using fEnv. But then it is the responsibility of
the programmer to implement applications of those entries.
It is up to the drawgfx
and drawps methods of each figure element to extract and use the entries in the table that are appropriate for it. For example, fCurve, fDisk, fEllipticalArc
and fPolygon all have a variable named fillColor. Each time the drawgfx method
of an instance of one of these classes is called it
- first checks to see if the fillColor variable of that instance has been
assigned a value (i.e. is not null). If so, that value is used, overriding
all values of fillColor stored in the tables env.
- otherwise, it checks to see if env has an entry named "fillColor". If
so, the corresponding value is used.
- otherwise, the value of the variable defaultFillColor for that class is
used.
Here are two typical statements that extract values from the hash table env.
Color fillColor = (Color)(env.get("fillColor")) ;
double linewidth = ((Double)(env.get("lineWidth"))).doubleValue() ;
The output of env.get() is always of class Object (the superclass of all
classes in Java). It has to be cast to whatever class the value is really
supposed to represent. That is the role of (Color) in the first example
and (Double) in the second. The method doubleValue() in the second example
converts the object of class Double to the primitive data type double, that you
actually want to compute with.
[Introduction to figPac | figPac API ]