Search in sources :

Example 61 with Graphics

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

the class CompositionArea method getCaretRectangle.

// returns a 0-width rectangle
private Rectangle getCaretRectangle(TextHitInfo caret) {
    int caretLocation = 0;
    TextLayout layout = composedTextLayout;
    if (layout != null) {
        caretLocation = Math.round(layout.getCaretInfo(caret)[0]);
    }
    Graphics g = getGraphics();
    FontMetrics metrics = null;
    try {
        metrics = g.getFontMetrics();
    } finally {
        g.dispose();
    }
    return new Rectangle(TEXT_ORIGIN_X + caretLocation, TEXT_ORIGIN_Y - metrics.getAscent(), 0, metrics.getAscent() + metrics.getDescent());
}
Also used : Graphics(java.awt.Graphics) FontMetrics(java.awt.FontMetrics) Rectangle(java.awt.Rectangle) Point(java.awt.Point) TextLayout(java.awt.font.TextLayout)

Example 62 with Graphics

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

the class RSLContextInvalidationTest method main.

public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(100, 100);
    vi.validate(gc);
    VolatileImage vi1 = gc.createCompatibleVolatileImage(100, 100);
    vi1.validate(gc);
    if (!(vi instanceof DestSurfaceProvider)) {
        System.out.println("Test considered PASSED: no HW acceleration");
        return;
    }
    DestSurfaceProvider p = (DestSurfaceProvider) vi;
    Surface s = p.getDestSurface();
    if (!(s instanceof AccelSurface)) {
        System.out.println("Test considered PASSED: no HW acceleration");
        return;
    }
    AccelSurface dst = (AccelSurface) s;
    Graphics g = vi.createGraphics();
    g.drawImage(vi1, 95, 95, null);
    g.setColor(Color.red);
    g.fillRect(0, 0, 100, 100);
    g.setColor(Color.black);
    g.fillRect(0, 0, 100, 100);
    // after this the validated context color is black
    RenderQueue rq = dst.getContext().getRenderQueue();
    rq.lock();
    try {
        dst.getContext().saveState();
        dst.getContext().restoreState();
    } finally {
        rq.unlock();
    }
    // this will cause ResetPaint (it will set color to extended EA=ff,
    // which is ffffffff==Color.white)
    g.drawImage(vi1, 95, 95, null);
    // now try filling with black again, but it will come up as white
    // because this fill rect won't validate the color properly
    g.setColor(Color.black);
    g.fillRect(0, 0, 100, 100);
    BufferedImage bi = vi.getSnapshot();
    if (bi.getRGB(50, 50) != Color.black.getRGB()) {
        throw new RuntimeException("Test FAILED: found color=" + Integer.toHexString(bi.getRGB(50, 50)) + " instead of " + Integer.toHexString(Color.black.getRGB()));
    }
    System.out.println("Test PASSED.");
}
Also used : Graphics(java.awt.Graphics) GraphicsDevice(java.awt.GraphicsDevice) VolatileImage(java.awt.image.VolatileImage) DestSurfaceProvider(sun.java2d.DestSurfaceProvider) RenderQueue(sun.java2d.pipe.RenderQueue) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Surface(sun.java2d.Surface)

Example 63 with Graphics

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

the class RSLAPITest method testGC.

private static void testGC(GraphicsConfiguration gc) {
    if (!(gc instanceof AccelGraphicsConfig)) {
        System.out.println("Test passed: no hw accelerated configs found.");
        return;
    }
    System.out.println("AccelGraphicsConfig exists, testing.");
    AccelGraphicsConfig agc = (AccelGraphicsConfig) gc;
    printAGC(agc);
    testContext(agc);
    VolatileImage vi = gc.createCompatibleVolatileImage(10, 10);
    vi.validate(gc);
    if (vi instanceof DestSurfaceProvider) {
        System.out.println("Passed: VI is DestSurfaceProvider");
        Surface s = ((DestSurfaceProvider) vi).getDestSurface();
        if (s instanceof AccelSurface) {
            System.out.println("Passed: Obtained Accel Surface");
            printSurface((AccelSurface) s);
        }
        Graphics g = vi.getGraphics();
        if (g instanceof DestSurfaceProvider) {
            System.out.println("Passed: VI graphics is " + "DestSurfaceProvider");
            printSurface(((DestSurfaceProvider) g).getDestSurface());
        }
    } else {
        System.out.println("VI is not DestSurfaceProvider");
    }
    testVICreation(agc, CAPS_RT_TEXTURE_ALPHA, TRANSLUCENT, RT_TEXTURE);
    testVICreation(agc, CAPS_RT_TEXTURE_OPAQUE, OPAQUE, RT_TEXTURE);
    testVICreation(agc, CAPS_RT_PLAIN_ALPHA, TRANSLUCENT, RT_PLAIN);
    testVICreation(agc, agc.getContextCapabilities().getCaps(), OPAQUE, TEXTURE);
    testForNPEDuringCreation(agc);
}
Also used : Graphics(java.awt.Graphics) AccelSurface(sun.java2d.pipe.hw.AccelSurface) VolatileImage(java.awt.image.VolatileImage) AccelGraphicsConfig(sun.java2d.pipe.hw.AccelGraphicsConfig) DestSurfaceProvider(sun.java2d.DestSurfaceProvider) Surface(sun.java2d.Surface) AccelSurface(sun.java2d.pipe.hw.AccelSurface)

