@@ -35,6 +35,16 @@ private WidgetStyle() {
35
35
// prevent instantiation of utility class
36
36
}
37
37
38
+ /**
39
+ * Check whether a given widget style contains the target style.
40
+ *
41
+ * @param widgetStyle
42
+ * The style declaration to test, usually a comma-separated
43
+ * {@code String}; trailing spaces are ignored.
44
+ * @param target
45
+ * The style being checked, case-insensitive.
46
+ * @return {@code true} if the target style matches.
47
+ */
38
48
public static boolean isStyle (String widgetStyle , String target ) {
39
49
if (widgetStyle == null || target == null )
40
50
return widgetStyle == target ;
@@ -44,20 +54,62 @@ public static boolean isStyle(String widgetStyle, String target) {
44
54
return false ;
45
55
}
46
56
57
+ /**
58
+ * Check whether a given {@link ModuleItem} has the target style.
59
+ *
60
+ * @param item
61
+ * The module item to test.
62
+ * @param target
63
+ * The style being checked, case-insensitive.
64
+ * @return {@code true} if the module item has the target style.
65
+ */
47
66
public static boolean isStyle (ModuleItem <?> item , String target ) {
48
67
return isStyle (item .getWidgetStyle (), target );
49
68
}
50
69
51
- public static String [] getStyleModifiers (String widgetStyle , String target ) {
70
+ /**
71
+ * Get the modifying value for a given style attribute in a style declaration.
72
+ *
73
+ * <p>
74
+ * For example, for {@code style="format:#0.00"}, this will return
75
+ * {@code "#0.00"}.
76
+ * </p>
77
+ *
78
+ * @param widgetStyle
79
+ * The style declaration string, e.g. <code>"format:#0.00"</code>.
80
+ * @param target
81
+ * The target style attribute, e.g. <code>"format"</code>.
82
+ * @return The modifier for the given target, e.g. <code>"#0.00"</code>.
83
+ */
84
+ public static String getStyleModifier (String widgetStyle , String target ) {
52
85
if (widgetStyle == null || target == null )
53
86
return null ;
54
87
String [] styles = widgetStyle .split ("," );
55
88
for (String s : styles ) {
56
89
if (s .trim ().toLowerCase ().startsWith (target .toLowerCase ())) {
57
- String suffix = s .split (":" )[1 ];
58
- return suffix .split ("/" );
90
+ return s .split (":" )[1 ];
59
91
}
60
92
}
61
93
return null ;
62
94
}
95
+
96
+ /**
97
+ * Get an array of all modifying values for a given style attribute.
98
+ *
99
+ * <p>
100
+ * For example, for {@code style="extensions:png/gif/bmp"}, this will return {@code ["png", "gif", "bmp"]}.
101
+ * </p>
102
+ *
103
+ * @param widgetStyle
104
+ * The style declaration string, e.g. <code>"extensions:png/gif/bmp"</code>.
105
+ * @param target
106
+ * The target style attribute, e.g. <code>"extensions"</code>.
107
+ * @return An array of modifiers for the given target, e.g. <code>["png", "gif", "bmp"]</code>.
108
+ */
109
+ public static String [] getStyleModifiers (String widgetStyle , String target ) {
110
+ String suffix = getStyleModifier (widgetStyle , target );
111
+ if (suffix == null ) return null ;
112
+ return suffix .split ("/" );
113
+ }
114
+
63
115
}
0 commit comments