-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
executable file
·60 lines (51 loc) · 2.23 KB
/
Main.java
File metadata and controls
executable file
·60 lines (51 loc) · 2.23 KB
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
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import org.multigraph.*;
public class Main {
private static void setAxisOrientations(Graph graph) {
for (HorizontalAxis haxis : graph.getHorizontalaxis()) {
haxis.setOrientation(AxisOrientation.HORIZONTAL);
}
for (VerticalAxis haxis : graph.getVerticalaxis()) {
haxis.setOrientation(AxisOrientation.VERTICAL);
}
for (Graph childgraph : graph.getGraph()) {
setAxisOrientations(childgraph);
}
}
public static void main(String[] args) {
try {
JAXBContext jc = JAXBContext.newInstance("org.multigraph");
Unmarshaller u = jc.createUnmarshaller();
JAXBElement mugle = (JAXBElement) u.unmarshal( new FileInputStream("multigraph.xml"));
Graph graph = (Graph) mugle.getValue();
setAxisOrientations(graph);
if (graph.getGraph().size() > 0) {
graph = graph.getGraph().get(0);
}
System.out.printf("horizontal axes:\n");
for (Axis axis : graph.getHorizontalaxis()) {
System.out.printf(" id='%s' min='%3d' max='%3d' orientation='%s'\n",
axis.getId(), axis.getMin(), axis.getMax(), axis.getOrientation());
}
System.out.printf("vertical axes:\n");
for (Axis axis : graph.getVerticalaxis()) {
System.out.printf(" id='%s' min='%3d' max='%3d' orientation='%s'\n",
axis.getId(), axis.getMin(), axis.getMax(), axis.getOrientation());
}
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(mugle, System.out);
} catch (JAXBException je) {
je.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}