Results 1 to 2 of 2
Thread: Listener for print job
- 11-12-2008, 08:32 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 17
- Rep Power
- 0
Listener for print job
Hello,
I have a java program that print files. I am using javax.print classes.
Eveything works fine.
I have made a Listener to control il the printing job ends correctly or not.
I am trying to define when:
- the file is printed correctly
- the print job is canceled
- the print job has failed
- the printer require attention (e.g. needs paper)
Here is the code:
PrintJobManagment(DocPrintJob job) {
// Add a listener to the print job
job.addPrintJobListener(new PrintJobAdapter() {
public void printDataTransferCompleted(PrintJobEvent pje) {
// The print data has been transferred to the print service
System.out.println("-> 1");
}
public void printJobCanceled(PrintJobEvent pje) {
// The print job was cancelled
System.out.println("-> 2");
setStatus(2);
}
public void printJobCompleted(PrintJobEvent pje) {
// The print job was completed
System.out.println("-> 3");
setStatus(3);
}
public void printJobFailed(PrintJobEvent pje) {
// The print job has failed
System.out.println("-> 4");
setStatus(4);
}
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("-> 5");
setStatus(5);
}
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("-> 6");
setStatus(6);
}
void setStatus(int iStatus) {
synchronized (PrintJobManagment.this) {
iResult = iStatus;
System.out.println("IRESULT: " + iStatus);
PrintJobManagment.this.notify();
}
}
});
}
/*
* This method is used to wait until the job has an event that will terminate it.
*/
public synchronized int waitForDone() {
try {
// If no event were executed or if only the data transfert event were
// launched executed or if the canceled job event were launched there
// is nothing to be done.
while (iResult==0)
wait();
} catch (InterruptedException e) {
}
return iResult;
}
However, every time, the printJobNoMoreEvents is executed. It means that the print service cannot determine the status of the current job.
Why this is happening?
What can I do for the print service be able to control the job status?
thanks
regards.Last edited by pjmorce; 11-13-2008 at 03:02 PM.
- 11-14-2008, 08:02 AM #2
Similar Threads
-
add an undo listener to a Jtable
By christina in forum Advanced JavaReplies: 12Last Post: 01-29-2009, 07:47 AM -
Print the text file and print preview them
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 11:04 PM -
Regarding Listener
By adeeb in forum AWT / SwingReplies: 2Last Post: 06-20-2008, 11:07 PM -
Regarding Listener
By adeeb in forum AWT / SwingReplies: 2Last Post: 06-10-2008, 02:00 AM -
Listener for SWT event
By Java Tip in forum Java TipReplies: 0Last Post: 01-08-2008, 09:04 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks