1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.PrintJob;
import java.awt.Toolkit;
import java.util.Properties;
public class JobMan implements Runnable {
LdtPrintManager pm;
boolean done=false;
boolean end=false;
PrintJob pjob = null;
public JobMan(LdtPrintManager pm) {
this.pm=pm;
Thread t = new Thread(this);
t.start();
while (!done) { Thread.yield();}
}
public PrintJob getPjob(){
if (pjob==null) end=true;
return pjob;
}
public void end() {
end=true;
}
LdtPage page = null;
LdtRowCursor documentCursor=null;
LdtRowCursor pageCursor=null;
public void printPage(LdtPage _page, LdtRowCursor documentCursor, LdtRowCursor pageCursor) {
while (page != null) { Thread.yield();}
this.documentCursor=documentCursor;
this.pageCursor=pageCursor;
page = _page;
while (page!=null) { Thread.yield();}
}
private void printPage() {
synchronized(page){
page.displayRowCursor(documentCursor,pageCursor);
Graphics pg = null;
pg = pjob.getGraphics();
pg.clearRect(0,0,1000, 2000);
page.printAll(pg);
pg.dispose();
page = null;
}
}
String documentName = "";
public void run() {
Properties properties = new Properties();
try {
Thread.sleep(2000);
pjob=Toolkit.getDefaultToolkit().getPrintJob(new Frame(),documentName, properties);
}
catch (Throwable t) {
}
done=true;
try{
while (!end) {Thread.yield();
if (page!=null) {
printPage();
}
}
} catch (Throwable t)
{ page = null;
}
if (pjob!=null) {
pjob.end();
pjob.finalize();
}
}
} |
Partager