View Javadoc
1   /*
2    * Copyright (c) 2011-2024 PrimeFaces Extensions
3    *
4    *  Permission is hereby granted, free of charge, to any person obtaining a copy
5    *  of this software and associated documentation files (the "Software"), to deal
6    *  in the Software without restriction, including without limitation the rights
7    *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    *  copies of the Software, and to permit persons to whom the Software is
9    *  furnished to do so, subject to the following conditions:
10   *
11   *  The above copyright notice and this permission notice shall be included in
12   *  all copies or substantial portions of the Software.
13   *
14   *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20   *  THE SOFTWARE.
21   */
22  package org.primefaces.extensions.component.counter;
23  
24  import javax.faces.component.UIComponentBase;
25  import javax.faces.component.behavior.ClientBehaviorHolder;
26  
27  import org.primefaces.component.api.PrimeClientBehaviorHolder;
28  import org.primefaces.component.api.Widget;
29  
30  /**
31   * <code>Counter</code> component.
32   *
33   * @author https://github.com/aripddev
34   * @since 8.0.1
35   */
36  public abstract class CounterBase extends UIComponentBase implements Widget, ClientBehaviorHolder, PrimeClientBehaviorHolder {
37  
38      public static final String COMPONENT_FAMILY = "org.primefaces.extensions.component";
39  
40      public static final String DEFAULT_RENDERER = "org.primefaces.extensions.component.CounterRenderer";
41  
42      @SuppressWarnings("java:S115")
43      protected enum PropertyKeys {
44          //@formatter:off
45          widgetVar,
46          style,
47          styleClass,
48          start,
49          end,
50          decimals,
51          duration,
52          useGrouping,
53          useEasing,
54          smartEasingThreshold,
55          smartEasingAmount,
56          locale,
57          separator,
58          decimal,
59          prefix,
60          suffix,
61          autoStart,
62          visible,
63          onstart,
64          onend
65          //@formatter:off
66      }
67  
68      public CounterBase() {
69          super.setRendererType(DEFAULT_RENDERER);
70      }
71  
72      @Override
73      public String getFamily() {
74          return COMPONENT_FAMILY;
75      }
76  
77      public String getWidgetVar() {
78          return (String) getStateHelper().eval(PropertyKeys.widgetVar, null);
79      }
80  
81      public void setWidgetVar(final String widgetVar) {
82          getStateHelper().put(PropertyKeys.widgetVar, widgetVar);
83      }
84  
85      public String getStyle() {
86          return (String) getStateHelper().eval(PropertyKeys.style, null);
87      }
88  
89      public void setStyle(final String style) {
90          getStateHelper().put(PropertyKeys.style, style);
91      }
92  
93      public String getStyleClass() {
94          return (String) getStateHelper().eval(PropertyKeys.styleClass, null);
95      }
96  
97      public void setStyleClass(final String styleClass) {
98          getStateHelper().put(PropertyKeys.styleClass, styleClass);
99      }
100 
101     public Double getStart() {
102         return (Double) getStateHelper().eval(PropertyKeys.start, 0.0);
103     }
104 
105     public void setStart(final Double start) {
106         getStateHelper().put(PropertyKeys.start, start);
107     }
108 
109     public Double getEnd() {
110         return (Double) getStateHelper().eval(PropertyKeys.end, null);
111     }
112 
113     public void setEnd(final Double end) {
114         getStateHelper().put(PropertyKeys.end, end);
115     }
116 
117     public Integer getDecimals() {
118         return (Integer) getStateHelper().eval(PropertyKeys.decimals, 0);
119     }
120 
121     public void setDecimals(final Integer decimals) {
122         getStateHelper().put(PropertyKeys.decimals, decimals);
123     }
124 
125     public Integer getDuration() {
126         return (Integer) getStateHelper().eval(PropertyKeys.duration, 2);
127     }
128 
129     public void setDuration(final Integer duration) {
130         getStateHelper().put(PropertyKeys.duration, duration);
131     }
132 
133     public Boolean isUseGrouping() {
134         return (Boolean) getStateHelper().eval(PropertyKeys.useGrouping, true);
135     }
136 
137     public void setUseGrouping(final Boolean useGrouping) {
138         getStateHelper().put(PropertyKeys.useGrouping, useGrouping);
139     }
140 
141     public Boolean isUseEasing() {
142         return (Boolean) getStateHelper().eval(PropertyKeys.useEasing, true);
143     }
144 
145     public void setUseEasing(final Boolean useEasing) {
146         getStateHelper().put(PropertyKeys.useEasing, useEasing);
147     }
148 
149     public Integer getSmartEasingThreshold() {
150         return (Integer) getStateHelper().eval(PropertyKeys.smartEasingThreshold, 999);
151     }
152 
153     public void setSmartEasingThreshold(final Integer smartEasingThreshold) {
154         getStateHelper().put(PropertyKeys.smartEasingThreshold, smartEasingThreshold);
155     }
156 
157     public Integer getSmartEasingAmount() {
158         return (Integer) getStateHelper().eval(PropertyKeys.smartEasingAmount, 333);
159     }
160 
161     public void setSmartEasingAmount(final Integer smartEasingAmount) {
162         getStateHelper().put(PropertyKeys.smartEasingAmount, smartEasingAmount);
163     }
164 
165     public Object getLocale() {
166         return getStateHelper().eval(PropertyKeys.locale, null);
167     }
168 
169     public void setLocale(final Object locale) {
170         getStateHelper().put(PropertyKeys.locale, locale);
171     }
172 
173     public String getSeparator() {
174         return (String) getStateHelper().eval(PropertyKeys.separator, null);
175     }
176 
177     public void setSeparator(final String separator) {
178         getStateHelper().put(PropertyKeys.separator, separator);
179     }
180 
181     public String getDecimal() {
182         return (String) getStateHelper().eval(PropertyKeys.decimal, null);
183     }
184 
185     public void setDecimal(final String decimal) {
186         getStateHelper().put(PropertyKeys.decimal, decimal);
187     }
188 
189     public String getPrefix() {
190         return (String) getStateHelper().eval(PropertyKeys.prefix, "");
191     }
192 
193     public void setPrefix(final String prefix) {
194         getStateHelper().put(PropertyKeys.prefix, prefix);
195     }
196 
197     public String getSuffix() {
198         return (String) getStateHelper().eval(PropertyKeys.suffix, "");
199     }
200 
201     public void setSuffix(final String suffix) {
202         getStateHelper().put(PropertyKeys.suffix, suffix);
203     }
204 
205     public Boolean isAutoStart() {
206         return (Boolean) getStateHelper().eval(PropertyKeys.autoStart, true);
207     }
208 
209     public void setAutoStart(final Boolean autoStart) {
210         getStateHelper().put(PropertyKeys.autoStart, autoStart);
211     }
212 
213     public boolean isVisible() {
214         return (Boolean) getStateHelper().eval(PropertyKeys.visible, true);
215     }
216 
217     public void setVisible(final boolean visible) {
218         getStateHelper().put(PropertyKeys.visible, visible);
219     }
220 
221     public String getOnend() {
222         return (String) getStateHelper().eval(PropertyKeys.onend, null);
223     }
224 
225     public void setOnend(final String onend) {
226         getStateHelper().put(PropertyKeys.onend, onend);
227     }
228 
229     public String getOnstart() {
230         return (String) getStateHelper().eval(PropertyKeys.onstart, null);
231     }
232 
233     public void setOnstart(final String onstart) {
234         getStateHelper().put(PropertyKeys.onstart, onstart);
235     }
236 
237 }