You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2015/11/19 11:10:36 UTC
svn commit: r1715142 - in /myfaces/tobago/branches/tobago-3.0.x:
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/layout/
tobago-core/src/main/java/org/apache/myfaces/tobago/layout/
tobago-core/src/main/java/org/apache/myfaces/tobago/util/ ...
Author: lofwyr
Date: Thu Nov 19 10:10:36 2015
New Revision: 1715142
URL: http://svn.apache.org/viewvc?rev=1715142&view=rev
Log:
TOBAGO-1511: Generalization of Measure class: support for other units like ex, em, mm, cm, in,
Added:
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/MeasureLayoutToken.java
- copied, changed from r1715139, myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/PixelLayoutToken.java
Removed:
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/layout/FactorList.java
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/PixelLayoutToken.java
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/util/LayoutInfo.java
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/util/LayoutInfoUnitTest.java
Modified:
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/LayoutTokens.java
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/Measure.java
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/PixelMeasure.java
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/layout/LayoutTokensUnitTest.java
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/layout/MeasureUnitTest.java
myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/FlexLayoutRenderer.java
myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/GridLayoutRenderer.java
myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java
myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-layout.js
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/LayoutTokens.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/LayoutTokens.java?rev=1715142&r1=1715141&r2=1715142&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/LayoutTokens.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/LayoutTokens.java Thu Nov 19 10:10:36 2015
@@ -53,18 +53,6 @@ public final class LayoutTokens implemen
return tokens.get(index);
}
- public void shrinkSizeTo(final int size) {
- for (int i = getSize() - 1; i >= size; i--) {
- tokens.remove(i);
- }
- }
-
- public void ensureSize(final int size, final LayoutToken token) {
- for (int index = getSize(); index < size; index++) {
- addToken(token);
- }
- }
-
public void addToken(final LayoutToken token) {
tokens.add(token);
}
@@ -122,15 +110,12 @@ public final class LayoutTokens implemen
return AutoLayoutToken.INSTANCE;
} else if ("minimum".equals(token)) {
return new MinimumLayoutToken();
- } else if (isPixelToken(token)) {
- return new PixelLayoutToken(Integer.parseInt(removeSuffix(token, PixelLayoutToken.SUFFIX)));
} else if (isPercentToken(token)) {
return new PercentLayoutToken(Integer.parseInt(removeSuffix(token, PercentLayoutToken.SUFFIX)));
} else if (isRelativeToken(token)) {
return new RelativeLayoutToken(Integer.parseInt(removeSuffix(token, RelativeLayoutToken.SUFFIX)));
} else {
- LOG.error("Unknown layout token '" + token + "'! Using 'auto' instead.");
- return AutoLayoutToken.INSTANCE;
+ return new MeasureLayoutToken(token);
}
} catch (final NumberFormatException e) {
LOG.error("Error parsing layout token '" + token + "'! Using 'auto' instead.");
@@ -138,10 +123,6 @@ public final class LayoutTokens implemen
}
}
- static boolean isPixelToken(final String token) {
- return isNumberAndSuffix(token, PixelLayoutToken.SUFFIX);
- }
-
static boolean isPercentToken(final String token) {
return isNumberAndSuffix(token, PercentLayoutToken.SUFFIX);
}
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/Measure.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/Measure.java?rev=1715142&r1=1715141&r2=1715142&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/Measure.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/Measure.java Thu Nov 19 10:10:36 2015
@@ -24,22 +24,47 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Serializable;
-import java.util.List;
/**
- * In JSPs the class {@link org.apache.myfaces.tobago.layout.MeasureEditor} will convert the string literals.
+ * In JSPs the class {@link org.apache.myfaces.tobago.layout.MeasureEditor} will convert the string literals.
*/
-public abstract class Measure implements Serializable {
+public final class Measure implements Serializable {
private static final long serialVersionUID = 1L;
private static final Logger LOG = LoggerFactory.getLogger(Measure.class);
public static final Measure ZERO = valueOf(0);
- public static final Measure MAX = valueOf(Integer.MAX_VALUE);
// todo: refactor and consolidate with LayoutToken
-
+
+ private final Double d;
+ private final Integer i;
+ private final Unit unit;
+
+ public Measure(int i, Unit unit) {
+ this.d = null;
+ this.i = i;
+ this.unit = unit;
+ }
+
+ public Measure(double d, Unit unit) {
+ this.d = d;
+ this.i = null;
+ this.unit = unit;
+ }
+
+ public Measure(String string, Unit unit) {
+ if (string.contains(".")) {
+ this.d = Double.parseDouble(string);
+ this.i = null;
+ } else {
+ this.d = null;
+ this.i = Integer.parseInt(string);
+ }
+ this.unit = unit;
+ }
+
public static Measure valueOf(final Measure value) {
if (value == null) {
return ZERO;
@@ -48,7 +73,7 @@ public abstract class Measure implements
}
public static Measure valueOf(final int value) {
- return PixelMeasure.pixelValueOf(value);
+ return new Measure(value, Unit.PX);
}
public static Measure valueOf(final Integer value) {
@@ -62,29 +87,27 @@ public abstract class Measure implements
if (value == null) {
return ZERO;
}
- return valueOf(value.intValue());
+ return valueOf(value.doubleValue());
}
public static Measure valueOf(final String value) {
- if (StringUtils.isEmpty(value)) {
- return ZERO;
- }
try {
- final int dot = value.indexOf('.');
- if (dot == 0) {
- return Measure.ZERO;
+ if (StringUtils.isEmpty(value)) {
+ return null;
}
- if (dot > 0) {
- return Measure.valueOf(Integer.parseInt(value.substring(0, dot)));
+ final int length = value.length();
+ if (value.endsWith("%")) {
+ return new Measure(value.substring(0, length - 1), Unit.PERCENT);
}
- if (value.endsWith("px")) {
- return Measure.valueOf(Integer.parseInt(value.substring(0, value.length() - 2)));
+ if (length >= 2 && Character.isLetter(value.charAt(length - 2))) {
+ return new Measure(value.substring(0, length - 2), Unit.valueOf(value.substring(length - 2).toUpperCase()));
}
- return Measure.valueOf(Integer.parseInt(value));
+ return new Measure(value, Unit.PX);
- } catch (final NumberFormatException e) {
- throw new IllegalArgumentException("Can't parse to any measure: '" + value + "'", e);
+ } catch (final RuntimeException e) {
+ LOG.warn("Can't parse to any measure: '" + value + "'");
}
+ return null;
}
public static Measure valueOf(final Object object) {
@@ -103,101 +126,63 @@ public abstract class Measure implements
return valueOf(object.toString());
}
- /**
- * @deprecated since 1.5.0, please use valueOf()
- */
- @Deprecated
- public static Measure parse(final String value) {
- return valueOf(value);
+ public String serialize() {
+ return "" + (i != null ? i : "") + (d != null ? d : "") + unit.getValue();
}
- public abstract Measure add(Measure m);
-
- public abstract Measure add(int m);
-
- public abstract Measure multiply(int times);
-
- public abstract Measure divide(int times);
-
- /**
- * @deprecated since 1.5.0, please use subtractNotNegative
- */
- @Deprecated
- public Measure substractNotNegative(final Measure m) {
- return subtractNotNegative(m);
+ public String toString() {
+ return serialize();
}
- public abstract Measure subtractNotNegative(Measure m);
-
- public abstract Measure subtract(Measure m);
-
- public abstract Measure subtract(int m);
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
- public boolean greaterThan(final Measure measure) {
- return measure != null && getPixel() > measure.getPixel();
- }
+ Measure measure = (Measure) o;
- public boolean greaterOrEqualThan(final Measure measure) {
- return measure != null && getPixel() >= measure.getPixel();
- }
+ if (d != null ? !d.equals(measure.d) : measure.d != null) {
+ return false;
+ }
+ if (i != null ? !i.equals(measure.i) : measure.i != null) {
+ return false;
+ }
+ return unit == measure.unit;
- public boolean lessThan(final Measure measure) {
- return measure != null && getPixel() < measure.getPixel();
}
- public boolean lessOrEqualThan(final Measure measure) {
- return measure != null && getPixel() <= measure.getPixel();
+ @Override
+ public int hashCode() {
+ int result = d != null ? d.hashCode() : 0;
+ result = 31 * result + (i != null ? i.hashCode() : 0);
+ result = 31 * result + unit.hashCode();
+ return result;
}
- public abstract int getPixel();
+ private enum Unit {
- public abstract String serialize();
+ EM,
+ PX,
+ EX,
+ PT,
+ CM,
+ MM,
+ IN,
+ PC,
+ PERCENT;
- /**
- * Returns the maximum. If all parameters are null, than the result is {@value #ZERO}.
- */
- public static Measure max(final List<Measure> list) {
- Measure max = ZERO;
- for (final Measure measure : list) {
- if (max.lessThan(measure)) {
- max = measure;
- }
- }
- return max;
- }
+ private final String value;
- /**
- * Returns the minimum. If all parameters are null, than the result is {@value #MAX}.
- */
- public static Measure min(final List<Measure> list) {
- Measure min = MAX;
- for (final Measure measure : list) {
- if (min.greaterThan(measure)) {
- min = measure;
- }
+ Unit() {
+ value = name().equals("PERCENT") ? "%" : name().toLowerCase();
}
- return min;
- }
- /**
- * Returns the maximum. If all parameters are null, than the result is {@value #ZERO}.
- */
- public static Measure max(final Measure m1, final Measure m2) {
- if (m1 != null) {
- return m1.lessThan(m2) ? m2 : m1;
- } else {
- return m2 != null ? m2 : ZERO;
- }
- }
-
- /**
- * Returns the minimum. If all parameters are null, than the result is {@value #MAX}.
- */
- public static Measure min(final Measure m1, final Measure m2) {
- if (m1 != null) {
- return m1.greaterThan(m2) ? m2 : m1;
- } else {
- return m2 != null ? m2 : MAX;
+ String getValue() {
+ return value;
}
}
}
Copied: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/MeasureLayoutToken.java (from r1715139, myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/PixelLayoutToken.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/MeasureLayoutToken.java?p2=myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/MeasureLayoutToken.java&p1=myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/PixelLayoutToken.java&r1=1715139&r2=1715142&rev=1715142&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/PixelLayoutToken.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/MeasureLayoutToken.java Thu Nov 19 10:10:36 2015
@@ -19,32 +19,31 @@
package org.apache.myfaces.tobago.layout;
+/**
+ * @since Tobago 3.0. Was renamed from PixelLayoutToken, because it's generalization.
+ */
+public class MeasureLayoutToken extends LayoutToken {
-public class PixelLayoutToken extends LayoutToken {
+ private final Measure measure;
- static final String SUFFIX = "px";
-
- private final PixelMeasure pixel;
-
- public PixelLayoutToken(final int pixel) {
+ public MeasureLayoutToken(final String measure) {
// here we cannot use this(PixelMeasure.pixelValueOf(pixel)), because of class initialization problems
- this((PixelMeasure) Measure.valueOf(pixel));
- }
-
- public PixelLayoutToken(final PixelMeasure pixel) {
- this.pixel = pixel;
+ this(Measure.valueOf(measure));
+ if (this.measure == null) {
+ throw new NumberFormatException(measure);
+ }
}
- public int getPixel() {
- return pixel.getPixel();
+ public MeasureLayoutToken(final Measure measure) {
+ this.measure = measure;
}
- public PixelMeasure getMeasure() {
- return pixel;
+ public Measure getMeasure() {
+ return measure;
}
public String toString() {
- return pixel.toString();
+ return measure.toString();
}
public boolean equals(final Object o) {
@@ -55,16 +54,13 @@ public class PixelLayoutToken extends La
return false;
}
- final PixelLayoutToken that = (PixelLayoutToken) o;
+ final MeasureLayoutToken that = (MeasureLayoutToken) o;
- if (pixel != that.pixel) {
- return false;
- }
+ return measure.equals(that.measure);
- return true;
}
public int hashCode() {
- return pixel.hashCode();
+ return measure.hashCode();
}
}
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/PixelMeasure.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/PixelMeasure.java?rev=1715142&r1=1715141&r2=1715142&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/PixelMeasure.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/PixelMeasure.java Thu Nov 19 10:10:36 2015
@@ -22,7 +22,7 @@ package org.apache.myfaces.tobago.layout
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public final class PixelMeasure extends Measure {
+public final class PixelMeasure /*extends Measure*/ {
private static final Logger LOG = LoggerFactory.getLogger(PixelMeasure.class);
@@ -49,64 +49,11 @@ public final class PixelMeasure extends
return new PixelMeasure(value);
}
- public Measure add(final Measure m) {
- if (m == null) {
- return this;
- } else {
- return pixelValueOf(pixel + m.getPixel());
- }
- }
-
- public Measure add(final int m) {
- return pixelValueOf(pixel + m);
- }
-
- public Measure multiply(final int times) {
- return pixelValueOf(pixel * times);
- }
-
- public Measure divide(final int times) {
- return pixelValueOf(pixel / times);
- }
-
- public Measure subtractNotNegative(final Measure m) {
- if (m == null) {
- return this;
- } else if (m.getPixel() > pixel) {
- LOG.warn("Not enough space! value=" + pixel);
- return ZERO;
- } else {
- return pixelValueOf(pixel - m.getPixel());
- }
- }
-
- public Measure subtract(final Measure m) {
- if (m == null) {
- return this;
- } else {
- return pixelValueOf(pixel - m.getPixel());
- }
- }
-
- public Measure subtract(final int m) {
- return pixelValueOf(pixel - m);
- }
-
public int getPixel() {
return pixel;
}
@Override
- public String toString() {
- return serialize();
- }
-
- @Override
- public String serialize() {
- return pixel + "px";
- }
-
- @Override
public boolean equals(final Object o) {
if (this == o) {
return true;
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/layout/LayoutTokensUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/layout/LayoutTokensUnitTest.java?rev=1715142&r1=1715141&r2=1715142&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/layout/LayoutTokensUnitTest.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/layout/LayoutTokensUnitTest.java Thu Nov 19 10:10:36 2015
@@ -25,16 +25,6 @@ import org.junit.Test;
public class LayoutTokensUnitTest {
@Test
- public void testIsPixelToken() {
- Assert.assertTrue(LayoutTokens.isPixelToken("120px"));
- }
-
- @Test
- public void testIsPixelToken0() {
- Assert.assertTrue(LayoutTokens.isPixelToken("0px"));
- }
-
- @Test
public void testIsPercentToken() {
Assert.assertTrue(LayoutTokens.isPercentToken("50%"));
}
@@ -57,7 +47,7 @@ public class LayoutTokensUnitTest {
Assert.assertEquals(RelativeLayoutToken.DEFAULT_INSTANCE, LayoutTokens.parseToken("*"));
Assert.assertEquals(new RelativeLayoutToken(3), LayoutTokens.parseToken("3*"));
Assert.assertEquals(new PercentLayoutToken(33), LayoutTokens.parseToken("33%"));
- Assert.assertEquals(new PixelLayoutToken(120), LayoutTokens.parseToken("120px"));
- Assert.assertEquals(new PixelLayoutToken(0), LayoutTokens.parseToken("0px"));
+ Assert.assertEquals(new MeasureLayoutToken("120px"), LayoutTokens.parseToken("120px"));
+ Assert.assertEquals(new MeasureLayoutToken("0px"), LayoutTokens.parseToken("0px"));
}
}
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/layout/MeasureUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/layout/MeasureUnitTest.java?rev=1715142&r1=1715141&r2=1715142&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/layout/MeasureUnitTest.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/test/java/org/apache/myfaces/tobago/layout/MeasureUnitTest.java Thu Nov 19 10:10:36 2015
@@ -22,52 +22,34 @@ package org.apache.myfaces.tobago.layout
import org.junit.Assert;
import org.junit.Test;
-import java.util.Arrays;
-
public class MeasureUnitTest {
- private static Measure px(final int pixel) {
- return Measure.valueOf(pixel);
- }
-
- @Test
- public void testMinList() {
- Assert.assertEquals(px(5), Measure.min(Arrays.asList(px(5), px(10), px(20))));
- Assert.assertEquals(px(5), Measure.min(Arrays.asList(px(5), null, px(20))));
- Assert.assertEquals(Measure.MAX, Measure.min(Arrays.asList((Measure) null, null, null)));
- Assert.assertEquals(Measure.MAX, Measure.min(Arrays.<Measure>asList()));
- }
-
@Test
- public void testMaxList() {
- Assert.assertEquals(px(20), Measure.max(Arrays.asList(px(5), px(10), px(20))));
- Assert.assertEquals(px(20), Measure.max(Arrays.asList(px(5), null, px(20))));
- Assert.assertEquals(Measure.ZERO, Measure.max(Arrays.asList((Measure) null, null, null)));
- Assert.assertEquals(Measure.ZERO, Measure.max(Arrays.<Measure>asList()));
+ public void testDecimal() {
+ Assert.assertEquals("13.3px", ""+Measure.valueOf("13.3px"));
+ Assert.assertEquals("13.7px", ""+Measure.valueOf("13.7px"));
+ Assert.assertEquals("13.3px",""+ Measure.valueOf("13.3"));
+ Assert.assertEquals("13.7px",""+ Measure.valueOf("13.7"));
+ Assert.assertEquals("0.7px",""+ Measure.valueOf(".7"));
+ Assert.assertEquals("0px",""+ Measure.valueOf("0"));
+ Assert.assertEquals(null, Measure.valueOf(""));
}
@Test
- public void testMin2() {
- Assert.assertEquals(px(5), Measure.min(px(5), px(10)));
- Assert.assertEquals(px(10), Measure.min(null, px(10)));
- Assert.assertEquals(px(5), Measure.min(px(5), null));
- Assert.assertEquals(Measure.MAX, Measure.min(null, null));
+ public void testOther() {
+ Assert.assertEquals("13.3cm", ""+Measure.valueOf("13.3cm"));
+ Assert.assertEquals("13.7mm", ""+Measure.valueOf("13.7mm"));
+ Assert.assertEquals("13.7ex", ""+Measure.valueOf("13.7ex"));
+ Assert.assertEquals("13.7em", ""+Measure.valueOf("13.7em"));
+ Assert.assertEquals("13.7in", ""+Measure.valueOf("13.7in"));
+ Assert.assertEquals("13.7%", ""+Measure.valueOf("13.7%"));
}
@Test
- public void testMax2() {
- Assert.assertEquals(px(10), Measure.max(px(5), px(10)));
- Assert.assertEquals(px(10), Measure.max(null, px(10)));
- Assert.assertEquals(px(5), Measure.max(px(5), null));
- Assert.assertEquals(Measure.ZERO, Measure.max(null, null));
+ public void testWrong() {
+ Assert.assertNull("Not parsable, so get null", Measure.valueOf("13.3xx"));
+ Assert.assertNull("Not parsable, so get null", Measure.valueOf("13.3x"));
+ Assert.assertNull("Not parsable, so get null", Measure.valueOf("13.3mmm"));
}
- @Test
- public void testDecimal() {
- Assert.assertEquals(Measure.valueOf("13.3px"), px(13));
- Assert.assertEquals(Measure.valueOf("13.7px"), px(13));
- Assert.assertEquals(Measure.valueOf("13.3"), px(13));
- Assert.assertEquals(Measure.valueOf("13.7"), px(13));
- Assert.assertEquals(Measure.valueOf(".7"), px(0));
- }
}
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/FlexLayoutRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/FlexLayoutRenderer.java?rev=1715142&r1=1715141&r2=1715142&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/FlexLayoutRenderer.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/FlexLayoutRenderer.java Thu Nov 19 10:10:36 2015
@@ -56,7 +56,7 @@ public class FlexLayoutRenderer extends
.replace("7*", "7")
.replace("8*", "8")
.replace("9*", "9")
- .replace("*", "1").replaceAll("(\\d+)px", "{\"pixel\":$1}"));
+ .replace("*", "1").replaceAll("(\\d+[a-zA-Z]{2})", "{\"measure\":\"$1\"}"));
b.append("]}");
}
final String rows = flexLayout.getRows();
@@ -74,7 +74,7 @@ public class FlexLayoutRenderer extends
.replace("7*", "7")
.replace("8*", "8")
.replace("9*", "9")
- .replace("*", "1").replaceAll("(\\d+)px", "{\"pixel\":$1}"));
+ .replace("*", "1").replaceAll("(\\d+[a-zA-Z]{2})", "{\"measure\":\"$1\"}"));
b.append("]}");
}
boolean vertically = rows.contains(";");
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/GridLayoutRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/GridLayoutRenderer.java?rev=1715142&r1=1715141&r2=1715142&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/GridLayoutRenderer.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/GridLayoutRenderer.java Thu Nov 19 10:10:36 2015
@@ -28,7 +28,7 @@ import org.apache.myfaces.tobago.layout.
import org.apache.myfaces.tobago.layout.LayoutToken;
import org.apache.myfaces.tobago.layout.LayoutTokens;
import org.apache.myfaces.tobago.layout.Measure;
-import org.apache.myfaces.tobago.layout.PixelLayoutToken;
+import org.apache.myfaces.tobago.layout.MeasureLayoutToken;
import org.apache.myfaces.tobago.layout.RelativeLayoutToken;
import org.apache.myfaces.tobago.renderkit.RendererBase;
import org.apache.myfaces.tobago.renderkit.css.Classes;
@@ -92,10 +92,10 @@ public class GridLayoutRenderer extends
builder.append(factor);
} else if (token instanceof AutoLayoutToken) {
builder.append("\"auto\"");
- } else if (token instanceof PixelLayoutToken) {
- builder.append("{\"pixel\":");
- builder.append(((PixelLayoutToken) token).getPixel());
- builder.append("}");
+ } else if (token instanceof MeasureLayoutToken) {
+ builder.append("{\"measure\":\"");
+ builder.append(((MeasureLayoutToken) token).getMeasure());
+ builder.append("\"}");
} else {
LOG.warn("Not supported: " + token);
}
@@ -144,17 +144,17 @@ public class GridLayoutRenderer extends
final Measure width = Measure.valueOf(element.getAttributes().get(Attributes.WIDTH));
if (width != null) {
builder.append("\"width\":");
- builder.append("{\"pixel\":");
- builder.append(width.getPixel());
- builder.append("}");
+// builder.append("{\"pixel\":");
+ builder.append(width.serialize());
+// builder.append("}");
builder.append(",");
}
final Measure height = Measure.valueOf(element.getAttributes().get(Attributes.HEIGHT));
if (height != null) {
builder.append("\"height\":");
- builder.append("{\"pixel\":");
- builder.append(height.getPixel());
- builder.append("}");
+// builder.append("{\"pixel\":");
+ builder.append(height.serialize());
+// builder.append("}");
builder.append(",");
}
if (builder.length() > 1) {
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java?rev=1715142&r1=1715141&r2=1715142&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java Thu Nov 19 10:10:36 2015
@@ -806,13 +806,6 @@ public class SheetRenderer extends Rende
writer.startElement(HtmlElements.DIV);
writer.writeClassAttribute(Classes.create(sheet, "headerCell"));
writer.startElement(HtmlElements.SPAN);
- final Style headerStyle = new Style();
- Measure headerHeight = Measure.valueOf(20).multiply(cell.getRowSpan());
- if (!pure) {
- headerHeight = headerHeight.subtract(6); // XXX todo
- }
- headerStyle.setHeight(headerHeight);
- writer.writeStyleAttribute(headerStyle);
final AbstractUIColumn column = renderedColumnList.get(j);
BootstrapClass sorterGlyphicon = null;
Markup markup = Markup.NULL;
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-layout.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-layout.js?rev=1715142&r1=1715141&r2=1715142&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-layout.js (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-layout.js Thu Nov 19 10:10:36 2015
@@ -15,6 +15,13 @@
* limitations under the License.
*/
+Tobago.Layout = {};
+
+Tobago.Layout.Orientation = {
+ HORIZONTAL: true,
+ VERTICAL: false
+};
+
function init(table) {
var elements = table.children("tbody").children("tr").children("td").children();
@@ -41,7 +48,7 @@ function init(table) {
});
}
-function layout(table, horizontal) {
+function layoutGrid(table, orientation) {
var cells;
var banks;
var tokens;
@@ -53,14 +60,14 @@ function layout(table, horizontal) {
return;
}
- if (horizontal) {
+ if (orientation == Tobago.Layout.Orientation.HORIZONTAL) {
// cells = table.find("tr:first>td");
banks = table.children("colgroup").children("col");
tokens = tobagoLayout.columns;
css = "width";
desired = table.outerWidth();
// desired = table.parent().data("tobago-style").width.replace("px", ""); // todo: data("tobago-layout") wohl doch nicht so gut...? der wert wurde ja schon berechnet...
- } else {
+ } else { // Tobago.Layout.Orientation.VERTICAL
// cells = table.find("tr");
banks = table.children("tbody").children("tr");
tokens = tobagoLayout.rows;
@@ -87,17 +94,20 @@ function layout(table, horizontal) {
// a string, currently only "auto" is supported
if ("auto" == tokens[i]) {
// nothing to do
- sumUsed += horizontal ? cell.outerWidth() : cell.outerHeight();
+ sumUsed += orientation == Tobago.Layout.Orientation.HORIZONTAL ? cell.outerWidth() : cell.outerHeight();
} else {
console.warn("currently only 'auto' is supported, but found: '" + tokens[i] + "'"); // @DEV_ONLY
}
break;
case "object":
- if (tokens[i].pixel) {
- setLength(table, banks, i, css, tokens[i].pixel + "px");
- sumUsed += tokens[i].pixel;
+ var m = tokens[i].measure;
+ if (m) {
+ setLength(table, banks, i, css, m);
+ if (/^\d+px$/.test(m)) {
+ sumUsed += m.substr(0, m.length - 2);
+ }
} else {
- console.warn("can't find pixel in object: '" + tokens[i] + "'"); // @DEV_ONLY
+ console.warn("can't find measure in object: '" + tokens[i] + "'"); // @DEV_ONLY
}
break;
default:
@@ -137,7 +147,7 @@ function setLength2(banks, i, css, lengt
banks.eq(i).css(css, length);
}
-function layoutFlex(container, horizontal) {
+function layoutFlex(container, orientation) {
// todo: modernizr
// if (!Modernizr.flexbox && !Modernizr.flexboxtweener) ... do other
@@ -152,11 +162,11 @@ function layoutFlex(container, horizonta
return;
}
- if (horizontal) {
+ if (orientation == Tobago.Layout.Orientation.HORIZONTAL) {
banks = container.children();
tokens = tobagoLayout.columns;
css = "width";
- } else {
+ } else { // Tobago.Layout.Orientation.VERTICAL
banks = container.children();
tokens = tobagoLayout.rows;
css = "height";
@@ -183,10 +193,10 @@ function layoutFlex(container, horizonta
// a string, currently only "auto" is supported
break;
case "object":
- if (tokens[i].pixel) {
- setLength2(banks, i, css, tokens[i].pixel + "px");
+ if (tokens[i].measure) {
+ setLength2(banks, i, css, tokens[i].measure);
} else {
- console.warn("can't find pixel in object: '" + tokens[i] + "'"); // @DEV_ONLY
+ console.warn("can't find measure in object: '" + tokens[i] + "'"); // @DEV_ONLY
}
break;
default:
@@ -207,8 +217,8 @@ jQuery(document).ready(function () {
gridLayouts.each(function () {
var table = jQuery(this);
- layout(table, true);
- layout(table, false);
+ layoutGrid(table, Tobago.Layout.Orientation.HORIZONTAL);
+ layoutGrid(table, Tobago.Layout.Orientation.VERTICAL);
});
//////////////////////////////////////////////
@@ -219,8 +229,8 @@ jQuery(document).ready(function () {
flexLayouts.each(function () {
var container = jQuery(this);
- layoutFlex(container, true);
- layoutFlex(container, false);
+ layoutFlex(container, Tobago.Layout.Orientation.HORIZONTAL);
+ layoutFlex(container, Tobago.Layout.Orientation.VERTICAL);
});
//////////////////////////////////////////////