blob: 1b045eb46ed76145ebf9ced5c6f6189a7159f9a6 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 4856008
27 * @summary Tests border insets
28 * @author Sergey Malenkov
29 */
30
31import com.sun.java.swing.plaf.motif.MotifBorders;
32import com.sun.java.swing.plaf.windows.WindowsBorders;
33
34import java.awt.Color;
35import java.awt.Font;
36import java.awt.Insets;
37
38import javax.swing.JComponent;
39import javax.swing.JFileChooser;
40import javax.swing.JLabel;
41import javax.swing.JPopupMenu;
42import javax.swing.JToggleButton;
43import javax.swing.JToolBar;
44import javax.swing.border.AbstractBorder;
45import javax.swing.border.BevelBorder;
46import javax.swing.border.Border;
47import javax.swing.border.CompoundBorder;
48import javax.swing.border.EmptyBorder;
49import javax.swing.border.EtchedBorder;
50import javax.swing.border.LineBorder;
51import javax.swing.border.MatteBorder;
52import javax.swing.border.SoftBevelBorder;
53import javax.swing.border.TitledBorder;
54import javax.swing.plaf.BorderUIResource;
55import javax.swing.plaf.synth.SynthLookAndFeel;
56import javax.swing.plaf.basic.BasicBorders;
57import javax.swing.plaf.basic.BasicToolBarUI;
58import javax.swing.plaf.metal.MetalBorders;
59import javax.swing.plaf.metal.MetalComboBoxEditor;
60
61import sun.swing.plaf.synth.SynthFileChooserUI;
62import sun.tools.jconsole.BorderedComponent;
63
64public class Test4856008 {
65 private static final JLabel LABEL = new JLabel();
66 private static final JPopupMenu POPUP = new JPopupMenu();
67 private static final JToolBar TOOLBAR = new JToolBar();
68
69 private static final Border[] BORDERS = {
70 new MotifBorders.BevelBorder(true, Color.BLACK, Color.WHITE),
71 new MotifBorders.ButtonBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
72 new MotifBorders.FocusBorder(Color.BLACK, Color.WHITE),
73 new MotifBorders.FrameBorder(LABEL),
74 new MotifBorders.MenuBarBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
75 new MotifBorders.MotifPopupMenuBorder(new Font(null, Font.PLAIN, 10), Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
76 new MotifBorders.ToggleButtonBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
77
78 new WindowsBorders.ProgressBarBorder(Color.BLACK, Color.WHITE),
79 new WindowsBorders.ToolBarBorder(Color.BLACK, Color.WHITE),
80 //- WindowsInternalFrameUI.XPBorder is not accessible: check it visually
81 //? WindowsTableHeaderUI.IconBorder is not accessible: check it visually
82 //- XPStyle.XPEmptyBorder is not accessible: check it visually
83 //- XPStyle.XPFillBorder is not accessible: check it visually
84 //- XPStyle.XPImageBorder is not accessible: check it visually
85
86 new BevelBorder(BevelBorder.RAISED),
87 new CompoundBorder(),
88 new EmptyBorder(1, 2, 3, 4),
89 new EtchedBorder(),
90 new LineBorder(Color.BLACK, 2, true),
91 new MatteBorder(1, 2, 3, 4, Color.BLACK),
92 new SoftBevelBorder(BevelBorder.LOWERED),
93 new TitledBorder("4856008"),
94
95 new BorderUIResource(new EmptyBorder(1, 2, 3, 4)),
96
97 new BasicBorders.ButtonBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
98 new BasicBorders.FieldBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
99 new BasicBorders.MarginBorder(),
100 new BasicBorders.MenuBarBorder(Color.BLACK, Color.WHITE),
101 new BasicBorders.RadioButtonBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
102 //+ BasicBorders.RolloverMarginBorder:
103 new ToolBar().getRolloverMarginBorder(),
104 new BasicBorders.SplitPaneBorder(Color.BLACK, Color.WHITE),
105 //+ BasicBorders.SplitPaneDividerBorder:
106 BasicBorders.getSplitPaneDividerBorder(),
107 new BasicBorders.ToggleButtonBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
108
109 new MetalBorders.ButtonBorder(),
110 //- MetalBorders.DialogBorder is not accessible: check it visually
111 new MetalBorders.Flush3DBorder(),
112 //- MetalBorders.FrameBorder is not accessible: check it visually
113 new MetalBorders.InternalFrameBorder(),
114 new MetalBorders.MenuBarBorder(),
115 new MetalBorders.MenuItemBorder(),
116 new MetalBorders.OptionDialogBorder(),
117 new MetalBorders.PaletteBorder(),
118 new MetalBorders.PopupMenuBorder(),
119 //- MetalBorders.RolloverMarginBorder is not accessible: check it visually
120 new MetalBorders.ScrollPaneBorder(),
121 new MetalBorders.TableHeaderBorder(),
122 new MetalBorders.ToolBarBorder(),
123 //+ MetalComboBoxEditor.EditorBorder:
124 new MetalEditor().getEditorBorder(),
125
126 //- SynthBorder is not accessible: check it visually
127 //- SynthScrollPaneUI.ViewportBorder is not accessible: check it visually
128
129 //? CSSBorder is not accessible: check it visually
130 //? CommentView.CommentBorder is not accessible: check it visually
131 //- HiddenTagView.EndTagBorder is not accessible: check it visually
132 //- HiddenTagView.StartTagBorder is not accessible: check it visually
133
134 //+ SynthFileChooserUI.UIBorder:
135 new SynthFileChooser().getUIBorder(),
136
137 //+ BorderedComponent.FocusBorder:
138 getBorder(false),
139 //+ BorderedComponent.LabeledBorder:
140 getBorder(true),
141 };
142
143 public static void main(String[] args) {
144 for (Border border : BORDERS) {
145 System.out.println(border.getClass());
146 test(border, border.getBorderInsets(getComponent(border)));
147 if (border instanceof AbstractBorder) {
148 test((AbstractBorder) border);
149 }
150 }
151 }
152
153 private static void test(AbstractBorder border) {
154 Insets insets = new Insets(0, 0, 0, 0);
155 if (insets != border.getBorderInsets(getComponent(border), insets)) {
156 throw new Error("both instances are differ for " + border.getClass());
157 }
158 test(border, insets);
159 }
160
161 private static void test(Border border, Insets insets) {
162 Insets result = border.getBorderInsets(getComponent(border));
163 if (insets == result) {
164 throw new Error("both instances are the same for " + border.getClass());
165 }
166 if (!insets.equals(result)) {
167 throw new Error("both insets are not equal for " + border.getClass());
168 }
169 }
170
171 private static JComponent getComponent(Border border) {
172 Class type = border.getClass();
173 if (type.equals(MotifBorders.MotifPopupMenuBorder.class)) {
174 return POPUP;
175 }
176 if (type.equals(WindowsBorders.ToolBarBorder.class)) {
177 return TOOLBAR;
178 }
179 if (type.equals(MetalBorders.ToolBarBorder.class)) {
180 return TOOLBAR;
181 }
182 return LABEL;
183 }
184
185 // This method is used to get the border from BorderedComponent
186 private static Border getBorder(boolean labeled) {
187 JComponent component = new BorderedComponent("4856008", null, true);
188 CompoundBorder border = (CompoundBorder) component.getBorder();
189 return labeled
190 ? border.getInsideBorder()
191 : border.getOutsideBorder();
192 }
193
194 // This class is used to get the instance of BasicBorders.RolloverMarginBorder
195 private static class ToolBar extends BasicToolBarUI {
196 private Border getRolloverMarginBorder() {
197 JToggleButton button = new JToggleButton();
198 CompoundBorder border = (CompoundBorder) getNonRolloverBorder(button);
199 return border.getInsideBorder();
200 }
201 }
202
203 // This class is used to get the instance of MetalComboBoxEditor.EditorBorder
204 private static class MetalEditor extends MetalComboBoxEditor {
205 private Border getEditorBorder() {
206 return editor.getBorder();
207 }
208 }
209
210 // This class is used to get the instance of SynthFileChooserUI.UIBorder
211 private static class SynthFileChooser extends SynthFileChooserUI {
212 private static final JFileChooser CHOOSER = new JFileChooser();
213 private String name;
214
215 private SynthFileChooser() {
216 super(CHOOSER);
217 }
218
219 private Border getUIBorder() {
220 new SynthLookAndFeel().initialize();
221 CHOOSER.setBorder(null);
222 installDefaults(CHOOSER);
223 return CHOOSER.getBorder();
224 }
225
226 @Override
227 public String getFileName() {
228 return this.name;
229 }
230
231 @Override
232 public void setFileName(String name) {
233 this.name = name;
234 }
235 }
236}