4444@ JsModule ("@xpertsea/paper-slider/l2t-paper-slider.js" )
4545public class Carousel extends Component implements HasSize {
4646
47+ private static final String HIDE_NAV = "hide-nav" ;
48+ private static final String DISABLE_SWIPE = "disable-swipe" ;
49+ private static final String POSITION = "position" ;
50+ private static final String SLIDE_DURATION = "slide-duration" ;
51+ private static final String AUTO_PROGRESS = "auto-progress" ;
4752 private static final int DEFAULT_SLIDE_DURATION = 2 ;
4853
4954 private Slide [] slides ;
50- private boolean autoProgress ;
51- private int slideDuration = DEFAULT_SLIDE_DURATION ;
52- private int startPosition ;
53- private boolean disableSwipe ;
54- private boolean hideNavigation ;
5555
5656 public Carousel (Slide ... paperSlides ) {
5757 this .setSlides (paperSlides );
5858 updateSlides (paperSlides );
59+ initProperties ();
5960 }
6061
6162 private void updateSlides (Slide ... paperSlides ) {
6263 for (Slide slide : paperSlides ) {
6364 this .getElement ().appendChild (slide .getElement ());
6465 }
65- updateProperties ();
6666 }
6767
68- private void updateProperties () {
69- if ( autoProgress ) this .getElement (). setAttribute ( "auto-progress" , "true" );
70- if ( disableSwipe ) this .getElement (). setAttribute ( "disable-swipe" , "true" );
71- if ( hideNavigation ) this .getElement (). setAttribute ( "hide-nav" , "true" );
72- this .getElement (). setAttribute ( "slide-duration" , "" + this . slideDuration );
73- this .getElement (). setAttribute ( "position" , "" + this . startPosition );
68+ private void initProperties () {
69+ this .setAutoProgress ( false );
70+ this .setSlideDuration ( DEFAULT_SLIDE_DURATION );
71+ this .setStartPosition ( 0 );
72+ this .setDisableSwipe ( false );
73+ this .setHideNavigation ( false );
7474 }
7575
7676 // PROPERTIES
@@ -84,73 +84,68 @@ public void setSlides(Slide[] slides) {
8484 }
8585
8686 public boolean isAutoProgress () {
87- return autoProgress ;
87+ return this . getElement (). getProperty ( AUTO_PROGRESS , false ) ;
8888 }
8989
9090 public void setAutoProgress (boolean autoProgress ) {
91- this .autoProgress = autoProgress ;
91+ this .getElement (). setAttribute ( AUTO_PROGRESS , autoProgress ) ;
9292 }
9393
9494 public int getSlideDuration () {
95- return slideDuration ;
95+ return this . getElement (). getProperty ( SLIDE_DURATION , 0 ) ;
9696 }
9797
9898 public void setSlideDuration (int slideDuration ) {
99- this .slideDuration = slideDuration ;
99+ this .getElement (). setProperty ( SLIDE_DURATION , slideDuration ) ;
100100 }
101101
102102 public int getStartPosition () {
103- return startPosition ;
103+ return this . getElement (). getProperty ( POSITION , 0 ) ;
104104 }
105105
106106 public void setStartPosition (int startPosition ) {
107- this .startPosition = startPosition ;
107+ this .getElement (). setAttribute ( POSITION , "" + startPosition ) ;
108108 }
109109
110110 public boolean isDisableSwipe () {
111- return disableSwipe ;
111+ return this . getElement (). getProperty ( DISABLE_SWIPE , false ) ;
112112 }
113113
114114 public void setDisableSwipe (boolean disableSwipe ) {
115- this .disableSwipe = disableSwipe ;
115+ this .getElement (). setAttribute ( DISABLE_SWIPE , disableSwipe ) ;
116116 }
117117
118118 public boolean isHideNavigation () {
119- return hideNavigation ;
119+ return this . getElement (). getProperty ( HIDE_NAV , false ) ;
120120 }
121121
122122 public void setHideNavigation (boolean hideNavigation ) {
123- this .hideNavigation = hideNavigation ;
123+ this .getElement (). setAttribute ( HIDE_NAV , hideNavigation ) ;
124124 }
125125
126126 // FLUENT API
127127 public Carousel withAutoProgress () {
128- this .autoProgress = true ;
129- updateProperties ();
128+ this .setAutoProgress (true );
130129 return this ;
131130 }
132131
133132 public Carousel withoutSwipe () {
134- this .disableSwipe = true ;
135- updateProperties ();
133+ this .setDisableSwipe (true );
136134 return this ;
137135 }
138136
139137 public Carousel withoutNavigation () {
140- this .hideNavigation = true ;
141- updateProperties ();
138+ this .setHideNavigation (false );
142139 return this ;
143140 }
144141
145142 public Carousel withSlideDuration (int slideDuration ) {
146- this .slideDuration = slideDuration ;
147- updateProperties ();
143+ this .setSlideDuration (slideDuration );
148144 return this ;
149145 }
150146
151147 public Carousel withStartPosition (int startPosition ) {
152- this .startPosition = startPosition ;
153- updateProperties ();
148+ this .setStartPosition (startPosition );
154149 return this ;
155150 }
156151
0 commit comments