Search in sources :

Example 76 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.

the class RasterPrinterJob method printDialog.

/**
     * Presents the user a dialog for changing properties of the
     * print job interactively.
     * The services browsable here are determined by the type of
     * service currently installed.
     * If the application installed a StreamPrintService on this
     * PrinterJob, only the available StreamPrintService (factories) are
     * browsable.
     *
     * @param attributes to store changed properties.
     * @return false if the user cancels the dialog and true otherwise.
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
     * returns true.
     * @see java.awt.GraphicsEnvironment#isHeadless
     */
public boolean printDialog(final PrintRequestAttributeSet attributes) throws HeadlessException {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }
    DialogTypeSelection dlg = (DialogTypeSelection) attributes.get(DialogTypeSelection.class);
    // Check for native, note that default dialog is COMMON.
    if (dlg == DialogTypeSelection.NATIVE) {
        this.attributes = attributes;
        try {
            debug_println("calling setAttributes in printDialog");
            setAttributes(attributes);
        } catch (PrinterException e) {
        }
        setParentWindowID(attributes);
        boolean ret = printDialog();
        clearParentWindowID();
        this.attributes = attributes;
        return ret;
    }
    /* A security check has already been performed in the
         * java.awt.print.printerJob.getPrinterJob method.
         * So by the time we get here, it is OK for the current thread
         * to print either to a file (from a Dialog we control!) or
         * to a chosen printer.
         *
         * We raise privilege when we put up the dialog, to avoid
         * the "warning applet window" banner.
         */
    final GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    PrintService service = (PrintService) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {

        public Object run() {
            PrintService service = getPrintService();
            if (service == null) {
                ServiceDialog.showNoPrintService(gc);
                return null;
            }
            return service;
        }
    });
    if (service == null) {
        return false;
    }
    PrintService[] services;
    StreamPrintServiceFactory[] spsFactories = null;
    if (service instanceof StreamPrintService) {
        spsFactories = lookupStreamPrintServices(null);
        services = new StreamPrintService[spsFactories.length];
        for (int i = 0; i < spsFactories.length; i++) {
            services[i] = spsFactories[i].getPrintService(null);
        }
    } else {
        services = (PrintService[]) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {

            public Object run() {
                PrintService[] services = PrinterJob.lookupPrintServices();
                return services;
            }
        });
        if ((services == null) || (services.length == 0)) {
            /*
                 * No services but default PrintService exists?
                 * Create services using defaultService.
                 */
            services = new PrintService[1];
            services[0] = service;
        }
    }
    Rectangle bounds = gc.getBounds();
    int x = bounds.x + bounds.width / 3;
    int y = bounds.y + bounds.height / 3;
    PrintService newService;
    // temporarily add an attribute pointing back to this job.
    PrinterJobWrapper jobWrapper = new PrinterJobWrapper(this);
    attributes.add(jobWrapper);
    try {
        newService = ServiceUI.printDialog(gc, x, y, services, service, DocFlavor.SERVICE_FORMATTED.PAGEABLE, attributes);
    } catch (IllegalArgumentException iae) {
        newService = ServiceUI.printDialog(gc, x, y, services, services[0], DocFlavor.SERVICE_FORMATTED.PAGEABLE, attributes);
    }
    attributes.remove(PrinterJobWrapper.class);
    if (newService == null) {
        return false;
    }
    if (!service.equals(newService)) {
        try {
            setPrintService(newService);
        } catch (PrinterException e) {
            /*
                 * The only time it would throw an exception is when
                 * newService is no longer available but we should still
                 * select this printer.
                 */
            myService = newService;
        }
    }
    return true;
}
Also used : HeadlessException(java.awt.HeadlessException) Rectangle(java.awt.Rectangle) PrinterException(java.awt.print.PrinterException) StreamPrintService(javax.print.StreamPrintService) DialogTypeSelection(javax.print.attribute.standard.DialogTypeSelection) GraphicsConfiguration(java.awt.GraphicsConfiguration) PrintService(javax.print.PrintService) StreamPrintService(javax.print.StreamPrintService) StreamPrintServiceFactory(javax.print.StreamPrintServiceFactory)

