|
19 | 19 | */ |
20 | 20 | package com.flowingcode.vaadin.addons.demo; |
21 | 21 |
|
22 | | -import java.util.HashMap; |
23 | | -import java.util.Map; |
24 | | - |
25 | 22 | import com.vaadin.flow.component.Component; |
26 | 23 | import com.vaadin.flow.component.checkbox.Checkbox; |
27 | 24 | import com.vaadin.flow.component.dependency.StyleSheet; |
|
30 | 27 | import com.vaadin.flow.component.splitlayout.SplitLayout.Orientation; |
31 | 28 | import com.vaadin.flow.component.tabs.Tab; |
32 | 29 | import com.vaadin.flow.component.tabs.Tabs; |
| 30 | +import java.util.HashMap; |
| 31 | +import java.util.Map; |
33 | 32 |
|
34 | 33 | @StyleSheet("context://frontend/styles/commons-demo/shared-styles.css") |
35 | 34 | @SuppressWarnings("serial") |
36 | 35 | public class TabbedDemo extends VerticalLayout { |
37 | 36 |
|
38 | | - private Tabs tabs; |
39 | | - private HorizontalLayout footer; |
40 | | - private SplitLayoutDemo currentLayout; |
41 | | - private Map<Tab, Component> demos; |
42 | | - private Checkbox orientationCB; |
43 | | - private Checkbox codeCB; |
| 37 | + private Tabs tabs; |
| 38 | + private HorizontalLayout footer; |
| 39 | + private SplitLayoutDemo currentLayout; |
| 40 | + private Map<Tab, Component> demos; |
| 41 | + private Checkbox orientationCB; |
| 42 | + private Checkbox codeCB; |
44 | 43 |
|
45 | | - public TabbedDemo() { |
46 | | - tabs = new Tabs(); |
47 | | - demos = new HashMap<>(); |
48 | | - tabs.setWidthFull(); |
| 44 | + public TabbedDemo() { |
| 45 | + tabs = new Tabs(); |
| 46 | + demos = new HashMap<>(); |
| 47 | + tabs.setWidthFull(); |
49 | 48 |
|
50 | | - // Footer |
51 | | - orientationCB = new Checkbox("Toggle Orientation"); |
52 | | - orientationCB.setValue(true); |
53 | | - orientationCB.addClassName("smallcheckbox"); |
54 | | - orientationCB.addValueChangeListener(cb -> { |
55 | | - updateSplitterOrientation(); |
56 | | - }); |
57 | | - codeCB = new Checkbox("Show Source Code"); |
58 | | - codeCB.setValue(true); |
59 | | - codeCB.addClassName("smallcheckbox"); |
60 | | - codeCB.addValueChangeListener(cb -> { |
61 | | - updateSplitterPosition(); |
62 | | - }); |
63 | | - footer = new HorizontalLayout(); |
64 | | - footer.setWidthFull(); |
65 | | - footer.setJustifyContentMode(JustifyContentMode.END); |
66 | | - footer.add(codeCB, orientationCB); |
| 49 | + // Footer |
| 50 | + orientationCB = new Checkbox("Toggle Orientation"); |
| 51 | + orientationCB.setValue(true); |
| 52 | + orientationCB.addClassName("smallcheckbox"); |
| 53 | + orientationCB.addValueChangeListener( |
| 54 | + cb -> { |
| 55 | + updateSplitterOrientation(); |
| 56 | + }); |
| 57 | + codeCB = new Checkbox("Show Source Code"); |
| 58 | + codeCB.setValue(true); |
| 59 | + codeCB.addClassName("smallcheckbox"); |
| 60 | + codeCB.addValueChangeListener( |
| 61 | + cb -> { |
| 62 | + updateSplitterPosition(); |
| 63 | + }); |
| 64 | + footer = new HorizontalLayout(); |
| 65 | + footer.setWidthFull(); |
| 66 | + footer.setJustifyContentMode(JustifyContentMode.END); |
| 67 | + footer.add(codeCB, orientationCB); |
67 | 68 |
|
68 | | - tabs.addSelectedChangeListener(e -> { |
69 | | - removeAll(); |
70 | | - Component currentDemo = demos.get(tabs.getSelectedTab()); |
71 | | - this.add(tabs, currentDemo); |
72 | | - if (currentDemo instanceof SplitLayoutDemo) { |
73 | | - currentLayout = (SplitLayoutDemo) currentDemo; |
74 | | - this.add(footer); |
75 | | - updateSplitterPosition(); |
76 | | - updateSplitterOrientation(); |
77 | | - } else { |
78 | | - currentLayout = null; |
79 | | - } |
80 | | - }); |
| 69 | + tabs.addSelectedChangeListener( |
| 70 | + e -> { |
| 71 | + removeAll(); |
| 72 | + Component currentDemo = demos.get(tabs.getSelectedTab()); |
| 73 | + this.add(tabs, currentDemo); |
| 74 | + if (currentDemo instanceof SplitLayoutDemo) { |
| 75 | + currentLayout = (SplitLayoutDemo) currentDemo; |
| 76 | + this.add(footer); |
| 77 | + updateSplitterPosition(); |
| 78 | + updateSplitterOrientation(); |
| 79 | + } else { |
| 80 | + currentLayout = null; |
| 81 | + } |
| 82 | + }); |
81 | 83 |
|
82 | | - setSizeFull(); |
83 | | - } |
| 84 | + setSizeFull(); |
| 85 | + } |
84 | 86 |
|
85 | | - /** |
86 | | - * |
87 | | - * @param demo the demo instance |
88 | | - * @param name the demo name (tab label) |
89 | | - * @param sourceCodeUrl the url of the demo, <b>null</b> to not show source code |
90 | | - * section. |
91 | | - */ |
92 | | - public void addDemo(Component demo, String label, String sourceCodeUrl) { |
93 | | - Tab tab = new Tab(label); |
94 | | - if (sourceCodeUrl != null) { |
95 | | - demos.put(tab, new SplitLayoutDemo(demo, sourceCodeUrl)); |
96 | | - } else { |
97 | | - demos.put(tab, demo); |
98 | | - } |
99 | | - tabs.add(tab); |
100 | | - } |
| 87 | + /** |
| 88 | + * @param demo the demo instance |
| 89 | + * @param name the demo name (tab label) |
| 90 | + * @param sourceCodeUrl the url of the demo, <b>null</b> to not show source code section. |
| 91 | + */ |
| 92 | + public void addDemo(Component demo, String label, String sourceCodeUrl) { |
| 93 | + Tab tab = new Tab(label); |
| 94 | + if (sourceCodeUrl != null) { |
| 95 | + demos.put(tab, new SplitLayoutDemo(demo, sourceCodeUrl)); |
| 96 | + } else { |
| 97 | + demos.put(tab, demo); |
| 98 | + } |
| 99 | + tabs.add(tab); |
| 100 | + } |
101 | 101 |
|
102 | | - public void addDemo(Component demo, String label) { |
103 | | - addDemo(demo, label, null); |
104 | | - } |
| 102 | + public void addDemo(Component demo, String label) { |
| 103 | + addDemo(demo, label, null); |
| 104 | + } |
105 | 105 |
|
106 | | - private void updateSplitterPosition() { |
107 | | - boolean b = codeCB.getValue(); |
108 | | - if (b) { |
109 | | - currentLayout.setSplitterPosition(50); |
110 | | - orientationCB.setEnabled(true); |
111 | | - } else { |
112 | | - currentLayout.setSplitterPosition(100); |
113 | | - orientationCB.setEnabled(false); |
114 | | - } |
115 | | - } |
| 106 | + private void updateSplitterPosition() { |
| 107 | + boolean b = codeCB.getValue(); |
| 108 | + if (b) { |
| 109 | + currentLayout.setSplitterPosition(50); |
| 110 | + orientationCB.setEnabled(true); |
| 111 | + } else { |
| 112 | + currentLayout.setSplitterPosition(100); |
| 113 | + orientationCB.setEnabled(false); |
| 114 | + } |
| 115 | + } |
116 | 116 |
|
117 | | - private void updateSplitterOrientation() { |
118 | | - boolean b = orientationCB.getValue(); |
119 | | - if (b) { |
120 | | - currentLayout.setOrientation(Orientation.HORIZONTAL); |
121 | | - } else { |
122 | | - currentLayout.setOrientation(Orientation.VERTICAL); |
123 | | - } |
124 | | - } |
| 117 | + private void updateSplitterOrientation() { |
| 118 | + boolean b = orientationCB.getValue(); |
| 119 | + if (b) { |
| 120 | + currentLayout.setOrientation(Orientation.HORIZONTAL); |
| 121 | + } else { |
| 122 | + currentLayout.setOrientation(Orientation.VERTICAL); |
| 123 | + } |
| 124 | + } |
125 | 125 | } |
0 commit comments