1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.yaml.snakeyaml.immutable;
17
18 import java.awt.Insets;
19 import java.awt.Rectangle;
20 import java.util.Arrays;
21
22 import javax.swing.border.MatteBorder;
23
24 import org.yaml.snakeyaml.nodes.Node;
25 import org.yaml.snakeyaml.nodes.Tag;
26 import org.yaml.snakeyaml.representer.Represent;
27 import org.yaml.snakeyaml.representer.Representer;
28
29 public class ImmutablesRepresenter extends Representer {
30
31 public ImmutablesRepresenter() {
32 super();
33 this.representers.put(java.awt.Color.class, new RepresentColor());
34 this.representers.put(Insets.class, new RepresentInsets());
35 this.representers.put(MatteBorder.class, new RepresentMatteBorder());
36 this.representers.put(Rectangle.class, new RepresentRectangle());
37 }
38
39 class RepresentInsets implements Represent {
40
41 public Node representData(Object data) {
42 Insets insets = (Insets) data;
43 return representSequence(
44 getTag(data.getClass(), new Tag(data.getClass())),
45 Arrays.asList(new Object[] { insets.top, insets.left, insets.bottom,
46 insets.right }), true);
47 }
48
49 }
50
51 class RepresentRectangle implements Represent {
52
53 public Node representData(Object data) {
54 Rectangle rect = (Rectangle) data;
55 return representSequence(getTag(data.getClass(), new Tag(data.getClass())),
56 Arrays.asList(new Object[] { rect.x, rect.y, rect.width, rect.height }), true);
57 }
58
59 }
60
61 class RepresentMatteBorder implements Represent {
62
63 public Node representData(Object data) {
64 MatteBorder mb = (MatteBorder) data;
65 return representSequence(getTag(data.getClass(), new Tag(data.getClass())),
66 Arrays.asList(new Object[] { mb.getBorderInsets(), mb.getMatteColor() }), true);
67 }
68
69 }
70
71 class RepresentColor implements Represent {
72
73 public Node representData(Object data) {
74 java.awt.Color color = (java.awt.Color) data;
75 return representSequence(
76 getTag(data.getClass(), new Tag(data.getClass())),
77 Arrays.asList(new Integer[] { color.getRed(), color.getGreen(),
78 color.getBlue(), color.getAlpha() }), true);
79 }
80
81 }
82 }