Skip to content

Commit f92c6d8

Browse files
Enhance Font Awesome icon support by adding additional icons and improving documentation for icon resolution strategies
1 parent 38dd5c9 commit f92c6d8

File tree

2 files changed

+570
-1
lines changed

2 files changed

+570
-1
lines changed

platform/ui/zk/src/main/java/tools/dynamia/zk/ui/FontAwesomeIconsProvider.java

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,48 @@
2727
import java.io.IOException;
2828
import java.util.Properties;
2929

30+
/**
31+
* IconsProvider implementation for Font Awesome icon library.
32+
* This provider loads and manages Font Awesome icons, supporting both predefined mappings
33+
* from a properties file and dynamic icon name resolution.
34+
*
35+
* <p>The provider supports multiple icon resolution strategies:</p>
36+
* <ul>
37+
* <li>Loading predefined icon mappings from {@code /META-INF/dynamia/fa-icons.properties}</li>
38+
* <li>Dynamically resolving icons with "fa-" prefix (e.g., "fa-save" → "fa fa-save")</li>
39+
* <li>Direct Font Awesome class names (e.g., "fa fa-user", "fab fa-github")</li>
40+
* </ul>
41+
*
42+
* <p>Example usage:</p>
43+
* <pre>{@code
44+
* Icon saveIcon = provider.getIcon("save"); // From properties file
45+
* Icon customIcon = provider.getIcon("fa-user"); // Dynamic resolution
46+
* Icon brandIcon = provider.getIcon("fab fa-github"); // Direct class name
47+
* }</pre>
48+
*
49+
* @see AbstractFontIconsProvider
50+
* @see FAIcon
51+
*/
3052
public class FontAwesomeIconsProvider extends AbstractFontIconsProvider {
3153

54+
/**
55+
* Logger for reporting icon loading errors and warnings.
56+
*/
3257
private static final LoggingService logger = new SLF4JLoggingService(FontAwesomeIconsProvider.class);
3358

34-
59+
/**
60+
* Provides the mapping between logical icon names and Font Awesome class names.
61+
* Loads the icon mappings from a properties file located at {@code /META-INF/dynamia/fa-icons.properties}.
62+
*
63+
* <p>The properties file format:</p>
64+
* <pre>
65+
* save=floppy-disk
66+
* edit=pen-to-square
67+
* delete=trash-can
68+
* </pre>
69+
*
70+
* @return Properties object containing icon name mappings, or empty Properties if loading fails
71+
*/
3572
@Override
3673
public Properties getNamesMapping() {
3774
Properties properties = new Properties();
@@ -44,10 +81,36 @@ public Properties getNamesMapping() {
4481
return properties;
4582
}
4683

84+
/**
85+
* Returns the classpath location of the Font Awesome icons properties file.
86+
* Subclasses can override this method to provide a different properties file location.
87+
*
88+
* @return the classpath path to the icons properties file
89+
*/
4790
protected String getIconsPath() {
4891
return "/META-INF/dynamia/fa-icons.properties";
4992
}
5093

94+
/**
95+
* Retrieves a Font Awesome icon by its name with support for multiple resolution strategies.
96+
*
97+
* <p>Resolution order:</p>
98+
* <ol>
99+
* <li>Checks the predefined mappings from properties file</li>
100+
* <li>If not found and name starts with "fa-", creates icon dynamically</li>
101+
* <li>If name starts with "fa " or "fab ", uses it as direct Font Awesome class</li>
102+
* </ol>
103+
*
104+
* <p>Examples:</p>
105+
* <pre>{@code
106+
* getIcon("save"); // From properties: fa fa-floppy-disk
107+
* getIcon("fa-user"); // Dynamic: fa fa-user
108+
* getIcon("fab fa-github"); // Direct: fab fa-github
109+
* }</pre>
110+
*
111+
* @param name the icon name or Font Awesome class
112+
* @return the Icon object, or null if not resolvable
113+
*/
51114
@Override
52115
public Icon getIcon(String name) {
53116
Icon icon = super.getIcon(name);
@@ -66,10 +129,24 @@ public Icon getIcon(String name) {
66129
return icon;
67130
}
68131

132+
/**
133+
* Returns the prefix used for Font Awesome icon names.
134+
* This prefix is used in dynamic icon resolution and icon class generation.
135+
*
136+
* @return the icon prefix, default is "fa-"
137+
*/
69138
protected String getIconsPrefix() {
70139
return "fa-";
71140
}
72141

142+
/**
143+
* Creates a new FAIcon instance with proper Font Awesome class formatting.
144+
* Constructs the full Font Awesome CSS class by combining "fa " prefix with the icon name.
145+
*
146+
* @param name the logical name of the icon
147+
* @param internalName the Font Awesome specific icon name (without "fa-" prefix)
148+
* @return a new FAIcon instance configured with Font Awesome classes
149+
*/
73150
@Override
74151
protected Icon newIcon(String name, String internalName) {
75152
return new FAIcon(name, "fa " + getIconsPrefix() + internalName);

0 commit comments

Comments
 (0)