Skip to content

Commit ca48ba5

Browse files
committed
Merge remote-tracking branch 'origin/GridAlignment' into GridAlignment
# Conflicts: # src/main/java/net/itarray/automotion/internal/ResponsiveUIChunkValidatorBase.java
2 parents a293dd0 + 7930f37 commit ca48ba5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1412
-286
lines changed

pom.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,35 @@
9696
</executions>
9797
<configuration>
9898
<additionalparam>-Xdoclint:none</additionalparam>
99+
<javadocDirectory>${project.basedir}/target/generated-sources/apidocs</javadocDirectory>
99100
</configuration>
100101
</plugin>
101102
<plugin>
102103
<groupId>org.pitest</groupId>
103104
<artifactId>pitest-maven</artifactId>
104105
<version>1.2.2</version>
105106
</plugin>
107+
<plugin>
108+
<groupId>org.codehaus.mojo</groupId>
109+
<artifactId>exec-maven-plugin</artifactId>
110+
<version>1.2.1</version>
111+
<executions>
112+
<execution>
113+
<id>compress-facelets</id>
114+
<phase>prepare-package</phase>
115+
<goals>
116+
<goal>java</goal>
117+
</goals>
118+
<configuration>
119+
<mainClass>net.itarray.automotion.JavadocImageGenerator</mainClass>
120+
<arguments>
121+
<argument>${project.basedir}/target</argument>
122+
</arguments>
123+
</configuration>
124+
</execution>
125+
</executions>
126+
</plugin>
127+
106128
</plugins>
107129
</build>
108130

@@ -214,5 +236,11 @@
214236
<version>2.8.47</version>
215237
<scope>test</scope>
216238
</dependency>
239+
<dependency>
240+
<groupId>junit</groupId>
241+
<artifactId>junit</artifactId>
242+
<version>4.12</version>
243+
<scope>test</scope>
244+
</dependency>
217245
</dependencies>
218246
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package net.itarray.automotion;
2+
3+
import com.google.common.collect.Lists;
4+
import net.itarray.automotion.validation.ChunkUIElementValidator;
5+
6+
import java.io.File;
7+
import java.io.IOException;
8+
import java.nio.charset.Charset;
9+
import java.nio.file.Files;
10+
import java.nio.file.Path;
11+
import java.util.List;
12+
import java.util.stream.Stream;
13+
14+
public class JavadocImageGenerator {
15+
16+
public static void main(String[] args) throws IOException {
17+
File targetDir = new File(args[0]);
18+
File generatedSourcesDir = new File(targetDir, "generated-sources");
19+
File apidocs = new File(generatedSourcesDir, "apidocs");
20+
String packageName = ChunkUIElementValidator.class.getPackage().getName();
21+
final File[] target = {apidocs};
22+
Stream.of(packageName.split("\\.")).forEach(n -> target[0] =new File(target[0], n));
23+
System.out.println("JavadocImageGenerator.main " +args[0]);
24+
System.out.println(target[0]);
25+
File docFiles = new File(target[0], "doc-files");
26+
docFiles.mkdirs();
27+
Path path = new File(docFiles, "sample.svg").toPath();
28+
List<String> lines = Lists.newArrayList(
29+
"<svg xmlns=\"http://www.w3.org/2000/svg\" \n" +
30+
" xmlns:xlink=\"http://www.w3.org/1999/xlink\" \n" +
31+
" version=\"1.1\" width=\"400\" height=\"110\">",
32+
"<rect width=\"300\" height=\"100\" style=\"fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)\" />",
33+
"</svg>"
34+
);
35+
Charset charset = Charset.forName("UTF-8");
36+
Files.write(path, lines, charset);
37+
}
38+
}

src/main/java/net/itarray/automotion/internal/ResponsiveUIChunkValidatorBase.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package net.itarray.automotion.internal;
22

3+
import net.itarray.automotion.internal.geometry.ConnectedIntervals;
4+
import net.itarray.automotion.internal.geometry.Interval;
35
import net.itarray.automotion.internal.geometry.Scalar;
46
import net.itarray.automotion.validation.ChunkUIElementValidator;
57
import net.itarray.automotion.validation.UISnapshot;
@@ -13,17 +15,19 @@
1315
import java.util.Map;
1416
import java.util.SortedMap;
1517
import java.util.TreeMap;
18+
import java.util.stream.Collectors;
1619

1720
import static net.itarray.automotion.internal.UIElement.*;
21+
import static net.itarray.automotion.internal.geometry.Interval.interval;
1822

