Java Code Examples for javax.print.attribute.HashPrintRequestAttributeSet#add()

The following examples show how to use javax.print.attribute.HashPrintRequestAttributeSet#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrintAttributeUpdateTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
 
Example 2
Source File: PrintAttributeUpdateTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
 
Example 3
Source File: PrintAttributeUpdateTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
 
Example 4
Source File: PrintAttributeUpdateTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
 
Example 5
Source File: PrintAttributeUpdateTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
 
Example 6
Source File: PrintAttributeUpdateTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
 
Example 7
Source File: PrintCrashTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintable((graphics, pageFormat, pageIndex) -> {
        if (pageIndex != 0) {
            return Printable.NO_SUCH_PAGE;
        } else {
            Shape shape = new Rectangle(110, 110, 10, 10);
            Rectangle rect = shape.getBounds();

            BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .getDefaultConfiguration().createCompatibleImage(rect.width, rect.height, Transparency.BITMASK);
            graphics.drawImage(image, rect.x, rect.y, rect.width, rect.height, null);

            return Printable.PAGE_EXISTS;
        }
    });

    File file = null;
    try {
        HashPrintRequestAttributeSet hashPrintRequestAttributeSet = new HashPrintRequestAttributeSet();
        file = File.createTempFile("out", "ps");
        file.deleteOnExit();
        Destination destination = new Destination(file.toURI());
        hashPrintRequestAttributeSet.add(destination);
        printerJob.print(hashPrintRequestAttributeSet);
    } finally {
        if (file != null) {
            file.delete();
        }
    }
}
 
Example 8
Source File: PrintCrashTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintable((graphics, pageFormat, pageIndex) -> {
        if (pageIndex != 0) {
            return Printable.NO_SUCH_PAGE;
        } else {
            Shape shape = new Rectangle(110, 110, 10, 10);
            Rectangle rect = shape.getBounds();

            BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .getDefaultConfiguration().createCompatibleImage(rect.width, rect.height, Transparency.BITMASK);
            graphics.drawImage(image, rect.x, rect.y, rect.width, rect.height, null);

            return Printable.PAGE_EXISTS;
        }
    });

    File file = null;
    try {
        HashPrintRequestAttributeSet hashPrintRequestAttributeSet = new HashPrintRequestAttributeSet();
        file = File.createTempFile("out", "ps");
        file.deleteOnExit();
        Destination destination = new Destination(file.toURI());
        hashPrintRequestAttributeSet.add(destination);
        printerJob.print(hashPrintRequestAttributeSet);
    } finally {
        if (file != null) {
            file.delete();
        }
    }
}
 
Example 9
Source File: PrintCrashTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintable((graphics, pageFormat, pageIndex) -> {
        if (pageIndex != 0) {
            return Printable.NO_SUCH_PAGE;
        } else {
            Shape shape = new Rectangle(110, 110, 10, 10);
            Rectangle rect = shape.getBounds();

            BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .getDefaultConfiguration().createCompatibleImage(rect.width, rect.height, Transparency.BITMASK);
            graphics.drawImage(image, rect.x, rect.y, rect.width, rect.height, null);

            return Printable.PAGE_EXISTS;
        }
    });

    File file = null;
    try {
        HashPrintRequestAttributeSet hashPrintRequestAttributeSet = new HashPrintRequestAttributeSet();
        file = File.createTempFile("out", "ps");
        file.deleteOnExit();
        Destination destination = new Destination(file.toURI());
        hashPrintRequestAttributeSet.add(destination);
        printerJob.print(hashPrintRequestAttributeSet);
    } finally {
        if (file != null) {
            file.delete();
        }
    }
}
 
Example 10
Source File: PrintCrashTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintable((graphics, pageFormat, pageIndex) -> {
        if (pageIndex != 0) {
            return Printable.NO_SUCH_PAGE;
        } else {
            Shape shape = new Rectangle(110, 110, 10, 10);
            Rectangle rect = shape.getBounds();

            BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .getDefaultConfiguration().createCompatibleImage(rect.width, rect.height, Transparency.BITMASK);
            graphics.drawImage(image, rect.x, rect.y, rect.width, rect.height, null);

            return Printable.PAGE_EXISTS;
        }
    });

    File file = null;
    try {
        HashPrintRequestAttributeSet hashPrintRequestAttributeSet = new HashPrintRequestAttributeSet();
        file = File.createTempFile("out", "ps");
        file.deleteOnExit();
        Destination destination = new Destination(file.toURI());
        hashPrintRequestAttributeSet.add(destination);
        printerJob.print(hashPrintRequestAttributeSet);
    } finally {
        if (file != null) {
            file.delete();
        }
    }
}
 
