Skip to content

Commit 7e7406c

Browse files
ngonzalezpazFCjavier-godoy
authored andcommitted
feat(demo): integrate commons-demo
1 parent cdd753f commit 7e7406c

File tree

8 files changed

+301
-68
lines changed

8 files changed

+301
-68
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*-
2+
* #%L
3+
* Carousel Addon
4+
* %%
5+
* Copyright (C) 2018 - 2019 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons;
21+
22+
import com.vaadin.flow.component.html.Div;
23+
import com.vaadin.flow.router.RouterLayout;
24+
25+
@SuppressWarnings("serial")
26+
public class DemoLayout extends Div implements RouterLayout {
27+
28+
public DemoLayout() {
29+
setSizeFull();
30+
}
31+
32+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*-
2+
* #%L
3+
* Carousel Addon
4+
* %%
5+
* Copyright (C) 2018 - 2019 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.carousel;
21+
22+
import com.vaadin.flow.component.Component;
23+
import com.vaadin.flow.component.html.H1;
24+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
25+
26+
@SuppressWarnings("serial")
27+
public class AutoProgressDemo extends VerticalLayout {
28+
29+
public AutoProgressDemo() {
30+
Slide s1 = new Slide(createSlideContent("Slide 1", "green"));
31+
Slide s2 = new Slide(createSlideContent("Slide 2", "blue"));
32+
Slide s3 = new Slide(createSlideContent("Slide 3", "red"));
33+
Slide s4 = new Slide(createSlideContent("Slide 4", "yellow"));
34+
35+
Carousel c = new Carousel(s1, s2, s3, s4).withAutoProgress().withSlideDuration(2).withStartPosition(1)
36+
.withoutSwipe();
37+
c.setWidth("100%");
38+
c.setHeight("180px");
39+
40+
add(c);
41+
}
42+
43+
private Component createSlideContent(String string, String color) {
44+
H1 label = new H1(string);
45+
label.getStyle().set("margin-top", "auto");
46+
label.getStyle().set("margin-bottom", "auto");
47+
VerticalLayout d = new VerticalLayout(label);
48+
d.setAlignItems(Alignment.CENTER);
49+
d.setSizeFull();
50+
d.getStyle().set("background-color", color);
51+
return d;
52+
}
53+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*-
2+
* #%L
3+
* Carousel Addon
4+
* %%
5+
* Copyright (C) 2018 - 2019 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.carousel;
21+
22+
import com.flowingcode.vaadin.addons.DemoLayout;
23+
import com.flowingcode.vaadin.addons.demo.impl.TabbedDemoImpl;
24+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
25+
import com.vaadin.flow.router.Route;
26+
27+
@SuppressWarnings("serial")
28+
@Route(value = "carousel", layout = DemoLayout.class)
29+
public class CarouselDemoView extends VerticalLayout {
30+
31+
private static final String LISTENER_DEMO = "Slide Listener";
32+
private static final String AUTOPROGRESS_DEMO = "Auto Progress";
33+
private static final String BUTTONS_DEMO = "Slide Buttons";
34+
private static final String LISTENER_SOURCE = "https://github.com/FlowingCode/CarouselAddon/blob/master/src/test/java/com/flowingcode/vaadin/addons/carousel/ListenerDemo.java";
35+
private static final String AUTPROGRESS_SOURCE = "https://github.com/FlowingCode/CarouselAddon/blob/master/src/test/java/com/flowingcode/vaadin/addons/carousel/AutoProgressDemo.java";
36+
private static final String BUTTONS_SOURCE = "https://github.com/FlowingCode/CarouselAddon/blob/master/src/test/java/com/flowingcode/vaadin/addons/carousel/SlideButtonsDemo.java";
37+
38+
public CarouselDemoView() {
39+
TabbedDemoImpl<ListenerDemo> carouselDemo = new TabbedDemoImpl<>(new ListenerDemo(), LISTENER_DEMO,
40+
LISTENER_SOURCE);
41+
carouselDemo.addDemo(new AutoProgressDemo(), AUTOPROGRESS_DEMO, AUTPROGRESS_SOURCE);
42+
carouselDemo.addDemo(new SlideButtonsDemo(), BUTTONS_DEMO, BUTTONS_SOURCE);
43+
add(carouselDemo);
44+
setSizeFull();
45+
}
46+
}

src/test/java/com/flowingcode/vaadin/addons/carousel/DemoView.java

Lines changed: 6 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -19,79 +19,17 @@
1919
*/
2020
package com.flowingcode.vaadin.addons.carousel;
2121

22-
import com.vaadin.flow.component.Component;
23-
import com.vaadin.flow.component.button.Button;
24-
import com.vaadin.flow.component.html.H1;
25-
import com.vaadin.flow.component.notification.Notification;
26-
import com.vaadin.flow.component.notification.Notification.Position;
27-
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
2822
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
23+
import com.vaadin.flow.router.BeforeEnterEvent;
24+
import com.vaadin.flow.router.BeforeEnterObserver;
2925
import com.vaadin.flow.router.Route;
3026

3127
@SuppressWarnings("serial")
3228
@Route("")
33-
public class DemoView extends VerticalLayout {
29+
public class DemoView extends VerticalLayout implements BeforeEnterObserver {
3430

35-
public DemoView() {
36-
37-
Slide s1 = new Slide(createSlideContent("Slide 1","green"));
38-
Slide s2 = new Slide(createSlideContent("Slide 2","blue"));
39-
Slide s3 = new Slide(createSlideContent("Slide 3","red"));
40-
Slide s4 = new Slide(createSlideContent("Slide 4","yellow"));
41-
42-
Carousel c = new Carousel(s1,s2,s3,s4);
43-
c.setWidth("100%");
44-
c.setHeight("180px");
45-
c.addChangeListener(e->Notification.show("changed!",1000,Position.BOTTOM_END));
46-
47-
add(c);
48-
49-
s1 = new Slide(createSlideContent("Slide 1","green"));
50-
s2 = new Slide(createSlideContent("Slide 2","blue"));
51-
s3 = new Slide(createSlideContent("Slide 3","red"));
52-
s4 = new Slide(createSlideContent("Slide 4","yellow"));
53-
54-
c = new Carousel(s1,s2,s3,s4)
55-
.withAutoProgress()
56-
.withSlideDuration(4)
57-
.withStartPosition(1);
58-
c.setWidth("100%");
59-
c.setHeight("180px");
60-
61-
add(c);
62-
63-
s1 = new Slide(createSlideContent("Slide 1","green"));
64-
s2 = new Slide(createSlideContent("Slide 2","blue"));
65-
s3 = new Slide(createSlideContent("Slide 3","red"));
66-
s4 = new Slide(createSlideContent("Slide 4","yellow"));
67-
68-
final Carousel cf = new Carousel(s1,s2,s3,s4)
69-
.withoutNavigation();
70-
cf.setWidth("100%");
71-
cf.setHeight("180px");
72-
Button next = new Button(">>");
73-
next.addClickListener(e->cf.moveNext());
74-
Button prev = new Button("<<");
75-
prev.addClickListener(e->cf.movePrev());
76-
Button last = new Button(">|");
77-
last.addClickListener(e->cf.movePos(3));
78-
Button first = new Button("|<");
79-
first.addClickListener(e->cf.movePos(0));
80-
cf.addChangeListener(e->Notification.show("changed!",1000,Position.BOTTOM_END));
81-
82-
83-
add(cf,new HorizontalLayout(first, prev, next, last));
84-
85-
}
86-
87-
private Component createSlideContent(String string, String color) {
88-
H1 label = new H1(string);
89-
label.getStyle().set("margin-top", "auto");
90-
label.getStyle().set("margin-bottom", "auto");
91-
VerticalLayout d = new VerticalLayout(label);
92-
d.setAlignItems(Alignment.CENTER);
93-
d.setSizeFull();
94-
d.getStyle().set("background-color", color);
95-
return d;
31+
@Override
32+
public void beforeEnter(BeforeEnterEvent event) {
33+
event.forwardTo(CarouselDemoView.class);
9634
}
9735
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*-
2+
* #%L
3+
* Carousel Addon
4+
* %%
5+
* Copyright (C) 2018 - 2019 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.carousel;
21+
22+
import com.vaadin.flow.component.Component;
23+
import com.vaadin.flow.component.html.H1;
24+
import com.vaadin.flow.component.notification.Notification;
25+
import com.vaadin.flow.component.notification.Notification.Position;
26+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
27+
28+
@SuppressWarnings("serial")
29+
public class ListenerDemo extends VerticalLayout {
30+
31+
public ListenerDemo() {
32+
Slide s1 = new Slide(createSlideContent("Slide 1", "green"));
33+
Slide s2 = new Slide(createSlideContent("Slide 2", "blue"));
34+
Slide s3 = new Slide(createSlideContent("Slide 3", "red"));
35+
Slide s4 = new Slide(createSlideContent("Slide 4", "yellow"));
36+
37+
Carousel c = new Carousel(s1, s2, s3, s4);
38+
c.setWidth("100%");
39+
c.setHeight("180px");
40+
c.addChangeListener(e -> Notification.show("Slide Changed!", 1000, Position.BOTTOM_START));
41+
42+
add(c);
43+
}
44+
45+
private Component createSlideContent(String string, String color) {
46+
H1 label = new H1(string);
47+
label.getStyle().set("margin-top", "auto");
48+
label.getStyle().set("margin-bottom", "auto");
49+
VerticalLayout d = new VerticalLayout(label);
50+
d.setAlignItems(Alignment.CENTER);
51+
d.setSizeFull();
52+
d.getStyle().set("background-color", color);
53+
return d;
54+
}
55+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*-
2+
* #%L
3+
* Carousel Addon
4+
* %%
5+
* Copyright (C) 2018 - 2019 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.carousel;
21+
22+
import com.vaadin.flow.component.Component;
23+
import com.vaadin.flow.component.button.Button;
24+
import com.vaadin.flow.component.html.H1;
25+
import com.vaadin.flow.component.notification.Notification;
26+
import com.vaadin.flow.component.notification.Notification.Position;
27+
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
28+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
29+
30+
@SuppressWarnings("serial")
31+
public class SlideButtonsDemo extends VerticalLayout {
32+
33+
public SlideButtonsDemo() {
34+
Slide s1 = new Slide(createSlideContent("Slide 1", "green"));
35+
Slide s2 = new Slide(createSlideContent("Slide 2", "blue"));
36+
Slide s3 = new Slide(createSlideContent("Slide 3", "red"));
37+
Slide s4 = new Slide(createSlideContent("Slide 4", "yellow"));
38+
39+
final Carousel cf = new Carousel(s1, s2, s3, s4).withoutNavigation();
40+
cf.setWidth("100%");
41+
cf.setHeight("180px");
42+
Button next = new Button(">>");
43+
Button prev = new Button("<<");
44+
Button last = new Button(">|");
45+
Button first = new Button("|<");
46+
next.addClickListener(e -> cf.moveNext());
47+
prev.addClickListener(e -> cf.movePrev());
48+
last.addClickListener(e -> cf.movePos(3));
49+
first.addClickListener(e -> cf.movePos(0));
50+
51+
cf.addChangeListener(e -> Notification.show("Slide Changed!", 1000, Position.BOTTOM_START));
52+
HorizontalLayout btns = new HorizontalLayout(first, prev, next, last);
53+
btns.setAlignItems(Alignment.CENTER);
54+
btns.setJustifyContentMode(JustifyContentMode.CENTER);
55+
btns.setWidthFull();
56+
add(cf, btns);
57+
}
58+
59+
private Component createSlideContent(String string, String color) {
60+
H1 label = new H1(string);
61+
label.getStyle().set("margin-top", "auto");
62+
label.getStyle().set("margin-bottom", "auto");
63+
VerticalLayout d = new VerticalLayout(label);
64+
d.setAlignItems(Alignment.CENTER);
65+
d.setSizeFull();
66+
d.getStyle().set("background-color", color);
67+
return d;
68+
}
69+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*-
2+
* #%L
3+
* Carousel Addon
4+
* %%
5+
* Copyright (C) 2018 - 2019 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.carousel.test;
21+
22+
import static org.junit.Assert.assertEquals;
23+
import static org.junit.Assert.assertNotEquals;
24+
25+
import org.junit.Test;
26+
27+
import com.flowingcode.vaadin.addons.DemoLayout;
28+
import com.flowingcode.vaadin.addons.carousel.CarouselDemoView;
29+
import com.vaadin.flow.router.Route;
30+
31+
public class LayoutTest {
32+
33+
@Test
34+
public void testDemoLayout() {
35+
Route route = CarouselDemoView.class.getAnnotation(Route.class);
36+
assertEquals("com.flowingcode.vaadin.addons.DemoLayout",DemoLayout.class.getName());
37+
assertEquals(DemoLayout.class, route.layout());
38+
assertNotEquals("", route.value());
39+
}
40+
}
File renamed without changes.

0 commit comments

Comments
 (0)