All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class att.grappa.GraphicContext

java.lang.Object
   |
   +----att.grappa.GraphicContext

public class GraphicContext
extends Object
implements Cloneable
This class provides a repository for drawing information such as foreground and background colors, font, font size and so on. Class methods associating color names with RGB values are also included.

Version:
1.1, 30 Sep 1999; Copyright 1996 - 1999 by AT&T Corp.
Author:
John Mocenigo, Research @ AT&T Labs

Variable Index

 o defaultBackground
The default background color (white).
 o defaultColor
The default color of last resort in all cases (black).
 o defaultFont
The default font resulting from Font(defaultFontname,defaultFontstyle,defaultFontsize)
 o defaultFontcolor
The default font color (black).
 o defaultFontname
The default font name (serif).
 o defaultFontsize
The default font size (14).
 o defaultFontstyle
The default font style (Font.PLAIN).
 o defaultForeground
The default foreground color (black).
 o defaultXOR
The default XOR color (light gray).

Constructor Index

 o GraphicContext()
Create a GraphicContext instance initialized with the default values.

Method Index

 o addColor(String, Color)
Adds a color to the application color table.
 o clone()
Creates a new object of the same class as this object.
 o equals(Object)
Determines whether two contexts are equal.
 o getBackground()
Get the background color of this graphic context.
 o getClipRect()
Get the clipping rectangle of this graphic context.
 o getColor(String, Color)
Return the color in the color table with the given name.
 o getColorName(Color)
Return the name of the supplied color.
 o getFillMode()
Get the fill mode of this graphic context.
 o getFont()
Get the font currently associated with this graphic context.
 o getFontcolor()
Get the font color of this graphic context.
 o getFontname()
Get the font name of this graphic context.
 o getFontsize()
Get the font size of this graphic context.
 o getFontstyle()
Get the font style of this graphic context.
 o getForeground()
Get the foreground color of this graphic context.
 o getLineStyle()
Get the line style of this graphic context (as an int).
 o getLineStyleString()
Get the line style of this graphic context (as a string).
 o getXORColor()
Get the XOR color of this graphic context.
 o getXORMode()
Get the XOR mode of this graphic context.
 o setBackground(Color)
Set the background color to the supplied color.
 o setBackground(String)
Set the background color to the named color.
 o setClipRect(int, int, int, int)
Set the clipping rectangle as specified.
 o setClipRect(Rectangle)
Set the clipping rectangle to the specified value.
 o setFillMode(boolean)
Set the fill mode as specified.
 o setFont()
Set the font as specified.
 o setFont(Font)
Set the font to the supplied font.
 o setFontcolor(Color)
Set the font color to the specified color.
 o setFontcolor(String)
Set the font color to the named color.
 o setFontname(String)
Set the font name.
 o setFontsize(int)
Set the font size.
 o setFontsize(String)
Set the font size.
 o setFontstyle(int)
Set the font style.
 o setForeground(Color)
Set the foreground color to the supplied color.
 o setForeground(String)
Set the foreground color to the named color.
 o setLineStyle(int)
Set the line style as specified.
 o setLineStyle(String)
Set the line style as specified.
 o setXORColor(Color)
Set the x-or color to the specified color.
 o setXORColor(String)
Set the x-or color to the named color.
 o setXORMode(boolean)
Set the x-or mode as specified.
 o xlateFontStyle(String)
Converts a string to an integer font style.

Variables

 o defaultForeground
 public static final Color defaultForeground
The default foreground color (black).

 o defaultBackground
 public static final Color defaultBackground
The default background color (white).

 o defaultXOR
 public static final Color defaultXOR
The default XOR color (light gray).

 o defaultFontcolor
 public static final Color defaultFontcolor
The default font color (black).

 o defaultColor
 public static final Color defaultColor
The default color of last resort in all cases (black).

 o defaultFontstyle
 public static final int defaultFontstyle
The default font style (Font.PLAIN).

 o defaultFontsize
 public static final int defaultFontsize
