Skip to content

Commit

Permalink
Addresses Issues #13 #12 #10
Browse files Browse the repository at this point in the history
  • Loading branch information
JarekToro committed Oct 26, 2016
1 parent 1de1cb1 commit f17fcfb
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 36 deletions.
40 changes: 33 additions & 7 deletions src/main/java/com/jarektoro/responsivelayout/ResponsiveColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public enum DisplaySize {
XS, SM, MD, LG
}

public enum ColumnComponentAlignment {
LEFT, CENTER, RIGHT
}


private void convenienceInIt() {

Expand All @@ -44,11 +48,11 @@ private void convenienceInIt() {


setPrimaryStyleName("col");
setSizeUndefined();
rules = new HashSet<>(4);
visibilityRules = new HashSet<>(4);
root = new CssLayout();
root.setStyleName("col-container");
root.setSizeFull();
setCompositionRoot(root);
}

Expand Down Expand Up @@ -299,15 +303,31 @@ public void setOffset(DisplaySize displaySize, int width) {
}


public void centerContent(boolean shouldCenter) {
if (shouldCenter) {
addStyleName("content-center");
} else {
removeStyleName("content-center");
public void setAlignment(ColumnComponentAlignment componentAlignment) {
removeStyleName("content-center");
removeStyleName("content-right");


switch (componentAlignment) {


case CENTER:
addStyleName("content-center");
break;
case LEFT:
break;
case RIGHT:
addStyleName("content-right");
break;
default:
break;
}
}





public void setComponent(Component component) {
root.removeAllComponents();
root.addComponent(component);
Expand Down Expand Up @@ -348,7 +368,13 @@ public ResponsiveColumn withComponent(Component component) {
}

public ResponsiveColumn withCenteredComponent(Component component) {
centerContent(true);
setAlignment(ColumnComponentAlignment.CENTER);
setComponent(component);
return this;
}

public ResponsiveColumn withRightAlignedComponent(Component component) {
setAlignment(ColumnComponentAlignment.RIGHT);
setComponent(component);
return this;
}
Expand Down
27 changes: 19 additions & 8 deletions src/main/java/com/jarektoro/responsivelayout/ResponsiveLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,38 @@
@StyleSheet("styles.css")
public class ResponsiveLayout extends CssLayout {

public enum ContainerType {
FIXED, FLUID
}


public ResponsiveLayout(ContainerType containerType) {
super();
setHeightUndefined();
setContainerType(containerType);
}

// just about the same as a StyleAdpterCssLayout
// mainly syntax diffs.
public ResponsiveLayout() {
super();
setHeightUndefined();
setWidth("100%");
}

public void setContainerType(ContainerType containerType) {
if (containerType == ContainerType.FLUID) {
setStyleName("container-fluid");
} else if (containerType == ContainerType.FIXED) {
setStyleName("container");

//when size is set to full. It sets the css property 'overflow' to 'hidden'
// this inhibits scrolling to counter act that you can set a boolean var to add scrolling
public void setSizeFull(boolean scrollable) {
super.setSizeFull();
}
}


public void setScrollable(boolean scrollable) {
if (scrollable) {
addStyleName("scrollable-anyway");
} else {
removeStyleName("scrollable-anyway");
}

}

/**
Expand Down
116 changes: 109 additions & 7 deletions src/main/java/com/jarektoro/responsivelayout/ResponsiveRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.vaadin.ui.Alignment;
import com.vaadin.ui.Component;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.VerticalLayout;

Expand All @@ -12,6 +13,14 @@
public class ResponsiveRow extends CssLayout {


public enum MarginSize {
NORMAL, SMALL
}

public enum SpacingSize {
NORMAL, SMALL
}

public ResponsiveRow() {

setPrimaryStyleName("row");
Expand All @@ -33,7 +42,7 @@ public void addColumn(ResponsiveColumn col) {

//add ResponsiveColumn to Component List then recalulates the margin and spacing to match

addComponent(col);
super.addComponent(col);

}

Expand All @@ -50,23 +59,38 @@ public void setMargin(boolean margin) {

}

public void setMarginSmall(boolean small) {

public void setMargin(MarginSize marginSize, boolean margin) {

if (small) {
addStyleName("margin-small");
} else {
if (margin){
removeStyleName("margin");
removeStyleName("margin-small");
if (marginSize == MarginSize.NORMAL) {
addStyleName("margin");

} else if (marginSize == MarginSize.SMALL) {
addStyleName("margin");
addStyleName("margin-small");
}
}else{
removeStyleName("margin");
removeStyleName("margin-small");
}


}


public void setSpacing(boolean spacing) {
setVerticalSpacing(spacing);
setHorizontalSpacing(spacing);
}

public void setSpacing(SpacingSize spacingSize, boolean spacing) {
setVerticalSpacing(spacingSize,spacing);
setHorizontalSpacing(spacingSize, spacing);
}

public void setVerticalSpacing(boolean verticalSpacing) {


Expand All @@ -88,6 +112,62 @@ public void setHorizontalSpacing(boolean horizontalSpacing) {
}


}

public void setVerticalSpacing(SpacingSize spacingSize, boolean verticalSpacing) {




if (verticalSpacing) {
removeStyleName("v-col-spacing");
removeStyleName("v-col-spacing-small");

if (spacingSize == SpacingSize.NORMAL) {
addStyleName("v-col-spacing");


} else if (spacingSize == SpacingSize.SMALL) {
addStyleName("v-col-spacing");
addStyleName("v-col-spacing-small");
}


} else {

removeStyleName("v-col-spacing");
removeStyleName("v-col-spacing-small");

}

}

public void setHorizontalSpacing(SpacingSize spacingSize, boolean horizontalSpacing) {



if (horizontalSpacing) {
removeStyleName("h-col-spacing");
removeStyleName("h-col-spacing-small");

if (spacingSize == SpacingSize.NORMAL) {
addStyleName("h-col-spacing");


} else if (spacingSize == SpacingSize.SMALL) {
addStyleName("h-col-spacing");
addStyleName("h-col-spacing-small");
}


} else {

removeStyleName("h-col-spacing");
removeStyleName("h-col-spacing-small");

}


}

public void setDefaultComponentAlignment(Alignment defaultAlignment) {
Expand Down Expand Up @@ -139,6 +219,22 @@ public void setDefaultComponentAlignment(Alignment defaultAlignment) {
}


@Override public void addComponents(Component... components){

for (Component component:components) {
ResponsiveColumn col = new ResponsiveColumn().withComponent(component);
col.setSizeUndefined();
addColumn(col);
}

}
@Override public void addComponent(Component component){

ResponsiveColumn col = new ResponsiveColumn().withComponent(component);
col.setSizeUndefined();
addColumn(col);

}
// Convenience API

public ResponsiveColumn addColumn() {
Expand All @@ -147,6 +243,11 @@ public ResponsiveColumn addColumn() {
return column;
}

public ResponsiveRow withComponents(Component... components) {
addComponents(components);
return this;
}

public ResponsiveRow withAlignment(Alignment alignment) {
setDefaultComponentAlignment(alignment);
return this;
Expand All @@ -158,8 +259,7 @@ public ResponsiveRow withMargin(boolean margin) {
}

public ResponsiveRow withSmallMargin(boolean margin) {
setMargin(margin);
setMarginSmall(margin);
setMargin(MarginSize.SMALL,margin);;
return this;
}

Expand All @@ -179,4 +279,6 @@ public ResponsiveRow withHorizontalSpacing(boolean spacing) {
return this;
}



}
Loading

0 comments on commit f17fcfb

Please sign in to comment.