jdk/test/javax/swing/JTableHeader/6889007/bug6889007.java
author alexp
Fri, 28 May 2010 19:46:26 +0400
changeset 5595 27cbc0c6ba34
child 6374 e214162c907e
permissions -rw-r--r--
6889007: No resize cursor during hovering mouse over JTable Reviewed-by: rupashka
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5595
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
     1
/*
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
     2
 * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
     4
 *
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
     8
 *
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    13
 * accompanied this code).
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    14
 *
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    18
 *
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    21
 * have any questions.
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    22
 */
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    23
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    24
/* @test
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    25
   @bug 6889007
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    26
   @summary No resize cursor during hovering mouse over JTable
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    27
   @author Alexander Potochkin
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    28
*/
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    29
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    30
import sun.awt.SunToolkit;
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    31
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    32
import javax.swing.*;
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    33
import javax.swing.plaf.basic.BasicTableHeaderUI;
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    34
import javax.swing.table.JTableHeader;
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    35
import java.awt.*;
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    36
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    37
public class bug6889007 {
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    38
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    40
        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    41
        Robot robot = new Robot();
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    42
        robot.setAutoDelay(20);
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    43
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    44
        final JFrame frame = new JFrame();
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    45
        frame.setUndecorated(true);
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    46
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    47
        SwingUtilities.invokeAndWait(new Runnable() {
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    48
            public void run() {
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    49
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    50
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    51
                JTableHeader th = new JTableHeader();
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    52
                th.setColumnModel(new JTable(20, 5).getColumnModel());
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    53
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    54
                th.setUI(new MyTableHeaderUI());
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    55
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    56
                frame.add(th);
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    57
                frame.pack();
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    58
                frame.setLocationRelativeTo(null);
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    59
                frame.setVisible(true);
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    60
            }
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    61
        });
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    62
        toolkit.realSync();
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    63
        Point point = frame.getLocationOnScreen();
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    64
        int shift = 10;
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    65
        int x = point.x;
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    66
        int y = point.y + frame.getHeight()/2;
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    67
        for(int i = -shift; i < frame.getWidth() + 2*shift; i++) {
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    68
            robot.mouseMove(x++, y);
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    69
        }
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    70
        toolkit.realSync();
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    71
        // 9 is a magic test number
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    72
        if (MyTableHeaderUI.getTestValue() != 9) {
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    73
            throw new RuntimeException("Unexpected test number "
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    74
                    + MyTableHeaderUI.getTestValue());
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    75
        }
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    76
        System.out.println("ok");
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    77
    }
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    78
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    79
    static class MyTableHeaderUI extends BasicTableHeaderUI {
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    80
        private static int testValue;
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    81
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    82
        protected void rolloverColumnUpdated(int oldColumn, int newColumn) {
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    83
            increaseTestValue(newColumn);
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    84
            Cursor cursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    85
            if (oldColumn != -1 && newColumn != -1 &&
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    86
                    header.getCursor() != cursor) {
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    87
                throw new RuntimeException("Wrong type of cursor!");
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    88
            }
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    89
        }
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    90
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    91
        private static synchronized void increaseTestValue(int increment) {
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    92
            testValue += increment;
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    93
        }
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    94
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    95
        public static synchronized int getTestValue() {
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    96
            return testValue;
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    97
        }
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    98
    }
27cbc0c6ba34 6889007: No resize cursor during hovering mouse over JTable
alexp
parents:
diff changeset
    99
}