4import java.awt.event.*;
6import java.nio.file.Files;
7import java.nio.file.Path;
8import java.nio.file.FileSystems;
12import org.apache.batik.swing.JSVGCanvas;
13import org.apache.batik.swing.JSVGScrollPane;
14import org.apache.batik.util.XMLResourceDescriptor;
16import org.apache.batik.anim.dom.SAXSVGDocumentFactory;
17import org.apache.batik.dom.svg.*;
18import org.apache.batik.anim.dom.*;
19import org.w3c.dom.svg.SVGDocument;
59 svgCanvas.setEnableRotateInteractor(
false);
65 dotfile=File.createTempFile(
"aud-dotviewer-",
".dot");
66 }
catch (IOException e) {
67 System.err.println(
"ERROR: "+e.getMessage());
81 final JPanel panel =
new JPanel(
new BorderLayout());
82 @SuppressWarnings(
"unused")
83 final JSVGScrollPane pane =
new JSVGScrollPane(
svgCanvas);
86 panel.add(
"South",
label);
91 public static void help() {
93 (
"Batik JSVGCanvas overview\n"+
94 "-------------------------\n"+
95 "Shift+Mouse Left\tpan\n"+
96 "Shift+Mouse Right\tzoom in/out (drag)\n"+
97 "Ctrl+Mouse Left\trectangle zoom\n"+
98 "Ctrl+Mouse Right\trotate [disabled!]\n"+
114 Path path=FileSystems.getDefault().getPath(svgfile.getPath());
117 String data=
new String(Files.readAllBytes(path));
118 data=data.replaceAll(
"stroke=\"transparent\"",
"stroke-opacity=\"0\"");
120 String parser=XMLResourceDescriptor.getXMLParserClassName();
121 SAXSVGDocumentFactory factory=
new SAXSVGDocumentFactory(parser);
122 SVGDocument document=
123 factory.createSVGDocument(
"",
new ByteArrayInputStream(data.getBytes(
"UTF-8")));
125 }
catch (IOException e) {
126 System.err.println(e);
144 JFrame f=
new JFrame(caption!=
null ? caption :
"aud.util.DotViewer");
155 parent().addWindowListener(
new WindowAdapter() {
156 public void windowClosing(WindowEvent e) {
163 public static void main(String[] args) {
164 if (args.length==0) {
165 System.err.println(
"usage: java aud.util.DotViewer file.dot\n");
169 for (String arg : args) {
Simple viewer for Graphvizable.
JComponent createComponents()
static DotViewer displayWindow(String code, String caption)
create new DotViewer (toplevel window) and display code
void display(Graphvizable object)
display object
static void main(String[] args)
visualize given dot files (file names as command line arguments)
static DotViewer displayWindow(Graphvizable object, String caption)
create new DotViewer (toplevel window) and display object
void display(String code)
display dot code
JLabel statusbar()
get status bar
JFrame parent()
get parent widget
void setExitOnClose()
exit application if viewer is closed
static void help()
print help (mouse/key bindings) to stdout
DotViewer(JFrame parent)
create new instance
Use GraphViz to render graph structures.
File renderDotFileToFile(File dotfile, String format)
Render dot file.
System related utilities.
static File writeToFile(File file, String text)
write text to file @endiliteral
static String readFile(File file)
read entire file and return contents as String
Interface for GraphViz rendering.