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.imagezoom;
23  
24  import javax.faces.application.ResourceDependency;
25  import javax.faces.component.UIComponentBase;
26  
27  import org.primefaces.component.api.Widget;
28  
29  /**
30   * Component class for the <code>ImageZoom</code> component.
31   *
32   * @author Melloware
33   * @since 11.0.3
34   */
35  @ResourceDependency(library = "primefaces", name = "jquery/jquery.js")
36  @ResourceDependency(library = "primefaces", name = "jquery/jquery-plugins.js")
37  @ResourceDependency(library = "primefaces", name = "core.js")
38  @ResourceDependency(library = "primefaces-extensions", name = "primefaces-extensions.js")
39  @ResourceDependency(library = "primefaces-extensions", name = "imagezoom/imagezoom.js")
40  @ResourceDependency(library = "primefaces-extensions", name = "imagezoom/imagezoom.css")
41  public class ImageZoom extends UIComponentBase implements Widget {
42  
43      public static final String COMPONENT_TYPE = "org.primefaces.extensions.component.ImageZoom";
44      public static final String COMPONENT_FAMILY = "org.primefaces.extensions.component";
45      private static final String DEFAULT_RENDERER = "org.primefaces.extensions.component.ImageZoomRenderer";
46  
47      @SuppressWarnings("java:S115")
48      protected enum PropertyKeys {
49  
50          // @formatter:off
51          widgetVar,
52          margin,
53          background,
54          scrollOffset,
55          container,
56          template,
57          forValue("for");
58          // @formatter:on
59  
60          private final String toString;
61  
62          PropertyKeys(final String toString) {
63              this.toString = toString;
64          }
65  
66          PropertyKeys() {
67              toString = null;
68          }
69  
70          @Override
71          public String toString() {
72              return ((toString != null) ? toString : super.toString());
73          }
74      }
75  
76      /**
77       * Default constructor
78       */
79      public ImageZoom() {
80          setRendererType(DEFAULT_RENDERER);
81      }
82  
83      /**
84       * {@inheritDoc}
85       */
86      @Override
87      public String getFamily() {
88          return COMPONENT_FAMILY;
89      }
90  
91      public String getWidgetVar() {
92          return (String) getStateHelper().eval(PropertyKeys.widgetVar, null);
93      }
94  
95      public void setWidgetVar(final String _widgetVar) {
96          getStateHelper().put(PropertyKeys.widgetVar, _widgetVar);
97      }
98  
99      public String getFor() {
100         return (String) getStateHelper().eval(PropertyKeys.forValue, null);
101     }
102 
103     public void setFor(final String _for) {
104         getStateHelper().put(PropertyKeys.forValue, _for);
105     }
106 
107     public Integer getMargin() {
108         return (Integer) getStateHelper().eval(PropertyKeys.margin, 0);
109     }
110 
111     public void setMargin(final Integer _margin) {
112         getStateHelper().put(PropertyKeys.margin, _margin);
113     }
114 
115     public Integer getScrollOffset() {
116         return (Integer) getStateHelper().eval(PropertyKeys.scrollOffset, 40);
117     }
118 
119     public void setScrollOffset(final Integer _scrollOffset) {
120         getStateHelper().put(PropertyKeys.scrollOffset, _scrollOffset);
121     }
122 
123     public String getBackground() {
124         return (String) getStateHelper().eval(PropertyKeys.background, "#fff");
125     }
126 
127     public void setBackground(final String _background) {
128         getStateHelper().put(PropertyKeys.background, _background);
129     }
130 
131     public String getContainer() {
132         return (String) getStateHelper().eval(PropertyKeys.container, null);
133     }
134 
135     public void setContainer(final String _container) {
136         getStateHelper().put(PropertyKeys.container, _container);
137     }
138 
139     public String getTemplate() {
140         return (String) getStateHelper().eval(PropertyKeys.template, null);
141     }
142 
143     public void setTemplate(final String _template) {
144         getStateHelper().put(PropertyKeys.template, _template);
145     }
146 }