diff --git a/src/main/java/com/jarektoro/responsivelayout/ResponsiveColumn.java b/src/main/java/com/jarektoro/responsivelayout/ResponsiveColumn.java index b730c0c..abdb794 100644 --- a/src/main/java/com/jarektoro/responsivelayout/ResponsiveColumn.java +++ b/src/main/java/com/jarektoro/responsivelayout/ResponsiveColumn.java @@ -49,7 +49,6 @@ public enum ColumnComponentAlignment { private void convenienceInIt() { - //set primary style name to 'col' // important in the addRule method @@ -67,6 +66,7 @@ private void convenienceInIt() { public ResponsiveColumn() { + super(); convenienceInIt(); } diff --git a/src/main/java/com/jarektoro/responsivelayout/ResponsiveRow.java b/src/main/java/com/jarektoro/responsivelayout/ResponsiveRow.java index df45dc9..2b809e9 100644 --- a/src/main/java/com/jarektoro/responsivelayout/ResponsiveRow.java +++ b/src/main/java/com/jarektoro/responsivelayout/ResponsiveRow.java @@ -57,6 +57,7 @@ public enum SpacingSize { public ResponsiveRow() { + super(); setPrimaryStyleName(CSS_ROW); setWidthUndefined(); addStyleName(CSS_MARGIN); diff --git a/src/main/java/com/jarektoro/responsivelayout/Styleable/StyleableComponent.java b/src/main/java/com/jarektoro/responsivelayout/Styleable/StyleableComponent.java index 01aee39..92b1e00 100644 --- a/src/main/java/com/jarektoro/responsivelayout/Styleable/StyleableComponent.java +++ b/src/main/java/com/jarektoro/responsivelayout/Styleable/StyleableComponent.java @@ -9,84 +9,18 @@ */ public class StyleableComponent extends CustomComponent { - public StyleableComponent() { + private final VisibilityCSSAdapter visibilityCSSAdapter; + public StyleableComponent() { + visibilityCSSAdapter = new VisibilityCSSAdapter(this); } public boolean isVisibleForDisplaySize(ResponsiveLayout.DisplaySize displaySize) { - if (displaySize == ResponsiveLayout.DisplaySize.XS) { - for (String clazz : VisibilityCSSAdapter.xsClassGroup.classes) { - - String styles = getStyleName(); - if (styles.contains(clazz)) { - if (clazz.contains("hidden")) { - return false; - } else { - return true; - } - } - } - } else if (displaySize == ResponsiveLayout.DisplaySize.SM) { - for (String clazz : VisibilityCSSAdapter.smClassGroup.classes) { - if (getStyleName().contains(clazz)) { - if (clazz.contains("hidden")) { - return false; - } else { - return true; - } - } - } - } else if (displaySize == ResponsiveLayout.DisplaySize.MD) { - for (String clazz : VisibilityCSSAdapter.mdClassGroup.classes) { - if (getStyleName().contains(clazz)) { - if (clazz.contains("hidden")) { - return false; - } else { - return true; - } - } - } - } else if (displaySize == ResponsiveLayout.DisplaySize.LG) { - for (String clazz : VisibilityCSSAdapter.lgClassGroup.classes) { - if (getStyleName().contains(clazz)) { - if (clazz.contains("hidden")) { - return false; - } else { - return true; - } - } - } - } - return true; + return visibilityCSSAdapter.isVisibleForDisplaySize(displaySize); } public void setVisibility(ResponsiveLayout.DisplaySize displaySize, boolean isVisible) { - - if (displaySize == ResponsiveLayout.DisplaySize.XS) { - for (String clazz : VisibilityCSSAdapter.xsClassGroup.classes) { - removeStyleName(clazz); - } - } - if (displaySize == ResponsiveLayout.DisplaySize.SM) { - for (String clazz : VisibilityCSSAdapter.smClassGroup.classes) { - removeStyleName(clazz); - } - } - if (displaySize == ResponsiveLayout.DisplaySize.MD) { - for (String clazz : VisibilityCSSAdapter.mdClassGroup.classes) { - removeStyleName(clazz); - } - } - if (displaySize == ResponsiveLayout.DisplaySize.LG) { - for (String clazz : VisibilityCSSAdapter.lgClassGroup.classes) { - removeStyleName(clazz); - } - } - - - addStyleName(VisibilityCSSAdapter.getCssForDisplaySize(displaySize, isVisible)); - - + visibilityCSSAdapter.setVisibility(displaySize, isVisible); } } diff --git a/src/main/java/com/jarektoro/responsivelayout/Styleable/StyleableLayout.java b/src/main/java/com/jarektoro/responsivelayout/Styleable/StyleableLayout.java index c869e69..26a0274 100644 --- a/src/main/java/com/jarektoro/responsivelayout/Styleable/StyleableLayout.java +++ b/src/main/java/com/jarektoro/responsivelayout/Styleable/StyleableLayout.java @@ -8,83 +8,18 @@ */ public class StyleableLayout extends CssLayout { + private final VisibilityCSSAdapter visibilityCSSAdapter; public StyleableLayout() { - + visibilityCSSAdapter = new VisibilityCSSAdapter(this); } public boolean isVisibleForDisplaySize(ResponsiveLayout.DisplaySize displaySize) { - if (displaySize == ResponsiveLayout.DisplaySize.XS) { - for (String clazz : VisibilityCSSAdapter.xsClassGroup.classes) { - if (getStyleName().contains(clazz)){ - if (clazz.contains("hidden")){ - return false; - }else{ - return true; - } - } - } - } else if (displaySize == ResponsiveLayout.DisplaySize.SM) { - for (String clazz : VisibilityCSSAdapter.smClassGroup.classes) { - if (getStyleName().contains(clazz)){ - if (clazz.contains("hidden")){ - return false; - }else{ - return true; - } - } - } - } else if (displaySize == ResponsiveLayout.DisplaySize.MD) { - for (String clazz : VisibilityCSSAdapter.mdClassGroup.classes) { - if (getStyleName().contains(clazz)){ - if (clazz.contains("hidden")){ - return false; - }else{ - return true; - } - } - } - } else if (displaySize == ResponsiveLayout.DisplaySize.LG) { - for (String clazz : VisibilityCSSAdapter.lgClassGroup.classes) { - if (getStyleName().contains(clazz)){ - if (clazz.contains("hidden")){ - return false; - }else{ - return true; - } - } - } - } - return true; + return visibilityCSSAdapter.isVisibleForDisplaySize(displaySize); } public void setVisibility(ResponsiveLayout.DisplaySize displaySize, boolean isVisible) { - - if (displaySize == ResponsiveLayout.DisplaySize.XS) { - for (String clazz : VisibilityCSSAdapter.xsClassGroup.classes) { - removeStyleName(clazz); - } - } - if (displaySize == ResponsiveLayout.DisplaySize.SM) { - for (String clazz : VisibilityCSSAdapter.smClassGroup.classes) { - removeStyleName(clazz); - } - } - if (displaySize == ResponsiveLayout.DisplaySize.MD) { - for (String clazz : VisibilityCSSAdapter.mdClassGroup.classes) { - removeStyleName(clazz); - } - } - if (displaySize == ResponsiveLayout.DisplaySize.LG) { - for (String clazz : VisibilityCSSAdapter.lgClassGroup.classes) { - removeStyleName(clazz); - } - } - - - addStyleName(VisibilityCSSAdapter.getCssForDisplaySize(displaySize, isVisible)); - - + visibilityCSSAdapter.setVisibility(displaySize, isVisible); } } diff --git a/src/main/java/com/jarektoro/responsivelayout/Styleable/VisibilityCSSAdapter.java b/src/main/java/com/jarektoro/responsivelayout/Styleable/VisibilityCSSAdapter.java index 9b33f1d..e19d1d8 100644 --- a/src/main/java/com/jarektoro/responsivelayout/Styleable/VisibilityCSSAdapter.java +++ b/src/main/java/com/jarektoro/responsivelayout/Styleable/VisibilityCSSAdapter.java @@ -1,7 +1,7 @@ package com.jarektoro.responsivelayout.Styleable; import com.jarektoro.responsivelayout.ResponsiveLayout; -import com.jarektoro.responsivelayout.Styleable.CSSClassGroup; +import com.vaadin.ui.Component; /** * Created by jarektoro on 11/22/16. @@ -26,10 +26,14 @@ public class VisibilityCSSAdapter { public static CSSClassGroup mdClassGroup = new CSSClassGroup(CSS_VISIBLE_MD, CSS_HIDDEN_MD); public static CSSClassGroup lgClassGroup = new CSSClassGroup(CSS_VISIBLE_LG, CSS_HIDDEN_LG); - public ResponsiveLayout.DisplaySize displaySize; - public boolean isVisible = false; + public final Component component; - public static String getCssForDisplaySize(ResponsiveLayout.DisplaySize displaySize, boolean isVisible) { + public VisibilityCSSAdapter(Component component) { + this.component = component; + } + + + public String getCssForDisplaySize(ResponsiveLayout.DisplaySize displaySize, boolean isVisible) { if (isVisible) { switch (displaySize) { case XS: @@ -59,4 +63,82 @@ public static String getCssForDisplaySize(ResponsiveLayout.DisplaySize displaySi } } } + + +// Manipulate user of adapter + + public boolean isVisibleForDisplaySize(ResponsiveLayout.DisplaySize displaySize) { + if (displaySize == ResponsiveLayout.DisplaySize.XS) { + for (String clazz : VisibilityCSSAdapter.xsClassGroup.classes) { + if (this.component.getStyleName().contains(clazz)) { + if (clazz.contains("hidden")) { + return false; + } else { + return true; + } + } + } + } else if (displaySize == ResponsiveLayout.DisplaySize.SM) { + for (String clazz : VisibilityCSSAdapter.smClassGroup.classes) { + if (this.component.getStyleName().contains(clazz)) { + if (clazz.contains("hidden")) { + return false; + } else { + return true; + } + } + } + } else if (displaySize == ResponsiveLayout.DisplaySize.MD) { + for (String clazz : VisibilityCSSAdapter.mdClassGroup.classes) { + if (this.component.getStyleName().contains(clazz)) { + if (clazz.contains("hidden")) { + return false; + } else { + return true; + } + } + } + } else if (displaySize == ResponsiveLayout.DisplaySize.LG) { + for (String clazz : VisibilityCSSAdapter.lgClassGroup.classes) { + if (this.component.getStyleName().contains(clazz)) { + if (clazz.contains("hidden")) { + return false; + } else { + return true; + } + } + } + } + return true; + } + + public void setVisibility(ResponsiveLayout.DisplaySize displaySize, boolean isVisible) { + + if (displaySize == ResponsiveLayout.DisplaySize.XS) { + for (String clazz : VisibilityCSSAdapter.xsClassGroup.classes) { + this.component.removeStyleName(clazz); + } + } + if (displaySize == ResponsiveLayout.DisplaySize.SM) { + for (String clazz : VisibilityCSSAdapter.smClassGroup.classes) { + this.component.removeStyleName(clazz); + } + } + if (displaySize == ResponsiveLayout.DisplaySize.MD) { + for (String clazz : VisibilityCSSAdapter.mdClassGroup.classes) { + this.component.removeStyleName(clazz); + } + } + if (displaySize == ResponsiveLayout.DisplaySize.LG) { + for (String clazz : VisibilityCSSAdapter.lgClassGroup.classes) { + this.component.removeStyleName(clazz); + } + } + + + this.component.addStyleName(getCssForDisplaySize(displaySize, isVisible)); + + + } + } diff --git a/src/test/java/com/jarektoro/responsivelayout/BasicFullPageUI.java b/src/test/java/com/jarektoro/responsivelayout/BasicFullPageUI.java index 442253b..74348e3 100644 --- a/src/test/java/com/jarektoro/responsivelayout/BasicFullPageUI.java +++ b/src/test/java/com/jarektoro/responsivelayout/BasicFullPageUI.java @@ -123,6 +123,17 @@ protected void init(VaadinRequest request) { setContent(responsiveLayout); + Panel panel = new Panel("Panel"); + setContent(panel); + ResponsiveLayout layout = new ResponsiveLayout(ResponsiveLayout.ContainerType.FLUID); + panel.setContent(layout); + layout.addRow() + .withMargin(ResponsiveRow.MarginSize.SMALL) + .withVerticalSpacing(ResponsiveRow.SpacingSize.SMALL, true) + .withHorizontalSpacing(true) + .addColumn().withDisplayRules(12, 12, 12, 12).setComponent(new Label("Test")); + + } public ResponsiveLayout createNestedLayout() {