The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.print.event  [3 examples]

e715. Listening for Print Job Attribute Changes

Status changes that are common to all print jobs are delivered through a print job listener; see e714 Listening for Print Job Status Changes. However, if a print service supports a status that is not supported by the print job listener (e.g., JobMediaSheetsCompleted), it delivers status changes through a print job attribute listener.
    // Create the print job
    DocPrintJob job = service.createPrintJob();
    PrintJobAttributeSet set = new HashPrintJobAttributeSet(job.getAttributes());
    set.add(new JobMediaSheetsCompleted(0));
    job.addPrintJobAttributeListener(new MyPrintJobAttributeListener(), set);
    
    class MyPrintJobAttributeListener implements PrintJobAttributeListener {
        public void attributeUpdate(PrintJobAttributeEvent pjae) {
            // Get the set of attributes that have changed
            Attribute[] attrs = pjae.getAttributes().toArray();
    
            for (int i=0; i<attrs.length; i++) {
                String attrName = attrs[i].getName();
                String attrValue = attrs[i].toString();
                process(pjae, attrName, attrValue);
            }
        }
    }

 Related Examples
e713. Listening for Print Service Status Changes
e714. Listening for Print Job Status Changes


© 2002 Addison-Wesley.