0N/A/*
3862N/A * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
3862N/A * @bug 4856008 7025987
0N/A * @summary Tests border insets
0N/A * @author Sergey Malenkov
0N/A */
0N/A
0N/Aimport com.sun.java.swing.plaf.motif.MotifBorders;
0N/Aimport com.sun.java.swing.plaf.windows.WindowsBorders;
0N/A
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Font;
0N/Aimport java.awt.Insets;
0N/A
1356N/Aimport javax.swing.ActionMap;
0N/Aimport javax.swing.JComponent;
0N/Aimport javax.swing.JFileChooser;
0N/Aimport javax.swing.JLabel;
0N/Aimport javax.swing.JPopupMenu;
0N/Aimport javax.swing.JToggleButton;
0N/Aimport javax.swing.JToolBar;
0N/Aimport javax.swing.border.AbstractBorder;
0N/Aimport javax.swing.border.BevelBorder;
0N/Aimport javax.swing.border.Border;
0N/Aimport javax.swing.border.CompoundBorder;
0N/Aimport javax.swing.border.EmptyBorder;
0N/Aimport javax.swing.border.EtchedBorder;
0N/Aimport javax.swing.border.LineBorder;
0N/Aimport javax.swing.border.MatteBorder;
0N/Aimport javax.swing.border.SoftBevelBorder;
0N/Aimport javax.swing.border.TitledBorder;
1356N/Aimport javax.swing.plaf.ActionMapUIResource;
0N/Aimport javax.swing.plaf.BorderUIResource;
0N/Aimport javax.swing.plaf.synth.SynthLookAndFeel;
0N/Aimport javax.swing.plaf.basic.BasicBorders;
0N/Aimport javax.swing.plaf.basic.BasicToolBarUI;
0N/Aimport javax.swing.plaf.metal.MetalBorders;
0N/Aimport javax.swing.plaf.metal.MetalComboBoxEditor;
3862N/Aimport javax.swing.plaf.nimbus.NimbusLookAndFeel;
0N/A
0N/Aimport sun.swing.plaf.synth.SynthFileChooserUI;
0N/A
0N/Apublic class Test4856008 {
0N/A private static final JLabel LABEL = new JLabel();
0N/A private static final JPopupMenu POPUP = new JPopupMenu();
0N/A private static final JToolBar TOOLBAR = new JToolBar();
0N/A
0N/A private static final Border[] BORDERS = {
0N/A new MotifBorders.BevelBorder(true, Color.BLACK, Color.WHITE),
0N/A new MotifBorders.ButtonBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
0N/A new MotifBorders.FocusBorder(Color.BLACK, Color.WHITE),
0N/A new MotifBorders.FrameBorder(LABEL),
0N/A new MotifBorders.MenuBarBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
0N/A new MotifBorders.MotifPopupMenuBorder(new Font(null, Font.PLAIN, 10), Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
0N/A new MotifBorders.ToggleButtonBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
0N/A
0N/A new WindowsBorders.ProgressBarBorder(Color.BLACK, Color.WHITE),
0N/A new WindowsBorders.ToolBarBorder(Color.BLACK, Color.WHITE),
0N/A //- WindowsInternalFrameUI.XPBorder is not accessible: check it visually
0N/A //? WindowsTableHeaderUI.IconBorder is not accessible: check it visually
0N/A //- XPStyle.XPEmptyBorder is not accessible: check it visually
0N/A //- XPStyle.XPFillBorder is not accessible: check it visually
0N/A //- XPStyle.XPImageBorder is not accessible: check it visually
0N/A
0N/A new BevelBorder(BevelBorder.RAISED),
0N/A new CompoundBorder(),
0N/A new EmptyBorder(1, 2, 3, 4),
0N/A new EtchedBorder(),
0N/A new LineBorder(Color.BLACK, 2, true),
0N/A new MatteBorder(1, 2, 3, 4, Color.BLACK),
0N/A new SoftBevelBorder(BevelBorder.LOWERED),
0N/A new TitledBorder("4856008"),
0N/A
0N/A new BorderUIResource(new EmptyBorder(1, 2, 3, 4)),
0N/A
0N/A new BasicBorders.ButtonBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
0N/A new BasicBorders.FieldBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
0N/A new BasicBorders.MarginBorder(),
0N/A new BasicBorders.MenuBarBorder(Color.BLACK, Color.WHITE),
0N/A new BasicBorders.RadioButtonBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
0N/A //+ BasicBorders.RolloverMarginBorder:
0N/A new ToolBar().getRolloverMarginBorder(),
0N/A new BasicBorders.SplitPaneBorder(Color.BLACK, Color.WHITE),
0N/A //+ BasicBorders.SplitPaneDividerBorder:
0N/A BasicBorders.getSplitPaneDividerBorder(),
0N/A new BasicBorders.ToggleButtonBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
0N/A
0N/A new MetalBorders.ButtonBorder(),
0N/A //- MetalBorders.DialogBorder is not accessible: check it visually
0N/A new MetalBorders.Flush3DBorder(),
0N/A //- MetalBorders.FrameBorder is not accessible: check it visually
0N/A new MetalBorders.InternalFrameBorder(),
0N/A new MetalBorders.MenuBarBorder(),
0N/A new MetalBorders.MenuItemBorder(),
0N/A new MetalBorders.OptionDialogBorder(),
0N/A new MetalBorders.PaletteBorder(),
0N/A new MetalBorders.PopupMenuBorder(),
0N/A //- MetalBorders.RolloverMarginBorder is not accessible: check it visually
0N/A new MetalBorders.ScrollPaneBorder(),
0N/A new MetalBorders.TableHeaderBorder(),
0N/A new MetalBorders.ToolBarBorder(),
0N/A //+ MetalComboBoxEditor.EditorBorder:
0N/A new MetalEditor().getEditorBorder(),
0N/A
0N/A //- SynthBorder is not accessible: check it visually
0N/A //- SynthScrollPaneUI.ViewportBorder is not accessible: check it visually
0N/A
0N/A //? CSSBorder is not accessible: check it visually
0N/A //? CommentView.CommentBorder is not accessible: check it visually
0N/A //- HiddenTagView.EndTagBorder is not accessible: check it visually
0N/A //- HiddenTagView.StartTagBorder is not accessible: check it visually
0N/A
0N/A //+ SynthFileChooserUI.UIBorder:
0N/A new SynthFileChooser().getUIBorder(),
3862N/A
3862N/A //+ LoweredBorder:
3862N/A new NimbusLookAndFeel().getDefaults().getBorder("TitledBorder.border"),
0N/A };
0N/A
0N/A public static void main(String[] args) {
0N/A for (Border border : BORDERS) {
0N/A System.out.println(border.getClass());
0N/A test(border, border.getBorderInsets(getComponent(border)));
0N/A if (border instanceof AbstractBorder) {
0N/A test((AbstractBorder) border);
0N/A }
0N/A }
0N/A }
0N/A
0N/A private static void test(AbstractBorder border) {
0N/A Insets insets = new Insets(0, 0, 0, 0);
0N/A if (insets != border.getBorderInsets(getComponent(border), insets)) {
0N/A throw new Error("both instances are differ for " + border.getClass());
0N/A }
0N/A test(border, insets);
0N/A }
0N/A
0N/A private static void test(Border border, Insets insets) {
0N/A Insets result = border.getBorderInsets(getComponent(border));
0N/A if (insets == result) {
0N/A throw new Error("both instances are the same for " + border.getClass());
0N/A }
0N/A if (!insets.equals(result)) {
0N/A throw new Error("both insets are not equal for " + border.getClass());
0N/A }
0N/A }
0N/A
0N/A private static JComponent getComponent(Border border) {
0N/A Class type = border.getClass();
0N/A if (type.equals(MotifBorders.MotifPopupMenuBorder.class)) {
0N/A return POPUP;
0N/A }
0N/A if (type.equals(WindowsBorders.ToolBarBorder.class)) {
0N/A return TOOLBAR;
0N/A }
0N/A if (type.equals(MetalBorders.ToolBarBorder.class)) {
0N/A return TOOLBAR;
0N/A }
0N/A return LABEL;
0N/A }
0N/A
0N/A // This class is used to get the instance of BasicBorders.RolloverMarginBorder
0N/A private static class ToolBar extends BasicToolBarUI {
0N/A private Border getRolloverMarginBorder() {
0N/A JToggleButton button = new JToggleButton();
0N/A CompoundBorder border = (CompoundBorder) getNonRolloverBorder(button);
0N/A return border.getInsideBorder();
0N/A }
0N/A }
0N/A
0N/A // This class is used to get the instance of MetalComboBoxEditor.EditorBorder
0N/A private static class MetalEditor extends MetalComboBoxEditor {
0N/A private Border getEditorBorder() {
0N/A return editor.getBorder();
0N/A }
0N/A }
0N/A
0N/A // This class is used to get the instance of SynthFileChooserUI.UIBorder
0N/A private static class SynthFileChooser extends SynthFileChooserUI {
0N/A private static final JFileChooser CHOOSER = new JFileChooser();
0N/A private String name;
0N/A
0N/A private SynthFileChooser() {
0N/A super(CHOOSER);
0N/A }
0N/A
0N/A private Border getUIBorder() {
0N/A new SynthLookAndFeel().initialize();
0N/A CHOOSER.setBorder(null);
0N/A installDefaults(CHOOSER);
0N/A return CHOOSER.getBorder();
0N/A }
0N/A
0N/A @Override
1356N/A protected ActionMap createActionMap() {
1356N/A return new ActionMapUIResource();
1356N/A }
1356N/A
1356N/A @Override
0N/A public String getFileName() {
0N/A return this.name;
0N/A }
0N/A
0N/A @Override
0N/A public void setFileName(String name) {
0N/A this.name = name;
0N/A }
0N/A }
0N/A}