Skip to content

Commit

Permalink
Refactored Code to solve issue #21
Browse files Browse the repository at this point in the history
  • Loading branch information
JarekToro committed Nov 30, 2016
1 parent 2260185 commit 71a7e6a
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public enum ColumnComponentAlignment {

private void convenienceInIt() {


//set primary style name to 'col'
// important in the addRule method

Expand All @@ -67,6 +66,7 @@ private void convenienceInIt() {


public ResponsiveColumn() {
super();
convenienceInIt();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public enum SpacingSize {

public ResponsiveRow() {

super();
setPrimaryStyleName(CSS_ROW);
setWidthUndefined();
addStyleName(CSS_MARGIN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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));


}

}
11 changes: 11 additions & 0 deletions src/test/java/com/jarektoro/responsivelayout/BasicFullPageUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 71a7e6a

Please sign in to comment.