Java 类javax.print.attribute.standard.MediaName 实例源码

项目:cn1    文件:LookupMultiDocPrintServicesTest.java   
public void testLookupMultiDocPrintServices() throws Exception {
    System.out
            .println("============= START LookupMultiDocPrintServicesTest ================");

    DocFlavor psFlavor = DocFlavor.INPUT_STREAM.GIF;
    MultiDocPrintService[] services;
    FileInputStream fis;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    HashDocAttributeSet daset = new HashDocAttributeSet();
    DocPrintJob pj;
    Doc doc;

    aset.add(new Copies(2));
    aset.add(MediaSizeName.ISO_A4);
    daset.add(MediaName.ISO_A4_WHITE);
    daset.add(Sides.TWO_SIDED_LONG_EDGE);

    services = PrintServiceLookup.lookupMultiDocPrintServices(
            new DocFlavor[] { psFlavor }, aset);
    if (services != null && services.length > 0) {
        fis = new FileInputStream("/Resources/1M.GIF");
        doc = new SimpleDoc(fis, psFlavor, daset);

        pj = services[0].createPrintJob();
        pj.print(doc, aset);
        System.out.println(fis.toString() + " printed on "
                + services[0].getName());
    } else {
        System.out.println("services not found");
    }

    System.out.println("============= END LookupMultiDocPrintServicesTest ================");
}
项目:cn1    文件:LookupDefaultPrintServiceTest.java   
public void testLookupDefaultPrintService() throws Exception {
    System.out
            .println("======= START LookupDefaultPrintServiceTest ======");

    DocFlavor psFlavor = DocFlavor.INPUT_STREAM.GIF;
    PrintService service;
    InputStream fis;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    HashDocAttributeSet daset = new HashDocAttributeSet();
    DocPrintJob pj;
    Doc doc;

    aset.add(new Copies(2));
    aset.add(MediaSizeName.ISO_A4);
    daset.add(MediaName.ISO_A4_WHITE);
    daset.add(Sides.TWO_SIDED_LONG_EDGE);

    service = PrintServiceLookup.lookupDefaultPrintService();
    if (service != null) {
        if (service.isDocFlavorSupported(psFlavor)) {
            if (service.getUnsupportedAttributes(psFlavor, aset)==null) {
                fis = this.getClass().getResourceAsStream(
                        "/Resources/GIF.gif");
                doc = new SimpleDoc(fis, psFlavor, daset);

                pj = service.createPrintJob();
                pj.print(doc, aset);
                System.out.println(fis.toString() + " printed on "
                        + service.getName());
            }
        } else {
            System.out.println("flavor is not supported");
        }
    } else {
        System.out.println("service not found");
    }

    System.out.println("======= END LookupDefaultPrintServiceTest =======");
}
项目:cn1    文件:ValueTests.java   
public void testSimpleDoc() {
    startTest("SimpleDoc class testing...");

    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    InputStream reader =
            getClass().getResourceAsStream("/Resources/picture.gif");
    if (reader == null) {
        fail("/Resources/picture.gif resource is not found!");
    }

    DocAttributeSet aSet = new HashDocAttributeSet();
    Doc doc = new SimpleDoc(reader, flavor, aSet);

    assertEquals(doc.getAttributes(), aSet);
    aSet.add(OrientationRequested.LANDSCAPE);
    aSet.add(MediaName.NA_LETTER_WHITE);
    assertEquals(doc.getAttributes(), aSet);
    assertEquals(doc.getDocFlavor(), DocFlavor.INPUT_STREAM.GIF);
    try {
        assertTrue(doc.getPrintData() instanceof java.io.InputStream);
        assertNull(doc.getReaderForText());
        assertEquals(doc.getStreamForBytes(), reader);
    } catch(Exception e) {
        e.printStackTrace();
        fail("Exception found: "+e);
    }
}
项目:cn1    文件:ValueTests.java   
public void testHashPrintRequestAttributeSet() {
    startTest("HashPrintRequestAttributeSet class testing...");

    Copies copies = new Copies(2);
    PrintRequestAttributeSet set1 = new HashPrintRequestAttributeSet();
    PrintRequestAttributeSet set2 = new HashPrintRequestAttributeSet(copies);
    PrintRequestAttributeSet set3 = new HashPrintRequestAttributeSet(set2);
    PrintRequestAttribute [] arr = {copies, 
                                    MediaName.NA_LETTER_WHITE};
    PrintRequestAttributeSet set4 = new HashPrintRequestAttributeSet(arr);
    Attribute [] attrArr = set1.toArray();

    assertTrue(set1.isEmpty());
    assertFalse(set2.isEmpty());
    assertTrue(set3.equals(set2));
    assertFalse(set3.equals(set1));
    set3.clear();
    assertEquals(set3, set1);
    set3.add(copies);
    set3.add(MediaName.NA_LETTER_WHITE);
    assertTrue(set3.containsKey(copies.getClass()));
    assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass()));
    assertTrue(set3.containsValue(copies));
    assertFalse(set3.containsValue(OrientationRequested.PORTRAIT));
    assertFalse(set3.containsValue(PrintQuality.DRAFT));
    assertEquals(set1.size(), 0);
    assertEquals(set2.size(), 1);
    assertEquals(set3.size(), 2);
    assertTrue(set4.equals(set3));
    assertEquals(set3.get(copies.getClass()), copies);
    set1.addAll(set3);
    assertEquals(set3, set1);
    set1.remove(copies.getClass());
    assertEquals(set1.size(), 1);
    attrArr = set1.toArray();
    assertEquals(attrArr.length, 1);
    assertEquals(attrArr[0], MediaName.NA_LETTER_WHITE);
}
项目:cn1    文件:ValueTests.java   
public void testHashPrintServiceAttributeSet() {
    startTest("HashPrintJobAttributeSet class testing...");

    PrintServiceAttributeSet set1 = new HashPrintServiceAttributeSet();
    PrintServiceAttributeSet set2 = new HashPrintServiceAttributeSet(
            ColorSupported.SUPPORTED);
    PrintServiceAttributeSet set3 = new HashPrintServiceAttributeSet(set2);
    PrinterLocation location = new PrinterLocation("room 222", Locale.ENGLISH);
    PrintServiceAttribute [] arr = { location, 
                                     ColorSupported.SUPPORTED };
    PrintServiceAttributeSet set4 = new HashPrintServiceAttributeSet(arr);

    assertTrue(set1.isEmpty());
    assertFalse(set2.isEmpty());
    assertTrue(set3.equals(set2));
    assertFalse(set3.equals(set1));
    set3.clear();
    assertEquals(set3, set1);
    set3.add(ColorSupported.SUPPORTED);
    set3.add(location);
    assertTrue(set3.containsKey(location.getClass()));
    assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass()));
    assertTrue(set4.equals(set3));
    assertEquals(set3.get(location.getClass()), location);
    set1.addAll(set3);
    assertEquals(set3, set1);
    set1.remove(location.getClass());
    assertEquals(set1.size(), 1);
}
项目:freeVM    文件:LookupMultiDocPrintServicesTest.java   
public void testLookupMultiDocPrintServices() {
    System.out
            .println("============= START LookupMultiDocPrintServicesTest ================");

    DocFlavor psFlavor = DocFlavor.INPUT_STREAM.GIF;
    MultiDocPrintService[] services;
    FileInputStream fis;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    HashDocAttributeSet daset = new HashDocAttributeSet();
    DocPrintJob pj;
    Doc doc;

    aset.add(new Copies(2));
    aset.add(MediaSizeName.ISO_A4);
    daset.add(MediaName.ISO_A4_WHITE);
    daset.add(Sides.TWO_SIDED_LONG_EDGE);

    try {
        services = PrintServiceLookup.lookupMultiDocPrintServices(
                new DocFlavor[] { psFlavor }, aset);
        if (services != null && services.length > 0) {
            fis = new FileInputStream("/Resources/1M.GIF");
            doc = new SimpleDoc(fis, psFlavor, daset);

            pj = services[0].createPrintJob();
            pj.print(doc, aset);
            System.out.println(fis.toString() + " printed on "
                    + services[0].getName());
        } else {
            System.out.println("services not found");
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }

    System.out
            .println("============= END LookupMultiDocPrintServicesTest ================");
}
项目:freeVM    文件:ValueTests.java   
public void testSimpleDoc() {
    startTest("SimpleDoc class testing...");

    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    InputStream reader =
            getClass().getResourceAsStream("/Resources/picture.gif");
    if (reader == null) {
        fail("/Resources/picture.gif resource is not found!");
    }

    DocAttributeSet aSet = new HashDocAttributeSet();
    Doc doc = new SimpleDoc(reader, flavor, aSet);

    assertEquals(doc.getAttributes(), aSet);
    aSet.add(OrientationRequested.LANDSCAPE);
    aSet.add(MediaName.NA_LETTER_WHITE);
    assertEquals(doc.getAttributes(), aSet);
    assertEquals(doc.getDocFlavor(), DocFlavor.INPUT_STREAM.GIF);
    try {
        assertTrue(doc.getPrintData() instanceof java.io.InputStream);
        assertNull(doc.getReaderForText());
        assertEquals(doc.getStreamForBytes(), reader);
    } catch(Exception e) {
        e.printStackTrace();
        fail("Exception found: "+e);
    }
}
项目:freeVM    文件:ValueTests.java   
public void testHashPrintRequestAttributeSet() {
    startTest("HashPrintRequestAttributeSet class testing...");

    Copies copies = new Copies(2);
    PrintRequestAttributeSet set1 = new HashPrintRequestAttributeSet();
    PrintRequestAttributeSet set2 = new HashPrintRequestAttributeSet(copies);
    PrintRequestAttributeSet set3 = new HashPrintRequestAttributeSet(set2);
    PrintRequestAttribute [] arr = {copies, 
                                    MediaName.NA_LETTER_WHITE};
    PrintRequestAttributeSet set4 = new HashPrintRequestAttributeSet(arr);
    Attribute [] attrArr = set1.toArray();

    assertTrue(set1.isEmpty());
    assertFalse(set2.isEmpty());
    assertTrue(set3.equals(set2));
    assertFalse(set3.equals(set1));
    set3.clear();
    assertEquals(set3, set1);
    set3.add(copies);
    set3.add(MediaName.NA_LETTER_WHITE);
    assertTrue(set3.containsKey(copies.getClass()));
    assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass()));
    assertTrue(set3.containsValue(copies));
    assertFalse(set3.containsValue(OrientationRequested.PORTRAIT));
    assertFalse(set3.containsValue(PrintQuality.DRAFT));
    assertEquals(set1.size(), 0);
    assertEquals(set2.size(), 1);
    assertEquals(set3.size(), 2);
    assertTrue(set4.equals(set3));
    assertEquals(set3.get(copies.getClass()), copies);
    set1.addAll(set3);
    assertEquals(set3, set1);
    set1.remove(copies.getClass());
    assertEquals(set1.size(), 1);
    attrArr = set1.toArray();
    assertEquals(attrArr.length, 1);
    assertEquals(attrArr[0], MediaName.NA_LETTER_WHITE);
}
项目:freeVM    文件:ValueTests.java   
public void testHashPrintServiceAttributeSet() {
    startTest("HashPrintJobAttributeSet class testing...");

    PrintServiceAttributeSet set1 = new HashPrintServiceAttributeSet();
    PrintServiceAttributeSet set2 = new HashPrintServiceAttributeSet(
            ColorSupported.SUPPORTED);
    PrintServiceAttributeSet set3 = new HashPrintServiceAttributeSet(set2);
    PrinterLocation location = new PrinterLocation("room 222", Locale.ENGLISH);
    PrintServiceAttribute [] arr = { location, 
                                     ColorSupported.SUPPORTED };
    PrintServiceAttributeSet set4 = new HashPrintServiceAttributeSet(arr);

    assertTrue(set1.isEmpty());
    assertFalse(set2.isEmpty());
    assertTrue(set3.equals(set2));
    assertFalse(set3.equals(set1));
    set3.clear();
    assertEquals(set3, set1);
    set3.add(ColorSupported.SUPPORTED);
    set3.add(location);
    assertTrue(set3.containsKey(location.getClass()));
    assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass()));
    assertTrue(set4.equals(set3));
    assertEquals(set3.get(location.getClass()), location);
    set1.addAll(set3);
    assertEquals(set3, set1);
    set1.remove(location.getClass());
    assertEquals(set1.size(), 1);
}
项目:freeVM    文件:LookupMultiDocPrintServicesTest.java   
public void testLookupMultiDocPrintServices() throws Exception {
    System.out
            .println("============= START LookupMultiDocPrintServicesTest ================");

    DocFlavor psFlavor = DocFlavor.INPUT_STREAM.GIF;
    MultiDocPrintService[] services;
    FileInputStream fis;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    HashDocAttributeSet daset = new HashDocAttributeSet();
    DocPrintJob pj;
    Doc doc;

    aset.add(new Copies(2));
    aset.add(MediaSizeName.ISO_A4);
    daset.add(MediaName.ISO_A4_WHITE);
    daset.add(Sides.TWO_SIDED_LONG_EDGE);

    services = PrintServiceLookup.lookupMultiDocPrintServices(
            new DocFlavor[] { psFlavor }, aset);
    if (services != null && services.length > 0) {
        fis = new FileInputStream("/Resources/1M.GIF");
        doc = new SimpleDoc(fis, psFlavor, daset);

        pj = services[0].createPrintJob();
        pj.print(doc, aset);
        System.out.println(fis.toString() + " printed on "
                + services[0].getName());
    } else {
        System.out.println("services not found");
    }

    System.out.println("============= END LookupMultiDocPrintServicesTest ================");
}
项目:freeVM    文件:LookupDefaultPrintServiceTest.java   
public void testLookupDefaultPrintService() throws Exception {
    System.out
            .println("======= START LookupDefaultPrintServiceTest ======");

    DocFlavor psFlavor = DocFlavor.INPUT_STREAM.GIF;
    PrintService service;
    InputStream fis;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    HashDocAttributeSet daset = new HashDocAttributeSet();
    DocPrintJob pj;
    Doc doc;

    aset.add(new Copies(2));
    aset.add(MediaSizeName.ISO_A4);
    daset.add(MediaName.ISO_A4_WHITE);
    daset.add(Sides.TWO_SIDED_LONG_EDGE);

    service = PrintServiceLookup.lookupDefaultPrintService();
    if (service != null) {
        if (service.isDocFlavorSupported(psFlavor)) {
            if (service.getUnsupportedAttributes(psFlavor, aset)==null) {
                fis = this.getClass().getResourceAsStream(
                        "/Resources/GIF.gif");
                doc = new SimpleDoc(fis, psFlavor, daset);

                pj = service.createPrintJob();
                pj.print(doc, aset);
                System.out.println(fis.toString() + " printed on "
                        + service.getName());
            }
        } else {
            System.out.println("flavor is not supported");
        }
    } else {
        System.out.println("service not found");
    }

    System.out.println("======= END LookupDefaultPrintServiceTest =======");
}
项目:freeVM    文件:ValueTests.java   
public void testSimpleDoc() {
    startTest("SimpleDoc class testing...");

    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    InputStream reader =
            getClass().getResourceAsStream("/Resources/picture.gif");
    if (reader == null) {
        fail("/Resources/picture.gif resource is not found!");
    }

    DocAttributeSet aSet = new HashDocAttributeSet();
    Doc doc = new SimpleDoc(reader, flavor, aSet);

    assertEquals(doc.getAttributes(), aSet);
    aSet.add(OrientationRequested.LANDSCAPE);
    aSet.add(MediaName.NA_LETTER_WHITE);
    assertEquals(doc.getAttributes(), aSet);
    assertEquals(doc.getDocFlavor(), DocFlavor.INPUT_STREAM.GIF);
    try {
        assertTrue(doc.getPrintData() instanceof java.io.InputStream);
        assertNull(doc.getReaderForText());
        assertEquals(doc.getStreamForBytes(), reader);
    } catch(Exception e) {
        e.printStackTrace();
        fail("Exception found: "+e);
    }
}
项目:freeVM    文件:ValueTests.java   
public void testHashPrintRequestAttributeSet() {
    startTest("HashPrintRequestAttributeSet class testing...");

    Copies copies = new Copies(2);
    PrintRequestAttributeSet set1 = new HashPrintRequestAttributeSet();
    PrintRequestAttributeSet set2 = new HashPrintRequestAttributeSet(copies);
    PrintRequestAttributeSet set3 = new HashPrintRequestAttributeSet(set2);
    PrintRequestAttribute [] arr = {copies, 
                                    MediaName.NA_LETTER_WHITE};
    PrintRequestAttributeSet set4 = new HashPrintRequestAttributeSet(arr);
    Attribute [] attrArr = set1.toArray();

    assertTrue(set1.isEmpty());
    assertFalse(set2.isEmpty());
    assertTrue(set3.equals(set2));
    assertFalse(set3.equals(set1));
    set3.clear();
    assertEquals(set3, set1);
    set3.add(copies);
    set3.add(MediaName.NA_LETTER_WHITE);
    assertTrue(set3.containsKey(copies.getClass()));
    assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass()));
    assertTrue(set3.containsValue(copies));
    assertFalse(set3.containsValue(OrientationRequested.PORTRAIT));
    assertFalse(set3.containsValue(PrintQuality.DRAFT));
    assertEquals(set1.size(), 0);
    assertEquals(set2.size(), 1);
    assertEquals(set3.size(), 2);
    assertTrue(set4.equals(set3));
    assertEquals(set3.get(copies.getClass()), copies);
    set1.addAll(set3);
    assertEquals(set3, set1);
    set1.remove(copies.getClass());
    assertEquals(set1.size(), 1);
    attrArr = set1.toArray();
    assertEquals(attrArr.length, 1);
    assertEquals(attrArr[0], MediaName.NA_LETTER_WHITE);
}
项目:freeVM    文件:ValueTests.java   
public void testHashPrintServiceAttributeSet() {
    startTest("HashPrintJobAttributeSet class testing...");

    PrintServiceAttributeSet set1 = new HashPrintServiceAttributeSet();
    PrintServiceAttributeSet set2 = new HashPrintServiceAttributeSet(
            ColorSupported.SUPPORTED);
    PrintServiceAttributeSet set3 = new HashPrintServiceAttributeSet(set2);
    PrinterLocation location = new PrinterLocation("room 222", Locale.ENGLISH);
    PrintServiceAttribute [] arr = { location, 
                                     ColorSupported.SUPPORTED };
    PrintServiceAttributeSet set4 = new HashPrintServiceAttributeSet(arr);

    assertTrue(set1.isEmpty());
    assertFalse(set2.isEmpty());
    assertTrue(set3.equals(set2));
    assertFalse(set3.equals(set1));
    set3.clear();
    assertEquals(set3, set1);
    set3.add(ColorSupported.SUPPORTED);
    set3.add(location);
    assertTrue(set3.containsKey(location.getClass()));
    assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass()));
    assertTrue(set4.equals(set3));
    assertEquals(set3.get(location.getClass()), location);
    set1.addAll(set3);
    assertEquals(set3, set1);
    set1.remove(location.getClass());
    assertEquals(set1.size(), 1);
}
项目:cn1    文件:ValueTests.java   
public void testHashDocAttributeSet() {
    startTest("HashDocAttributeSet class testing...");

    DocAttributeSet set1 = new HashDocAttributeSet();
    DocAttributeSet set2 = 
        new HashDocAttributeSet(OrientationRequested.LANDSCAPE);
    DocAttributeSet set3 = new HashDocAttributeSet(set2);
    DocAttribute [] arr = {OrientationRequested.LANDSCAPE,
                           MediaName.NA_LETTER_WHITE};
    DocAttributeSet set4 = new HashDocAttributeSet(arr);
    Attribute [] attrArr;

    assertTrue(set1.isEmpty());
    assertFalse(set2.isEmpty());
    assertTrue(set3.equals(set2));
    assertFalse(set3.equals(set1));
    set3.clear();
    assertEquals(set3, set1);
    set3.add(OrientationRequested.LANDSCAPE);
    set3.add(MediaName.NA_LETTER_WHITE);
    assertTrue(set3.containsKey(OrientationRequested.LANDSCAPE.getClass()));
    assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass()));
    assertTrue(set3.containsValue(OrientationRequested.LANDSCAPE));
    assertFalse(set3.containsValue(OrientationRequested.PORTRAIT));
    assertFalse(set3.containsValue(PrintQuality.DRAFT));
    assertEquals(set1.size(), 0);
    assertEquals(set2.size(), 1);
    assertEquals(set3.size(), 2);
    assertTrue(set4.equals(set3));
    assertEquals(set3.get(OrientationRequested.PORTRAIT.getClass()),
                 OrientationRequested.LANDSCAPE);
    assertFalse((set3.get(OrientationRequested.PORTRAIT.getClass()))
            .equals(OrientationRequested.PORTRAIT));
    set1.addAll(set3);
    assertEquals(set3, set1);
    set1.remove(OrientationRequested.PORTRAIT.getClass());
    assertEquals(set1.size(), 1);
    attrArr = set1.toArray();
    assertEquals(attrArr.length, 1);
    assertEquals(attrArr[0], MediaName.NA_LETTER_WHITE);
}
项目:cn1    文件:ValueTests.java   
public void testHashPrintJobAttributeSet() {
    startTest("HashPrintJobAttributeSet class testing...");

    PrintJobAttributeSet set1 = new HashPrintJobAttributeSet();
    PrintJobAttributeSet set2 = 
        new HashPrintJobAttributeSet(OrientationRequested.LANDSCAPE);
    PrintJobAttributeSet set3 = new HashPrintJobAttributeSet(set2);
    PrintJobAttribute [] arr = {OrientationRequested.LANDSCAPE,
                                MediaName.NA_LETTER_WHITE};
    PrintJobAttributeSet set4 = new HashPrintJobAttributeSet(arr);
    Attribute [] attrArr;

    assertTrue(set1.isEmpty());
    assertFalse(set2.isEmpty());
    assertTrue(set3.equals(set2));
    assertFalse(set3.equals(set1));
    set3.clear();
    assertEquals(set3, set1);
    set3.add(OrientationRequested.LANDSCAPE);
    set3.add(MediaName.NA_LETTER_WHITE);
    assertTrue(set3.containsKey(OrientationRequested.LANDSCAPE.getClass()));
    assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass()));
    assertTrue(set3.containsValue(OrientationRequested.LANDSCAPE));
    assertFalse(set3.containsValue(OrientationRequested.PORTRAIT));
    assertFalse(set3.containsValue(PrintQuality.DRAFT));
    assertEquals(set1.size(), 0);
    assertEquals(set2.size(), 1);
    assertEquals(set3.size(), 2);
    assertTrue(set4.equals(set3));
    assertEquals(set3.get(OrientationRequested.PORTRAIT.getClass()),
                 OrientationRequested.LANDSCAPE);
    assertFalse((set3.get(OrientationRequested.PORTRAIT.getClass()))
            .equals(OrientationRequested.PORTRAIT));
    set1.addAll(set3);
    assertEquals(set3, set1);
    set1.remove(OrientationRequested.PORTRAIT.getClass());
    assertEquals(set1.size(), 1);
    attrArr = set1.toArray();
    assertEquals(attrArr.length, 1);
    assertEquals(attrArr[0], MediaName.NA_LETTER_WHITE);
}
项目:freeVM    文件:LookupDefaultPrintServiceTest.java   
public void testLookupDefaultPrintService() {
    System.out
            .println("======= START LookupDefaultPrintServiceTest ======");

    DocFlavor psFlavor = DocFlavor.INPUT_STREAM.GIF;
    PrintService service;
    InputStream fis;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    HashDocAttributeSet daset = new HashDocAttributeSet();
    DocPrintJob pj;
    Doc doc;

    aset.add(new Copies(2));
    aset.add(MediaSizeName.ISO_A4);
    daset.add(MediaName.ISO_A4_WHITE);
    daset.add(Sides.TWO_SIDED_LONG_EDGE);

    try {
        service = PrintServiceLookup.lookupDefaultPrintService();
        if (service != null) {
            if (service.isDocFlavorSupported(psFlavor)) {
                if (service.getUnsupportedAttributes(psFlavor, aset)==null) {
                    fis = this.getClass().getResourceAsStream(
                            "/Resources/GIF.gif");
                    doc = new SimpleDoc(fis, psFlavor, daset);

                    pj = service.createPrintJob();
                    pj.print(doc, aset);
                    System.out.println(fis.toString() + " printed on "
                            + service.getName());
                }
            } else {
                System.out.println("flavor is not supported");
            }
        } else {
            System.out.println("service not found");
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }

    System.out.println("======= END LookupDefaultPrintServiceTest =======");
}
项目:freeVM    文件:ValueTests.java   
public void testHashDocAttributeSet() {
    startTest("HashDocAttributeSet class testing...");

    DocAttributeSet set1 = new HashDocAttributeSet();
    DocAttributeSet set2 = 
        new HashDocAttributeSet(OrientationRequested.LANDSCAPE);
    DocAttributeSet set3 = new HashDocAttributeSet(set2);
    DocAttribute [] arr = {OrientationRequested.LANDSCAPE,
                           MediaName.NA_LETTER_WHITE};
    DocAttributeSet set4 = new HashDocAttributeSet(arr);
    Attribute [] attrArr;

    assertTrue(set1.isEmpty());
    assertFalse(set2.isEmpty());
    assertTrue(set3.equals(set2));
    assertFalse(set3.equals(set1));
    set3.clear();
    assertEquals(set3, set1);
    set3.add(OrientationRequested.LANDSCAPE);
    set3.add(MediaName.NA_LETTER_WHITE);
    assertTrue(set3.containsKey(OrientationRequested.LANDSCAPE.getClass()));
    assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass()));
    assertTrue(set3.containsValue(OrientationRequested.LANDSCAPE));
    assertFalse(set3.containsValue(OrientationRequested.PORTRAIT));
    assertFalse(set3.containsValue(PrintQuality.DRAFT));
    assertEquals(set1.size(), 0);
    assertEquals(set2.size(), 1);
    assertEquals(set3.size(), 2);
    assertTrue(set4.equals(set3));
    assertEquals(set3.get(OrientationRequested.PORTRAIT.getClass()),
                 OrientationRequested.LANDSCAPE);
    assertFalse((set3.get(OrientationRequested.PORTRAIT.getClass()))
            .equals(OrientationRequested.PORTRAIT));
    set1.addAll(set3);
    assertEquals(set3, set1);
    set1.remove(OrientationRequested.PORTRAIT.getClass());
    assertEquals(set1.size(), 1);
    attrArr = set1.toArray();
    assertEquals(attrArr.length, 1);
    assertEquals(attrArr[0], MediaName.NA_LETTER_WHITE);
}
项目:freeVM    文件:ValueTests.java   
public void testHashPrintJobAttributeSet() {
    startTest("HashPrintJobAttributeSet class testing...");

    PrintJobAttributeSet set1 = new HashPrintJobAttributeSet();
    PrintJobAttributeSet set2 = 
        new HashPrintJobAttributeSet(OrientationRequested.LANDSCAPE);
    PrintJobAttributeSet set3 = new HashPrintJobAttributeSet(set2);
    PrintJobAttribute [] arr = {OrientationRequested.LANDSCAPE,
                                MediaName.NA_LETTER_WHITE};
    PrintJobAttributeSet set4 = new HashPrintJobAttributeSet(arr);
    Attribute [] attrArr;

    assertTrue(set1.isEmpty());
    assertFalse(set2.isEmpty());
    assertTrue(set3.equals(set2));
    assertFalse(set3.equals(set1));
    set3.clear();
    assertEquals(set3, set1);
    set3.add(OrientationRequested.LANDSCAPE);
    set3.add(MediaName.NA_LETTER_WHITE);
    assertTrue(set3.containsKey(OrientationRequested.LANDSCAPE.getClass()));
    assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass()));
    assertTrue(set3.containsValue(OrientationRequested.LANDSCAPE));
    assertFalse(set3.containsValue(OrientationRequested.PORTRAIT));
    assertFalse(set3.containsValue(PrintQuality.DRAFT));
    assertEquals(set1.size(), 0);
    assertEquals(set2.size(), 1);
    assertEquals(set3.size(), 2);
    assertTrue(set4.equals(set3));
    assertEquals(set3.get(OrientationRequested.PORTRAIT.getClass()),
                 OrientationRequested.LANDSCAPE);
    assertFalse((set3.get(OrientationRequested.PORTRAIT.getClass()))
            .equals(OrientationRequested.PORTRAIT));
    set1.addAll(set3);
    assertEquals(set3, set1);
    set1.remove(OrientationRequested.PORTRAIT.getClass());
    assertEquals(set1.size(), 1);
    attrArr = set1.toArray();
    assertEquals(attrArr.length, 1);
    assertEquals(attrArr[0], MediaName.NA_LETTER_WHITE);
}
项目:freeVM    文件:ValueTests.java   
public void testHashDocAttributeSet() {
    startTest("HashDocAttributeSet class testing...");

    DocAttributeSet set1 = new HashDocAttributeSet();
    DocAttributeSet set2 = 
        new HashDocAttributeSet(OrientationRequested.LANDSCAPE);
    DocAttributeSet set3 = new HashDocAttributeSet(set2);
    DocAttribute [] arr = {OrientationRequested.LANDSCAPE,
                           MediaName.NA_LETTER_WHITE};
    DocAttributeSet set4 = new HashDocAttributeSet(arr);
    Attribute [] attrArr;

    assertTrue(set1.isEmpty());
    assertFalse(set2.isEmpty());
    assertTrue(set3.equals(set2));
    assertFalse(set3.equals(set1));
    set3.clear();
    assertEquals(set3, set1);
    set3.add(OrientationRequested.LANDSCAPE);
    set3.add(MediaName.NA_LETTER_WHITE);
    assertTrue(set3.containsKey(OrientationRequested.LANDSCAPE.getClass()));
    assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass()));
    assertTrue(set3.containsValue(OrientationRequested.LANDSCAPE));
    assertFalse(set3.containsValue(OrientationRequested.PORTRAIT));
    assertFalse(set3.containsValue(PrintQuality.DRAFT));
    assertEquals(set1.size(), 0);
    assertEquals(set2.size(), 1);
    assertEquals(set3.size(), 2);
    assertTrue(set4.equals(set3));
    assertEquals(set3.get(OrientationRequested.PORTRAIT.getClass()),
                 OrientationRequested.LANDSCAPE);
    assertFalse((set3.get(OrientationRequested.PORTRAIT.getClass()))
            .equals(OrientationRequested.PORTRAIT));
    set1.addAll(set3);
    assertEquals(set3, set1);
    set1.remove(OrientationRequested.PORTRAIT.getClass());
    assertEquals(set1.size(), 1);
    attrArr = set1.toArray();
    assertEquals(attrArr.length, 1);
    assertEquals(attrArr[0], MediaName.NA_LETTER_WHITE);
}
项目:freeVM    文件:ValueTests.java   
public void testHashPrintJobAttributeSet() {
    startTest("HashPrintJobAttributeSet class testing...");

    PrintJobAttributeSet set1 = new HashPrintJobAttributeSet();
    PrintJobAttributeSet set2 = 
        new HashPrintJobAttributeSet(OrientationRequested.LANDSCAPE);
    PrintJobAttributeSet set3 = new HashPrintJobAttributeSet(set2);
    PrintJobAttribute [] arr = {OrientationRequested.LANDSCAPE,
                                MediaName.NA_LETTER_WHITE};
    PrintJobAttributeSet set4 = new HashPrintJobAttributeSet(arr);
    Attribute [] attrArr;

    assertTrue(set1.isEmpty());
    assertFalse(set2.isEmpty());
    assertTrue(set3.equals(set2));
    assertFalse(set3.equals(set1));
    set3.clear();
    assertEquals(set3, set1);
    set3.add(OrientationRequested.LANDSCAPE);
    set3.add(MediaName.NA_LETTER_WHITE);
    assertTrue(set3.containsKey(OrientationRequested.LANDSCAPE.getClass()));
    assertFalse(set2.containsKey(MediaName.NA_LETTER_WHITE.getClass()));
    assertTrue(set3.containsValue(OrientationRequested.LANDSCAPE));
    assertFalse(set3.containsValue(OrientationRequested.PORTRAIT));
    assertFalse(set3.containsValue(PrintQuality.DRAFT));
    assertEquals(set1.size(), 0);
    assertEquals(set2.size(), 1);
    assertEquals(set3.size(), 2);
    assertTrue(set4.equals(set3));
    assertEquals(set3.get(OrientationRequested.PORTRAIT.getClass()),
                 OrientationRequested.LANDSCAPE);
    assertFalse((set3.get(OrientationRequested.PORTRAIT.getClass()))
            .equals(OrientationRequested.PORTRAIT));
    set1.addAll(set3);
    assertEquals(set3, set1);
    set1.remove(OrientationRequested.PORTRAIT.getClass());
    assertEquals(set1.size(), 1);
    attrArr = set1.toArray();
    assertEquals(attrArr.length, 1);
    assertEquals(attrArr[0], MediaName.NA_LETTER_WHITE);
}