1923
public class ResponsiveUIChunkValidatorBase extends ResponsiveUIValidatorBase implements ChunkUIElementValidator {
2024

2125
private final List<UIElement> rootElements;
2226
//private final OffsetLineCommands offsetLineCommands = new OffsetLineCommands();
2327

24-
public ResponsiveUIChunkValidatorBase(UISnapshot snapshot, List<WebElement> webElements) {
28+
public ResponsiveUIChunkValidatorBase(UISnapshot snapshot, List<WebElement> webElements, boolean allowEmpty) {
2529
super(snapshot);
26-
if (webElements.isEmpty()) {
30+
if (!allowEmpty && webElements.isEmpty()) {
2731
String message = "Set root web element";
2832
addError(message);
2933
} else {
@@ -92,6 +96,26 @@ public ResponsiveUIChunkValidatorBase alignedAsGrid(int horizontalGridSize, int
9296
return this;
9397
}
9498

99+
@Override
100+
public ChunkUIElementValidator areAlignedAsGridCells() {
101+
validateAlignedAsGridCells(rootElements);
102+
return this;
103+
}
104+
105+
public void validateAlignedAsGridCells(List<UIElement> rootElements) {
106+
ConnectedIntervals columns = new ConnectedIntervals(rootElements.stream().map(e -> e.getXInterval()).collect(Collectors.toList()));
107+
ConnectedIntervals rows = new ConnectedIntervals(rootElements.stream().map(e -> e.getYInterval()).collect(Collectors.toList()));
108+
for (UIElement element : rootElements) {
109+
Interval xInterval = element.getXInterval();
110+
Interval xCell = columns.get(columns.indexOf(xInterval));
111+
Interval yInterval = element.getYInterval();
112+
Interval yCell = rows.get(rows.indexOf(yInterval));
113+
if (!(xInterval.equals(xCell) && yInterval.equals(yCell))) {
114+
errors.add(String.format("banane"));
115+
}
116+
}
117+
}
118+
95119
/**
96120
* Verify that every element in the list is not overlapped with another element from this list
97121
*

src/main/java/net/itarray/automotion/internal/UIElement.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import net.itarray.automotion.internal.geometry.Direction;
44
import net.itarray.automotion.internal.geometry.ExtendGiving;
5-
import net.itarray.automotion.internal.geometry.Group;
5+
import net.itarray.automotion.internal.geometry.GroupElement;
6+
import net.itarray.automotion.internal.geometry.Interval;
67
import net.itarray.automotion.internal.geometry.Rectangle;
78
import net.itarray.automotion.internal.geometry.Scalar;
89
import net.itarray.automotion.internal.geometry.Vector;
@@ -22,6 +23,7 @@
2223

2324
import static net.itarray.automotion.internal.geometry.Direction.*;
2425
import static net.itarray.automotion.internal.geometry.Rectangle.ORIGIN_CORNER;
26+
import static net.itarray.automotion.internal.geometry.Scalar.scalar;
2527
import static org.apache.commons.lang3.text.WordUtils.capitalize;
2628

2729
public class UIElement {
@@ -91,7 +93,7 @@ public Scalar getEnd(Direction direction) {
9193
return direction.end(rectangle);
9294
}
9395

94-
public <V extends Group<V>> V getExtend(ExtendGiving<V> direction) {
96+
public <V extends GroupElement<V>> V getExtend(ExtendGiving<V> direction) {
9597
return direction.extend(rectangle);
9698
}
9799

@@ -147,7 +149,7 @@ public boolean hasEqualBottomOffsetAs(UIElement other) {
147149
return hasEqualBegin(UP, other);
148150
}
149151

150-
public <V extends Group<V>> boolean hasEqualExtendAs(ExtendGiving<V> direction, UIElement other) {
152+
public <V extends GroupElement<V>> boolean hasEqualExtendAs(ExtendGiving<V> direction, UIElement other) {
151153
return direction.extend(rectangle).equals(direction.extend(other.rectangle));
152154
}
153155

@@ -192,7 +194,7 @@ public boolean hasEqualOppositeOffsets(Direction direction, UIElement page) {
192194
}
193195

194196
public boolean hasSuccessor(Direction direction, UIElement possibleSuccessor) {
195-
return signedDistanceToSuccessor(direction, possibleSuccessor).isGreaterOrEqualTo(new Scalar(0));
197+
return signedDistanceToSuccessor(direction, possibleSuccessor).isGreaterOrEqualTo(scalar(0));
196198
}
197199

198200
public Scalar signedDistanceToSuccessor(Direction direction, UIElement successor) {
@@ -283,7 +285,7 @@ public void validateSameWidth(UIElement element, Errors errors) {
283285
validateSameExtend(RIGHT, element, errors);
284286
}
285287

286-
public <V extends Group<V>> void validateSameExtend(ExtendGiving<V> direction, UIElement element, Errors errors) {
288+
public <V extends GroupElement<V>> void validateSameExtend(ExtendGiving<V> direction, UIElement element, Errors errors) {
287289
if (!hasEqualExtendAs(direction, element)) {
288290
errors.add(
289291
String.format("Element %s has not the same %s as element %s. %s of %s is %s. %s of element is %s",
@@ -299,7 +301,7 @@ public <V extends Group<V>> void validateSameExtend(ExtendGiving<V> direction, U
299301
}
300302
}
301303

302-
public <V extends Group<V>> void validateNotSameExtend(ExtendGiving<V> direction, UIElement element, Errors errors) {
304+
public <V extends GroupElement<V>> void validateNotSameExtend(ExtendGiving<V> direction, UIElement element, Errors errors) {
303305
if (hasEqualExtendAs(direction, element)) {
304306
errors.add(
305307
String.format("Element %s has the same %s as element %s. %s of %s is %s. %s of element is %s",
@@ -534,4 +536,16 @@ public void validateInsideOfContainer(UIElement element, Errors errors, Scalar t
534536
element);
535537
}
536538
}
539+
540+
public Interval getYInterval() {
541+
return getInterval(Direction.DOWN);
542+
}
543+
544+
public Interval getXInterval() {
545+
return getInterval(Direction.RIGHT);
546+
}
547+
548+
private Interval getInterval(Direction direction) {
549+
return Interval.interval(getBegin(direction), getEnd(direction));
550+
}
537551
}

src/main/java/net/itarray/automotion/internal/UIValidatorBase.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
import java.util.List;
1919

20+
import static net.itarray.automotion.internal.UIElement.*;
21+
import static net.itarray.automotion.internal.geometry.Scalar.scalar;
22+
import static net.itarray.automotion.validation.properties.Expression.percentOrPixels;
23+
import static net.itarray.automotion.validation.Constants.*;
24+
import static net.itarray.automotion.validation.properties.Condition.*;
2025
import static net.itarray.automotion.internal.UIElement.asElement;
2126
import static net.itarray.automotion.internal.UIElement.asElements;
2227
import static net.itarray.automotion.internal.properties.PercentReference.PAGE;
@@ -106,7 +111,7 @@ public UIValidatorBase isLeftOf(WebElement element, Condition<Scalar> distanceCo
106111
}
107112

108113
private Expression<Scalar> scalarExpression(int width) {
109-
return isPixels() ? new PixelConstant(new Scalar(width)) : Expression.percent(new Scalar(width), PAGE);
114+
return isPixels() ? new PixelConstant(scalar(width)) : Expression.percent(scalar(width), PAGE);
110115
}
111116

112117
private Condition<Scalar> betweenCondition(int minMargin, int maxMargin) {
@@ -462,7 +467,7 @@ public boolean isNotSwitchedOff(int top, int right, int bottom, int left) {
462467
}
463468

464469
public boolean isNotSwitchedOff(int value, Direction direction) {
465-
return percentOrPixels(value).evaluateIn(getContext(), direction).isGreaterThan(new Scalar(MIN_OFFSET));
470+
return percentOrPixels(value).evaluateIn(getContext(), direction).isGreaterThan(scalar(MIN_OFFSET));
466471
}
467472

468473
public void validateMinOffsetNew(int top, int right, int bottom, int left) {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package net.itarray.automotion.internal.geometry;
2+
3+
import com.google.common.collect.Lists;
4+
5+
import java.util.ArrayList;
6+
import java.util.Collections;
7+
import java.util.Comparator;
8+
import java.util.List;
9+
10+
import static java.lang.String.format;
11+
12+
public class ConnectedIntervals {
13+
private final List<Interval> components;
14+
15+
public ConnectedIntervals(List<Interval> intervals) {
16+
this.components = Lists.newArrayList();
17+
ArrayList<Interval> sorted = new ArrayList<>(intervals);
18+
Comparator<Interval> comparator = Interval.comparator();
19+
Collections.sort(sorted, comparator);
20+
int i = 0;
21+
while (i < sorted.size()) {
22+
Interval interval = sorted.get(i);
23+
i++;
24+
while (i < sorted.size() && !interval.intersect(sorted.get(i)).isEmpty()) {
25+
interval = interval.span(sorted.get(i));
26+
i++;
27+
}
28+
components.add(interval);
29+
}
30+
}
31+
32+
public Interval get(int index) {
33+
return components.get(index);
34+
}
35+
36+
public int size() {
37+
return components.size();
38+
}
39+
40+
public int indexOf(Interval interval) {
41+
for (int i = 0; i < components.size(); i++) {
42+
Interval component = components.get(i);
43+
if (!component.intersect(interval).isEmpty()) {
44+
return i;
45+
}
46+
}
47+
throw new RuntimeException(format("interval %s is not in connected intervals", interval));
48+
}
49+
}

src/main/java/net/itarray/automotion/internal/geometry/ExtendGiving.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package net.itarray.automotion.internal.geometry;
22

3-
public interface ExtendGiving<V extends Group<V>> {
3+
public interface ExtendGiving<V extends GroupElement<V>> {
44
String extendName();
55
V begin(Rectangle rectangle);
66
V end(Rectangle rectangle);

src/main/java/net/itarray/automotion/internal/geometry/Group.java renamed to src/main/java/net/itarray/automotion/internal/geometry/GroupElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package net.itarray.automotion.internal.geometry;
22

3-
public interface Group<V> {
3+
public interface GroupElement<V> {
44
V plus(V addend);
55
V minus(V subtrahend);
66
String toStringWithUnits(String units);

0 commit comments

Comments
 (0)