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