jdk/test/javax/swing/RepaintManager/6608456/bug6608456.java
author dcubed
Wed, 20 Jun 2012 14:18:25 -0700
changeset 13092 3b4aad065f27
parent 5506 202f599c92aa
child 31660 1a4e2e5c15e1
permissions -rw-r--r--
7175255: symlinks are wrong, which caused jdk8-promote-2 to fail (client/64/64 directories in debuginfo zips) Summary: Fix bad paths in client/64 and server/64 debug info and symlink creation Reviewed-by: ohair, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1291
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     2
 * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
1291
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
     4
 *
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
     8
 *
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    13
 * accompanied this code).
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    14
 *
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    21
 * questions.
1291
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    22
 */
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    23
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    24
/* @test
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    25
 *
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    26
 * @bug 6608456
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    27
 * @author Igor Kushnirskiy
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    28
 * @summary tests if delegate RepaintManager gets invoked.
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    29
 */
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    30
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    31
import java.awt.*;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    32
import java.lang.reflect.Method;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    33
import java.util.concurrent.Callable;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    34
import java.util.concurrent.FutureTask;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    35
import java.util.concurrent.TimeUnit;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    36
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    37
import javax.swing.JComponent;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    38
import javax.swing.JButton;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    39
import javax.swing.JFrame;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    40
import javax.swing.RepaintManager;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    41
import javax.swing.SwingUtilities;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    42
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    43
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    44
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    45
public class bug6608456 {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    46
    private static final TestFuture testFuture = new TestFuture();
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    47
    public static void main(String[] args) throws Exception {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    48
        final JComponent component = invokeAndWait(
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    49
            new Callable<JComponent>() {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    50
                public JComponent call() throws Exception {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    51
                    RepaintManager.setCurrentManager(new TestRepaintManager());
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    52
                    JFrame frame = new JFrame("test");
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    53
                    frame.setLayout(new FlowLayout());
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    54
                    JButton button = new JButton("default");
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    55
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    56
                    frame.add(button);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    57
                    button = new JButton("delegate");
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    58
                    if ( ! registerDelegate(
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    59
                             button, new TestRepaintManager())) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    60
                        return null;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    61
                    }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    62
                    frame.add(button);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    63
                    frame.pack();
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    64
                    frame.setVisible(true);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    65
                    return button;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    66
                }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    67
            });
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    68
        if (component == null) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    69
            throw new RuntimeException("failed. can not register delegate");
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    70
        }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    71
        blockTillDisplayed(component);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    72
        // trigger repaint for delegate RepaintManager
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    73
        invokeAndWait(
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    74
            new Callable<Void>() {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    75
                public Void call() {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    76
                    component.repaint();
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    77
                    return null;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    78
                }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    79
        });
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    80
        try {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    81
            if (testFuture.get(10, TimeUnit.SECONDS)) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    82
                // passed
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    83
            }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    84
        } catch (Exception e) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    85
            throw new RuntimeException("failed", e);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    86
        } finally {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    87
            JFrame frame = (JFrame) SwingUtilities
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    88
                .getAncestorOfClass(JFrame.class, component);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    89
            if (frame != null) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    90
                frame.dispose();
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    91
            }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    92
        }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    93
    }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    94
    static class TestRepaintManager extends RepaintManager {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    95
        @Override
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    96
        public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    97
            if (RepaintManager.currentManager(c) == this) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    98
                testFuture.defaultCalled();
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
    99
            } else {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   100
                testFuture.delegateCalled();
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   101
            }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   102
            super.addDirtyRegion(c, x, y, w, h);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   103
        }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   104
    }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   105
    static class TestFuture extends FutureTask<Boolean> {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   106
        private volatile boolean defaultCalled = false;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   107
        private volatile boolean delegateCalled = false;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   108
        public TestFuture() {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   109
            super(new Callable<Boolean>() {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   110
                public Boolean call() {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   111
                    return null;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   112
                }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   113
            });
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   114
        }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   115
        public void defaultCalled() {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   116
            defaultCalled = true;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   117
            updateState();
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   118
        }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   119
        public void delegateCalled() {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   120
            delegateCalled = true;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   121
            updateState();
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   122
        }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   123
        private void updateState() {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   124
            if (defaultCalled && delegateCalled) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   125
                set(Boolean.TRUE);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   126
            }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   127
        }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   128
    }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   129
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   130
    private static boolean registerDelegate(JComponent c,
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   131
            RepaintManager repaintManager) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   132
        boolean rv = false;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   133
        try {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   134
            Class<?> clazz = Class.forName("com.sun.java.swing.SwingUtilities3");
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   135
            Method method = clazz.getMethod("setDelegateRepaintManager",
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   136
                JComponent.class, RepaintManager.class);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   137
            method.invoke(clazz, c, repaintManager);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   138
            rv = true;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   139
        } catch (Exception ignore) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   140
        }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   141
        return rv;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   142
    }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   143
    static <T> T invokeAndWait(Callable<T> callable) throws Exception {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   144
        FutureTask<T> future = new FutureTask<T>(callable);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   145
        SwingUtilities.invokeLater(future);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   146
        return future.get();
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   147
    }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   148
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   149
    public static void blockTillDisplayed(Component comp) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   150
        Point p = null;
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   151
        while (p == null) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   152
            try {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   153
                p = comp.getLocationOnScreen();
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   154
            } catch (IllegalStateException e) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   155
                try {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   156
                    Thread.sleep(100);
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   157
                } catch (InterruptedException ie) {
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   158
                }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   159
            }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   160
        }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   161
    }
e56898d6642d 6608456: need API to define RepaintManager per components hierarchy
idk
parents:
diff changeset
   162
}