001: /*
002: * Author: Chris Seguin
003: *
004: * This software has been developed under the copyleft
005: * rules of the GNU General Public License. Please
006: * consult the GNU General Public License for more
007: * details about use and distribution of this software.
008: */
009: package org.acm.seguin.print.text;
010:
011: import java.io.*;
012: import java.awt.print.*;
013: import org.acm.seguin.util.FileSettings;
014: import org.acm.seguin.util.MissingSettingsException;
015: import org.acm.seguin.awt.ExceptionPrinter;
016:
017: /**
018: * Places the print operations in a separate thread
019: *
020: *@author Chris Seguin
021: *@created August 6, 1999
022: */
023: public class PrintingThread extends Thread {
024: private String data;
025: private LinePrinter printer;
026: private String filename;
027:
028: /**
029: * Constructor for the PrintingThread object
030: *
031: *@param filename Description of Parameter
032: *@param init Description of Parameter
033: *@param printer Description of Parameter
034: */
035: public PrintingThread(String filename, String init,
036: LinePrinter printer) {
037: data = init;
038: this .printer = printer;
039: this .filename = filename;
040: }
041:
042: /**
043: * This is where the work actually gets done
044: */
045: public void run() {
046: PrinterJob job = PrinterJob.getPrinterJob();
047: Book book = new Book();
048: // Cover Page goes here
049: // Package picture
050: TextPagePrinter textpp = new TextPagePrinter(filename, data,
051: printer);
052: loadDefaults(textpp);
053: PageFormat pf = TextPagePrinter.getPageFormat(false);
054: if (pf == null) {
055: pf = TextPagePrinter.getPageFormat(true);
056: }
057:
058: int count = textpp.calculatePageCount(pf);
059: book.append(textpp, pf, count);
060: job.setPageable(book);
061: if (job.printDialog()) {
062: try {
063: job.print();
064: } catch (Throwable ex) {
065: ExceptionPrinter.print(ex, false);
066: }
067: }
068: }
069:
070: /**
071: * Description of the Method
072: *
073: *@param textpp Description of Parameter
074: */
075: private void loadDefaults(TextPagePrinter textpp) {
076: try {
077: FileSettings bundle = FileSettings
078: .getRefactorySettings("printing");
079: textpp.setTextFontSize(Integer.parseInt(bundle
080: .getString("text.font.size")));
081: textpp.setBetweenLineSpacing(Integer.parseInt(bundle
082: .getString("text.space")));
083: textpp.setFilenameFontSize(Integer.parseInt(bundle
084: .getString("filename.font.size")));
085: textpp.setDatePageCountFontSize(Integer.parseInt(bundle
086: .getString("date.font.size")));
087: } catch (MissingSettingsException mre) {
088: ExceptionPrinter.print(mre, false);
089: } catch (NumberFormatException inf) {
090: ExceptionPrinter.print(inf, false);
091: }
092: }
093:
094: /**
095: * The main program for the PrintingThread class
096: *
097: *@param args The command line arguments
098: */
099: public static void main(String[] args) {
100: try {
101: FileReader in = new FileReader(args[0]);
102: BufferedReader input = new BufferedReader(in);
103: StringBuffer all = new StringBuffer();
104:
105: String line = input.readLine();
106: while (line != null) {
107: all.append(line);
108: all.append("\n");
109: line = input.readLine();
110: }
111:
112: input.close();
113: (new PrintingThread(args[0], all.toString(),
114: new LinePrinter())).run();
115: } catch (IOException ioe) {
116: ExceptionPrinter.print(ioe, false);
117: }
118: }
119: }
|