Search in sources :

Example 96 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project poi by apache.

the class HwmfGraphics method updateWindowMapMode.

/**
     * After setting various window and viewport related properties,
     * the underlying graphics context needs to be adapted.
     * This methods gathers and sets the corresponding graphics transformations.
     */
public void updateWindowMapMode() {
    Rectangle2D win = prop.getWindow();
    HwmfMapMode mapMode = prop.getMapMode();
    graphicsCtx.setTransform(initialAT);
    switch(mapMode) {
        default:
        case MM_ANISOTROPIC:
            // scale window bounds to output bounds
            graphicsCtx.scale(bbox.getWidth() / win.getWidth(), bbox.getHeight() / win.getHeight());
            graphicsCtx.translate(-win.getX(), -win.getY());
            break;
        case MM_ISOTROPIC:
            // TODO: to be validated ...
            // like anisotropic, but use x-axis as reference
            graphicsCtx.scale(bbox.getWidth() / win.getWidth(), bbox.getWidth() / win.getWidth());
            graphicsCtx.translate(-win.getX(), -win.getY());
            break;
        case MM_LOMETRIC:
        case MM_HIMETRIC:
        case MM_LOENGLISH:
        case MM_HIENGLISH:
        case MM_TWIPS:
            {
                // TODO: to be validated ...
                GraphicsConfiguration gc = graphicsCtx.getDeviceConfiguration();
                graphicsCtx.transform(gc.getNormalizingTransform());
                graphicsCtx.scale(1. / mapMode.scale, -1. / mapMode.scale);
                graphicsCtx.translate(-win.getX(), -win.getY());
                break;
            }
        case MM_TEXT:
            // TODO: to be validated ...
            break;
    }
}
Also used : HwmfMapMode(org.apache.poi.hwmf.record.HwmfMapMode) Rectangle2D(java.awt.geom.Rectangle2D) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 97 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project JMRI by JMRI.

the class ReportContext method addScreenSize.

/**
     * Provide screen - size information. This is based on the
     * jmri.util.JmriJFrame calculation, but isn't refactored to there because
     * we also want diagnostic info
     */
public void addScreenSize() {
    try {
        // Find screen size. This throws null-pointer exceptions on
        // some Java installs, however, for unknown reasons, so be
        // prepared to fall back.
        JFrame dummy = new JFrame();
        try {
            Insets insets = dummy.getToolkit().getScreenInsets(dummy.getGraphicsConfiguration());
            Dimension screen = dummy.getToolkit().getScreenSize();
            addString("Screen size h:" + screen.height + ", w:" + screen.width + " Inset t:" + insets.top + ", b:" + insets.bottom + "; l:" + insets.left + ", r:" + insets.right);
        } catch (NoSuchMethodError ex) {
            Dimension screen = dummy.getToolkit().getScreenSize();
            addString("Screen size h:" + screen.height + ", w:" + screen.width + " (No Inset method available)");
        }
    } catch (HeadlessException ex) {
        // failed, fall back to standard method
        addString("(Cannot sense screen size due to " + ex.toString() + ")");
    }
    try {
        // Find screen resolution. Not expected to fail, but just in case....
        int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
        addString("Screen resolution: " + dpi);
    } catch (HeadlessException ex) {
        addString("Screen resolution not available");
    }
    //Rectangle virtualBounds = new Rectangle();
    try {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        addString("Environment max bounds: " + ge.getMaximumWindowBounds());
        try {
            GraphicsDevice[] gs = ge.getScreenDevices();
            for (GraphicsDevice gd : gs) {
                GraphicsConfiguration[] gc = gd.getConfigurations();
                for (int i = 0; i < gc.length; i++) {
                    addString("bounds[" + i + "] = " + gc[i].getBounds());
                // virtualBounds = virtualBounds.union(gc[i].getBounds());
                }
                addString("Device: " + gd.getIDstring() + " bounds = " + gd.getDefaultConfiguration().getBounds() + " " + gd.getDefaultConfiguration().toString());
            }
        } catch (HeadlessException ex) {
            addString("Exception getting device bounds " + ex.getMessage());
        }
    } catch (HeadlessException ex) {
        addString("Exception getting max window bounds " + ex.getMessage());
    }
    // various Linux window managers
    try {
        Insets jmriInsets = JmriInsets.getInsets();
        addString("JmriInsets t:" + jmriInsets.top + ", b:" + jmriInsets.bottom + "; l:" + jmriInsets.left + ", r:" + jmriInsets.right);
    } catch (Exception ex) {
        addString("Exception getting JmriInsets" + ex.getMessage());
    }
}
Also used : Insets(java.awt.Insets) JmriInsets(jmri.util.JmriInsets) GraphicsDevice(java.awt.GraphicsDevice) HeadlessException(java.awt.HeadlessException) JFrame(javax.swing.JFrame) Dimension(java.awt.Dimension) GraphicsEnvironment(java.awt.GraphicsEnvironment) SocketException(java.net.SocketException) HeadlessException(java.awt.HeadlessException) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 98 with GraphicsConfiguration

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

