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;
60 svgCanvas.setEnableRotateInteractor(
false);
66 dotfile=File.createTempFile(
"aud-dotviewer-",
".dot");
67 }
catch (IOException e) {
68 System.err.println(
"ERROR: "+e.getMessage());
82 final JPanel panel =
new JPanel(
new BorderLayout());
83 @SuppressWarnings(
"unused")
84 final JSVGScrollPane pane =
new JSVGScrollPane(
svgCanvas);
87 panel.add(
"South",
label);
92 public static void help() {
94 (
"Batik JSVGCanvas overview\n"+
95 "-------------------------\n"+
96 "Shift+Mouse Left\tpan\n"+
97 "Shift+Mouse Right\tzoom in/out (drag)\n"+
98 "Ctrl+Mouse Left\trectangle zoom\n"+
99 "Ctrl+Mouse Right\trotate [disabled!]\n"+
115 Path path=FileSystems.getDefault().getPath(svgfile.getPath());
118 String data=
new String(Files.readAllBytes(path));
119 data=data.replaceAll(
"stroke=\"transparent\"",
"stroke-opacity=\"0\"");
121 String parser=XMLResourceDescriptor.getXMLParserClassName();
122 SAXSVGDocumentFactory factory=
new SAXSVGDocumentFactory(parser);
123 SVGDocument document=
124 factory.createSVGDocument(
"",
new ByteArrayInputStream(data.getBytes(
"UTF-8")));
126 }
catch (IOException e) {
127 System.err.println(e);
145 JFrame f=
new JFrame(caption!=
null ? caption :
"aud.util.DotViewer");
156 parent().addWindowListener(
new WindowAdapter() {
157 public void windowClosing(WindowEvent e) {
164 public static void main(String[] args) {
165 if (args.length==0) {
166 System.err.println(
"usage: java aud.util.DotViewer file.dot\n");
170 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.