| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | |||
| 6 | 6 | ||
| 7 | 7 | ## [Unreleased] | |
| 8 | 8 | ||
| 9 | + ### Added | ||
| 10 | + | ||
| 11 | + - Add `PredefinedIcon.predefinedIcon(String iconName)` | ||
| 12 | + | ||
| 9 | 13 | ## [0.4.2] - 2025-12-17 | |
| 10 | 14 | ||
| 11 | 15 | ### Added | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,6 +49,40 @@ public final class PredefinedIcon implements | |||
| 49 | 49 | SVGElementDataMethods<SVGElement, PredefinedIcon>, | |
| 50 | 50 | SVGElementStyleMethods<SVGElement, PredefinedIcon> { | |
| 51 | 51 | ||
| 52 | + // ------------------------------------------------------ factory | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * Constructs a predefined SVG icon based on the provided icon name. The method supports multiple icon groups, such as | ||
| 56 | + * "fab", "far", "fas", and "patternfly". If the name contains a group prefix (e.g., "fab.iconName"), the method will use | ||
| 57 | + * that group; otherwise, it defaults to the "fas" group. | ||
| 58 | + * <p> | ||
| 59 | + * Normally you should use the static methods from {@link IconSets} to get predefined icons. Only use this method if you | ||
| 60 | + * need to get an icon based on the icon name provided as string. | ||
| 61 | + * | ||
| 62 | + * @param name the name of the icon, optionally prefixed with the group name (e.g., "fab.iconName"). If no group is | ||
| 63 | + * specified, "fas" is used by default. | ||
| 64 | + * @return a {@code PredefinedIcon} instance representing the specified icon. | ||
| 65 | + * @throws IllegalArgumentException if the group or icon name is unknown. | ||
| 66 | + */ | ||
| 67 | + public static PredefinedIcon predefinedIcon(String name) { | ||
| 68 | + String group = "fas"; | ||
| 69 | + String iconName = name; | ||
| 70 | + if (name.contains(".")) { | ||
| 71 | + group = name.substring(0, name.indexOf('.')); | ||
| 72 | + iconName = name.substring(name.indexOf('.') + 1); | ||
| 73 | + } | ||
| 74 | + IconSpec iconSpec = switch (group) { | ||
| 75 | + case "fab" -> IconSpecs.fab.valueOf(iconName).iconSpec; | ||
| 76 | + case "far" -> IconSpecs.far.valueOf(iconName).iconSpec; | ||
| 77 | + case "fas" -> IconSpecs.fas.valueOf(iconName).iconSpec; | ||
| 78 | + case "patternfly" -> IconSpecs.patternfly.valueOf(iconName).iconSpec; | ||
| 79 | + default -> throw new IllegalArgumentException("Unknown icon group/name: '" + name + "'"); | ||
| 80 | + }; | ||
| 81 | + return new PredefinedIcon(iconSpec); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + // ------------------------------------------------------ instance | ||
| 85 | + | ||
| 52 | 86 | public final IconSpec iconSpec; | |
| 53 | 87 | private final SVGElement element; | |
| 54 | 88 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments