//
// $Id: Driver.java,v 1.2 2001/07/17 01:54:19 mdb Exp $

package com.samskivert.viztool;

import java.awt.*;
import java.awt.print.*;

import com.samskivert.viztool.enum.*;
import com.samskivert.viztool.viz.*;

public class Driver
{
    public static void main (String[] args)
    {
        if (args.length < 1) {
            System.err.println("Usage: Driver package_root");
            System.exit(-1);
        }
        String pkgroot = args[0];

        boolean print = false;
        if (args.length > 1) {
            print = (args[1].equals("-print"));
        }

        // run ourselves on the classpath
        String classpath = System.getProperty("java.class.path");
        ClassEnumerator enum = new ClassEnumerator(classpath);

        // print out the warnings
        ClassEnumerator.Warning[] warnings = enum.getWarnings();
        for (int i = 0; i < warnings.length; i++) {
            System.err.println("Warning: " + warnings[i].reason);
        }

        // and finally generate the visualization
        PackageEnumerator penum = new PackageEnumerator(pkgroot, enum, true);
        HierarchyVisualizer viz = new HierarchyVisualizer(pkgroot, penum);

        if (print) {
            // we use the print system to render things
            PrinterJob job = PrinterJob.getPrinterJob();
            // pop up a dialog to format our pages
            // PageFormat format = job.pageDialog(job.defaultPage());
            PageFormat format = job.defaultPage();
            job.setPrintable(viz);
            // pop up a dialog to control printing
            job.printDialog();

            try {
                job.print();
            } catch (PrinterException pe) {
                pe.printStackTrace(System.err);
            }
            System.exit(0);
        } else {
            TestFrame frame = new TestFrame(viz);

            // center the frame in the screen and show it
            Toolkit tk = frame.getToolkit();
            Dimension ss = tk.getScreenSize();
            int width = 640, height = 480;
            frame.setBounds((ss.width-width)/2, (ss.height-height)/2,
                            width, height);
            frame.setVisible(true);
        }
    }
}

@@ -20,17 +20,17 @@
 ava,v 1.
-2
+3
  2001/07
@@ -38,15 +38,15 @@
 17 0
-1:54:19
+5:21:33
  mdb
@@ -355,16 +355,25 @@
 : Driver
+ %5B-print%5D
  package
@@ -411,32 +411,64 @@
 t(-1);%0A        %7D
+%0A%0A        // parse our arguments
 %0A        String 
@@ -481,17 +481,13 @@
 t = 
-args%5B0%5D;%0A
+null;
 %0A   
@@ -514,36 +514,52 @@
  false;%0A        
-if (
+for (int i = 0; i %3C 
 args.length %3E 1)
@@ -557,12 +557,13 @@
 ngth
- %3E 1
+; i++
 ) %7B%0A
@@ -578,23 +578,18 @@
     
-print =
+if
  (args%5B
-1
+i
 %5D.eq
@@ -603,17 +603,139 @@
 print%22))
-;
+ %7B%0A                print = true;%0A            %7D else if (pkgroot == null) %7B%0A                pkgroot = args%5Bi%5D;%0A            %7D
 %0A       
@@ -1472,24 +1472,60 @@
 interJob();%0A
+            job.setPrintable(viz);%0A%0A
             
@@ -1688,42 +1688,8 @@
 ();%0A
-            job.setPrintable(viz);
 %0A   
@@ -1912,32 +1912,143 @@
 );%0A            %7D
+%0A%0A            // printing starts up the AWT threads, so we have to%0A            // explicitly exit at this point
 %0A            Sys
@@ -2060,16 +2060,17 @@
 xit(0);%0A
+%0A
         

Parse arguments less stupidly.