Example 11
Source File: PrintCrashTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintable((graphics, pageFormat, pageIndex) -> {
        if (pageIndex != 0) {
            return Printable.NO_SUCH_PAGE;
        } else {
            Shape shape = new Rectangle(110, 110, 10, 10);
            Rectangle rect = shape.getBounds();

            BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .getDefaultConfiguration().createCompatibleImage(rect.width, rect.height, Transparency.BITMASK);
            graphics.drawImage(image, rect.x, rect.y, rect.width, rect.height, null);

            return Printable.PAGE_EXISTS;
        }
    });

    File file = null;
    try {
        HashPrintRequestAttributeSet hashPrintRequestAttributeSet = new HashPrintRequestAttributeSet();
        file = File.createTempFile("out", "ps");
        file.deleteOnExit();
        Destination destination = new Destination(file.toURI());
        hashPrintRequestAttributeSet.add(destination);
        printerJob.print(hashPrintRequestAttributeSet);
    } finally {
        if (file != null) {
            file.delete();
        }
    }
}
 
Example 12
Source File: ServiceDialogValidateTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void printTest() {
    PrintService defService = null, service[] = null;
    HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;

    service = PrintServiceLookup.lookupPrintServices(flavor, null);
    defService = PrintServiceLookup.lookupDefaultPrintService();

    if ((service == null) || (service.length == 0)) {
        throw new RuntimeException("No Printer services found");
    }
    File f = new File("output.ps");
    Destination d = new Destination(f.toURI());
    prSet.add(d);
    if (defService != null) {
        System.out.println("isAttrCategory Supported? " +
                defService.isAttributeCategorySupported(Destination.class));
        System.out.println("isAttrValue Supported? " +
                defService.isAttributeValueSupported(d, flavor, null));
    }

    defService = ServiceUI.printDialog(null, 100, 100, service, defService,
            flavor, prSet);

    ServiceUI.printDialog(null, 100, 100, service, defService,
            DocFlavor.SERVICE_FORMATTED.PAGEABLE,
            new HashPrintRequestAttributeSet());
}
 
Example 13
Source File: PrintCrashTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintable((graphics, pageFormat, pageIndex) -> {
        if (pageIndex != 0) {
            return Printable.NO_SUCH_PAGE;
        } else {
            Shape shape = new Rectangle(110, 110, 10, 10);
            Rectangle rect = shape.getBounds();

            BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .getDefaultConfiguration().createCompatibleImage(rect.width, rect.height, Transparency.BITMASK);
            graphics.drawImage(image, rect.x, rect.y, rect.width, rect.height, null);

            return Printable.PAGE_EXISTS;
        }
    });

    File file = null;
    try {
        HashPrintRequestAttributeSet hashPrintRequestAttributeSet = new HashPrintRequestAttributeSet();
        file = File.createTempFile("out", "ps");
        file.deleteOnExit();
        Destination destination = new Destination(file.toURI());
        hashPrintRequestAttributeSet.add(destination);
        printerJob.print(hashPrintRequestAttributeSet);
    } finally {
        if (file != null) {
            file.delete();
        }
    }
}
 
Example 14
Source File: PrintCrashTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintable((graphics, pageFormat, pageIndex) -> {
        if (pageIndex != 0) {
            return Printable.NO_SUCH_PAGE;
        } else {
            Shape shape = new Rectangle(110, 110, 10, 10);
            Rectangle rect = shape.getBounds();

            BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .getDefaultConfiguration().createCompatibleImage(rect.width, rect.height, Transparency.BITMASK);
            graphics.drawImage(image, rect.x, rect.y, rect.width, rect.height, null);

            return Printable.PAGE_EXISTS;
        }
    });

    File file = null;
    try {
        HashPrintRequestAttributeSet hashPrintRequestAttributeSet = new HashPrintRequestAttributeSet();
        file = File.createTempFile("out", "ps");
        file.deleteOnExit();
        Destination destination = new Destination(file.toURI());
        hashPrintRequestAttributeSet.add(destination);
        printerJob.print(hashPrintRequestAttributeSet);
    } finally {
        if (file != null) {
            file.delete();
        }
    }
}