lib/browser/GraphBrowser/Console.java
author wenzelm
Thu, 14 Jul 2005 19:28:20 +0200
changeset 16838 131ca99f6abf
parent 14981 e73f8140af78
child 18018 82206a6c75c0
permissions -rw-r--r--
use existing Inttab;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13968
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
     1
/***************************************************************************
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
     2
  Title:      GraphBrowser/Console.java
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
     3
  ID:         $Id$
13970
4aef7117817b cleanup, comments
kleing
parents: 13968
diff changeset
     4
  Author:     Gerwin Klein, TU Muenchen
13968
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
     5
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
     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
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
     9
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    10
***************************************************************************/
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    11
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    12
package GraphBrowser;
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    13
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    14
import java.io.*;
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    15
import java.util.*;
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    16
import java.net.*;
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    17
import awtUtilities.*;
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    18
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    19
public class Console {
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    20
	Graph g;
13972
fac2aa7618ed fixed uncollapsed dirs (should be collapsed by default)
kleing
parents: 13970
diff changeset
    21
	String gfname;  
13968
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    22
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    23
  public Console(String name) {
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    24
    gfname = name;
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    25
  }
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    26
13970
4aef7117817b cleanup, comments
kleing
parents: 13968
diff changeset
    27
	public void PS(String fname, boolean printable) throws IOException {
13968
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    28
    g.layout(null);
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    29
		g.PS(fname,printable);
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    30
	}
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    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
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    48
	public void initBrowser(InputStream is) {
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    49
		try {
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    50
			TreeNode tn = new TreeNode("Root", "", -1, true);
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    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
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    55
		} catch (IOException exn) {
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    56
			System.err.println("\nI/O error while reading graph file.");
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    57
		} catch (ParseError exn) {
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    58
			System.err.println("\nParse error in graph file:");
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    59
			System.err.println(exn.getMessage());
13970
4aef7117817b cleanup, comments
kleing
parents: 13968
diff changeset
    60
			System.err.println("\nSyntax:\n<vertexname> <vertexID> <dirname> [ + ] <path> "+
4aef7117817b cleanup, comments
kleing
parents: 13968
diff changeset
    61
                         "[ < | > ] [ <vertexID> [ ... [ <vertexID> ] ... ] ] ;");
13968
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    62
		}
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    63
	}
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    64
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    65
	public static void main(String[] args) {
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    66
		try {
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    67
      if (args.length <= 1) {
13970
4aef7117817b cleanup, comments
kleing
parents: 13968
diff changeset
    68
        System.err.println("Graph and output file expected.");
13968
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    69
        return;
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    70
      }
13970
4aef7117817b cleanup, comments
kleing
parents: 13968
diff changeset
    71
13968
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    72
			Console console=new Console(args[0]);
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    73
      InputStream is=new FileInputStream(args[0]);
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    74
      console.initBrowser(is);
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    75
      is.close();      
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    76
    
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    77
      try {
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    78
        if (args[1].endsWith(".ps"))
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    79
          console.PS(args[1], true);
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    80
        else if (args[1].endsWith(".eps"))
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    81
          console.PS(args[1], false);
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    82
        else
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    83
          System.err.println("Unknown file type: " + args[1]);
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    84
      } catch (IOException exn) {
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    85
        System.err.println("Unable to write file " + args[1]);
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    86
      }
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    87
		} catch (IOException exn) {
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    88
			System.err.println("Can't open graph file "+args[0]);
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    89
		}
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    90
	}
689868b99bde eliminated dependencies on AWT for batch mode
kleing
parents:
diff changeset
    91
}