AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
aud.util.DotViewer Class Reference

Simple viewer for Graphvizable. More...

+ Collaboration diagram for aud.util.DotViewer:

Public Member Functions

 DotViewer (JFrame parent)
 create new instance More...
 
JFrame parent ()
 get parent widget More...
 
JLabel statusbar ()
 get status bar More...
 
void display (String code)
 display dot code More...
 
void display (Graphvizable object)
 display object
More...
 
void setExitOnClose ()
 exit application if viewer is closed More...
 

Static Public Member Functions

static void help ()
 print help (mouse/key bindings) to stdout More...
 
static DotViewer displayWindow (Graphvizable object, String caption)
 create new DotViewer (toplevel window) and display object
More...
 
static DotViewer displayWindow (String code, String caption)
 create new DotViewer (toplevel window) and display code
More...
 
static void main (String[] args)
 visualize given dot files (file names as command line arguments) More...
 

Protected Member Functions

JComponent createComponents ()
 

Protected Attributes

File dotfile
 
JFrame frame
 
JSVGCanvas svgCanvas
 
Graphviz graphviz
 
JLabel label
 

Detailed Description

Simple viewer for Graphvizable.

Based on Batik's SVGCanvas.

Usage:

  • Shift+Mouse Left = pan
  • Shift+Mouse Right (drag) = zoom in/out
  • Ctrl+Mouse Left = rectangle zoom
  • Ctrl+Mouse Right (drag) = rotate [disabled]
  • Ctrl+I = zoom in
  • Ctrl+O = zoom out

DotViewer can be used with SingleStepper to visualize progress of an algorithm. GraphDemo shows an example.

See also
SingleStepper

TODO: link GraphDemo

Definition at line 48 of file DotViewer.java.

Constructor & Destructor Documentation

◆ DotViewer()

aud.util.DotViewer.DotViewer ( JFrame  parent)

create new instance

Definition at line 57 of file DotViewer.java.

57 {
59 svgCanvas=new JSVGCanvas();
60 svgCanvas.setEnableRotateInteractor(false);//
61
62 label=new JLabel();
63 parent.getContentPane().add(createComponents());
64
65 try {
66 dotfile=File.createTempFile("aud-dotviewer-",".dot");
67 } catch (IOException e) {
68 System.err.println("ERROR: "+e.getMessage());
69 System.exit(-1);
70 }
71 //System.err.println(dotfile);
72 graphviz=new Graphviz();
73 dotfile.deleteOnExit();
74 }
JComponent createComponents()
Definition: DotViewer.java:81
JSVGCanvas svgCanvas
Definition: DotViewer.java:52
JFrame parent()
get parent widget
Definition: DotViewer.java:77

References aud.util.DotViewer.createComponents(), aud.util.DotViewer.dotfile, aud.util.DotViewer.frame, aud.util.DotViewer.graphviz, aud.util.DotViewer.label, aud.util.DotViewer.parent(), and aud.util.DotViewer.svgCanvas.

+ Here is the call graph for this function:

Member Function Documentation

◆ createComponents()

JComponent aud.util.DotViewer.createComponents ( )
protected

Definition at line 81 of file DotViewer.java.

81 {
82 final JPanel panel = new JPanel(new BorderLayout());
83 @SuppressWarnings("unused")
84 final JSVGScrollPane pane = new JSVGScrollPane(svgCanvas);
85
86 panel.add("Center", svgCanvas);
87 panel.add("South", label);
88 return panel;
89 }

References aud.util.DotViewer.label, and aud.util.DotViewer.svgCanvas.

Referenced by aud.util.DotViewer.DotViewer().

+ Here is the caller graph for this function:

◆ display() [1/2]

void aud.util.DotViewer.display ( Graphvizable  object)

display object

Definition at line 135 of file DotViewer.java.

135 {
136 display(object.toDot());
137 }
void display(String code)
display dot code
Definition: DotViewer.java:108

References aud.util.DotViewer.display().

+ Here is the call graph for this function:

◆ display() [2/2]

void aud.util.DotViewer.display ( String  code)

display dot code

See also
Graphviz

Definition at line 108 of file DotViewer.java.

108 {
109 Sys.writeToFile(dotfile,code);
110 //System.err.println(dotfile);
111 File svgfile=graphviz.renderDotFileToFile(dotfile,"svg");
112 //svgfile.deleteOnExit();
113 //svgCanvas.setURI(svgfile.toURI().toString());
114
115 Path path=FileSystems.getDefault().getPath(svgfile.getPath());
116
117 try {
118 String data=new String(Files.readAllBytes(path));
119 data=data.replaceAll("stroke=\"transparent\"","stroke-opacity=\"0\"");
120
121 String parser=XMLResourceDescriptor.getXMLParserClassName();
122 SAXSVGDocumentFactory factory=new SAXSVGDocumentFactory(parser);
123 SVGDocument document=
124 factory.createSVGDocument("",new ByteArrayInputStream(data.getBytes("UTF-8")));
125 svgCanvas.setDocument(document);
126 } catch (IOException e) {
127 System.err.println(e);
128 System.exit(-1);
129 }
130
131 svgfile.delete();
132 }
File renderDotFileToFile(File dotfile, String format)
Render dot file.
Definition: Graphviz.java:36

