1 /* 2 * Copyright (c) 2009, 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 6657026 27 * @summary Tests constancy of borders 28 * @author Sergey Malenkov 29 */ 30 31 import java.awt.Insets; 32 import javax.swing.border.Border; 33 import javax.swing.plaf.metal.MetalBorders.ButtonBorder; 34 import javax.swing.plaf.metal.MetalBorders.MenuBarBorder; 35 import javax.swing.plaf.metal.MetalBorders.MenuItemBorder; 36 import javax.swing.plaf.metal.MetalBorders.PopupMenuBorder; 37 38 public class Test6657026 { 39 40 private static final Insets NEGATIVE = new Insets(Integer.MIN_VALUE, 41 Integer.MIN_VALUE, 42 Integer.MIN_VALUE, 43 Integer.MIN_VALUE); 44 main(String[] args)45 public static void main(String[] args) { 46 new ButtonBorder() {{borderInsets = NEGATIVE;}}; 47 new MenuBarBorder() {{borderInsets = NEGATIVE;}}; 48 new MenuItemBorder() {{borderInsets = NEGATIVE;}}; 49 new PopupMenuBorder() {{borderInsets = NEGATIVE;}}; 50 51 test(create("ButtonBorder")); 52 test(create("MenuBarBorder")); 53 test(create("MenuItemBorder")); 54 test(create("PopupMenuBorder")); 55 56 test(create("Flush3DBorder")); 57 test(create("InternalFrameBorder")); 58 // NOT USED: test(create("FrameBorder")); 59 // NOT USED: test(create("DialogBorder")); 60 test(create("PaletteBorder")); 61 test(create("OptionDialogBorder")); 62 test(create("ScrollPaneBorder")); 63 } 64 create(String name)65 private static Border create(String name) { 66 try { 67 name = "javax.swing.plaf.metal.MetalBorders$" + name; 68 return (Border) Class.forName(name).newInstance(); 69 } 70 catch (Exception exception) { 71 throw new Error("unexpected exception", exception); 72 } 73 } 74 test(Border border)75 private static void test(Border border) { 76 Insets actual = border.getBorderInsets(null); 77 if (NEGATIVE.equals(actual)) { 78 throw new Error("unexpected insets in " + border.getClass()); 79 } 80 Insets expected = (Insets) actual.clone(); 81 // modify 82 actual.top++; 83 actual.left++; 84 actual.right++; 85 actual.bottom++; 86 // validate 87 if (!expected.equals(border.getBorderInsets(null))) { 88 throw new Error("shared insets in " + border.getClass()); 89 } 90 } 91 } 92