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