Example usage for javax.print StreamPrintService getSupportedAttributeValues

List of usage examples for javax.print StreamPrintService getSupportedAttributeValues

Introduction

In this page you can find the example usage for javax.print StreamPrintService getSupportedAttributeValues.

Prototype

public Object getSupportedAttributeValues(Class<? extends Attribute> category, DocFlavor flavor,
        AttributeSet attributes);

Source Link

Document

Determines the printing attribute values a client can specify in the given category when setting up a job for this print service.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps"));
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor,
            DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());

    StreamPrintService service = factories[0].getPrintService(fos);
    Class category = OrientationRequested.class;
    Object o = service.getSupportedAttributeValues(category, null, null);
    if (o == null) {
        System.out.println("Attribute is not supported");
    } else if (o.getClass() == category) {
        System.out.println("irrelevant");
    } else if (o.getClass().isArray()) {
        System.out.println("array");
        for (int i = 0; i < Array.getLength(o); i++) {
            Object v = Array.get(o, i);
            System.out.println(v);
        }/*  w  w  w  .j  a  v a  2  s.co m*/
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps"));
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor,
            DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());

    StreamPrintService service = factories[0].getPrintService(fos);
    Class[] cats = service.getSupportedAttributeCategories();
    for (int j = 0; j < cats.length; j++) {
        Attribute attr = (Attribute) service.getDefaultAttributeValue(cats[j]);

        if (attr != null) {
            String attrName = attr.getName();
            String attrValue = attr.toString();

            Object o = service.getSupportedAttributeValues(attr.getCategory(), null, null);
            if (o.getClass().isArray()) {
                for (int k = 0; k < Array.getLength(o); k++) {
                    Object o2 = Array.get(o, k);
                    System.out.println(o2);
                }/*from   w  w  w.j a  v a2  s.c  o m*/
            }
        }
    }
}