Listening for Print Service Status Changes - Java 2D Graphics

Java examples for 2D Graphics:Print

Description

Listening for Print Service Status Changes

Demo Code


import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.Attribute;
import javax.print.event.PrintServiceAttributeEvent;
import javax.print.event.PrintServiceAttributeListener;

public class Main {
  public static void main(String[] args) {
    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
    for (int i = 0; i < services.length; i++) {
      services[i].addPrintServiceAttributeListener(new MyPrintServiceAttributeListener());
    }/* ww  w .  j a  v a 2  s  . c om*/
  }
}

class MyPrintServiceAttributeListener implements PrintServiceAttributeListener {
  public void attributeUpdate(PrintServiceAttributeEvent psae) {
    PrintService service = psae.getPrintService();

    Attribute[] attrs = psae.getAttributes().toArray();
    for (int i = 0; i < attrs.length; i++) {
      String attrName = attrs[i].getName();

      String attrValue = attrs[i].toString();
      //process(service, attrName, attrValue);
    }
  }
}

Related Tutorials