Search in sources :

Example 66 with Graphics

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

the class RGBImageTest method getSrc.

protected BufferedImage getSrc() {
    if (src == null) {
        src = new BufferedImage(dx * usedColors.length, height, BufferedImage.TYPE_INT_RGB);
        Graphics g = src.createGraphics();
        for (int i = 0; i < usedColors.length; i++) {
            g.setColor(usedColors[i]);
            g.fillRect(dx * i, 0, dx, height);
        }
    }
    return src;
}
Also used : Graphics(java.awt.Graphics) BufferedImage(java.awt.image.BufferedImage)

Example 67 with Graphics

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

the class TestBadBreak method test.

private static void test(final String text, final BufferedImage i1) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            frame = new JFrame();
            final JLabel label = new JLabel(text) {

                @Override
                protected void paintComponent(Graphics g) {
                    Graphics2D g2d = i1.createGraphics();
                    super.paintComponent(g2d);
                    g2d.dispose();
                }
            };
            frame.getContentPane().add(label);
            frame.setBounds(200, 200, 200, 90);
        }
    });
    robot.waitForIdle();
    SwingUtilities.invokeAndWait(() -> frame.setVisible(true));
    robot.waitForIdle();
    SwingUtilities.invokeAndWait(frame::dispose);
    robot.waitForIdle();
}
Also used : Graphics(java.awt.Graphics) JFrame(javax.swing.JFrame) JLabel(javax.swing.JLabel) Graphics2D(java.awt.Graphics2D)

Example 68 with Graphics

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

the class OnScreenRenderingResizeTest method main.

public static void main(String[] args) {
    for (String arg : args) {
        if ("-inf".equals(arg)) {
            System.err.println("Test will run indefinitely");
            RUN_TIME = Long.MAX_VALUE;
        } else if ("-nocheck".equals(arg)) {
            System.err.println("Test will not check rendering results");
            nocheck = true;
        } else {
            System.err.println("Usage: OnScreenRenderingResizeTest [-inf][-nocheck]");
        }
    }
    BufferedImage output = new BufferedImage(IMAGE_W, IMAGE_H, BufferedImage.TYPE_INT_RGB);
    output.setAccelerationPriority(0.0f);
    Graphics g = output.getGraphics();
    g.setColor(renderColor);
    g.fillRect(0, 0, output.getWidth(), output.getHeight());
    final Frame frame = new Frame("OnScreenRenderingResizeTest") {

        public void paint(Graphics g) {
        }

        public void update(Graphics g) {
        }
    };
    frame.setBackground(bgColor);
    frame.setUndecorated(true);
    frame.pack();
    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    Rectangle gcBounds = gc.getBounds();
    frame.setBounds(gcBounds.width / 4, gcBounds.height / 4, FRAME_W, FRAME_H);
    frame.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            done = true;
        }
    });
    try {
        EventQueue.invokeAndWait(new Runnable() {

            public void run() {
                frame.setVisible(true);
            }
        });
        // wait for Vista's effects to complete
        Thread.sleep(2000);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    int maxW = gcBounds.width / 2;
    int maxH = gcBounds.height / 2;
    int minW = frame.getWidth();
    int minH = frame.getHeight();
    int incW = 10, incH = 10, cnt = 0;
    Robot robot = null;
    if (!nocheck && gc.getColorModel().getPixelSize() > 8) {
        try {
            robot = new Robot();
        } catch (AWTException ex) {
            System.err.println("Robot creation failed, continuing.");
        }
    } else {
        System.err.println("No screen rendering checks.");
    }
    VolatileImage vi = gc.createCompatibleVolatileImage(512, 512);
    vi.validate(gc);
    long timeStarted = System.currentTimeMillis();
    while (!done && (System.currentTimeMillis() - timeStarted) < RUN_TIME) {
        if (++cnt > 100) {
            int w = frame.getWidth() + incW;
            int h = frame.getHeight() + incH;
            if (w < minW || w > maxW) {
                incW = -incW;
            }
            if (h < minH || h > maxH) {
                incH = -incH;
            }
            frame.setSize(w, h);
            cnt = 0;
        }
        // try to put the device into non-default state, for example,
        // this operation below will set the transform
        vi.validate(gc);
        Graphics2D vig = (Graphics2D) vi.getGraphics();
        vig.rotate(30.0f, vi.getWidth() / 2, vi.getHeight() / 2);
        vig.drawImage(output, 0, 0, vi.getWidth(), vi.getHeight(), null);
        Insets in = frame.getInsets();
        frame.getGraphics().drawImage(output, in.left, in.top, null);
        if (cnt == 90 && robot != null) {
            robot.waitForIdle();
            // area where we blitted to should be either white or green
            Point p = frame.getLocationOnScreen();
            p.translate(in.left + 10, in.top + 10);
            BufferedImage bi = robot.createScreenCapture(new Rectangle(p.x, p.y, IMAGE_W / 2, IMAGE_H / 2));
            int[] accepted1 = { Color.white.getRGB(), Color.green.getRGB() };
            checkBI(bi, accepted1);
            // the are where we didn't render should stay white
            p = frame.getLocationOnScreen();
            p.translate(in.left, in.top + IMAGE_H + 5);
            bi = robot.createScreenCapture(new Rectangle(p.x, p.y, frame.getWidth() - in.left - in.right, frame.getHeight() - in.top - in.bottom - 5 - IMAGE_H));
            int[] accepted2 = { Color.white.getRGB() };
            checkBI(bi, accepted2);
        }
        Thread.yield();
    }
    frame.dispose();
    System.out.println("Test Passed");
}
Also used : Frame(java.awt.Frame) Insets(java.awt.Insets) Rectangle(java.awt.Rectangle) WindowAdapter(java.awt.event.WindowAdapter) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) AWTException(java.awt.AWTException) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D) Graphics(java.awt.Graphics) VolatileImage(java.awt.image.VolatileImage) WindowEvent(java.awt.event.WindowEvent) Robot(java.awt.Robot) AWTException(java.awt.AWTException)

