import java.awt.Canvas;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.JFrame;
/* 21 November 2001, 9pm - */
/* 22 November 2001, 10pm - 11:30pm */
/* 23 November 2001, 10pm - 11:30pm */
/* 24 November 2001, 9pm - 1:30am */
/* 25 November 2001, on and off during the day. */
class Generate extends JFrame {
// This part is all about showing the thumbnails as they are created.
static Generate frame = new Generate();
Image theImage;
Canvas canvas;
int w = 200;
int h = 200;
public Generate() {
super("Thumbnail");
Container container = getContentPane();
container.setBackground(Color.white);
container.setForeground(Color.black);
canvas = new Canvas() {
public synchronized void paint(Graphics g) {
if (theImage != null)
g.drawImage(theImage,
(int) (w - theImage.getWidth(null)) / 2,
(int) (h - theImage.getHeight(null)) / 2, this);
else
super.paint(g);
}
};
canvas.setSize(new Dimension(w, h));
container.add(canvas);
pack();
setVisible(true);
}
// Thumbnails, after creation, call this to
// show themselves.
static void putImage(Image img) {
frame.theImage = img;
frame.canvas.repaint();
}
public static void main(String[] args) {
// Read in index.txt, and for each line of the form
// TYPE base
// process file base.txt,
// in combination with subdirectory base
//
// Will receive all the pictures, what have you.
Vector v = new Vector();
try {
System.gc();
BufferedReader in = new BufferedReader(new FileReader("index.txt"));
int lineno = 0;
String s = in.readLine();
while (s != null) {
PictureParameters pictureParameters = new PictureParameters();
// process lines of the form "TYPE pagename"
lineno++;
StringTokenizer stok = new StringTokenizer(s);
String type = null;
String base = null;
try {
type = stok.nextToken();
} catch (NoSuchElementException ex) {
s = in.readLine();
continue; // ignore blank lines
}
try {
base = stok.nextToken();
} catch (NoSuchElementException ex) {
System.err
.println("Line "
+ lineno
+ " contained only one word instead of type and pagename");
s = in.readLine();
continue;
}
while (stok.hasMoreTokens()) {
String tok = stok.nextToken();
int eq = tok.indexOf('=');
if (eq > 0) {
String sym = tok.substring(0, eq);
String val = tok.substring(eq + 1);
Utility.set(pictureParameters, sym, val);
}
}
System.out.println(pictureParameters.toString());
if (type.equalsIgnoreCase("pictures")) {
Pictures p = new Pictures(base, pictureParameters);
if (p.error != null) {
System.err.println(p.error);
} else {
v.add(p);
}
} else if (type.equalsIgnoreCase("wordypictures")) {
Pictures p = new WordyPictures(base, pictureParameters);
if (p.error != null) {
System.err.println(p.error);
} else {
v.add(p);
}
} else if (type.equalsIgnoreCase("pageslides")) {
PageSlides p = new PageSlides(base, pictureParameters);
if (p.error != null) {
System.err.println(p.error);
} else {
v.add(p);
}
} else if (type.equalsIgnoreCase("text")) {
TextPage p = new TextPage(base, pictureParameters);
if (p.error != null) {
System.err.println(p.error);
} else {
v.add(p);
}
} else if (type.equalsIgnoreCase("directory")) {
Directory p = new Directory(base, pictureParameters);
if (p.error != null) {
System.err.println(p.error);
} else {
v.add(p);
}
} else {
System.err.println("Line " + lineno
+ " began with unknown type " + type);
}
s = in.readLine();
}
} catch (Throwable ex) {
ex.printStackTrace();
}
try {
// Eventually, this will depend on what pages get made.
for (int i = 0; i < v.size(); i++) {
AbstractPage p = (AbstractPage) (v.elementAt(i));
makePage(v, p);
}
makePage(v, new Index(new PictureParameters(), "index"));
} catch (Throwable ex) {
ex.printStackTrace();
}
System.out.print(" zip -9 website.zip");
for (String s : LogsCreatedFiles.manifest) {
System.out.print(" \"" + s + "\"");
}
System.out.println();
System.exit(0);
}
/**
* @param v
* @param p
* @throws IOException
*/
private static void makePage(Vector v, AbstractPage p) throws IOException {
Template t;
if (p instanceof TextPage || p instanceof PageSlides) {
t = new NavTemplate((Template) null, v, p.title, /*
* rhs
* padding
*/
true);
} else {
t = new NavTemplate((Template) null, v, p.title);
}
if (p.pictureParameters.style != null)
t.bodyStyle = p.pictureParameters.style;
p.makePage(t);
}
}