1/*************************************************************************** 2 Title: GraphBrowser/Console.java 3 Author: Gerwin Klein, TU Muenchen 4 Options: :tabSize=2: 5 6 This is the graph browser's main class when run as a console application. 7 It duplicates some logic from GraphBrowser and GraphView. 8 It does so to remove dependency on AWT. 9 10***************************************************************************/ 11 12package GraphBrowser; 13 14import java.io.*; 15import java.util.*; 16 17public class Console { 18 Graph g; 19 String gfname; 20 21 public Console(String name) { 22 gfname = name; 23 } 24 25 public void PS(String fname, boolean printable) throws IOException { 26 g.layout(null); 27 g.PS(fname,printable); 28 } 29 30 31 public void collapseNodes(Vector collapsedDir) { 32 Enumeration e1=collapsedDir.elements(); 33 Graph gra=(Graph)(g.clone()); 34 35 while (e1.hasMoreElements()) { 36 Directory d=(Directory)(e1.nextElement()); 37 Vector v=gra.decode(d.getCollapsed()); 38 if (!v.isEmpty()) 39 gra.collapse(v,"["+d.getName()+"]",d.getCollapsed()); 40 } 41 42 g = gra; 43 } 44 45 46 public void initBrowser(InputStream is) { 47 try { 48 TreeNode tn = new TreeNode("Root", "", -1, true); 49 g = new Graph(is, tn); 50 Vector v = new Vector(10,10); 51 tn.collapsedDirectories(v); 52 collapseNodes(v); 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()); 58 System.err.println("\nSyntax:\n<vertexname> <vertexID> <dirname> [ + ] <path> "+ 59 "[ < | > ] [ <vertexID> [ ... [ <vertexID> ] ... ] ] ;"); 60 } 61 } 62 63 public static void main(String[] args) { 64 try { 65 if (args.length <= 1) { 66 System.err.println("Graph and output file expected."); 67 return; 68 } 69 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} 90