Example 77 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.

the class RasterPrinterJob method pageDialog.

/**
     * return a PageFormat corresponding to the updated attributes,
     * or null if the user cancelled the dialog.
     */
public PageFormat pageDialog(final PrintRequestAttributeSet attributes) throws HeadlessException {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }
    DialogTypeSelection dlg = (DialogTypeSelection) attributes.get(DialogTypeSelection.class);
    // Check for native, note that default dialog is COMMON.
    if (dlg == DialogTypeSelection.NATIVE) {
        PrintService pservice = getPrintService();
        PageFormat pageFrmAttrib = attributeToPageFormat(pservice, attributes);
        setParentWindowID(attributes);
        PageFormat page = pageDialog(pageFrmAttrib);
        clearParentWindowID();
        // page object and as per spec, we should return null in that case.
        if (page == pageFrmAttrib) {
            return null;
        }
        updateAttributesWithPageFormat(pservice, page, attributes);
        return page;
    }
    final GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    Rectangle bounds = gc.getBounds();
    int x = bounds.x + bounds.width / 3;
    int y = bounds.y + bounds.height / 3;
    PrintService service = (PrintService) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {

        public Object run() {
            PrintService service = getPrintService();
            if (service == null) {
                ServiceDialog.showNoPrintService(gc);
                return null;
            }
            return service;
        }
    });
    if (service == null) {
        return null;
    }
    if (onTop != null) {
        attributes.add(onTop);
    }
    ServiceDialog pageDialog = new ServiceDialog(gc, x, y, service, DocFlavor.SERVICE_FORMATTED.PAGEABLE, attributes, (Frame) null);
    pageDialog.show();
    if (pageDialog.getStatus() == ServiceDialog.APPROVE) {
        PrintRequestAttributeSet newas = pageDialog.getAttributes();
        Class amCategory = SunAlternateMedia.class;
        if (attributes.containsKey(amCategory) && !newas.containsKey(amCategory)) {
            attributes.remove(amCategory);
        }
        attributes.addAll(newas);
        return attributeToPageFormat(service, attributes);
    } else {
        return null;
    }
}
Also used : ServiceDialog(sun.print.ServiceDialog) HeadlessException(java.awt.HeadlessException) Rectangle(java.awt.Rectangle) DialogTypeSelection(javax.print.attribute.standard.DialogTypeSelection) PrintService(javax.print.PrintService) StreamPrintService(javax.print.StreamPrintService) GraphicsConfiguration(java.awt.GraphicsConfiguration) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) PageFormat(java.awt.print.PageFormat)

Example 78 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.

the class PixelTests method initTest.

public Object initTest(TestEnvironment env, Result result) {
    Context ctx = new Context();
    ctx.bimg = ((BufImg) env.getModifier(bufimgsrcroot)).getImage();
    if (env.isEnabled(doRenderTo)) {
        Graphics2D g2d = ctx.bimg.createGraphics();
        g2d.setColor(Color.white);
        g2d.fillRect(3, 0, 1, 1);
        g2d.dispose();
    }
    if (env.isEnabled(doRenderFrom)) {
        GraphicsConfiguration cfg = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
        VolatileImage vimg = cfg.createCompatibleVolatileImage(8, 1);
        vimg.validate(cfg);
        Graphics2D g2d = vimg.createGraphics();
        for (int i = 0; i < 100; i++) {
            g2d.drawImage(ctx.bimg, 0, 0, null);
        }
        g2d.dispose();
        vimg.flush();
    }
    result.setUnits(1);
    result.setUnitName(getUnitName());
    return ctx;
}
Also used : VolatileImage(java.awt.image.VolatileImage) Graphics2D(java.awt.Graphics2D) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 79 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.