The default font size (14).

 o defaultFontname
 public static final String defaultFontname
The default font name (serif).

 o defaultFont
 public static final Font defaultFont
The default font resulting from Font(defaultFontname,defaultFontstyle,defaultFontsize)

Constructors

 o GraphicContext
 public GraphicContext()
Create a GraphicContext instance initialized with the default values.

Methods

 o addColor
 public static void addColor(String name,
                             Color color) throws IllegalArgumentException
Adds a color to the application color table. For search purposes, names are canonicalized by converting to lower case and stripping non-alphanumerics. A name must contains at least one alphabetic. Once in the table, colors can be set by name, and names can be retrieved by color (although a single color referred to by multiple names only causes the retrieval of the last name mapped to that color).

Parameters:
name - the name to be used to reference the color.
color - the Color value.
 o getColor
 public static Color getColor(String name,
                              Color color)
Return the color in the color table with the given name. If the color is not found, the supplied default is returned. If the supplied default is null, the class default is returned. If the name consists of three comma or space separated floating point numbers in the range 0 to 1 inclusive, then it is assumed to represent an HSB color specification and generated directly. The name search is case insensitive and looks at alphanumerics only.

Parameters:
name - the name of the color to be retrieved.
color - the color value to return if requested color is not found.
Returns:
the color matching the name or the default.
 o getColorName
 public static String getColorName(Color color)
Return the name of the supplied color.

Parameters:
color - the color whose name is to be retrieved.
Returns:
the color's (most recently entered) name, if it is in the color table, or null.
 o setForeground
 public Color setForeground(String color)
Set the foreground color to the named color.

Parameters:
color - the name of the color to be used as the foreground color.
Returns:
the previous value of the foreground color.
 o setForeground
 public Color setForeground(Color color)
Set the foreground color to the supplied color.

Parameters:
color - the value of the color to be used as the foreground color.
Returns:
the previous value of the foreground color.
 o setBackground
 public Color setBackground(String color)
Set the background color to the named color.

Parameters:
color - the name of the color to be used as the background color.
Returns:
the previous value of the background color.
 o setBackground
 public Color setBackground(Color color)
Set the background color to the supplied color.

Parameters:
color - the value of the color to be used as the background color.
Returns:
the previous value of the background color.
 o setXORColor
 public Color setXORColor(String color)
Set the x-or color to the named color.

Parameters:
color - the name of the color to be used as the x-or color.
Returns:
the previous value of the x-or color.
 o setXORColor
 public Color setXORColor(Color color)
Set the x-or color to the specified color.

Parameters:
color - the value of the color to be used as the x-or color.
Returns:
the previous value of the x-or color.
 o setFontcolor
 public Color setFontcolor(String color)
Set the font color to the named color.

Parameters:
color - the name of the color to be used as the font color.
Returns:
the previous value of the font color.
 o setFontcolor
 public Color setFontcolor(Color color)
Set the font color to the specified color.

Parameters:
color - the value of the color to be used as the font color.
Returns:
the previous value of the font color.
 o setFontname
 public String setFontname(String name)
Set the font name. A call to setFont() is needed to actually change the font setting.

Parameters:
name - the new font name.
Returns:
the previous font name.
See Also:
setFont
 o setFontsize
 public int setFontsize(String size)
Set the font size. A call to setFont() is needed to actually change the font setting.

Parameters:
size - the new font size.
Returns:
the previous font size.
See Also:
setFont
 o setFontsize
 public int setFontsize(int size)
Set the font size. A call to setFont() is needed to actually change the font setting.

Parameters:
size - the new font size.
Returns:
the previous font size.
See Also:
setFont
 o setFontstyle
 public int setFontstyle(int style)
Set the font style. A call to setFont() is needed to actually change the font setting.

Parameters:
style - the new font style.
Returns:
the previous font style.
See Also:
setFont, PLAIN, BOLD, ITALIC
 o setFont
 public Font setFont()
Set the font as specified. The specification was set by calls to setFontname, setFontsize and setFontstyle.

