Blame |
Last modification |
View Log
| RSS feed
/*
* Copyright (C) 2014 Steve Ratcliffe
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 or
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
package test.svg.subdiv;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
/**
* Convert a nod file to svg to show the routing relationships.
*
* @author Steve Ratcliffe
*/
public class Main
{
private static final String USAGE_MSG =
"Usage: div2svg [--level <n>] <filename>\n" +
"By default divisions at level 0 are shown";
private SvgDivDoc doc
;
/**
* Create an XML document.
*/
private void createDoc
() {
doc =
new SvgDivDoc
();
doc.
createDoc();
}
/**
* Write the document.
*/
private void writeDoc
() {
doc.
setTransform(doc.
getLeftOffset(), doc.
getTopOffset());
try {
OutputFormat fmt = OutputFormat.
createPrettyPrint();
XMLWriter output =
new XMLWriter
(new FileWriter(new File("out.svg")), fmt
);
output.
write(doc.
getDoc());
output.
close();
} catch (IOException e
) {
e.
printStackTrace();
}
}
private void run
(String[] args
) {
createDoc
();
String name =
null;
int level =
0;
int i =
0;
while (i
< args.
length) {
String s = args
[i
];
if (s.
startsWith("--level")) {
level =
Integer.
parseInt(args
[++i
]);
} else {
name = s
;
}
i++
;
}
if (name ==
null)
System.
out.
println(USAGE_MSG
);
// Draw the route network
DivDisp divDisp =
new DivDisp
(doc
);
divDisp.
run(name, level
);
writeDoc
();
}
public static void main
(String[] args
) {
if (args.
length < 1) {
System.
err.
println(USAGE_MSG
);
System.
exit(1);
}
Main main =
new Main
();
main.
run(args
);
}
}