Updated old driver to deal with the new deal.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@497 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2001-12-03 08:53:45 +00:00
parent 5309e8649d
commit 594ef4f482
@@ -1,5 +1,5 @@
//
// $Id: DriverTask.java,v 1.1 2001/12/03 08:34:53 mdb Exp $
// $Id: DriverTask.java,v 1.2 2001/12/03 08:53:45 mdb Exp $
//
// viztool - a tool for visualizing collections of java classes
// Copyright (C) 2001 Michael Bayne
@@ -20,9 +20,21 @@
package com.samskivert.viztool;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Destination;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import org.apache.tools.ant.AntClassLoader;
@@ -69,6 +81,11 @@ public class DriverTask extends Task
_classes = classes;
}
public void setOutput (File output)
{
_output = output;
}
public Path createClasspath ()
{
return _cmdline.createClasspath(project).createPath();
@@ -79,11 +96,21 @@ public class DriverTask extends Task
*/
public void execute () throws BuildException
{
// make sure everything was set up properly
ensureSet(_vizclass, "Must specify the visualizer class " +
"via the 'visualizer' attribute.");
ensureSet(_pkgroot, "Must specify the package root " +
"via the 'pkgroot' attribute.");
ensureSet(_pkgroot, "Must specify the class regular expression " +
"via the 'classes' attribute.");
Path classpath = _cmdline.getClasspath();
ensureSet(classpath, "Must provide a <classpath> subelement " +
"describing the classpath to be searched for classes.");
// initialize the font picker
FontPicker.init(false);
FontPicker.init(_output != null);
// create the classloader we'll use to load the visualized classes
Path classpath = _cmdline.getClasspath();
ClassLoader cl = new AntClassLoader(null, project, classpath, false);
// scan the classpath and determine which classes will be
@@ -135,25 +162,72 @@ public class DriverTask extends Task
viz.setPackageRoot(_pkgroot);
viz.setClasses(classes.iterator());
VizFrame frame = new VizFrame(viz);
frame.pack();
SwingUtil.centerWindow(frame);
frame.setVisible(true);
// if no output file was specified, pop up a window
if (_output == null) {
VizFrame frame = new VizFrame(viz);
frame.pack();
SwingUtil.centerWindow(frame);
frame.setVisible(true);
// prevent ant from kicking the JVM out from under us
synchronized (this) {
while (true) {
try {
wait();
} catch (InterruptedException ie) {
// prevent ant from kicking the JVM out from under us
synchronized (this) {
while (true) {
try {
wait();
} catch (InterruptedException ie) {
}
}
}
} else {
// we use the print system to render things
PrinterJob job = PrinterJob.getPrinterJob();
// use sensible margins
PageFormat format = job.defaultPage();
Paper paper = new Paper();
paper.setImageableArea(72*0.5, 72*0.5, 72*7.5, 72*10);
format.setPaper(paper);
// use our configured page format
job.setPrintable(viz, format);
// tell our printjob to print to a file
PrintRequestAttributeSet attrs =
new HashPrintRequestAttributeSet();
String outpath = _output.getPath();
try {
URI target = new URI("file:" + outpath);
attrs.add(new Destination(target));
} catch (URISyntaxException use) {
String errmsg = "Can't create URI for 'output' file path? " +
"[output=" + outpath + "].";
throw new BuildException(errmsg, use);
}
// invoke the printing process
try {
log("Generating visualization to '" + outpath + "'.");
job.print(attrs);
} catch (PrinterException pe) {
throw new BuildException("Error printing visualization.", pe);
}
}
}
protected void ensureSet (Object value, String errmsg)
throws BuildException
{
if (value == null) {
throw new BuildException(errmsg);
}
}
protected String _vizclass;
protected String _pkgroot;
protected String _classes;
protected File _output;
// use use this for accumulating our classpath
protected CommandlineJava _cmdline = new CommandlineJava();