Returns:
the previous font value.
See Also:
setFontname, setFontsize, setFontstyle
 o setFont
 public Font setFont(Font newFont)
Set the font to the supplied font.

Parameters:
font - the new font value to use.
Returns:
the previous font value.
 o setXORMode
 public boolean setXORMode(boolean mode)
Set the x-or mode as specified.

Parameters:
mode - the new x-or mode value.
Returns:
the previous x-or mode value;
 o setClipRect
 public Rectangle setClipRect(int x,
                              int y,
                              int width,
                              int height)
Set the clipping rectangle as specified.

Parameters:
x - the x coordinate.
y - the y coordinate.
width - the width of the rectangle.
height - the height of the rectangle.
Returns:
the previous value of the clipping rectangle.
 o setClipRect
 public Rectangle setClipRect(Rectangle rect)
Set the clipping rectangle to the specified value.

Parameters:
rect - the new clipping rectangle to use.
Returns:
the previous value of the clipping rectangle.
 o setFillMode
 public boolean setFillMode(boolean mode)
Set the fill mode as specified.

Parameters:
mode - the new fill mode value.
Returns:
the previous fill mode value;
 o setLineStyle
 public int setLineStyle(int style)
Set the line style as specified.

Parameters:
style - the new line style value.
Returns:
the previous line style value;
 o setLineStyle
 public String setLineStyle(String style)
Set the line style as specified.

Parameters:
style - the new line style value.
Returns:
the previous line style value;
 o getForeground
 public Color getForeground()
Get the foreground color of this graphic context.

Returns:
the foreground color.
 o getBackground
 public Color getBackground()
Get the background color of this graphic context.

Returns:
the background color.
 o getXORColor
 public Color getXORColor()
Get the XOR color of this graphic context.

Returns:
the XOR color.
 o getFontcolor
 public Color getFontcolor()
Get the font color of this graphic context.

Returns:
the fontcolor.
 o getFontname
 public String getFontname()
Get the font name of this graphic context.

Returns:
the font name.
 o getFontsize
 public int getFontsize()
Get the font size of this graphic context.

Returns:
the font size.
 o getFontstyle
 public int getFontstyle()
Get the font style of this graphic context.

Returns:
the font style.
 o getFont
 public Font getFont()
Get the font currently associated with this graphic context. Calls setFont() before returning the font, if needed.

Returns:
the font.
 o getXORMode
 public boolean getXORMode()
Get the XOR mode of this graphic context.

Returns:
the XOR mode.
 o getClipRect
 public Rectangle getClipRect()
Get the clipping rectangle of this graphic context.

Returns:
the clipping rectangle.
 o getFillMode
 public boolean getFillMode()
Get the fill mode of this graphic context.

Returns:
the fill mode.
 o getLineStyle
 public int getLineStyle()
Get the line style of this graphic context (as an int).

Returns:
the line style as an int.
 o getLineStyleString
 public String getLineStyleString()
Get the line style of this graphic context (as a string).

Returns:
the line style as a String.
 o equals
 public boolean equals(Object obj)
Determines whether two contexts are equal. Two instances of GraphicContext are equal if the values of their foreground color, background color, XOR color, font color, font, XOR mode and clipping rectangle are all equal.

Parameters:
obj - an object to be compared with this point.
Returns:
true if the object to be compared is an instance of Point and has the same values; false otherwise.
Overrides:
equals in class Object
 o xlateFontStyle
 public static int xlateFontStyle(String fontstyle)
Converts a string to an integer font style. The string is first canonicalized (converted to lower case and non-alphanumerics are removed) then compared to italic, bold or bolditalic. A match returns Font.ITALIC, Font.BOLD, or a bitwise OR-ing of the two, respectively. When there is no match, Font.PLAIN is returned.

Parameters:
fontstyle - a string representing a font style
Returns:
an integer representation of the supplied font style string
 o clone
 public Object clone()
Creates a new object of the same class as this object. The object is initialized with the current values of this context.

Returns:
a new object which is an instance of GraphicContext
Overrides:
clone in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index