1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package coras.representations;
22
23 import java.awt.Component;
24
25 import no.sintef.assetrepository.Representation;
26
27 import org.apache.batik.swing.JSVGCanvas;
28 import org.w3c.dom.Document;
29 import org.w3c.dom.Node;
30
31
32
33 /***
34 * @author fvr
35 *
36 * TODO To change the template for this generated type comment go to
37 * Window - Preferences - Java - Code Style - Code Templates
38 */
39 public class SVGImage extends DiagramRepresentation implements XmlRepresentation {
40
41 private JSVGCanvas canvas = null;
42
43 /***
44 * @param representation
45 */
46 protected SVGImage(Representation representation) {
47 super(representation);
48 }
49
50
51
52
53 public synchronized Component getUIComponent() {
54 if (canvas == null) {
55 Node content = getXmlContent();
56 canvas = createUIComponent(content);
57 }
58 return canvas;
59 }
60
61
62
63
64 public Node getXmlContent() {
65 Object content = getContent();
66 if (content == null || content instanceof Node) {
67 return (Node) content;
68 } else {
69 return null;
70 }
71 }
72
73 public static JSVGCanvas createUIComponent(Node content) {
74 Document doc;
75 if (content instanceof Document) {
76 doc = (Document) content;
77 } else {
78 doc = content.getOwnerDocument();
79 }
80 JSVGCanvas c = new JSVGCanvas();
81 c.setDocument(doc);
82 return c;
83 }
84
85 }