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