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
GraphDemo

Definition at line 47 of file DotViewer.java.

Constructor & Destructor Documentation

◆ DotViewer()

aud.util.DotViewer.DotViewer ( JFrame  parent)

create new instance

Definition at line 56 of file DotViewer.java.

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

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 80 of file DotViewer.java.

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

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 134 of file DotViewer.java.

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

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 107 of file DotViewer.java.

107 {
108 Sys.writeToFile(dotfile,code);
109 //System.err.println(dotfile);
110 File svgfile=graphviz.renderDotFileToFile(dotfile,"svg");
111 //svgfile.deleteOnExit();
112 //svgCanvas.setURI(svgfile.toURI().toString());
113
114 Path path=FileSystems.getDefault().getPath(svgfile.getPath());
115
116 try {
117 String data=new String(Files.readAllBytes(path));
118 data=data.replaceAll("stroke=\"transparent\"","stroke-opacity=\"0\"");
119
120 String parser=XMLResourceDescriptor.getXMLParserClassName();
121 SAXSVGDocumentFactory factory=new SAXSVGDocumentFactory(parser);
122 SVGDocument document=
123 factory.createSVGDocument("",new ByteArrayInputStream(data.getBytes("UTF-8")));
124 svgCanvas.setDocument(document);
125 } catch (IOException e) {
126 System.err.println(e);
127 System.exit(-1);
128 }
129
130 svgfile.delete();
131 }
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.A234TreeExample.onHalt(), aud.example.AVLTreeExample.onHalt(), aud.example.BinarySearchTreeExample.onHalt(), aud.example.BinaryTreeTraversal.onHalt(), aud.example.BTreeExample.onHalt(), aud.example.expr.ExpressionTreeTraversal.onHalt(), aud.example.graph.MaxFlowExample.onHalt(), aud.example.graph.TraversalExample.onHalt(), aud.example.RedBlackTreeExample.onHalt(), aud.util.GraphDemo.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 139 of file DotViewer.java.

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

References aud.util.DotViewer.displayWindow().

Referenced by aud.util.Graphviz.display(), aud.util.DotViewer.displayWindow(), aud.example.graph.GraphParser.main(), 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 143 of file DotViewer.java.

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

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 91 of file DotViewer.java.

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

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 163 of file DotViewer.java.

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

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 76 of file DotViewer.java.

76{ 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 154 of file DotViewer.java.

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

References aud.util.DotViewer.parent().

Referenced by aud.example.graph.GraphParser.main(), and 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 78 of file DotViewer.java.

78{ return label; }

References aud.util.DotViewer.label.

Member Data Documentation

◆ dotfile

File aud.util.DotViewer.dotfile
protected

Definition at line 49 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 50 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 52 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: