|
7 | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | 8 | * you may not use this file except in compliance with the License. |
9 | 9 | * You may obtain a copy of the License at |
10 | | - * |
| 10 | + * |
11 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | - * |
| 12 | + * |
13 | 13 | * Unless required by applicable law or agreed to in writing, software |
14 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
37 | 37 | @JsModule("@xpertsea/paper-slider/l2t-paper-slider.js") |
38 | 38 | public class Carousel extends Component implements HasSize { |
39 | 39 |
|
40 | | - private static final int DEFAULT_SLIDE_DURATION = 2; |
41 | | - |
42 | | - private Slide[] slides; |
43 | | - private boolean autoProgress; |
44 | | - private int slideDuration = DEFAULT_SLIDE_DURATION; |
45 | | - private int startPosition; |
46 | | - private boolean disableSwipe; |
47 | | - private boolean hideNavigation; |
48 | | - |
49 | | - public Carousel(Slide... paperSlides) { |
50 | | - this.setSlides(paperSlides); |
51 | | - updateSlides(paperSlides); |
52 | | - } |
53 | | - |
54 | | - private void updateSlides(Slide... paperSlides) { |
55 | | - for (Slide slide : paperSlides) { |
56 | | - this.getElement().appendChild(slide.getElement()); |
57 | | - } |
58 | | - updateProperties(); |
59 | | - } |
60 | | - |
61 | | - private void updateProperties() { |
62 | | - if (autoProgress) |
63 | | - this.getElement().setAttribute("auto-progress", "true"); |
64 | | - if (disableSwipe) |
65 | | - this.getElement().setAttribute("disable-swipe", "true"); |
66 | | - if (hideNavigation) |
67 | | - this.getElement().setAttribute("hide-nav", "true"); |
68 | | - this.getElement().setAttribute("slide-duration", "" + this.slideDuration); |
69 | | - this.getElement().setAttribute("position", "" + this.startPosition); |
70 | | - } |
71 | | - |
72 | | - // PROPERTIES |
73 | | - public Slide[] getSlides() { |
74 | | - return slides; |
75 | | - } |
76 | | - |
77 | | - public void setSlides(Slide[] slides) { |
78 | | - this.slides = slides; |
79 | | - updateSlides(slides); |
80 | | - } |
81 | | - |
82 | | - public boolean isAutoProgress() { |
83 | | - return autoProgress; |
84 | | - } |
85 | | - |
86 | | - public void setAutoProgress(boolean autoProgress) { |
87 | | - this.autoProgress = autoProgress; |
88 | | - } |
89 | | - |
90 | | - public int getSlideDuration() { |
91 | | - return slideDuration; |
92 | | - } |
93 | | - |
94 | | - public void setSlideDuration(int slideDuration) { |
95 | | - this.slideDuration = slideDuration; |
96 | | - } |
97 | | - |
98 | | - public int getStartPosition() { |
99 | | - return startPosition; |
100 | | - } |
101 | | - |
102 | | - public void setStartPosition(int startPosition) { |
103 | | - this.startPosition = startPosition; |
104 | | - } |
105 | | - |
106 | | - public boolean isDisableSwipe() { |
107 | | - return disableSwipe; |
108 | | - } |
109 | | - |
110 | | - public void setDisableSwipe(boolean disableSwipe) { |
111 | | - this.disableSwipe = disableSwipe; |
112 | | - } |
113 | | - |
114 | | - public boolean isHideNavigation() { |
115 | | - return hideNavigation; |
116 | | - } |
117 | | - |
118 | | - public void setHideNavigation(boolean hideNavigation) { |
119 | | - this.hideNavigation = hideNavigation; |
120 | | - } |
121 | | - |
122 | | - // FLUENT API |
123 | | - public Carousel withAutoProgress() { |
124 | | - this.autoProgress = true; |
125 | | - updateProperties(); |
126 | | - return this; |
127 | | - } |
128 | | - |
129 | | - public Carousel withoutSwipe() { |
130 | | - this.disableSwipe = true; |
131 | | - updateProperties(); |
132 | | - return this; |
133 | | - } |
134 | | - |
135 | | - public Carousel withoutNavigation() { |
136 | | - this.hideNavigation = true; |
137 | | - updateProperties(); |
138 | | - return this; |
139 | | - } |
140 | | - |
141 | | - public Carousel withSlideDuration(int slideDuration) { |
142 | | - this.slideDuration = slideDuration; |
143 | | - updateProperties(); |
144 | | - return this; |
145 | | - } |
146 | | - |
147 | | - public Carousel withStartPosition(int startPosition) { |
148 | | - this.startPosition = startPosition; |
149 | | - updateProperties(); |
150 | | - return this; |
151 | | - } |
152 | | - |
153 | | - |
154 | | - // SIZING |
155 | | - @Override |
156 | | - public void setHeight(String height) { |
157 | | - getElement().getStyle().set("--paper-slide-height", height); |
158 | | - } |
159 | | - |
160 | | - @Override |
161 | | - public String getHeight() { |
162 | | - return getElement().getStyle().get("--paper-slide-height"); |
163 | | - } |
164 | | - |
165 | | - // METHODS |
166 | | - /** |
167 | | - * Move to the next slide |
168 | | - */ |
169 | | - public void moveNext() { |
170 | | - this.getElement().callJsFunction("moveNext"); |
171 | | - } |
172 | | - |
173 | | - /** |
174 | | - * Move to the previous slide |
175 | | - */ |
176 | | - public void movePrev() { |
177 | | - this.getElement().callJsFunction("movePrev"); |
178 | | - } |
179 | | - |
180 | | - /** |
181 | | - * Move to a specific slide |
182 | | - * @param slide |
183 | | - */ |
184 | | - public void movePos(int slide) { |
185 | | - this.getElement().callJsFunction("movePos", ""+slide); |
186 | | - } |
187 | | - |
188 | | - // EVENTS |
189 | | - @DomEvent("position-changed") |
190 | | - public static class SlideChangeEvent extends ComponentEvent<Carousel> { |
191 | | - public SlideChangeEvent(Carousel source, boolean fromClient) { |
192 | | - super(source, true); |
193 | | - } |
194 | | - } |
195 | | - |
196 | | - public Registration addChangeListener(ComponentEventListener<SlideChangeEvent> listener) { |
197 | | - return addListener(SlideChangeEvent.class, listener); |
198 | | - } |
199 | | - |
200 | | - |
201 | | - |
| 40 | + private static final int DEFAULT_SLIDE_DURATION = 2; |
| 41 | + |
| 42 | + private Slide[] slides; |
| 43 | + private boolean autoProgress; |
| 44 | + private int slideDuration = DEFAULT_SLIDE_DURATION; |
| 45 | + private int startPosition; |
| 46 | + private boolean disableSwipe; |
| 47 | + private boolean hideNavigation; |
| 48 | + |
| 49 | + public Carousel(Slide... paperSlides) { |
| 50 | + this.setSlides(paperSlides); |
| 51 | + updateSlides(paperSlides); |
| 52 | + } |
| 53 | + |
| 54 | + private void updateSlides(Slide... paperSlides) { |
| 55 | + for (Slide slide : paperSlides) { |
| 56 | + this.getElement().appendChild(slide.getElement()); |
| 57 | + } |
| 58 | + updateProperties(); |
| 59 | + } |
| 60 | + |
| 61 | + private void updateProperties() { |
| 62 | + if (autoProgress) this.getElement().setAttribute("auto-progress", "true"); |
| 63 | + if (disableSwipe) this.getElement().setAttribute("disable-swipe", "true"); |
| 64 | + if (hideNavigation) this.getElement().setAttribute("hide-nav", "true"); |
| 65 | + this.getElement().setAttribute("slide-duration", "" + this.slideDuration); |
| 66 | + this.getElement().setAttribute("position", "" + this.startPosition); |
| 67 | + } |
| 68 | + |
| 69 | + // PROPERTIES |
| 70 | + public Slide[] getSlides() { |
| 71 | + return slides; |
| 72 | + } |
| 73 | + |
| 74 | + public void setSlides(Slide[] slides) { |
| 75 | + this.slides = slides; |
| 76 | + updateSlides(slides); |
| 77 | + } |
| 78 | + |
| 79 | + public boolean isAutoProgress() { |
| 80 | + return autoProgress; |
| 81 | + } |
| 82 | + |
| 83 | + public void setAutoProgress(boolean autoProgress) { |
| 84 | + this.autoProgress = autoProgress; |
| 85 | + } |
| 86 | + |
| 87 | + public int getSlideDuration() { |
| 88 | + return slideDuration; |
| 89 | + } |
| 90 | + |
| 91 | + public void setSlideDuration(int slideDuration) { |
| 92 | + this.slideDuration = slideDuration; |
| 93 | + } |
| 94 | + |
| 95 | + public int getStartPosition() { |
| 96 | + return startPosition; |
| 97 | + } |
| 98 | + |
| 99 | + public void setStartPosition(int startPosition) { |
| 100 | + this.startPosition = startPosition; |
| 101 | + } |
| 102 | + |
| 103 | + public boolean isDisableSwipe() { |
| 104 | + return disableSwipe; |
| 105 | + } |
| 106 | + |
| 107 | + public void setDisableSwipe(boolean disableSwipe) { |
| 108 | + this.disableSwipe = disableSwipe; |
| 109 | + } |
| 110 | + |
| 111 | + public boolean isHideNavigation() { |
| 112 | + return hideNavigation; |
| 113 | + } |
| 114 | + |
| 115 | + public void setHideNavigation(boolean hideNavigation) { |
| 116 | + this.hideNavigation = hideNavigation; |
| 117 | + } |
| 118 | + |
| 119 | + // FLUENT API |
| 120 | + public Carousel withAutoProgress() { |
| 121 | + this.autoProgress = true; |
| 122 | + updateProperties(); |
| 123 | + return this; |
| 124 | + } |
| 125 | + |
| 126 | + public Carousel withoutSwipe() { |
| 127 | + this.disableSwipe = true; |
| 128 | + updateProperties(); |
| 129 | + return this; |
| 130 | + } |
| 131 | + |
| 132 | + public Carousel withoutNavigation() { |
| 133 | + this.hideNavigation = true; |
| 134 | + updateProperties(); |
| 135 | + return this; |
| 136 | + } |
| 137 | + |
| 138 | + public Carousel withSlideDuration(int slideDuration) { |
| 139 | + this.slideDuration = slideDuration; |
| 140 | + updateProperties(); |
| 141 | + return this; |
| 142 | + } |
| 143 | + |
| 144 | + public Carousel withStartPosition(int startPosition) { |
| 145 | + this.startPosition = startPosition; |
| 146 | + updateProperties(); |
| 147 | + return this; |
| 148 | + } |
| 149 | + |
| 150 | + // SIZING |
| 151 | + @Override |
| 152 | + public void setHeight(String height) { |
| 153 | + getElement().getStyle().set("--paper-slide-height", height); |
| 154 | + } |
| 155 | + |
| 156 | + @Override |
| 157 | + public String getHeight() { |
| 158 | + return getElement().getStyle().get("--paper-slide-height"); |
| 159 | + } |
| 160 | + |
| 161 | + // METHODS |
| 162 | + /** Move to the next slide */ |
| 163 | + public void moveNext() { |
| 164 | + this.getElement().callJsFunction("moveNext"); |
| 165 | + } |
| 166 | + |
| 167 | + /** Move to the previous slide */ |
| 168 | + public void movePrev() { |
| 169 | + this.getElement().callJsFunction("movePrev"); |
| 170 | + } |
| 171 | + |
| 172 | + /** |
| 173 | + * Move to a specific slide |
| 174 | + * |
| 175 | + * @param slide |
| 176 | + */ |
| 177 | + public void movePos(int slide) { |
| 178 | + this.getElement().callJsFunction("movePos", "" + slide); |
| 179 | + } |
| 180 | + |
| 181 | + // EVENTS |
| 182 | + @DomEvent("position-changed") |
| 183 | + public static class SlideChangeEvent extends ComponentEvent<Carousel> { |
| 184 | + public SlideChangeEvent(Carousel source, boolean fromClient) { |
| 185 | + super(source, true); |
| 186 | + } |
| 187 | + } |
| 188 | + |
| 189 | + public Registration addChangeListener(ComponentEventListener<SlideChangeEvent> listener) { |
| 190 | + return addListener(SlideChangeEvent.class, listener); |
| 191 | + } |
202 | 192 | } |
0 commit comments