author | wenzelm |
Thu, 14 Jul 2005 19:28:20 +0200 | |
changeset 16838 | 131ca99f6abf |
parent 14981 | e73f8140af78 |
child 18018 | 82206a6c75c0 |
permissions | -rw-r--r-- |
13968 | 1 |
/*************************************************************************** |
2 |
Title: GraphBrowser/Console.java |
|
3 |
ID: $Id$ |
|
13970 | 4 |
Author: Gerwin Klein, TU Muenchen |
13968 | 5 |
|
6 |
This is the graph browser's main class when run as a console application. |
|
13972
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
7 |
It duplicates some logic from GraphBrowser and GraphView. |
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
8 |
It does so to remove dependency on AWT. |
13968 | 9 |
|
10 |
***************************************************************************/ |
|
11 |
||
12 |
package GraphBrowser; |
|
13 |
||
14 |
import java.io.*; |
|
15 |
import java.util.*; |
|
16 |
import java.net.*; |
|
17 |
import awtUtilities.*; |
|
18 |
||
19 |
public class Console { |
|
20 |
Graph g; |
|
13972
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
21 |
String gfname; |
13968 | 22 |
|
23 |
public Console(String name) { |
|
24 |
gfname = name; |
|
25 |
} |
|
26 |
||
13970 | 27 |
public void PS(String fname, boolean printable) throws IOException { |
13968 | 28 |
g.layout(null); |
29 |
g.PS(fname,printable); |
|
30 |
} |
|
31 |
||
13972
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
32 |
|
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
33 |
public void collapseNodes(Vector collapsedDir) { |
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
34 |
Enumeration e1=collapsedDir.elements(); |
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
35 |
Graph gra=(Graph)(g.clone()); |
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
36 |
|
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
37 |
while (e1.hasMoreElements()) { |
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
38 |
Directory d=(Directory)(e1.nextElement()); |
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
39 |
Vector v=gra.decode(d.getCollapsed()); |
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
40 |
if (!v.isEmpty()) |
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
41 |
gra.collapse(v,"["+d.getName()+"]",d.getCollapsed()); |
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
42 |
} |
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
43 |
|
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
44 |
g = gra; |
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
45 |
} |
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
46 |
|
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
47 |
|
13968 | 48 |
public void initBrowser(InputStream is) { |
49 |
try { |
|
50 |
TreeNode tn = new TreeNode("Root", "", -1, true); |
|
51 |
g = new Graph(is, tn); |
|
13972
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
52 |
Vector v = new Vector(10,10); |
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
53 |
tn.collapsedDirectories(v); |
fac2aa7618ed
fixed uncollapsed dirs (should be collapsed by default)
kleing
parents:
13970
diff
changeset
|
54 |
collapseNodes(v); |
13968 | 55 |
} catch (IOException exn) { |
56 |
System.err.println("\nI/O error while reading graph file."); |
|
57 |
} catch (ParseError exn) { |
|
58 |
System.err.println("\nParse error in graph file:"); |
|
59 |
System.err.println(exn.getMessage()); |
|
13970 | 60 |
System.err.println("\nSyntax:\n<vertexname> <vertexID> <dirname> [ + ] <path> "+ |
61 |
"[ < | > ] [ <vertexID> [ ... [ <vertexID> ] ... ] ] ;"); |
|
13968 | 62 |
} |
63 |
} |
|
64 |
||
65 |
public static void main(String[] args) { |
|
66 |
try { |
|
67 |
if (args.length <= 1) { |
|
13970 | 68 |
System.err.println("Graph and output file expected."); |
13968 | 69 |
return; |
70 |
} |
|
13970 | 71 |
|
13968 | 72 |
Console console=new Console(args[0]); |
73 |
InputStream is=new FileInputStream(args[0]); |
|
74 |
console.initBrowser(is); |
|
75 |
is.close(); |
|
76 |
||
77 |
try { |
|
78 |
if (args[1].endsWith(".ps")) |
|
79 |
console.PS(args[1], true); |
|
80 |
else if (args[1].endsWith(".eps")) |
|
81 |
console.PS(args[1], false); |
|
82 |
else |
|
83 |
System.err.println("Unknown file type: " + args[1]); |
|
84 |
} catch (IOException exn) { |
|
85 |
System.err.println("Unable to write file " + args[1]); |
|
86 |
} |
|
87 |
} catch (IOException exn) { |
|
88 |
System.err.println("Can't open graph file "+args[0]); |
|
89 |
} |
|
90 |
} |
|
91 |
} |