2727import java .util .Properties ;
2828
2929/**
30- * IconsProvider for Fonts Icons
30+ * Abstract base class for IconsProvider implementations that serve font-based icons.
31+ * This class provides common functionality for loading and managing icon sets from font libraries
32+ * such as FontAwesome, Material Icons, or other web font icon systems.
3133 *
32- * @author Mario
34+ * <p>Font icons are lightweight, scalable, and customizable through CSS. This provider manages
35+ * the mapping between logical icon names and their internal font class names or Unicode values.</p>
36+ *
37+ * <p>Subclasses must implement {@link #getNamesMapping()} to provide a Properties object
38+ * that maps logical icon names to their internal font-specific identifiers.</p>
39+ *
40+ * <p>The initialization process:</p>
41+ * <ul>
42+ * <li>Loads icon name mappings from the Properties returned by getNamesMapping()</li>
43+ * <li>Creates Icon objects with IconType.FONT for each mapping</li>
44+ * <li>Stores icons in an internal cache for quick retrieval</li>
45+ * <li>Logs the installation progress for debugging</li>
46+ * </ul>
47+ *
48+ * <p>Example implementation:</p>
49+ * <pre>{@code
50+ * @Component
51+ * public class FontAwesomeProvider extends AbstractFontIconsProvider {
52+ *
53+ * @Override
54+ * public Properties getNamesMapping() {
55+ * Properties props = new Properties();
56+ * props.setProperty("save", "fa-save");
57+ * props.setProperty("edit", "fa-edit");
58+ * props.setProperty("delete", "fa-trash");
59+ * return props;
60+ * }
61+ * }
62+ * }</pre>
63+ *
64+ * @author Mario A. Serrano Leones
65+ * @see IconsProvider
66+ * @see Icon
67+ * @see IconType
3368 */
3469public abstract class AbstractFontIconsProvider implements IconsProvider {
3570
71+ /**
72+ * Internal cache storing all loaded icons by their logical name.
73+ */
3674 private final Map <String , Icon > icons = new HashMap <>();
75+
76+ /**
77+ * Logging service for reporting icon loading progress and issues.
78+ */
3779 private final LoggingService logger = new SLF4JLoggingService (getClass ());
3880
81+ /**
82+ * Constructs a new AbstractFontIconsProvider and automatically initializes
83+ * the icon mappings by calling {@link #init()}.
84+ */
3985 public AbstractFontIconsProvider () {
4086 init ();
4187 }
4288
89+ /**
90+ * Initializes the icon provider by loading all icon mappings.
91+ * This method retrieves the Properties from {@link #getNamesMapping()},
92+ * iterates through all entries, and creates Icon objects for each mapping.
93+ *
94+ * <p>The initialization process:</p>
95+ * <ul>
96+ * <li>Obtains the Properties object from the subclass</li>
97+ * <li>Logs the number of icons being installed</li>
98+ * <li>Iterates through each property entry</li>
99+ * <li>Creates a new Icon with IconType.FONT for each mapping</li>
100+ * <li>Stores the icon in the internal cache</li>
101+ * <li>Logs successful completion</li>
102+ * </ul>
103+ */
43104 private void init () {
44105 Properties names = getNamesMapping ();
45106 if (names != null ) {
@@ -56,10 +117,26 @@ private void init() {
56117 }
57118 }
58119
120+ /**
121+ * Factory method for creating Icon instances.
122+ * Subclasses can override this method to customize how Icon objects are created,
123+ * for example to add additional metadata or use custom Icon subclasses.
124+ *
125+ * @param name the logical name of the icon (e.g., "save", "edit")
126+ * @param internalName the internal font-specific identifier (e.g., "fa-save", "md-edit")
127+ * @return a new Icon instance configured for font-based rendering
128+ */
59129 protected Icon newIcon (String name , String internalName ) {
60130 return new Icon (name , internalName , IconType .FONT );
61131 }
62132
133+ /**
134+ * Retrieves a font icon by its logical name.
135+ * If the icons cache is empty, triggers initialization automatically.
136+ *
137+ * @param name the logical name of the icon to retrieve
138+ * @return the Icon object if found, or null if not available in this provider
139+ */
63140 @ Override
64141 public Icon getIcon (String name ) {
65142 if (icons .isEmpty ()) {
@@ -69,13 +146,50 @@ public Icon getIcon(String name) {
69146 return icons .get (name );
70147 }
71148
149+ /**
150+ * Provides the mapping between logical icon names and font-specific identifiers.
151+ * Subclasses must implement this method to supply their icon set configuration.
152+ *
153+ * <p>The Properties object should contain entries where:</p>
154+ * <ul>
155+ * <li>Key: logical icon name used throughout the application (e.g., "save", "edit")</li>
156+ * <li>Value: font-specific CSS class or identifier (e.g., "fa-save", "md-edit")</li>
157+ * </ul>
158+ *
159+ * <p>Example:</p>
160+ * <pre>{@code
161+ * Properties props = new Properties();
162+ * props.setProperty("save", "fa-floppy-disk");
163+ * props.setProperty("edit", "fa-pen-to-square");
164+ * props.setProperty("delete", "fa-trash-can");
165+ * return props;
166+ * }</pre>
167+ *
168+ * @return a Properties object containing icon name mappings, or null if no icons are available
169+ */
72170 public abstract Properties getNamesMapping ();
73171
172+ /**
173+ * Returns all icons provided by this font icon provider.
174+ * The returned list is a copy of the internal cache values.
175+ *
176+ * @return a list containing all font icons managed by this provider
177+ */
74178 @ Override
75179 public List <Icon > getAll () {
76180 return new ArrayList <>(icons .values ());
77181 }
78182
183+ /**
184+ * Manually adds an icon to this provider's cache.
185+ * This method allows runtime addition of icons without requiring them to be
186+ * defined in the Properties returned by {@link #getNamesMapping()}.
187+ *
188+ * <p>Useful for dynamically registering icons or overriding existing ones.</p>
189+ *
190+ * @param name the logical name for the icon
191+ * @param icon the Icon object to register
192+ */
79193 public void addIcon (String name , Icon icon ) {
80194 icons .put (name , icon );
81195 }
0 commit comments