AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
GraphDemo.java
Go to the documentation of this file.
1package aud.util;
2
3import aud.graph.*;
4
7public class GraphDemo extends SingleStepper {
8
9 protected AbstractGraph<?,?> g = null;
10 protected DotViewer v = DotViewer.displayWindow((String) null,
11 "aud.util.GraphDemo");
12
13 static class MyGraph extends GraphAM<SimpleNode,SimpleEdge> {
14 final GraphvizDecorator decorator = new SimpleDecorator();
15
16 MyGraph() {
17 super(new SimpleNode(),new SimpleEdge(),true);
18 }
19 @Override public GraphvizDecorator getDecorator() {
20 return decorator;
21 }
22 }
23
25 super("aud.util.GraphDemo");
26 this.g=g;
27 }
28
29 protected void onHalt() {
30 if (g!=null)
31 v.display(g);
32 }
33
34 public static void main(String args[]) {
35
36 MyGraph g=new MyGraph();
37 GraphDemo app=new GraphDemo(g);
38
39 SimpleNode n0=g.addNode(); app.halt();
40 SimpleNode n1=g.addNode(); app.halt();
41 SimpleNode n2=g.addNode(); app.halt();
42
43 SimpleEdge e0=g.addEdge(n0,n1); app.whereAmI().showSource().halt("add e0");
44 SimpleEdge e1=g.addEdge(n1,n0); app.halt("add e1");
45
46 SimpleEdge e2=g.addEdge(n0,n2); app.halt("add e2");
47 SimpleEdge e3=g.addEdge(n2,n1); app.halt("add e3");
48
49 System.out.println("n0="+n0);
50 System.out.println("n1="+n1);
51 System.out.println("n2="+n2);
52 System.out.println("e0="+e0);
53 System.out.println("e1="+e1);
54 System.out.println("e2="+e2);
55 System.out.println("e3="+e3);
56
58 decorator.markNode(n0); app.halt();
59 n0.setLabel("A");
60 e0.setLabel("a b c");
61 decorator.markEdge(e0); app.halt();
62 decorator.unmarkNode(n0);
63 decorator.markNode(n1); app.halt();
64 decorator.highlightNode(n2);
65 decorator.highlightEdge(e2); app.halt();
66
67 app.halt("QUIT");
68 System.exit(0);
69 }
70
71}
GraphvizDecorator getDecorator()
get decoration or null
abstract Edge addEdge(Node source, Node destination)
Create and add new edge from source to destination.
abstract Node addNode()
create and add new node
Graph implementation based on adjacency matrix.
Definition: GraphAM.java:15
plain simple edge
Definition: SimpleEdge.java:4
void setLabel(String label)
set label (default label if label==null)
Definition: SimpleEdge.java:17
plain simple node
Definition: SimpleNode.java:4
void setLabel(String label)
set label (default label if label==null)
Definition: SimpleNode.java:16
Simple viewer for Graphvizable.
Definition: DotViewer.java:47
static DotViewer displayWindow(Graphvizable object, String caption)
create new DotViewer (toplevel window) and display object
Definition: DotViewer.java:139
void display(String code)
display dot code
Definition: DotViewer.java:107
Demonstrate visualization of graph algorithms.
Definition: GraphDemo.java:7
AbstractGraph<?,?> g
Definition: GraphDemo.java:9
static void main(String args[])
Definition: GraphDemo.java:34
Decorator for items of Graphvizable objects.
Example for a simple decorator.
void highlightEdge(GraphvizDecorable object)
Set highlighted edge.
void markEdge(GraphvizDecorable object)
void markNode(GraphvizDecorable object)
void unmarkNode(GraphvizDecorable object)
unmark node object
void highlightNode(GraphvizDecorable object)
Set highlighted node.
Simple framework for single stepping code.
SingleStepper whereAmI()
print location of calling code
SingleStepper showSource()
jmp to caller's location in editor (emacs only)
void halt(String text, int timeout)
display text and wait for user or timeout
Graph data structures and algorithms.
AuD lecture: Data structures, algorithms, examples.
Definition: A234Tree.java:1