Example 64 with Graphics

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

the class RSLAPITest method testVICreation.

private static void testVICreation(AccelGraphicsConfig agc, int cap, int transparency, int type) {
    int caps = agc.getContextCapabilities().getCaps();
    int w = 11, h = 17;
    VolatileImage vi = agc.createCompatibleVolatileImage(w, h, transparency, type);
    if ((cap & caps) != 0) {
        if (vi == null) {
            System.out.printf("Failed: cap=%d is supported but " + "image wasn't created\n", cap);
            throw new RuntimeException("Failed: image wasn't created " + "for supported cap");
        } else {
            if (!(vi instanceof DestSurfaceProvider)) {
                throw new RuntimeException("Failed: created VI is not " + "DestSurfaceProvider");
            }
            Surface s = ((DestSurfaceProvider) vi).getDestSurface();
            if (s instanceof AccelSurface) {
                AccelSurface as = (AccelSurface) s;
                printSurface(as);
                if (as.getType() != type) {
                    throw new RuntimeException("Failed: returned VI is" + " of incorrect type: " + as.getType() + " requested type=" + type);
                } else {
                    System.out.printf("Passed: VI of type %d was " + "created for cap=%d\n", type, cap);
                }
                if (as.getType() == TEXTURE) {
                    boolean ex = false;
                    try {
                        Graphics g = vi.getGraphics();
                        g.dispose();
                    } catch (UnsupportedOperationException e) {
                        ex = true;
                    }
                    if (!ex) {
                        throw new RuntimeException("Failed: " + "texture.getGraphics() didn't throw exception");
                    } else {
                        System.out.println("Passed: VI.getGraphics()" + " threw exception for texture-based VI");
                    }
                }
            } else {
                System.out.printf("Passed: VI of type %d was " + "created for cap=%d but accel surface is null\n", type, cap);
            }
        }
    } else {
        if (vi != null) {
            throw new RuntimeException("Failed: created VI for " + "unsupported cap=" + cap);
        }
    }
}
Also used : Graphics(java.awt.Graphics) AccelSurface(sun.java2d.pipe.hw.AccelSurface) VolatileImage(java.awt.image.VolatileImage) DestSurfaceProvider(sun.java2d.DestSurfaceProvider) Surface(sun.java2d.Surface) AccelSurface(sun.java2d.pipe.hw.AccelSurface)

Example 65 with Graphics

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

the class EncodeSubImageTest method createTestImage.

private static BufferedImage createTestImage() {
    int w = 100;
    int h = 100;
    BufferedImage src = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED);
    Graphics g = src.createGraphics();
    g.setColor(Color.red);
    g.fillRect(0, 0, w, h);
    g.setColor(Color.green);
    g.fillRect(subImageOffset, subImageOffset, w - 2 * subImageOffset, h - 2 * subImageOffset);
    g.setColor(Color.blue);
    g.fillRect(2 * subImageOffset, 2 * subImageOffset, w - 4 * subImageOffset, h - 4 * subImageOffset);
    g.dispose();
    return src;
}
Also used : Graphics(java.awt.Graphics) BufferedImage(java.awt.image.BufferedImage)

Aggregations

Graphics (java.awt.Graphics)217 BufferedImage (java.awt.image.BufferedImage)104 Dimension (java.awt.Dimension)35 Point (java.awt.Point)32 Graphics2D (java.awt.Graphics2D)31 Color (java.awt.Color)28 JPanel (javax.swing.JPanel)22 Insets (java.awt.Insets)21 Rectangle (java.awt.Rectangle)21 JLabel (javax.swing.JLabel)19 BorderLayout (java.awt.BorderLayout)18 File (java.io.File)18 FontMetrics (java.awt.FontMetrics)16 Frame (java.awt.Frame)16 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)16 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)16 Component (java.awt.Component)15 Font (java.awt.Font)15 GridBagLayout (java.awt.GridBagLayout)15 JScrollPane (javax.swing.JScrollPane)15