the class DrawImageBgTest method main.

public static void main(String[] args) {
    GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    if (gc.getColorModel().getPixelSize() <= 8) {
        System.out.println("8-bit color model, test considered passed");
        return;
    }
    /*
         * Set up images:
         * 1.) VolatileImge for rendering to,
         * 2.) BufferedImage for reading back the contents of the VI
         * 3.) The image triggering the problem
         */
    VolatileImage vImg = null;
    BufferedImage readBackBImg;
    // create a BITMASK ICM such that the transparent color is
    // tr. black (and it's the first in the color map so a buffered image
    // created with this ICM is transparent
    byte[] r = { 0x00, (byte) 0xff };
    byte[] g = { 0x00, (byte) 0xff };
    byte[] b = { 0x00, (byte) 0xff };
    IndexColorModel icm = new IndexColorModel(8, 2, r, g, b, 0);
    WritableRaster wr = icm.createCompatibleWritableRaster(25, 25);
    BufferedImage tImg = new BufferedImage(icm, wr, false, null);
    do {
        if (vImg == null || vImg.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) {
            vImg = gc.createCompatibleVolatileImage(tImg.getWidth(), tImg.getHeight());
        }
        Graphics viG = vImg.getGraphics();
        viG.setColor(Color.red);
        viG.fillRect(0, 0, vImg.getWidth(), vImg.getHeight());
        viG.drawImage(tImg, 0, 0, Color.green, null);
        viG.fillRect(0, 0, vImg.getWidth(), vImg.getHeight());
        viG.drawImage(tImg, 0, 0, Color.white, null);
        readBackBImg = vImg.getSnapshot();
    } while (vImg.contentsLost());
    for (int x = 0; x < readBackBImg.getWidth(); x++) {
        for (int y = 0; y < readBackBImg.getHeight(); y++) {
            int currPixel = readBackBImg.getRGB(x, y);
            if (currPixel != Color.white.getRGB()) {
                String fileName = "DrawImageBgTest.png";
                try {
                    ImageIO.write(readBackBImg, "png", new File(fileName));
                    System.err.println("Dumped image to " + fileName);
                } catch (IOException ex) {
                }
                throw new RuntimeException("Test Failed: found wrong color: 0x" + Integer.toHexString(currPixel));
            }
        }
    }
    System.out.println("Test Passed.");
}
Also used : Graphics(java.awt.Graphics) VolatileImage(java.awt.image.VolatileImage) WritableRaster(java.awt.image.WritableRaster) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) IndexColorModel(java.awt.image.IndexColorModel)

Example 99 with GraphicsConfiguration

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

the class CustomCompositeTest method main.

public static void main(String[] args) {
    paintLatch = new CountDownLatch(1);
    paintError = null;
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            initGUI();
        }
    });
    try {
        paintLatch.await();
    } catch (InterruptedException e) {
    }
    ;
    System.out.println("Paint is done!");
    if (paintError != null) {
        frame.dispose();
        throw new RuntimeException("Test FAILED.", paintError);
    }
    System.out.println("Phase 1: PASSED.");
    // now resise the frame in order to cause re-paint with accelerated
    // source images.
    paintError = null;
    paintLatch = new CountDownLatch(1);
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            Dimension size = frame.getSize();
            size.width += 50;
            size.height += 50;
            frame.setSize(size);
        }
    });
    try {
        paintLatch.await();
    } catch (InterruptedException e) {
    }
    ;
    if (paintError != null) {
        frame.dispose();
        throw new RuntimeException("Resize test FAILED.", paintError);
    }
    frame.dispose();
    System.out.println("Phase 2: PASSED.");
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration cfg = env.getDefaultScreenDevice().getDefaultConfiguration();
    // test rendering to accelerated volatile image
    testVolatileImage(cfg, true);
    System.out.println("Phase 3: PASSED.");
    // test rendering to unaccelerated volatile image
    testVolatileImage(cfg, false);
    System.out.println("Phase 4: PASSED.");
}
Also used : Dimension(java.awt.Dimension) CountDownLatch(java.util.concurrent.CountDownLatch) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 100 with GraphicsConfiguration

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

the class DrawCachedImageAndTransform method main.

public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(100, 100);
    Graphics2D g2d = vi.createGraphics();
    g2d.scale(2, 2);
    BufferedImage img = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
    g2d.drawImage(img, 10, 25, Color.blue, null);
    g2d.dispose();
}
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