|
| 1 | +/* |
| 2 | + * Copyright (c) 1997, 2024, 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 | +/* |
| 25 | + * @test |
| 26 | + * @bug 4045781 |
| 27 | + * @summary Exposed/damaged canvases don't always update correctly |
| 28 | + * @library /java/awt/regtesthelpers |
| 29 | + * @build PassFailJFrame |
| 30 | + * @run main/manual PaintGlitchTest |
| 31 | + */ |
| 32 | + |
| 33 | +import java.awt.Button; |
| 34 | +import java.awt.Canvas; |
| 35 | +import java.awt.Checkbox; |
| 36 | +import java.awt.Choice; |
| 37 | +import java.awt.Color; |
| 38 | +import java.awt.Component; |
| 39 | +import java.awt.Dialog; |
| 40 | +import java.awt.Dimension; |
| 41 | +import java.awt.Font; |
| 42 | +import java.awt.Frame; |
| 43 | +import java.awt.Graphics; |
| 44 | +import java.awt.Label; |
| 45 | +import java.awt.Menu; |
| 46 | +import java.awt.MenuBar; |
| 47 | +import java.awt.MenuItem; |
| 48 | +import java.awt.Panel; |
| 49 | +import java.awt.Scrollbar; |
| 50 | +import java.awt.TextArea; |
| 51 | +import java.awt.TextField; |
| 52 | +import java.lang.reflect.InvocationTargetException; |
| 53 | +import javax.swing.JButton; |
| 54 | +import javax.swing.JCheckBox; |
| 55 | +import javax.swing.JComboBox; |
| 56 | +import javax.swing.JLabel; |
| 57 | +import javax.swing.JList; |
| 58 | +import javax.swing.JPanel; |
| 59 | +import javax.swing.JScrollBar; |
| 60 | +import javax.swing.JTextArea; |
| 61 | +import javax.swing.JTextField; |
| 62 | + |
| 63 | +public class PaintGlitchTest extends Frame { |
| 64 | + static final String INSTRUCTIONS = """ |
| 65 | + 1. Click on the 'Painting Glitch Test' window and select from |
| 66 | + its menu a content type (text, gradient, fill, |
| 67 | + AWT components, Swing components etc.). |
| 68 | + 2. Select 'Modal Dialog...' to create a dialog. |
| 69 | + 3. Drag the dialog over the content very fast |
| 70 | + for 10 seconds or so - make sure you |
| 71 | + keep dragging while the content is painting. |
| 72 | + 4. Verify that the area exposed by the drag (the damaged regions) |
| 73 | + always update properly no white areas or bits of the dialog |
| 74 | + should be left after the drag operation is |
| 75 | + completed (i.e. after you let go of the mouse). |
| 76 | + 5. Repeat for all other content types. |
| 77 | + 6. If for any content type the damaged dialog is not properly |
| 78 | + repainted press Fail. Otherwise press Pass. |
| 79 | + """; |
| 80 | + |
| 81 | + public PaintGlitchTest() { |
| 82 | + super("Painting Glitch Test"); |
| 83 | + |
| 84 | + TextPanel textPanel = new TextPanel(); |
| 85 | + GradientPanel gradientPanel = new GradientPanel(); |
| 86 | + ComponentPanel componentPanel = new ComponentPanel(); |
| 87 | + SwingPanel swingPanel = new SwingPanel(); |
| 88 | + |
| 89 | + add(textPanel); |
| 90 | + |
| 91 | + MenuBar menubar = new MenuBar(); |
| 92 | + Menu testMenu = new Menu("Test"); |
| 93 | + testMenu.add(makeContentItem("Text Lines", textPanel) ); |
| 94 | + testMenu.add(makeContentItem("Gradient Fill", gradientPanel) ); |
| 95 | + testMenu.add(makeContentItem("AWT Components", componentPanel) ); |
| 96 | + testMenu.add(makeContentItem("Swing Components", swingPanel) ); |
| 97 | + testMenu.addSeparator(); |
| 98 | + MenuItem dialogItem = new MenuItem("Modal Dialog..."); |
| 99 | + dialogItem.addActionListener(ev -> new ObscuringDialog(PaintGlitchTest.this).show()); |
| 100 | + testMenu.add(dialogItem); |
| 101 | + testMenu.addSeparator(); |
| 102 | + menubar.add(testMenu); |
| 103 | + |
| 104 | + setMenuBar(menubar); |
| 105 | + setSize(400,300); |
| 106 | + } |
| 107 | + |
| 108 | + public static void main(String args[]) throws InterruptedException, |
| 109 | + InvocationTargetException { |
| 110 | + PassFailJFrame.builder() |
| 111 | + .title("Repaint Glitch") |
| 112 | + .testUI(PaintGlitchTest::new) |
| 113 | + .instructions(INSTRUCTIONS) |
| 114 | + .columns(40) |
| 115 | + .logArea() |
| 116 | + .build() |
| 117 | + .awaitAndCheck(); |
| 118 | + } |
| 119 | + |
| 120 | + public MenuItem makeContentItem(String title, final Component content) { |
| 121 | + MenuItem menuItem = new MenuItem(title); |
| 122 | + menuItem.addActionListener( |
| 123 | + ev -> { |
| 124 | + remove(0); |
| 125 | + add(content); |
| 126 | + validate(); |
| 127 | + } |
| 128 | + ); |
| 129 | + |
| 130 | + return menuItem; |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +class GradientPanel extends Canvas { |
| 135 | + public void paint(Graphics g) { |
| 136 | + long ms = System.currentTimeMillis(); |
| 137 | + // just paint something that'll take a while |
| 138 | + int x, y; |
| 139 | + int width = getSize().width; |
| 140 | + int height = getSize().height; |
| 141 | + int step = 8; |
| 142 | + |
| 143 | + for (x = 0; x < width; x += step) { |
| 144 | + for (y = 0; y < height; y += step) { |
| 145 | + int red = (255 * y) / height; |
| 146 | + int green = (255 * x * y) / (width * height); |
| 147 | + int blue = (255 * x) / width; |
| 148 | + |
| 149 | + Color color = new Color(red, green, blue); |
| 150 | + g.setColor(color); |
| 151 | + g.fillRect(x, y, step, step); |
| 152 | + } |
| 153 | + } |
| 154 | + long time = System.currentTimeMillis() - ms; |
| 155 | + PassFailJFrame.log("GradientPanel paint took " + time + " ms"); |
| 156 | + } |
| 157 | + |
| 158 | + public Dimension getPreferredSize() { |
| 159 | + return new Dimension(200,1000); |
| 160 | + } |
| 161 | +} |
| 162 | + |
| 163 | +class TextPanel extends Canvas { |
| 164 | + public void paint(Graphics g) { |
| 165 | + long ms = System.currentTimeMillis(); |
| 166 | + Font font = new Font("SanSerif", Font.ITALIC, 12); |
| 167 | + |
| 168 | + g.setFont(font); |
| 169 | + // just paint something that'll take a while |
| 170 | + int x, y; |
| 171 | + int height = getHeight(); |
| 172 | + int step = 16; |
| 173 | + |
| 174 | + for (x = y = 0; y < height; y += step) { |
| 175 | + g.drawString(y + " : The quick brown fox jumps over the lazy dog. " + |
| 176 | + "The rain in Spain falls mainly on the plain.", x, y); |
| 177 | + } |
| 178 | + long time = System.currentTimeMillis() - ms; |
| 179 | + PassFailJFrame.log("TextPanel paint took " + time + " ms"); |
| 180 | + } |
| 181 | + |
| 182 | + public Dimension getPreferredSize() { |
| 183 | + return new Dimension(640,1000); |
| 184 | + } |
| 185 | +} |
| 186 | + |
| 187 | +class ComponentPanel extends Panel { |
| 188 | + ComponentPanel() { |
| 189 | + add(new Label("Label")); |
| 190 | + add(new Button("Button")); |
| 191 | + add(new Checkbox("Checkbox")); |
| 192 | + Choice c = new Choice(); |
| 193 | + c.add("choice"); |
| 194 | + java.awt.List l = new java.awt.List(); |
| 195 | + l.add("list"); |
| 196 | + add(new Scrollbar()); |
| 197 | + add(new TextField("TextField")); |
| 198 | + add(new TextArea("TextArea")); |
| 199 | + add(new Panel()); |
| 200 | + add(new Canvas()); |
| 201 | + } |
| 202 | +} |
| 203 | + |
| 204 | +class SwingPanel extends JPanel { |
| 205 | + SwingPanel() { |
| 206 | + add(new JLabel("JLabel")); |
| 207 | + add(new JButton("JButton")); |
| 208 | + add(new JCheckBox("JCheckBox")); |
| 209 | + JComboBox c = new JComboBox(); |
| 210 | + JList l = new JList(); |
| 211 | + add(new JScrollBar()); |
| 212 | + add(new JTextField("This is a JTextField with some text in it to make it longer.")); |
| 213 | + add(new JTextArea("This is a JTextArea with some text in it to make it longer.")); |
| 214 | + } |
| 215 | +} |
| 216 | + |
| 217 | +class ObscuringDialog extends Dialog { |
| 218 | + ObscuringDialog(Frame f) { |
| 219 | + super(f, "Obscuring Dialog"); |
| 220 | + Button ok = new Button("OK, go away"); |
| 221 | + ok.addActionListener(ev -> dispose()); |
| 222 | + add(ok); |
| 223 | + pack(); |
| 224 | + } |
| 225 | +} |
0 commit comments