jdk/test/javax/swing/JComponent/6989617/bug6989617.java
author alexp
Fri, 15 Apr 2011 20:50:06 +0400
changeset 9228 6d4f3b084c97
parent 8372 786e091594a0
child 27764 4e79ff3e0602
permissions -rw-r--r--
7032903: javax/swing/JComponent/6989617/bug6989617.java test fails against jdk7 Reviewed-by: rupashka
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
     1
/*
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
     4
 *
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
     8
 *
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    13
 * accompanied this code).
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    14
 *
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    18
 *
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    21
 * questions.
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    22
 */
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    23
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    24
/* @test
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    25
   @bug 6989617
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    26
   @summary Enable JComponent to control repaintings of its children
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    27
   @author Alexander Potochkin
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    28
   @run main bug6989617
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    29
*/
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    30
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    31
import sun.awt.SunToolkit;
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    32
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    33
import javax.swing.*;
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    34
import java.awt.*;
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    35
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    36
public class bug6989617 {
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    37
    private static MyPanel panel;
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    38
    private static JButton button;
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    39
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    40
    public static void main(String... args) throws Exception {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    41
        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    42
        SwingUtilities.invokeAndWait(new Runnable() {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    43
            public void run() {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    44
                JFrame frame = new JFrame();
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    45
                frame. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    46
                panel = new MyPanel();
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    47
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    48
                button = new JButton("Hello");
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    49
                panel.add(button);
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    50
                frame.add(panel);
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    51
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    52
                frame.setSize(200, 300);
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    53
                frame.setVisible(true);
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    54
            }
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    55
        });
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    56
        // Testing the panel as a painting origin,
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    57
        // the panel.paintImmediately() must be triggered
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    58
        // when button.repaint() is called
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    59
        toolkit.realSync();
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    60
        SwingUtilities.invokeAndWait(new Runnable() {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    61
            public void run() {
9228
6d4f3b084c97 7032903: javax/swing/JComponent/6989617/bug6989617.java test fails against jdk7
alexp
parents: 8372
diff changeset
    62
                panel.resetPaintRectangle();
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    63
                button.repaint();
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    64
            }
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    65
        });
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    66
        toolkit.realSync();
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    67
        SwingUtilities.invokeAndWait(new Runnable() {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    68
            public void run() {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    69
                Rectangle pr = panel.getPaintRectangle();
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    70
                if (!pr.getSize().equals(button.getSize())) {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    71
                    throw new RuntimeException("wrong size of the dirty area");
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    72
                }
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    73
                if (!pr.getLocation().equals(button.getLocation())) {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    74
                    throw new RuntimeException("wrong location of the dirty area");
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    75
                }
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    76
            }
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    77
        });
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    78
        // Testing the panel as NOT a painting origin
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    79
        // the panel.paintImmediately() must NOT be triggered
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    80
        // when button.repaint() is called
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    81
        toolkit.realSync();
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    82
        SwingUtilities.invokeAndWait(new Runnable() {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    83
            public void run() {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    84
                panel.resetPaintRectangle();
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    85
                panel.setPaintingOrigin(false);
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    86
                if (panel.getPaintRectangle() != null) {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    87
                    throw new RuntimeException("paint rectangle is not null");
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    88
                }
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    89
                button.repaint();
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
    90
            }
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    91
        });
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    92
        toolkit.realSync();
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    93
        SwingUtilities.invokeAndWait(new Runnable() {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    94
            public void run() {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    95
                if(panel.getPaintRectangle() != null) {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    96
                    throw new RuntimeException("paint rectangle is not null");
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    97
                }
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    98
                System.out.println("Test passed...");
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
    99
            }
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   100
        });
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   101
    }
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
   102
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   103
    static class MyPanel extends JPanel {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   104
        private boolean isPaintingOrigin = true;
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   105
        private Rectangle paintRectangle;
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
   106
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   107
        {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   108
            setLayout(new GridBagLayout());
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   109
        }
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   110
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   111
        public boolean isPaintingOrigin() {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   112
            return isPaintingOrigin;
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
   113
        }
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   114
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   115
        public void setPaintingOrigin(boolean paintingOrigin) {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   116
            isPaintingOrigin = paintingOrigin;
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
   117
        }
8372
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   118
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   119
        public void paintImmediately(int x, int y, int w, int h) {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   120
            super.paintImmediately(x, y, w, h);
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   121
            paintRectangle = new Rectangle(x, y, w, h);
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   122
        }
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   123
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   124
        public Rectangle getPaintRectangle() {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   125
            return paintRectangle == null? null: new Rectangle(paintRectangle);
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   126
        }
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   127
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   128
        public void resetPaintRectangle() {
786e091594a0 6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents: 7005
diff changeset
   129
            this.paintRectangle = null;
7005
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
   130
        }
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
   131
    }
5e6d24f4303b 6989617: Enable JComponent to control repaintings of its children
alexp
parents:
diff changeset
   132
}