References aud.util.DotViewer.dotfile, aud.util.DotViewer.graphviz, aud.util.Graphviz.renderDotFileToFile(), aud.util.DotViewer.svgCanvas, and aud.util.Sys.writeToFile().

Referenced by aud.util.DotViewer.display(), aud.util.DotViewer.displayWindow(), aud.example.BinaryTreeTraversal.onHalt(), aud.example.expr.ExpressionTreeTraversal.onHalt(), and aud.util.SingleStepperDemo.onHalt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ displayWindow() [1/2]

static DotViewer aud.util.DotViewer.displayWindow ( Graphvizable  object,
String  caption 
)
static

create new DotViewer (toplevel window) and display object

Definition at line 140 of file DotViewer.java.

140 {
141 return displayWindow(object.toDot(),caption);
142 }
static DotViewer displayWindow(Graphvizable object, String caption)
create new DotViewer (toplevel window) and display object
Definition: DotViewer.java:140

References aud.util.DotViewer.displayWindow().

Referenced by aud.util.Graphviz.display(), aud.util.DotViewer.displayWindow(), and aud.util.DotViewer.main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ displayWindow() [2/2]

static DotViewer aud.util.DotViewer.displayWindow ( String  code,
String  caption 
)
static

create new DotViewer (toplevel window) and display code

Definition at line 144 of file DotViewer.java.

144 {
145 JFrame f=new JFrame(caption!=null ? caption : "aud.util.DotViewer");
146 DotViewer dot=new DotViewer(f);
147 f.setSize(800, 600);
148 f.setVisible(true);
149 if (code!=null)
150 dot.display(code);
151 return dot;
152 }
DotViewer(JFrame parent)
create new instance
Definition: DotViewer.java:57

References aud.util.DotViewer.display().

+ Here is the call graph for this function:

◆ help()

static void aud.util.DotViewer.help ( )
static

print help (mouse/key bindings) to stdout

Definition at line 92 of file DotViewer.java.

92 {
93 System.out.println
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"+
100 "Ctrl+I\tzoom in\n"+
101 "Ctrl+O\tzoom out\n"
102 );
103 }

Referenced by aud.util.DotViewer.main().

+ Here is the caller graph for this function:

◆ main()

static void aud.util.DotViewer.main ( String[]  args)
static

visualize given dot files (file names as command line arguments)

Definition at line 164 of file DotViewer.java.

164 {
165 if (args.length==0) {
166 System.err.println("usage: java aud.util.DotViewer file.dot\n");
167 DotViewer.help();
168 }
169 else
170 for (String arg : args) {
171 String dotCode=Sys.readFile(new File(arg));
172 DotViewer v=DotViewer.displayWindow(dotCode,arg);
173 v.setExitOnClose();
174 }
175 }

References aud.util.DotViewer.displayWindow(), aud.util.DotViewer.help(), aud.util.Sys.readFile(), and aud.util.DotViewer.setExitOnClose().

+ Here is the call graph for this function:

◆ parent()

JFrame aud.util.DotViewer.parent ( )

get parent widget

Definition at line 77 of file DotViewer.java.

77{ return frame; }

References aud.util.DotViewer.frame.

Referenced by aud.util.DotViewer.DotViewer(), and aud.util.DotViewer.setExitOnClose().

+ Here is the caller graph for this function:

◆ setExitOnClose()

void aud.util.DotViewer.setExitOnClose ( )

exit application if viewer is closed

Definition at line 155 of file DotViewer.java.

155 {
156 parent().addWindowListener(new WindowAdapter() {
157 public void windowClosing(WindowEvent e) {
158 System.exit(0);
159 }
160 });
161 }

References aud.util.DotViewer.parent().

Referenced by aud.util.DotViewer.main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ statusbar()

JLabel aud.util.DotViewer.statusbar ( )

get status bar

Definition at line 79 of file DotViewer.java.

79{ return label; }

References aud.util.DotViewer.label.

Member Data Documentation

◆ dotfile

File aud.util.DotViewer.dotfile
protected

Definition at line 50 of file DotViewer.java.

Referenced by aud.util.DotViewer.display(), and aud.util.DotViewer.DotViewer().

◆ frame

JFrame aud.util.DotViewer.frame
protected

Definition at line 51 of file DotViewer.java.

Referenced by aud.util.DotViewer.DotViewer(), and aud.util.DotViewer.parent().

◆ graphviz

Graphviz aud.util.DotViewer.graphviz
protected

Definition at line 53 of file DotViewer.java.

Referenced by aud.util.DotViewer.display(), and aud.util.DotViewer.DotViewer().

◆ label

JLabel aud.util.DotViewer.label
protected

◆ svgCanvas

JSVGCanvas aud.util.DotViewer.svgCanvas
protected

The documentation for this class was generated from the following file: