forked from sbgn/libsbgn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadExampleWithRender.java
124 lines (99 loc) · 3.13 KB
/
ReadExampleWithRender.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package org.sbgn;
import java.io.File;
import javax.xml.bind.JAXBException;
import javax.xml.transform.TransformerException;
import org.sbgn.SbgnUtil;
import org.sbgn.bindings.Arc;
import org.sbgn.bindings.ColorDefinition;
import org.sbgn.bindings.Glyph;
import org.sbgn.bindings.LinearGradient;
import org.sbgn.bindings.Map;
import org.sbgn.bindings.RenderInformation;
import org.sbgn.bindings.Sbgn;
import org.sbgn.bindings.Style;
public class ReadExampleWithRender
{
private static void printRenderInfo(RenderInformation ri)
{
if (ri == null)
{
System.out.println("no render info");
return;
}
if (ri.getBackgroundColor() != null && ri.getBackgroundColor().length() > 0)
{
System.out.println(String.format(" background color: %s", ri.getBackgroundColor()));
}
if (ri.getListOfColorDefinitions() != null)
{
for (ColorDefinition cd : ri.getListOfColorDefinitions().getColorDefinition())
{
System.out.println(String.format(" color def: %s = %s", cd.getId(), cd.getValue()));
}
}
if (ri.getListOfGradientDefinitions() != null)
{
for (LinearGradient grad : ri.getListOfGradientDefinitions().getLinearGradient())
{
System.out.println(String.format(" grad def: %s = # %d stops", grad.getId(), grad.getStop().size()));
}
}
if (ri.getListOfStyles() != null)
{
for (Style style : ri.getListOfStyles().getStyle())
{
System.out.println(String.format(" style def: applies to ids: %s and types: %s", style.getIdList(), style.getTypeList()));
}
}
}
public static void main(String[] args) throws JAXBException, TransformerException
{
// our sbgnml file goes in "f"
String fileName = "../test-files/PD/adh.sbgn";
if (args.length > 0)
fileName = args[0];
File f = new File (fileName);
// Now read from "f" and put the result in "sbgn"
Sbgn sbgn = SbgnUtil.readFromFile(f);
// map is a container for the glyphs and arcs
Map map = sbgn.getMap().get(0);
RenderInformation ri = RenderUtil.getRenderInformation(map);
if (ri == null)
{
System.out.println("This file contains no render information.");
return;
}
else
{
printRenderInfo(ri);
}
// we can get a list of glyphs (nodes) in this map with getGlyph()
for (Glyph g : map.getGlyph())
{
// print the sbgn class of this glyph
System.out.print (" Glyph with class " + g.getId());
// if there is a label, print it as well
if (g.getLabel() != null)
System.out.print (", and label " + g.getLabel().getText());
else
System.out.print (", without label");
// lets see if we have a render style for it
Style style = RenderUtil.getStyle(ri, g);
if (style != null)
{
System.out.println (String.format(", with style: fill: %s, stroke: %s, stroke-width: %f",
RenderUtil.getStyleProperty(style, "fill"), RenderUtil.getStyleProperty(style, "stroke"),
RenderUtil.getStyleProperty(style, "strokeWidth")));
}
else{
System.out.println (", without style");
}
}
// we can get a list of arcs (edges) in this map with getArc()
for (Arc a : map.getArc())
{
// print the class of this arc
System.out.println (" Arc with class " + a.getClazz());
}
}
}