Example 69 with Graphics

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

the class InfiniteValidationLoopTest method runTest.

private void runTest(Graphics g) {
    int status = IMAGE_OK;
    int count1 = 0;
    do {
        GraphicsConfiguration gc = getGraphicsConfiguration();
        int count2 = 0;
        while (vi == null || (status = vi.validate(gc)) != IMAGE_OK) {
            if (++count2 > LOOP_THRESHOLD) {
                System.err.println("Infinite loop detected: count2=" + count2);
                failed = true;
                return;
            }
            if (vi == null || status == IMAGE_INCOMPATIBLE) {
                if (vi != null) {
                    vi.flush();
                    vi = null;
                }
                vi = gc.createCompatibleVolatileImage(100, 100);
                continue;
            }
            if (status == IMAGE_RESTORED) {
                Graphics gg = vi.getGraphics();
                gg.setColor(Color.green);
                gg.fillRect(0, 0, vi.getWidth(), vi.getHeight());
                break;
            }
        }
        g.drawImage(vi, getInsets().left, getInsets().top, null);
        if (++count1 > LOOP_THRESHOLD) {
            System.err.println("Infinite loop detected: count1=" + count1);
            failed = true;
            return;
        }
    } while (vi.contentsLost());
}
Also used : Graphics(java.awt.Graphics) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 70 with Graphics

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

the class TSFrame method createGui.

public static Frame createGui(final boolean useSwing, final boolean useShape, final boolean useTransl, final boolean useNonOpaque, final float factor) {
    Frame frame;
    done = false;
    if (useNonOpaque) {
        if (useSwing) {
            frame = new NonOpaqueJFrame();
        //                frame = new NonOpaqueJAppletFrame(gc);
        } else {
            frame = new NonOpaqueFrame();
        }
        animateComponent(frame);
    } else if (useSwing) {
        frame = new JFrame("Swing Frame");
        JComponent p = new JButton("Swing!");
        p.setPreferredSize(new Dimension(200, 100));
        frame.add("North", p);
        p = new MyJPanel();
        animateComponent(p);
        frame.add("Center", p);
    } else {
        frame = new Frame("AWT Frame") {

            public void paint(Graphics g) {
                g.setColor(Color.red);
                g.fillRect(0, 0, 100, 100);
            }
        };
        frame.setLayout(new BorderLayout());
        Canvas c = new MyCanvas();
        frame.add("North", c);
        animateComponent(c);
        c = new MyCanvas();
        frame.add("Center", c);
        animateComponent(c);
        c = new MyCanvas();
        frame.add("South", c);
        animateComponent(c);
    }
    final Frame finalFrame = frame;
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            finalFrame.dispose();
            done = true;
        }
    });
    frame.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            finalFrame.dispose();
            done = true;
        }
    });
    frame.setPreferredSize(new Dimension(800, 600));
    if (useShape) {
        frame.setUndecorated(true);
    }
    frame.setLocation(450, 10);
    frame.pack();
    GraphicsDevice gd = frame.getGraphicsConfiguration().getDevice();
    if (useShape) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSPARENT)) {
            System.out.println("applying PERPIXEL_TRANSPARENT");
            frame.setShape(new Ellipse2D.Double(0, 0, frame.getWidth(), frame.getHeight() / 3));
            frame.setTitle("PERPIXEL_TRANSPARENT");
        } else {
            System.out.println("Passed: PERPIXEL_TRANSPARENT unsupported");
        }
    }
    if (useTransl) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
            System.out.println("applying TRANSLUCENT");
            frame.setOpacity(factor);
            frame.setTitle("TRANSLUCENT");
        } else {
            System.out.println("Passed: TRANSLUCENT unsupported");
        }
    }
    if (useNonOpaque) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
            System.out.println("applying PERPIXEL_TRANSLUCENT");
            frame.setBackground(new Color(0, 0, 0, 0));
            frame.setTitle("PERPIXEL_TRANSLUCENT");
        } else {
            System.out.println("Passed: PERPIXEL_TRANSLUCENT unsupported");
        }
    }
    frame.setVisible(true);
    return frame;
}
Also used : JFrame(javax.swing.JFrame) Frame(java.awt.Frame) MouseEvent(java.awt.event.MouseEvent) Canvas(java.awt.Canvas) Color(java.awt.Color) JButton(javax.swing.JButton) JComponent(javax.swing.JComponent) MouseAdapter(java.awt.event.MouseAdapter) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) Ellipse2D(java.awt.geom.Ellipse2D) Graphics(java.awt.Graphics) GraphicsDevice(java.awt.GraphicsDevice) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent)

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