1 /*
2  * Copyright (c) 2010, 2015, 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 6978482 7025987
27  * @requires (os.family == "windows")
28  * @summary Tests unchecked casts
29  * @author Sergey Malenkov
30  * @modules java.desktop/com.sun.java.swing.plaf.motif
31  *          java.desktop/com.sun.java.swing.plaf.windows
32  *          java.desktop/sun.swing.plaf.synth
33  */
34 
35 import com.sun.java.swing.plaf.motif.MotifBorders;
36 import com.sun.java.swing.plaf.windows.WindowsBorders;
37 
38 import java.awt.Color;
39 import java.awt.Component;
40 import java.awt.Font;
41 import java.awt.Graphics;
42 import java.awt.image.BufferedImage;
43 
44 import javax.swing.ActionMap;
45 import javax.swing.JFileChooser;
46 import javax.swing.JLabel;
47 import javax.swing.JToggleButton;
48 import javax.swing.JToolBar;
49 import javax.swing.border.BevelBorder;
50 import javax.swing.border.Border;
51 import javax.swing.border.CompoundBorder;
52 import javax.swing.border.EmptyBorder;
53 import javax.swing.border.EtchedBorder;
54 import javax.swing.border.LineBorder;
55 import javax.swing.border.MatteBorder;
56 import javax.swing.border.SoftBevelBorder;
57 import javax.swing.border.TitledBorder;
58 import javax.swing.plaf.ActionMapUIResource;
59 import javax.swing.plaf.BorderUIResource;
60 import javax.swing.plaf.synth.SynthLookAndFeel;
61 import javax.swing.plaf.basic.BasicBorders;
62 import javax.swing.plaf.basic.BasicToolBarUI;
63 import javax.swing.plaf.metal.MetalBorders;
64 import javax.swing.plaf.metal.MetalComboBoxEditor;
65 import javax.swing.plaf.nimbus.NimbusLookAndFeel;
66 
67 import sun.swing.plaf.synth.SynthFileChooserUI;
68 
69 public class Test6978482 {
70     private static final JLabel LABEL = new JLabel();
71     private static final JToolBar TOOLBAR = new JToolBar(); // init non-rollover border
72 
73     private static final Border[] BORDERS = {
74             new MotifBorders.BevelBorder(true, Color.BLACK, Color.WHITE),
75             new MotifBorders.ButtonBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
76             new MotifBorders.FocusBorder(Color.BLACK, Color.WHITE),
77             new MotifBorders.FrameBorder(LABEL),
78             new MotifBorders.MenuBarBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
79             new MotifBorders.MotifPopupMenuBorder(new Font(null, Font.PLAIN, 10), Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
80             new MotifBorders.ToggleButtonBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
81 
82             new WindowsBorders.ProgressBarBorder(Color.BLACK, Color.WHITE),
83             new WindowsBorders.ToolBarBorder(Color.BLACK, Color.WHITE),
84             //- WindowsInternalFrameUI.XPBorder is not accessible: check it visually
85             //? WindowsTableHeaderUI.IconBorder is not accessible: check it visually
86             //- XPStyle.XPEmptyBorder is not accessible: check it visually
87             //- XPStyle.XPFillBorder is not accessible: check it visually
88             //- XPStyle.XPImageBorder is not accessible: check it visually
89 
90             new BevelBorder(BevelBorder.RAISED),
91             new CompoundBorder(),
92             new EmptyBorder(1, 2, 3, 4),
93             new EtchedBorder(),
94             new LineBorder(Color.BLACK, 2, true),
95             new MatteBorder(1, 2, 3, 4, Color.BLACK),
96             new SoftBevelBorder(BevelBorder.LOWERED),
97             new TitledBorder("4856008"),
98 
99             new BorderUIResource(new EmptyBorder(1, 2, 3, 4)),
100 
101             new BasicBorders.ButtonBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
102             new BasicBorders.FieldBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
103             new BasicBorders.MarginBorder(),
104             new BasicBorders.MenuBarBorder(Color.BLACK, Color.WHITE),
105             new BasicBorders.RadioButtonBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
106             //+ BasicBorders.RolloverMarginBorder:
107             new ToolBar().getRolloverMarginBorder(),
108             new BasicBorders.SplitPaneBorder(Color.BLACK, Color.WHITE),
109             //+ BasicBorders.SplitPaneDividerBorder:
110             BasicBorders.getSplitPaneDividerBorder(),
111             new BasicBorders.ToggleButtonBorder(Color.CYAN, Color.MAGENTA, Color.YELLOW, Color.BLACK),
112 
113             new MetalBorders.ButtonBorder(),
114             //- MetalBorders.DialogBorder is not accessible: check it visually
115             new MetalBorders.Flush3DBorder(),
116             //- MetalBorders.FrameBorder is not accessible: check it visually
117             new MetalBorders.InternalFrameBorder(),
118             new MetalBorders.MenuBarBorder(),
119             new MetalBorders.MenuItemBorder(),
120             new MetalBorders.OptionDialogBorder(),
121             new MetalBorders.PaletteBorder(),
122             new MetalBorders.PopupMenuBorder(),
123             //- MetalBorders.RolloverMarginBorder is not accessible: check it visually
124             new MetalBorders.ScrollPaneBorder(),
125             new MetalBorders.TableHeaderBorder(),
126             new MetalBorders.ToolBarBorder(),
127             //+ MetalComboBoxEditor.EditorBorder:
128             new MetalEditor().getEditorBorder(),
129 
130             //- SynthBorder is not accessible: check it visually
131             //- SynthScrollPaneUI.ViewportBorder is not accessible: check it visually
132 
133             //? CSSBorder is not accessible: check it visually
134             //? CommentView.CommentBorder is not accessible: check it visually
135             //- HiddenTagView.EndTagBorder is not accessible: check it visually
136             //- HiddenTagView.StartTagBorder is not accessible: check it visually
137 
138             //+ SynthFileChooserUI.UIBorder:
139             new SynthFileChooser().getUIBorder(),
140 
141             //+ LoweredBorder:
142             new NimbusLookAndFeel().getDefaults().getBorder("TitledBorder.border"),
143     };
144 
main(String[] args)145     public static void main(String[] args) {
146         Component c = new Component() {};
147         c.setBackground(Color.WHITE);
148         c.setForeground(Color.BLACK);
149         Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics();
150         g.setClip(0, 0, 1024, 768);
151         for (Border border : BORDERS) {
152             System.out.println(border.getClass());
153             border.getBorderInsets(c);
154             border.paintBorder(c, g, 0, 0, 1024, 768);
155         }
156     }
157 
158     // This class is used to get the instance of BasicBorders.RolloverMarginBorder
159     private static class ToolBar extends BasicToolBarUI {
getRolloverMarginBorder()160         private Border getRolloverMarginBorder() {
161             JToggleButton button = new JToggleButton();
162             CompoundBorder border = (CompoundBorder) getNonRolloverBorder(button);
163             return border.getInsideBorder();
164         }
165     }
166 
167     // This class is used to get the instance of MetalComboBoxEditor.EditorBorder
168     private static class MetalEditor extends MetalComboBoxEditor {
getEditorBorder()169         private Border getEditorBorder() {
170             return editor.getBorder();
171         }
172     }
173 
174     // This class is used to get the instance of SynthFileChooserUI.UIBorder
175     private static class SynthFileChooser extends SynthFileChooserUI {
176         private static final JFileChooser CHOOSER = new JFileChooser();
177         private String name;
178 
SynthFileChooser()179         private SynthFileChooser() {
180             super(CHOOSER);
181         }
182 
getUIBorder()183         private Border getUIBorder() {
184             new SynthLookAndFeel().initialize();
185             CHOOSER.setBorder(null);
186             installDefaults(CHOOSER);
187             return CHOOSER.getBorder();
188         }
189 
190         @Override
createActionMap()191         protected ActionMap createActionMap() {
192             return new ActionMapUIResource();
193         }
194 
195         @Override
getFileName()196         public String getFileName() {
197             return this.name;
198         }
199 
200         @Override
setFileName(String name)201         public void setFileName(String name) {
202             this.name = name;
203         }
204     }
205 }
206