1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.opencastproject.composer.layout;
23
24 import static org.opencastproject.util.Jsons.obj;
25 import static org.opencastproject.util.Jsons.p;
26
27 import org.opencastproject.util.JsonObj;
28 import org.opencastproject.util.Jsons;
29
30 public final class Serializer {
31 private Serializer() {
32 }
33
34 public static Jsons.Obj json(Dimension a) {
35 return obj(p("w", a.getWidth()),
36 p("h", a.getHeight()));
37 }
38
39 public static Dimension dimension(JsonObj json) {
40 return new Dimension(json.get(Integer.class, "w"), json.get(Integer.class, "h"));
41 }
42
43 public static Jsons.Obj json(Anchor a) {
44 return obj(p("left", a.getLeft()),
45 p("top", a.getTop()));
46 }
47
48 public static Anchor anchor(JsonObj json) {
49 return new Anchor(json.get(Double.class, "left"), json.get(Double.class, "top"));
50 }
51
52 public static Jsons.Obj json(Offset a) {
53 return obj(p("x", a.getX()),
54 p("y", a.getY()));
55 }
56
57 public static Offset offset(JsonObj json) {
58 return new Offset(json.get(Integer.class, "x"), json.get(Integer.class, "y"));
59 }
60
61 public static Jsons.Obj json(AnchorOffset a) {
62 return obj(p("offset", json(a.getOffset())),
63 p("reference", json(a.getReferenceAnchor())),
64 p("referring", json(a.getReferringAnchor())));
65 }
66
67 public static AnchorOffset anchorOffset(JsonObj json) {
68 return new AnchorOffset(anchor(json.getObj("reference")),
69 anchor(json.getObj("referring")),
70 offset(json.getObj("offset")));
71 }
72
73 public static Jsons.Obj json(TwoShapeLayout a) {
74 return obj(p("canvas", json(a.getCanvas())),
75 p("upper", json(a.getUpper())),
76 p("lower", json(a.getLower())));
77 }
78
79 public static TwoShapeLayout twoShapeLayout(JsonObj json) {
80 return new TwoShapeLayout(dimension(json.getObj("canvas")),
81 layout(json.getObj("upper")),
82 layout(json.getObj("lower")));
83 }
84
85 public static Jsons.Obj json(Layout a) {
86 return obj(p("dimension", json(a.getDimension())),
87 p("offset", json(a.getOffset())));
88 }
89
90 public static Layout layout(JsonObj json) {
91 return new Layout(dimension(json.getObj("dimension")),
92 offset(json.getObj("offset")));
93 }
94
95 public static Jsons.Obj json(HorizontalCoverageLayoutSpec a) {
96 return obj(p("anchorOffset", json(a.getAnchorOffset())),
97 p("horizontalCoverage", a.getHorizontalCoverage()));
98 }
99
100 public static HorizontalCoverageLayoutSpec horizontalCoverageLayoutSpec(JsonObj json) {
101 return new HorizontalCoverageLayoutSpec(anchorOffset(json.getObj("anchorOffset")),
102 json.get(Double.class, "horizontalCoverage"));
103 }
104
105 public static Jsons.Obj json(AbsolutePositionLayoutSpec a) {
106 return obj(p("anchorOffset", json(a.getAnchorOffset())));
107 }
108
109 public static AbsolutePositionLayoutSpec absolutePositionLayoutSpec(JsonObj json) {
110 return new AbsolutePositionLayoutSpec(anchorOffset(json.obj("anchorOffset")));
111 }
112 }