Interface StyleSource
-
- All Known Implementing Classes:
MemoryStyleSource
,NopStyleSource
public interface StyleSource
Interface for sources of style configuration.A StyleSource provides access to style definitions organized by groups and names. It allows retrieving, setting, and removing style definitions, as well as listing available style groups and styles.
Style definitions are stored as strings in the format understood by
StyleResolver
, such as "bold,fg:red" or "underline,fg:blue".Implementations of this interface include:
MemoryStyleSource
- Stores styles in memoryNopStyleSource
- Always returns null (no styles)
Example usage:
StyleSource source = new MemoryStyleSource(); source.set("mygroup", "error", "bold,fg:red"); source.set("mygroup", "warning", "bold,fg:yellow"); String errorStyle = source.get("mygroup", "error"); // Returns "bold,fg:red"
- Since:
- 3.4
- See Also:
Styler
,StyleResolver
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
clear()
Clears all style definitions from this source.java.lang.String
get(java.lang.String group, java.lang.String name)
Returns the style definition for the given style group and name, ornull
if not found.java.lang.Iterable<java.lang.String>
groups()
Returns the names of all configured style groups.void
remove(java.lang.String group)
Removes all styles for the given style group.void
remove(java.lang.String group, java.lang.String name)
Removes a specific style from a style group.void
set(java.lang.String group, java.lang.String name, java.lang.String style)
Sets a style definition for the given style group and name.java.util.Map<java.lang.String,java.lang.String>
styles(java.lang.String group)
Returns all configured styles for the given style group.
-
-
-
Method Detail
-
get
@Nullable java.lang.String get(java.lang.String group, java.lang.String name)
Returns the style definition for the given style group and name, ornull
if not found.This method retrieves a style definition from the source. Style definitions are strings in the format understood by
StyleResolver
, such as "bold,fg:red" or "underline,fg:blue".Style groups are used to organize styles by category or purpose, such as "error", "warning", or "info" styles within a "messages" group.
- Parameters:
group
- the style group name (must not be null)name
- the style name within the group (must not be null)- Returns:
- the style definition string, or
null
if no style is defined for the given group and name - Throws:
java.lang.NullPointerException
- if group or name is null
-
set
void set(java.lang.String group, java.lang.String name, java.lang.String style)
Sets a style definition for the given style group and name.This method stores a style definition in the source. Style definitions are strings in the format understood by
StyleResolver
, such as "bold,fg:red" or "underline,fg:blue".If a style with the same group and name already exists, it will be replaced.
Example:
source.set("messages", "error", "bold,fg:red"); source.set("messages", "warning", "bold,fg:yellow"); source.set("links", "url", "fg:blue,underline");
- Parameters:
group
- the style group name (must not be null)name
- the style name within the group (must not be null)style
- the style definition string (must not be null)- Throws:
java.lang.NullPointerException
- if any parameter is null
-
remove
void remove(java.lang.String group)
Removes all styles for the given style group.This method removes all style definitions associated with the specified group. If the group does not exist or has no styles, this method has no effect.
- Parameters:
group
- the style group name to remove (must not be null)- Throws:
java.lang.NullPointerException
- if group is null
-
remove
void remove(java.lang.String group, java.lang.String name)
Removes a specific style from a style group.This method removes the style definition for the specified group and name. If the style does not exist, this method has no effect.
- Parameters:
group
- the style group name (must not be null)name
- the style name to remove (must not be null)- Throws:
java.lang.NullPointerException
- if group or name is null
-
clear
void clear()
Clears all style definitions from this source.This method removes all style groups and their associated styles from the source. After calling this method, the source will be empty.
-
groups
java.lang.Iterable<java.lang.String> groups()
Returns the names of all configured style groups.This method returns an iterable of all style group names that have been configured in this source. If no groups have been configured, an empty iterable is returned.
- Returns:
- an immutable iterable of style group names (never null)
-
styles
java.util.Map<java.lang.String,java.lang.String> styles(java.lang.String group)
Returns all configured styles for the given style group.This method returns a map of style names to style definitions for the specified group. If the group does not exist or has no styles, an empty map is returned.
- Parameters:
group
- the style group name (must not be null)- Returns:
- an immutable map of style names to style definitions (never null)
- Throws:
java.lang.NullPointerException
- if group is null
-
-