Package com.iizix.prop
Class GBadge
- java.lang.Object
- com.iizix.prop.GBadge
- All Implemented Interfaces:
java.lang.Cloneable
public final class GBadge extends java.lang.Object implements java.lang.Cloneable
A badge holds a short text with a color and font size. Longer texts can be applied and will be shown with trailing ellipsis and will show a tooltip when the component is focused. This is typically used for error or warning messages.The class immutable and its clone is therefore itself.
- Author:
- Christopher Mindus
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GBadge.Color
Specifies the color of the badge.static class
GBadge.Location
The location of the badge relative the component.
Field Summary
Fields Modifier and Type Field Description GBadge.Color
color
The color.static int
DEFAULT_FONT_SIZE
The default font size (16 px).int
fontSize
The font size in pixels (6-255), zero for default 16.GBadge.Location
location
The location.KString
text
The KString holding the text.
Constructor Summary
Constructors Constructor Description GBadge(KString text)
Creates a new red badge with default font size (16 pixels).GBadge(KString text, GBadge badge)
Creates a new badge with a text and the settings from an old badge.GBadge(KString text, GBadge.Color color)
Creates a new badge with default font size.GBadge(KString text, GBadge.Color color, GBadge.Location location)
Creates a new badge with default font size (16 pixels).GBadge(KString text, GBadge.Color color, GBadge.Location location, int fontSize)
Creates a new badge.GBadge(KString text, GBadge.Location location)
Creates a new red badge with default font size (16 pixels).GBadge(java.lang.String text)
Creates a new red badge with default font size (16 pixels).
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GBadge
clone()
Clones the badge.void
dispose()
Disposes of the badge when no longer needed.boolean
equals(java.lang.Object o)
Checks if two badge objects are equal.boolean
equalsOmitReferenceRefreshCheck(GBadge badge)
Checks for pure equality between two GBadge's, excluding reference refresh counter checking but including potential original source string.protected void
finalize()
Called when the badge is being garbage collected.int
hashCode()
Hash code.java.lang.String
toString()
Returns a string representation of this class instance and its values.
Field Detail
DEFAULT_FONT_SIZE
public static final int DEFAULT_FONT_SIZE
The default font size (16 px).- See Also:
- Constant Field Values
text
public final KString text
The KString holding the text.
color
public final GBadge.Color color
The color.
location
public final GBadge.Location location
The location.
fontSize
public final int fontSize
The font size in pixels (6-255), zero for default 16.
Constructor Detail
GBadge
public GBadge(java.lang.String text)
Creates a new red badge with default font size (16 pixels). The location is top-trailing.- Parameters:
text
- The plain text string, i.e. not in HTML.- Throws:
java.lang.NullPointerException
- If text is null.
GBadge
public GBadge(KString text)
Creates a new red badge with default font size (16 pixels). The location is top-trailing.- Parameters:
text
- The text.- Throws:
java.lang.NullPointerException
- If text is null.
GBadge
public GBadge(KString text, GBadge.Color color)
Creates a new badge with default font size. The location is top-trailing.- Parameters:
text
- The text.color
- The color, null for default red.- Throws:
java.lang.NullPointerException
- If text is null.
GBadge
public GBadge(KString text, GBadge.Location location)
Creates a new red badge with default font size (16 pixels).- Parameters:
text
- The text.location
- The location, null for default top-trailing.- Throws:
java.lang.NullPointerException
- If text is null.
GBadge
public GBadge(KString text, GBadge.Color color, GBadge.Location location)
Creates a new badge with default font size (16 pixels).- Parameters:
text
- The text.color
- The color, null for default red.location
- The location, null for default top-trailing.- Throws:
java.lang.NullPointerException
- If text is null.
GBadge
public GBadge(KString text, GBadge badge)
Creates a new badge with a text and the settings from an old badge.- Parameters:
text
- The text.badge
- The badge to use all settings from, exception the text.- Throws:
java.lang.NullPointerException
- If text is null.
GBadge
public GBadge(KString text, GBadge.Color color, GBadge.Location location, int fontSize)
Creates a new badge.- Parameters:
text
- The text.color
- The color, null for default red.location
- The location, null for default top-trailing.fontSize
- The font size between 6 to 255 pixels, 0 for default (16).- Throws:
java.lang.NullPointerException
- If text is null.java.lang.IllegalArgumentException
- If fontSize is not 6 to 255 pixels.
Method Detail
clone
public GBadge clone()
Clones the badge.- Overrides:
clone
in classjava.lang.Object
- Returns:
- A cloned badge instance.
dispose
public void dispose()
Disposes of the badge when no longer needed. This method is required for KString text.
finalize
protected void finalize() throws java.lang.Throwable
Called when the badge is being garbage collected.The KString will be disposed if not previously disposed of.
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
equals
public boolean equals(java.lang.Object o)
Checks if two badge objects are equal.- Overrides:
equals
in classjava.lang.Object
hashCode
public int hashCode()
Hash code.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- Returns the hash code.
equalsOmitReferenceRefreshCheck
public boolean equalsOmitReferenceRefreshCheck(GBadge badge)
Checks for pure equality between two GBadge's, excluding reference refresh counter checking but including potential original source string.This method is used when comparing values for e.g. save file.
- Parameters:
badge
- Another GBadge, perhaps null.- Returns:
- true if equal, false otherwise.
toString
public java.lang.String toString()
Returns a string representation of this class instance and its values.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of this class instance.