Class BWColor
- java.lang.Object
-
- BWColor
-
public class BWColor extends java.lang.Object
The BWColor class represents a color used for drawing, encapsulating both a color name and an AWT Color object. It provides methods to retrieve BWColor objects based on color names or hexadecimal color codes, and ensures a consistent representation of color names.- Author:
- Jim Williams
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static BWColor
getColor(java.lang.String colorStr)
Retrieves a BWColor object based on the specified color name or hexadecimal color code.java.lang.String
toString()
Returns a string representation of the BWColor object.java.lang.String
toStringFixedWidth()
Returns a string representation of this BWColor.
-
-
-
Method Detail
-
toStringFixedWidth
public java.lang.String toStringFixedWidth()
Returns a string representation of this BWColor. If the color name is not set, it returns the hexadecimal RGB value of the AWT Color.- Returns:
- a string representation of this BWColor.
-
toString
public java.lang.String toString()
Returns a string representation of the BWColor object. This method overrides the default toString method and calls the toStringFixedWidth method to get a fixed-width string representation, then trims any leading or trailing whitespace.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a trimmed string representation of the BWColor object
-
getColor
public static BWColor getColor(java.lang.String colorStr)
Retrieves a BWColor object based on the specified color name or hexadecimal color code.If the color name is recognized, it returns the corresponding BWColor object from the color map. If the color code is in hexadecimal format (e.g., "#FFFFFF"), it creates a new BWColor object with the corresponding AWT Color and stores it in the color map.
- Parameters:
colorStr
- the name of the color or a hexadecimal color code.- Returns:
- the corresponding BWColor object, or a default gray color if the input is unrecognized.
-
-