jdk/test/javax/swing/border/Test7022041.java
author serb
Tue, 12 Nov 2013 20:24:25 +0400
changeset 21596 0e3a39f29dbc
parent 14856 92a1bcf46888
child 23010 6dadb192ad81
permissions -rw-r--r--
8027696: Incorrect copyright header in the tests Reviewed-by: alanb, malenkov, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13236
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
     1
/*
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
     4
 *
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 14856
diff changeset
     7
 * published by the Free Software Foundation.
13236
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
     8
 *
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    13
 * accompanied this code).
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    14
 *
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
14856
92a1bcf46888 8004982: JDK8 source with GPL header errors
katleman
parents: 13236
diff changeset
    18
 *
92a1bcf46888 8004982: JDK8 source with GPL header errors
katleman
parents: 13236
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
92a1bcf46888 8004982: JDK8 source with GPL header errors
katleman
parents: 13236
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
92a1bcf46888 8004982: JDK8 source with GPL header errors
katleman
parents: 13236
diff changeset
    21
 * questions.
13236
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    22
 */
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    23
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    24
import java.awt.Color;
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    25
import java.awt.Font;
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    26
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    27
import javax.swing.border.EmptyBorder;
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    28
import javax.swing.border.TitledBorder;
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    29
import javax.swing.UIManager;
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    30
import javax.swing.UnsupportedLookAndFeelException;
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    31
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    32
/* @test
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    33
 * @bug 7022041
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    34
 * @summary This test check the behaviour of getTitleFont() and getTitleColor()
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    35
 *          methods of the TitledBorder class.
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    36
 * @author Pavel Tisnovsky
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    37
 */
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    38
public class Test7022041 {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    39
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    40
    public static void main(String[] args) throws Exception {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    41
        UIManager.LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    42
        // try to test all installed Look and Feels
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    43
        for (UIManager.LookAndFeelInfo lookAndFeel : installedLookAndFeels) {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    44
            String name = lookAndFeel.getName();
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    45
            System.out.println("Testing " + name);
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    46
            // Some Look and Feels work only when test is run in a GUI environment
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    47
            // (GTK+ LAF is an example)
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    48
            try {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    49
                UIManager.setLookAndFeel(lookAndFeel.getClassName());
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    50
                checkTitleColor();
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    51
                System.out.println("    titleColor test ok");
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    52
                checkTitleFont();
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    53
                System.out.println("    titleFont test ok");
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    54
            }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    55
            catch (UnsupportedLookAndFeelException e) {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    56
                System.out.println("    Note: LookAndFeel " + name
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    57
                                 + " is not supported on this configuration");
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    58
            }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    59
        }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    60
    }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    61
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    62
    /**
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    63
      * Check behaviour of method TitledBorder.getTitleColor()
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    64
      */
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    65
    private static void checkTitleColor() {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    66
        TitledBorder titledBorder = new TitledBorder(new EmptyBorder(1, 1, 1, 1));
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    67
        Color defaultColor = UIManager.getLookAndFeelDefaults().getColor("TitledBorder.titleColor");
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    68
        Color titledBorderColor = titledBorder.getTitleColor();
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    69
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    70
        // check default configuration
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    71
        if (defaultColor == null) {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    72
            if (titledBorderColor == null) {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    73
                return;
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    74
            }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    75
            else {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    76
                throw new RuntimeException("TitledBorder default color should be null");
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    77
            }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    78
        }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    79
        if (!defaultColor.equals(titledBorderColor)) {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    80
            throw new RuntimeException("L&F default color " + defaultColor.toString()
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    81
                                     + " differs from TitledBorder color " + titledBorderColor.toString());
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    82
        }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    83
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    84
        // title color is explicitly specified
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    85
        Color color = Color.green;
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    86
        titledBorder.setTitleColor(color);
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    87
        if (!color.equals(titledBorder.getTitleColor())) {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    88
            throw new RuntimeException("TitledBorder color should be " + color.toString());
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    89
        }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    90
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    91
        // title color is unspecified
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    92
        titledBorder.setTitleColor(null);
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    93
        if (!defaultColor.equals(titledBorder.getTitleColor())) {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    94
            throw new RuntimeException("L&F default color " + defaultColor.toString()
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    95
                                     + " differs from TitledBorder color " + titledBorderColor.toString());
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    96
        }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    97
    }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    98
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
    99
    /**
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   100
      * Check behaviour of method TitledBorder.getTitleFont()
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   101
      */
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   102
    private static void checkTitleFont() {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   103
        TitledBorder titledBorder = new TitledBorder(new EmptyBorder(1, 1, 1, 1));
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   104
        Font defaultFont = UIManager.getLookAndFeelDefaults().getFont("TitledBorder.font");
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   105
        Font titledBorderFont = titledBorder.getTitleFont();
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   106
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   107
        // check default configuration
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   108
        if (defaultFont == null) {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   109
            if (titledBorderFont == null) {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   110
                return;
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   111
            }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   112
            else {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   113
                throw new RuntimeException("TitledBorder default font should be null");
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   114
            }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   115
        }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   116
        if (!defaultFont.equals(titledBorderFont)) {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   117
            throw new RuntimeException("L&F default font " + defaultFont.toString()
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   118
                                     + " differs from TitledBorder font " + titledBorderFont.toString());
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   119
        }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   120
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   121
        // title font is explicitly specified
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   122
        Font font = new Font("Dialog", Font.PLAIN, 10);
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   123
        titledBorder.setTitleFont(font);
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   124
        if (!font.equals(titledBorder.getTitleFont())) {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   125
            throw new RuntimeException("TitledBorder font should be " + font.toString());
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   126
        }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   127
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   128
        // title Font is unspecified
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   129
        titledBorder.setTitleFont(null);
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   130
        if (!defaultFont.equals(titledBorder.getTitleFont())) {
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   131
            throw new RuntimeException("L&F default font " + defaultFont.toString()
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   132
                                     + " differs from TitledBorder font " + titledBorderFont.toString());
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   133
        }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   134
    }
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   135
}
80fab7a1ebd6 7022041: TitleBorder Null Pointer Exception
ptisnovs
parents:
diff changeset
   136