the class TextRenderingTest method main.

public static void main(final String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(width, height);
    while (true) {
        vi.validate(gc);
        Graphics2D g2d = vi.createGraphics();
        g2d.setColor(Color.white);
        g2d.fillRect(0, 0, width, height);
        g2d.setPaint(new GradientPaint(new Point2D.Float(0, height / 2), Color.white, new Point2D.Float(width, height / 2), Color.black));
        g2d.fillRect(0, 0, width, height);
        String fnt = g2d.getFont().getFamily();
        g2d.setFont(new Font(fnt, Font.PLAIN, 100));
        // draw text with offset
        g2d.drawString("IIIIIIIIII", 100, 100);
        g2d.dispose();
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
            continue;
        }
        if (vi.contentsLost()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
            continue;
        }
        break;
    }
    BufferedImage bi = vi.getSnapshot();
    // the text shifted shouldn't be visible onto a painted rectangle!
    // so the check: color component (blue) must decrease monotonously
    int prev = Integer.MAX_VALUE;
    for (int x = 0; x < width; ++x) {
        int color = bi.getRGB(x, height / 2);
        int b = color & 0xFF;
        if (b > prev) {
            throw new RuntimeException("test failed: can see the text rendered!");
        }
        prev = b;
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) GradientPaint(java.awt.GradientPaint) GraphicsEnvironment(java.awt.GraphicsEnvironment) Font(java.awt.Font) BufferedImage(java.awt.image.BufferedImage) GradientPaint(java.awt.GradientPaint) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 80 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.

the class IncorrectAlphaSurface2SW method main.

public static void main(final String[] args) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    BufferedImage destVI;
    BufferedImage destBI;
    BufferedImage sourceBI;
    VolatileImage sourceVI;
    for (final int s : SIZES) {
        for (final int srcType : srcTypes) {
            for (final int dstType : dstTypes) {
                for (final int scale : SCALES) {
                    int sw = s * scale;
                    destVI = new BufferedImage(sw, sw, dstType);
                    destBI = new BufferedImage(sw, sw, dstType);
                    sourceBI = gc.createCompatibleImage(sw, sw, srcType);
                    sourceVI = gc.createCompatibleVolatileImage(s, s, srcType);
                    // draw to dest BI using compatible image
                    fill(sourceBI, s);
                    Graphics2D big = destBI.createGraphics();
                    big.setComposite(AlphaComposite.Src);
                    big.drawImage(sourceBI, 0, 0, sw, sw, null);
                    big.dispose();
                    // draw to dest BI using compatible image
                    fill(sourceVI, s);
                    drawVItoBI(gc, destVI, sourceVI);
                    validate(destVI, destBI);
                    sourceVI.flush();
                }
            }
        }
    }
    System.out.println("Test PASSED");
}
Also used : VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Aggregations

GraphicsConfiguration (java.awt.GraphicsConfiguration)134 GraphicsEnvironment (java.awt.GraphicsEnvironment)55 BufferedImage (java.awt.image.BufferedImage)46 Rectangle (java.awt.Rectangle)43 GraphicsDevice (java.awt.GraphicsDevice)38 Graphics2D (java.awt.Graphics2D)33 VolatileImage (java.awt.image.VolatileImage)31 Point (java.awt.Point)29 Dimension (java.awt.Dimension)21 Insets (java.awt.Insets)16 File (java.io.File)16 Graphics (java.awt.Graphics)13 IOException (java.io.IOException)13 Frame (java.awt.Frame)11 JFrame (javax.swing.JFrame)8 HeadlessException (java.awt.HeadlessException)7 Window (java.awt.Window)7 ImageIcon (javax.swing.ImageIcon)7 Color (java.awt.Color)6 AffineTransform (java.awt.geom.AffineTransform)6