Results 1 to 2 of 2
  1. #1
    pjmorce is offline Member
    Join Date
    Nov 2008
    Posts
    17
    Rep Power
    0

    Default 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.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,252
    Rep Power
    19

Similar Threads

  1. add an undo listener to a Jtable
    By christina in forum Advanced Java
    Replies: 12
    Last Post: 01-29-2009, 07:47 AM
  2. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM
  3. Regarding Listener
    By adeeb in forum AWT / Swing
    Replies: 2
    Last Post: 06-20-2008, 11:07 PM
  4. Regarding Listener
    By adeeb in forum AWT / Swing
    Replies: 2
    Last Post: 06-10-2008, 02:00 AM
  5. Listener for SWT event
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-08-2008, 09:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •