Class sgraphics.util.GraphicsUtil
All Packages Class Hierarchy This Package Previous Next Index
Class sgraphics.util.GraphicsUtil
java.lang.Object
|
+----sgraphics.util.GraphicsUtil
- public class GraphicsUtil
- extends Object
A class that extends the drawxxx and fillxxx
methods of java.awt.Graphics. In particular, it adds a Line Width
argument to most of the drawxxx methods, a Color argument to most
of the drawxxx and fillxxx methods, and a Font argument to
drawString and drawChars.
Rather than including the Graphics object in a call to a constructor,
the methods are all static, and the Graphics is included as
the first argument to each of the methods.
Don't forget to include it.
For instance, here is how you would draw a 10-pixel wide blue
line from (10,10) to (200, 200) and a 5-pixel thick red
circle of radius 50 centered at (200, 200):
import GraphicsUtil
...
public void paint(Graphics G) {
...
GraphicsUtil.drawLine(G, 10, 10, 200, 200, 10, Color.blue);
GraphicsUtil.drawCircle(G, 200, 200, 50, 5, Color.red);
...
}
The latest version of the source is at
http://www.apl.jhu.edu/~hall/java/GraphicsUtil.java. The latest
version of the documentation is at
http://www.apl.jhu.edu/~hall/java/GraphicsUtil.html.
No warranty of any kind is provided (obviously :-).
Permission to use and/or modify the class file or sources for any
purpose is granted provided this notice is retained. 4/96
Marty Hall
(hall@apl.jhu.edu).
- See Also:
- Graphics
-
GraphicsUtil()
-
-
draw3DRect(Painter, float, float, float, float, boolean, Color)
- Draws a 1-pixel thick 3D rectangle in the specified location with
the given color.
-
draw3DRect(Painter, float, float, float, float, boolean, float)
- Draws a 3D rectangle in the specified location with the given
line thickness.
-
draw3DRect(Painter, float, float, float, float, boolean, float, Color)
- Draws a 3D rectangle in the specified location with the given
line thickness and color.
-
drawArc(Painter, float, float, float, float, int, int, Color)
- Adds a Color argument to the drawArc method of java.awt.Graphics.
-
drawChars(Painter, char[], int, int, float, float, Color)
- Adds a Color argument to the drawChars method of java.awt.Graphics.
-
drawChars(Painter, char[], int, int, float, float, Font)
- Adds a Font argument to the drawChars method of java.awt.Graphics.
-
drawChars(Painter, char[], int, int, float, float, Font, Color)
- Adds Font and Color arguments to the drawChars method of
java.awt.Graphics.
-
drawCircle(Painter, float, float, float)
- Calls the drawOval method of java.awt.Graphics with a
square bounding box centered at specified location with
width/height of 2R.
-
drawCircle(Painter, float, float, float, Color)
- Calls the drawOval method of java.awt.Graphics with a
square bounding box centered at specified location with
width/height of 2R.
-
drawCircle(Painter, float, float, float, float)
- Draws a circle of radius R at location (X,Y) with
the specified line width.
-
drawCircle(Painter, float, float, float, float, Color)
- Draws a circle of radius R at location (X,Y) with
the specified line width and color.
-
drawLine(Painter, float, float, float, float, Color)
- Draws a 1-pixel wide line from (X1, Y1) to (X2, Y2) using the
specified color.
-
drawLine(Painter, float, float, float, float, float)
- Draws a line from (X1, Y1) to (X2, Y2) using the specified
pen thickness.
-
drawLine(Painter, float, float, float, float, float, Color)
- Draws a line from (X1, Y1) to (X2, Y2) using the specified
pen thickness and color.
-
drawOval(Painter, float, float, float, float, Color)
- Draws a 1-pixel thick oval in the specified bounding rectangle with
the specified color.
-
drawOval(Painter, float, float, float, float, float)
- Draws an oval in the specified bounding rectangle with
the specified pen thickness.
-
drawOval(Painter, float, float, float, float, float, Color)
- Draws an oval in the specified bounding rectangle with
the specified pen thickness and color.
-
drawPolygon(Painter, float[], float[], int, Color)
- Draws a polygon in the specified color.
-
drawRect(Painter, float, float, float, float, Color)
- Draws a 1-pixel thick rectangle at the specified location with the
supplied color.
-
drawRect(Painter, float, float, float, float, float)
- Draws a rectangle at the specified location with the
supplied pen thickness.
-
drawRect(Painter, float, float, float, float, float, Color)
- Draws a rectangle at the specified location with the
supplied pen thickness and color.
-
drawRoundRect(Painter, float, float, float, float, float, float, Color)
- Draws a 1-pixel wide rounded rectangle with the specified color.
-
drawRoundRect(Painter, float, float, float, float, float, float, float)
- Draws a rounded rectangle at the specified location with the
supplied pen thickness.
-
drawRoundRect(Painter, float, float, float, float, float, float, float, Color)
- Draws a rounded rectangle at the specified location with the
supplied pen thickness and color.
-
drawString(Painter, String, float, float, Color)
- Calls G.drawString(S, X, Y) after setting the color to C.
-
drawString(Painter, String, float, float, Font)
- Calls G.drawString(S, X, Y) after setting the font to F.
-
drawString(Painter, String, float, float, Font, Color)
- Calls G.drawString(S, X, Y) after setting the font to F
and the color to C.
-
fill3DRect(Painter, float, float, float, float, boolean, Color)
-
-
fillArc(Painter, float, float, float, float, int, int, Color)
- Adds a Color argument to the fillArc method of java.awt.Graphics.
-
fillCircle(Painter, float, float, float)
- Calls the fillOval method of java.awt.Graphics with a
square bounding box centered at specified location with
width/height of 2R.
-
fillCircle(Painter, float, float, float, Color)
- Calls the fillOval method of java.awt.Graphics with a
square bounding box centered at specified location with
width/height of 2R.
-
fillOval(Painter, float, float, float, float, Color)
- Calls G.fillOval(Left, Top, Width, Height) after setting
the color appropriately.
-
fillPolygon(Painter, float[], float[], int, Color)
- Draws a solid polygon in the specified color.
-
fillRect(Painter, float, float, float, float, Color)
- Calls G.fillRect(Left, Top, Width, Height) after setting
the color appropriately.
-
fillRoundRect(Painter, float, float, float, float, float, float, Color)
- Draws a solid rounded rectangle with the specified color.
GraphicsUtil
public GraphicsUtil()
drawArc
public static void drawArc(Painter G,
float X,
float Y,
float Width,
float Height,
int Start_Angle,
int End_Angle,
Color C)
- Adds a Color argument to the drawArc method of java.awt.Graphics.
- Parameters:
- G - The Graphics object.
Ie G.drawArc(X, Y, Width, Height, X, Y, Start_Angle, End_Angle)
will get called as a result of a call to this method.
- X - The left side of the bounding rectangle
- Y - The top of the bounding rectangle
- Width - The width of the bounding rectangle
- Height - The height of the bounding rectangle
- Start_Angle - The beginning angle in degrees. 0
is 3 o'clock, increasing counterclockwise.
- End_Angle - The ending angle in degrees.
- C - The color in which to draw the arc.
fillArc
public static void fillArc(Painter G,
float X,
float Y,
float Width,
float Height,
int Start_Angle,
int End_Angle,
Color C)
- Adds a Color argument to the fillArc method of java.awt.Graphics.
- Parameters:
- G - The Graphics object.
Ie G.fillArc(X, Y, Width, Height, X, Y, Start_Angle, End_Angle)
will get called as a result of a call to this method.
- X - The left side of the bounding rectangle
- Y - The top of the bounding rectangle
- Width - The width of the bounding rectangle
- Height - The height of the bounding rectangle
- Start_Angle - The beginning angle in degrees.0
is 3 o'clock, increasing counterclockwise.
- End_Angle - The ending angle in degrees.
- C - The color in which to draw the arc.
drawChars
public static void drawChars(Painter G,
char Chars[],
int Start,
int Num_Chars,
float X,
float Y,
Color C)
- Adds a Color argument to the drawChars method of java.awt.Graphics.
- Parameters:
- G - The Graphics object.
- Chars - An array of characters.
- Start - The index in Chars at which the string starts.
- Num_Chars - Number of characters to draw (starting at Start).
- X - The left side of the string that gets drawn
- Y - The bottom (not top) of the string.
- C - The color in which to draw the string.
drawChars
public static void drawChars(Painter G,
char Chars[],
int Start,
int Num_Chars,
float X,
float Y,
Font F)
- Adds a Font argument to the drawChars method of java.awt.Graphics.
- Parameters:
- G - The Graphics object.
- Chars - An array of characters.
- Start - The index in Chars at which the string starts.
- Num_Chars - Number of characters to draw (starting at Start).
- X - The left side of the string that gets drawn
- Y - The bottom (not top) of the string.
- F - The font in which to draw the string.
drawChars
public static void drawChars(Painter G,
char Chars[],
int Start,
int Num_Chars,
float X,
float Y,
Font F,
Color C)
- Adds Font and Color arguments to the drawChars method of
java.awt.Graphics.
- Parameters:
- G - The Graphics object.
- Chars - An array of characters.
- Start - The index in Chars at which the string starts.
- Num_Chars - Number of characters to draw (starting at Start).
- X - The left side of the string that gets drawn
- Y - The bottom (not top) of the string.
- F - The font in which to draw the string.
- C - The color in which to draw the string.
drawCircle
public static void drawCircle(Painter G,
float X,
float Y,
float R)
- Calls the drawOval method of java.awt.Graphics with a
square bounding box centered at specified location with
width/height of 2R.
- Parameters:
- G - The Graphics object.
- X - The x-coordinate of the center of the circle.
- Y - The y-coordinate of the center of the circle.
- R - The radius of the circle.
drawCircle
public static void drawCircle(Painter G,
float X,
float Y,
float R,
float Line_Width)
- Draws a circle of radius R at location (X,Y) with
the specified line width. Note that the radius R is to the
center of the doughnut drawn. The outside radius will
be R+Line_Width/2 (rounded down). Inside radius will be
R-Line_Width/2 (rounded down).
- Parameters:
- G - The Graphics object.
- X - The x-coordinate of the center of the circle.
- Y - The y-coordinate of the center of the circle.
- R - The radius of the circle.
- Line_Width - Pen thickness of circle drawn.
drawCircle
public static void drawCircle(Painter G,
float X,
float Y,
float R,
float Line_Width,
Color C)
- Draws a circle of radius R at location (X,Y) with
the specified line width and color. Note that the radius R is to
the center of the doughnut drawn. The outside radius will
be R+Line_Width/2 (rounded down). Inside radius will be
R-Line_Width/2 (rounded down).
- Parameters:
- G - The Graphics object.
- X - The x-coordinate of the center of the circle.
- Y - The y-coordinate of the center of the circle.
- R - The radius of the circle.
- Line_Width - Pen thickness of circle drawn.
- C - The color in which to draw.
drawCircle
public static void drawCircle(Painter G,
float X,
float Y,
float R,
Color C)
- Calls the drawOval method of java.awt.Graphics with a
square bounding box centered at specified location with
width/height of 2R. Draws in the color specified.
- Parameters:
- G - The Graphics object.
- X - The x-coordinate of the center of the circle.
- Y - The y-coordinate of the center of the circle.
- R - The radius of the circle.
- C - The color in which to draw.
fillCircle
public static void fillCircle(Painter G,
float X,
float Y,
float R)
- Calls the fillOval method of java.awt.Graphics with a
square bounding box centered at specified location with
width/height of 2R.
- Parameters:
- G - The Graphics object.
- X - The x-coordinate of the center of the circle.
- Y - The y-coordinate of the center of the circle.
- R - The radius of the circle.
fillCircle
public static void fillCircle(Painter G,
float X,
float Y,
float R,
Color C)
- Calls the fillOval method of java.awt.Graphics with a
square bounding box centered at specified location with
width/height of 2R. Draws in the color specified.
- Parameters:
- G - The Graphics object.
- X - The x-coordinate of the center of the circle.
- Y - The y-coordinate of the center of the circle.
- R - The radius of the circle.
- C - The color in which to draw.
drawLine
public static void drawLine(Painter G,
float X1,
float Y1,
float X2,
float Y2,
float Line_Width)
- Draws a line from (X1, Y1) to (X2, Y2) using the specified
pen thickness.
- Parameters:
- G - The Graphics object.
- X1 - X position of start of line.
- Y1 - Y position of start of line.
- X2 - X position of end of line.
- Y2 - Y position of end of line.
- Line_Width - Thickness of line drawn.
drawLine
public static void drawLine(Painter G,
float X1,
float Y1,
float X2,
float Y2,
float Line_Width,
Color C)
- Draws a line from (X1, Y1) to (X2, Y2) using the specified
pen thickness and color.
- Parameters:
- G - The Graphics object.
- X1 - X position of start of line.
- Y1 - Y position of start of line.
- X2 - X position of end of line.
- Y2 - Y position of end of line.
- Line_Width - Thickness of line drawn.
- C - The color in which to draw.
drawLine
public static void drawLine(Painter G,
float X1,
float Y1,
float X2,
float Y2,
Color C)
- Draws a 1-pixel wide line from (X1, Y1) to (X2, Y2) using the
specified color.
- Parameters:
- G - The Graphics object.
- X1 - X position of start of line.
- Y1 - Y position of start of line.
- X2 - X position of end of line.
- Y2 - Y position of end of line.
- C - The color in which to draw.
drawOval
public static void drawOval(Painter G,
float Left,
float Top,
float Width,
float Height,
float Line_Width)
- Draws an oval in the specified bounding rectangle with
the specified pen thickness. Note that the rectangle
bounds the center (not the outside) of the oval.
So the oval will really go Line_Width/2 pixels beyond bounding
rectangle in all directions. Specifying a width of 1 has
the identical effect to G.drawOval(Left, Top, Width, Height).
- Parameters:
- G - The Graphics object.
- Left - The left side of the bounding rectangle.
- Top - The y-coordinate of the top of the bounding rectangle.
- Width - The width of the bounding rectangle.
- Height - The height of the bounding rectangle.
- Line_Width - The pen thickness.
drawOval
public static void drawOval(Painter G,
float Left,
float Top,
float Width,
float Height,
float Line_Width,
Color C)
- Draws an oval in the specified bounding rectangle with
the specified pen thickness and color. Note that the rectangle
bounds the center (not the outside) of the oval.
So the oval will really go Line_Width/2 pixels beyond bounding
rectangle in all directions. Specifying a width of 1 has
the identical effect to G.drawOval(Left, Top, Width, Height).
- Parameters:
- G - The Graphics object.
- Left - The left side of the bounding rectangle.
- Top - The y-coordinate of the top of the bounding rectangle.
- Width - The width of the bounding rectangle.
- Height - The height of the bounding rectangle.
- Line_Width - The pen thickness.
- C - The color in which to draw.
drawOval
public static void drawOval(Painter G,
float Left,
float Top,
float Width,
float Height,
Color C)
- Draws a 1-pixel thick oval in the specified bounding rectangle with
the specified color.
- Parameters:
- G - The Graphics object.
- Left - The left side of the bounding rectangle.
- Top - The y-coordinate of the top of the bounding rectangle.
- Width - The width of the bounding rectangle.
- Height - The height of the bounding rectangle.
- C - The color in which to draw.
fillOval
public static void fillOval(Painter G,
float Left,
float Top,
float Width,
float Height,
Color C)
- Calls G.fillOval(Left, Top, Width, Height) after setting
the color appropriately. Resets color after drawing.
- Parameters:
- G - The Graphics object.
- Left - The left side of the bounding rectangle.
- Top - The y-coordinate of the top of the bounding rectangle.
- Width - The width of the bounding rectangle.
- Height - The height of the bounding rectangle.
- C - The color in which to draw.
drawPolygon
public static void drawPolygon(Painter G,
float Xs[],
float Ys[],
int Num_Points,
Color C)
- Draws a polygon in the specified color.
Having a drawPolygon with a line width argument would be nice,
but you can't just do it by drawing thick lines, since you could
jagged corners. Filling in those corners takes more work, so
is postponed. If someone wants to implement this and send
it to me, it would be great.
fillPolygon
public static void fillPolygon(Painter G,
float Xs[],
float Ys[],
int Num_Points,
Color C)
- Draws a solid polygon in the specified color.
drawRect
public static void drawRect(Painter G,
float Left,
float Top,
float Width,
float Height,
float Line_Width)
- Draws a rectangle at the specified location with the
supplied pen thickness. Left/Top are the center of the lines
drawn. Ie Width/Height are from the center of one side to the center
of the other. So the inside width/heights are really
Line_Width less than the values of Width and Height.
- Parameters:
- G - The Graphics object.
- Left - Center of left side edge.
- Top - Center of the top edge.
- Width - Distance from center of L side to center of R side.
- Height - Distance from center of top side to center of bottom side.
- Line_Width - Pen thickness.
drawRect
public static void drawRect(Painter G,
float Left,
float Top,
float Width,
float Height,
float Line_Width,
Color C)
- Draws a rectangle at the specified location with the
supplied pen thickness and color. Left/Top are the center
of the lines
drawn. Ie Width/Height are from the center of one side to the center
of the other. So the inside width/heights are really
Line_Width less than the values of Width and Height.
- Parameters:
- G - The Graphics object.
- Left - Center of left side edge.
- Top - Center of the top edge.
- Width - Distance from center of L side to center of R side.
- Height - Distance from center of top side to center of bottom side.
- Line_Width - Pen thickness.
- C - The color in which to draw.
drawRect
public static void drawRect(Painter G,
float Left,
float Top,
float Width,
float Height,
Color C)
- Draws a 1-pixel thick rectangle at the specified location with the
supplied color.
- Parameters:
- G - The Graphics object.
- Left - The x-coordinate of left side edge.
- Top - The y-coordinate of the top edge.
- Width - Width of rectangle.
- Height - Height of rectangle.
- C - The color in which to draw.
fillRect
public static void fillRect(Painter G,
float Left,
float Top,
float Width,
float Height,
Color C)
- Calls G.fillRect(Left, Top, Width, Height) after setting
the color appropriately. Resets the color when done.
drawRoundRect
public static void drawRoundRect(Painter G,
float Left,
float Top,
float Width,
float Height,
float Arc_Width,
float Arc_Height,
float Line_Width)
- Draws a rounded rectangle at the specified location with the
supplied pen thickness. Left/Top are the center of the lines
drawn. Ie Width/Height are from the center of one side to the center
of the other. So the inside width/heights are really
Line_Width less than the values of Width and Height, and the
outside width/heights are Line_Width more.
- Parameters:
- G - The Graphics object.
- Left - Center of left side edge.
- Top - Center of the top edge.
- Width - Distance from center of L side to center of R side.
- Height - Distance from center of top side to center of bottom side.
- Arc_Width - Horizontal diameter of arc at corners.
- Arc_Height - Vertical diameter of arc at corners.
- Line_Width - Pen thickness.
drawRoundRect
public static void drawRoundRect(Painter G,
float Left,
float Top,
float Width,
float Height,
float Arc_Width,
float Arc_Height,
float Line_Width,
Color C)
- Draws a rounded rectangle at the specified location with the
supplied pen thickness and color. Left/Top are the center
of the lines
drawn. Ie Width/Height are from the center of one side to the center
of the other. So the inside width/heights are really
Line_Width less than the values of Width and Height, and the
outside width/heights are Line_Width more.
- Parameters:
- G - The Graphics object.
- Left - Center of left side edge.
- Top - Center of the top edge.
- Width - Distance from center of L side to center of R side.
- Height - Distance from center of top side to center of bottom side.
- Arc_Width - Horizontal diameter of arc at corners.
- Arc_Height - Vertical diameter of arc at corners.
- Line_Width - Pen thickness.
- C - Pen color.
drawRoundRect
public static void drawRoundRect(Painter G,
float Left,
float Top,
float Width,
float Height,
float Arc_Width,
float Arc_Height,
Color C)
- Draws a 1-pixel wide rounded rectangle with the specified color.
Same as G.drawRoundRect except for the color.
- Parameters:
- G - The Graphics object.
- Left - The x-coordinate of left edge.
- Top - The y-coordinate of the top edge.
- Width - Distance from L side to R side.
- Height - Distance from top side to bottom side.
- Arc_Width - Horizontal diameter of arc at corners.
- Arc_Height - Vertical diameter of arc at corners.
- C - Pen color.
fillRoundRect
public static void fillRoundRect(Painter G,
float Left,
float Top,
float Width,
float Height,
float Arc_Width,
float Arc_Height,
Color C)
- Draws a solid rounded rectangle with the specified color.
Same as G.fillRoundRect except for the color.
- Parameters:
- G - The Graphics object.
- Left - Center of left side edge.
- Top - Center of the top edge.
- Width - Distance from center of L side to center of R side.
- Height - Distance from center of top side to center of bottom side.
- Arc_Width - Horizontal diameter of arc at corners.
- Arc_Height - Vertical diameter of arc at corners.
- C - Pen color.
draw3DRect
public static void draw3DRect(Painter G,
float Left,
float Top,
float Width,
float Height,
boolean Is_Raised,
float Line_Width)
- Draws a 3D rectangle in the specified location with the given
line thickness. Left/Top are the center of the lines
drawn. Ie Width/Height are from the center of one side to the center
of the other. So the inside width/heights are really
Line_Width less than the values of Width and Height, and the
outside width/heights are Line_Width more.
- Parameters:
- G - The Graphics object.
- Left - Center of left side edge.
- Top - Center of the top edge.
- Width - Distance from center of L side to center of R side.
- Height - Distance from center of top side to center of bottom side.
- Is_Raised - A boolean variable that determines if the right
and bottom sides are shaded so as to try to make the rectangle
look like it is higher than background (true) or lower (false).
Works best with relatively thin lines and gray colors.
- Line_Width - The pen thickness.
draw3DRect
public static void draw3DRect(Painter G,
float Left,
float Top,
float Width,
float Height,
boolean Is_Raised,
float Line_Width,
Color C)
- Draws a 3D rectangle in the specified location with the given
line thickness and color. Left/Top are the center of the lines
drawn. Ie Width/Height are from the center of one side to the center
of the other. So the inside width/heights are really
Line_Width less than the values of Width and Height, and the
outside width/heights are Line_Width more.
- Parameters:
- G - The Graphics object.
- Left - Center of left side edge.
- Top - Center of the top edge.
- Width - Distance from center of L side to center of R side.
- Height - Distance from center of top side to center of bottom side.
- Is_Raised - A boolean variable that determines if the right
and bottom sides are shaded so as to try to make the rectangle
look like it is higher than background (true) or lower (false).
Works best with relatively thin lines and gray colors.
- Line_Width - The pen thickness.
- C - The pen color.
draw3DRect
public static void draw3DRect(Painter G,
float Left,
float Top,
float Width,
float Height,
boolean Is_Raised,
Color C)
- Draws a 1-pixel thick 3D rectangle in the specified location with
the given color.
- Parameters:
- G - The Graphics object.
- Left - The x-coordinate of left side edge.
- Top - The y-coordinate of the top edge.
- Width - Distance from L side to R side.
- Height - Distance from top side bottom side.
- Is_Raised - A boolean variable that determines if the right
and bottom sides are shaded so as to try to make the rectangle
look like it is higher than background (true) or lower (false).
Works best with gray colors.
- C - The pen color.
fill3DRect
public static void fill3DRect(Painter G,
float Left,
float Top,
float Width,
float Height,
boolean Is_Raised,
Color C)
drawString
public static void drawString(Painter G,
String S,
float X,
float Y,
Color C)
- Calls G.drawString(S, X, Y) after setting the color to C.
Resets the color after drawing.
- Parameters:
- G - The Graphics object.
- S - The string to be drawn.
- X - The left side of the string that gets drawn.
- Y - The bottom (not top) of the string.
- C - The color in which to draw the string.
drawString
public static void drawString(Painter G,
String S,
float X,
float Y,
Font F)
- Calls G.drawString(S, X, Y) after setting the font to F.
Resets the font after drawing.
- Parameters:
- G - The Graphics object.
- S - The string to be drawn.
- X - The left side of the string that gets drawn.
- Y - The bottom (not top) of the string.
- F - The font in which to draw the string.
drawString
public static void drawString(Painter G,
String S,
float X,
float Y,
Font F,
Color C)
- Calls G.drawString(S, X, Y) after setting the font to F
and the color to C. Resets the font and color after drawing.
- Parameters:
- G - The Graphics object.
- S - The string to be drawn.
- X - The left side of the string that gets drawn.
- Y - The bottom (not top) of the string.
- F - The font in which to draw the string.
- C - The color in which to draw the string.
All Packages Class Hierarchy This Package Previous Next Index