|
| 1 | +/* |
| 2 | + * Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +import java.awt.Color; |
| 25 | +import java.awt.Dimension; |
| 26 | +import java.awt.Font; |
| 27 | +import java.awt.FontMetrics; |
| 28 | +import java.awt.Frame; |
| 29 | +import java.awt.Graphics; |
| 30 | +import java.awt.Image; |
| 31 | +import java.awt.image.BufferedImage; |
| 32 | +import java.lang.reflect.InvocationTargetException; |
| 33 | + |
| 34 | +/* |
| 35 | + * @test |
| 36 | + * @bug 4081126 4129709 |
| 37 | + * @summary Test for proper repainting on multiprocessor systems. |
| 38 | + * @library /java/awt/regtesthelpers |
| 39 | + * @build PassFailJFrame |
| 40 | + * @run main/manual RepeatedRepaintTest |
| 41 | + */ |
| 42 | +public class RepeatedRepaintTest extends Frame { |
| 43 | + private Font font = null; |
| 44 | + private Image background; |
| 45 | + |
| 46 | + static String INSTRUCTIONS = """ |
| 47 | + The frame next to this window called "AWT Draw Test" has |
| 48 | + some elements drawn on it. Move this window partially outside of the |
| 49 | + screen bounds and then drag it back. Repeat it couple of times. |
| 50 | + Drag the instructions window over the frame partially obscuring it. |
| 51 | + If after number of attempts the frame content stops repainting |
| 52 | + press "Fail", otherwise press "Pass". |
| 53 | + """; |
| 54 | + |
| 55 | + public RepeatedRepaintTest() { |
| 56 | + setTitle("AWT Draw Test"); |
| 57 | + setSize(300, 300); |
| 58 | + background = new BufferedImage(300, 300, BufferedImage.TYPE_INT_ARGB); |
| 59 | + Graphics g = background.getGraphics(); |
| 60 | + g.setColor(Color.black); |
| 61 | + g.fillRect(0, 0, 300, 300); |
| 62 | + g.dispose(); |
| 63 | + } |
| 64 | + |
| 65 | + public void paint(Graphics g) { |
| 66 | + Dimension dim = this.getSize(); |
| 67 | + super.paint(g); |
| 68 | + g.drawImage(background, 0, 0, dim.width, dim.height, null); |
| 69 | + g.setColor(Color.white); |
| 70 | + if (font == null) { |
| 71 | + font = new Font("SansSerif", Font.PLAIN, 24); |
| 72 | + } |
| 73 | + g.setFont(font); |
| 74 | + FontMetrics metrics = g.getFontMetrics(); |
| 75 | + String message = "Draw Test"; |
| 76 | + g.drawString(message, (dim.width / 2) - (metrics.stringWidth(message) / 2), |
| 77 | + (dim.height / 2) + (metrics.getHeight() / 2)); |
| 78 | + |
| 79 | + int counter = 50; |
| 80 | + for (int i = 0; i < 50; i++) { |
| 81 | + counter += 4; |
| 82 | + g.drawOval(counter, 50, i, i); |
| 83 | + } |
| 84 | + |
| 85 | + counter = 20; |
| 86 | + for (int i = 0; i < 100; i++) { |
| 87 | + counter += 4; |
| 88 | + g.drawOval(counter, 150, i, i); |
| 89 | + } |
| 90 | + g.setColor(Color.black); |
| 91 | + g.drawLine(0, dim.height - 25, dim.width, dim.height - 25); |
| 92 | + g.setColor(Color.gray); |
| 93 | + g.drawLine(0, dim.height - 24, dim.width, dim.height - 24); |
| 94 | + g.setColor(Color.lightGray); |
| 95 | + g.drawLine(0, dim.height - 23, dim.width, dim.height - 23); |
| 96 | + g.fillRect(0, dim.height - 22, dim.width, dim.height); |
| 97 | + |
| 98 | + |
| 99 | + g.setXORMode(Color.blue); |
| 100 | + g.fillRect(0, 0, 25, dim.height - 26); |
| 101 | + g.setColor(Color.red); |
| 102 | + g.fillRect(0, 0, 25, dim.height - 26); |
| 103 | + g.setColor(Color.green); |
| 104 | + g.fillRect(0, 0, 25, dim.height - 26); |
| 105 | + g.setPaintMode(); |
| 106 | + |
| 107 | + Image img = createImage(50, 50); |
| 108 | + Graphics imgGraphics = img.getGraphics(); |
| 109 | + imgGraphics.setColor(Color.magenta); |
| 110 | + imgGraphics.fillRect(0, 0, 50, 50); |
| 111 | + imgGraphics.setColor(Color.yellow); |
| 112 | + imgGraphics.drawString("offscreen", 0, 20); |
| 113 | + imgGraphics.drawString("image", 0, 30); |
| 114 | + |
| 115 | + g.drawImage(img, dim.width - 100, dim.height - 100, Color.blue, null); |
| 116 | + |
| 117 | + g.setXORMode(Color.white); |
| 118 | + drawAt(g, 100, 100, 50, 50); |
| 119 | + drawAt(g, 105, 105, 50, 50); |
| 120 | + drawAt(g, 110, 110, 50, 50); |
| 121 | + } |
| 122 | + |
| 123 | + public void drawAt(Graphics g, int x, int y, int width, int height) { |
| 124 | + g.setColor(Color.magenta); |
| 125 | + g.fillRect(x, y, width, height); |
| 126 | + } |
| 127 | + |
| 128 | + public static void main(String[] args) throws InterruptedException, |
| 129 | + InvocationTargetException { |
| 130 | + PassFailJFrame.builder() |
| 131 | + .title("Repeated Repaint Test Instructions") |
| 132 | + .instructions(INSTRUCTIONS) |
| 133 | + .testUI(RepeatedRepaintTest::new) |
| 134 | + .build() |
| 135 | + .awaitAndCheck(); |
| 136 | + } |
| 137 | +} |
0 commit comments