public interface Grf
Plot
s.
Each Plot owns an object which implements this interface and
uses it to do the actual graphical output.
Implementations of Grf are expected to keep track of all the
graphics written to them (i.e. line
, mark
and text
calls) and be able actually to paint all
resulting graphics so far requested onto a given graphics context
at any time in response to a call of the paint
method.Modifier and Type | Field and Description |
---|---|
static int |
GRF__COLOUR
Symbolic attribute type indicating colour index.
|
static int |
GRF__ESC
Symbolic capability type indicating escape sequence recognition.
|
static int |
GRF__FONT
Symbolic attribute type indicating character font.
|
static int |
GRF__LINE
Symbolic primitive type indicating lines.
|
static int |
GRF__MARK
Symbolic primitive type indicating markers.
|
static int |
GRF__MJUST
Symbolic capability type indicating M-type justification.
|
static int |
GRF__SCALES
Symbolic capability type indicating a working
scales() method. |
static int |
GRF__SIZE
Symbolic attribute type indicating character/marker size
scale factor.
|
static int |
GRF__STYLE
Symbolic attribute type indicating line style.
|
static int |
GRF__TEXT
Symbolic primitive type indicating text.
|
static int |
GRF__WIDTH
Symbolic attribute type indicating line width.
|
Modifier and Type | Method and Description |
---|---|
double |
attr(int attr,
double value,
int prim)
Enquires or sets a graphics attribute value.
|
int |
cap(int cap,
int value)
Indicates which abilities this
Grf implementation has. |
void |
clear()
Clears all known graphics.
|
void |
flush()
Flushes all pending graphics to the output device.
|
void |
line(int n,
float[] x,
float[] y)
Draws a polyline (a set of connected lines).
|
void |
mark(int n,
float[] x,
float[] y,
int type)
Displays markers at the given positions.
|
void |
paint(Graphics g2)
Paints the graphics written to this Grf object since its
construction or the last call of
clear into the
graphics context given. |
float[] |
qch()
Returns the character height in world coordinates.
|
float[] |
scales()
Gets the axis scales.
|
void |
text(String text,
float x,
float y,
String just,
float upx,
float upy)
Displays a character string at a given position using a specified
justification and up-vector.
|
float[][] |
txExt(String text,
float x,
float y,
String just,
float upx,
float upy)
Gets the extent of a character string.
|
static final int GRF__STYLE
static final int GRF__WIDTH
static final int GRF__SIZE
static final int GRF__FONT
static final int GRF__COLOUR
static final int GRF__LINE
static final int GRF__MARK
static final int GRF__TEXT
static final int GRF__ESC
static final int GRF__MJUST
static final int GRF__SCALES
scales()
method.void paint(Graphics g2)
clear
into the
graphics context given.g2
- the graphics context. It will be cast to a
Graphics2D
, but hopefully it will be
one of those anyway.void clear()
paint
will draw
nothing to its graphics context.void flush() throws Exception
Exception
- an Exception may be thrown if there is an errorvoid line(int n, float[] x, float[] y) throws Exception
n
is less than 2, or if
x
or y
are null.n
- the number of points to plotx
- an array of n
x-coordinatesy
- an array of n
y-coordinatesException
- an Exception may be thrown if there is an errorvoid mark(int n, float[] x, float[] y, int type) throws Exception
n
is less than 2, or if
x
or y
are null.n
- the number of points to plotx
- an array of n
x-coordinatesy
- an array of n
y-coordinatestype
- an integer indicating the type of marker to plotException
- an Exception may be thrown if there is an errorvoid text(String text, float x, float y, String just, float upx, float upy) throws Exception
just
is equivalent to supplying "CC". upx=upy=0
should
throw an Exception.text
- the string to be displayedx
- the reference x coordinatey
- the reference y coordinatejust
- a character string which specifies the location within
the text string which is to be placed at the reference
position given by x and y. The first character
may be 'T' for "top", 'C' for "centre", or 'B' for
"bottom", and specifies the vertical location of the
reference position. Note, "bottom" corresponds to the
base-line of normal text. Some characters (eg "y",
"g", "p", etc) descend below the base-line. The
second character may be 'L' for "left", 'C' for
"centre", or 'R' for "right", and specifies the
horizontal location of the reference position. If
the string has less than 2 characters then 'C'
is used for the missing characters.upx
- The x component of the up-vector for the text,
in graphics world coordinates. If necessary the
supplied value should be negated to ensure that
positive values always refer to displacements from
left to right on the screen.upy
- The y component of the up-vector for the text,
in graphics world coordinates. If necessary the
supplied value should be negated to ensure that
positive values always refer to displacements from
bottom to top on the screen.Exception
- an Exception may be thrown if there is an errordouble attr(int attr, double value, int prim) throws Exception
attr
- an integer value identifying the required attribute.
One of the following:
value
- a new value to store for the attribute. If this is
AstObject.AST__BAD no value is stored.prim
- the sort of graphics primitive to be drawn with the
new attribute. One of the following:
Exception
- an Exception may be thrown if there is an errorfloat[] qch() throws Exception
Exception
- an Exception may be thrown if there is an errorfloat[][] txExt(String text, float x, float y, String just, float upx, float upy) throws Exception
text
method.
The returned box includes any leading or trailing spaces.
The order of the corners is anti-clockwise (in world coordinates)
starting at the bottom left. A null value for just
is equivalent to supplying "CC". upx=upy=0
should
throw an Exception.text
- the string to be displayedx
- the reference x coordinatey
- the reference y coordinatejust
- a character string which specifies the location within
the text string which is to be placed at the reference
position given by x and y. The first character
may be 'T' for "top", 'C' for "centre", or 'B' for
"bottom", and specifies the vertical location of the
reference position. Note, "bottom" corresponds to the
base-line of normal text. Some characters (eg "y",
"g", "p", etc) descend below the base-line. The
second character may be 'L' for "left", 'C' for
"centre", or 'R' for "right", and specifies the
horizontal location of the reference position. If
the string has less than 2 characters then 'C'
is used for the missing characters.upx
- The x component of the up-vector for the text,
in graphics world coordinates. If necessary the
supplied value should be negated to ensure that
positive values always refer to displacements from
left to right on the screen.upy
- The y component of the up-vector for the text,
in graphics world coordinates. If necessary the
supplied value should be negated to ensure that
positive values always refer to displacements from
bottom to top on the screen.Exception
- an Exception may be thrown if there is an errorfloat[] scales() throws Exception
Exception
int cap(int cap, int value)
Grf
implementation has.
This method is used by a Plot
to determine if
this object has given capability. Which capability is being
enquired about is indicated by the value of the cap
argument.
According to the values of cap
and val
,
the method should return a value indicating
capability as described below:
scales()
method, and zero otherwise.
The value
argument should be ignored.
text(java.lang.String, float, float, java.lang.String, float, float)
and txExt(java.lang.String, float, float, java.lang.String, float, float)
methods recognise "M" as a
character in the justification string. If the first character of
a justification string is "M", then the text should be justified
with the given reference point at the bottom of the bounding box.
This is different to "B" justification, which requests that the
reference point be put on the baseline of the text, since some
characters hang down below the baseline. If text
or txExt
cannot differentiate between "M" and "B",
then this method should return zero, in which case "M"
justification will never be requested by Plot
The value
argument should be ignored.
text(java.lang.String, float, float, java.lang.String, float, float)
and txExt(java.lang.String, float, float, java.lang.String, float, float)
methods can recognise and interpret graphics escape sequences
within the supplied string. Zero should be returned if
escape sequences cannot be interpreted (in which case the
Plot
will interpret them itself if needed).
The value
argument should be ignored only if
escape cannot be interpreted by text
and
txExt
. Otherwise value
indicates
whether text
and txExt
should
interpret escape sequences in subsequent calls.
If value
is non-zero then escape sequences
should be interpreted by text
and txExt
.
Otherwise they should be drawn as literal text.
See GrfEscape
for more information
about escape sequences.
cap
- graphics capability type - one of
GRF__SCALES, GRF__MJUST, GRF__ESC as described abovevalue
- flag whose meaning is dependent on cap
as described aboveGrfEscape
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.