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
|
PrintJobManagment(DocPrintJob job) {
job.addPrintJobListener(new PrintJobAdapter() {
public void printDataTransferCompleted(PrintJobEvent pje) {
System.out.println("-> " + PrintStatus.DATA_TRANSFERT_COMPLETED);
}
public void printJobCanceled(PrintJobEvent pje) {
System.out.println("-> " + PrintStatus.CANCELED);
setStatus(PrintStatus.CANCELED);
}
public void printJobCompleted(PrintJobEvent pje) {
// The print job was completed
System.out.println("-> " + PrintStatus.COMPLETED);
setStatus(PrintStatus.COMPLETED);
}
public void printJobFailed(PrintJobEvent pje) {
// The print job has failed
System.out.println("-> " + PrintStatus.FAILED);
setStatus(PrintStatus.FAILED);
}
public void printJobNoMoreEvents(PrintJobEvent pje) {
// No more events will be delivered from this
// print service for this print job.
// This event is fired in cases where the print service
// is not able to determine when the job completes.
System.out.println("-> " + PrintStatus.NO_MORE_EVENTS);
setStatus(PrintStatus.NO_MORE_EVENTS);
}
public void printJobRequiresAttention(PrintJobEvent pje) {
// The print service requires some attention to repair
// some problem.
// Example: running out of paper would cause this event
// to be fired.
System.out.println("-> " + PrintStatus.REQUIRES_ATTENTION);
setStatus(PrintStatus.REQUIRES_ATTENTION);
}
void setStatus(int iStatus) {
synchronized (PrintJobManagment.this) {
iResult = iStatus;
System.out.println("IRESULT: " + iStatus);
PrintJobManagment.this.notify();
}
}
});
}
public synchronized int waitForDone() {
try {
while (iResult==0 || iResult == 1 || iResult == 5) {
wait();
}
} catch (InterruptedException e) {
}
return iResult;
} |
Partager