1 /* 2 * Copyright (c) 2010, 2011, 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 * @summary Tests unchecked casts 28 * @author Sergey Malenkov 29 */ 30 31 import com.sun.java.swing.plaf.motif.MotifBorders; 32 import com.sun.java.swing.plaf.windows.WindowsBorders; 33 34 import java.awt.Color; 35 import java.awt.Component; 36 import java.awt.Font; 37 import java.awt.Graphics; 38 import java.awt.image.BufferedImage; 39 40 import javax.swing.ActionMap; 41 import javax.swing.JFileChooser; 42 import javax.swing.JLabel; 43 import javax.swing.JToggleButton; 44 import javax.swing.JToolBar; 45 import javax.swing.border.BevelBorder; 46 import javax.swing.border.Border; 47 import javax.swing.border.CompoundBorder; 48 import javax.swing.border.EmptyBorder; 49 import javax.swing.border.EtchedBorder; 50 import javax.swing.border.LineBorder; 51 import javax.swing.border.MatteBorder; 52 import javax.swing.border.SoftBevelBorder; 53 import javax.swing.border.TitledBorder; 54 import javax.swing.plaf.ActionMapUIResource; 55 import javax.swing.plaf.BorderUIResource; 56 import javax.swing.plaf.synth.SynthLookAndFeel; 57 import javax.swing.plaf.basic.BasicBorders; 58 import javax.swing.plaf.basic.BasicToolBarUI; 59 import javax.swing.plaf.metal.MetalBorders; 60 import javax.swing.plaf.metal.MetalComboBoxEditor; 61 import javax.swing.plaf.nimbus.NimbusLookAndFeel; 62 63 import sun.swing.plaf.synth.SynthFileChooserUI; 64 65 public class Test6978482 { 66 private static final JLabel LABEL = new JLabel(); 67 private static final JToolBar TOOLBAR = new JToolBar(); // init non-rollover border 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 //+ LoweredBorder: 138 new NimbusLookAndFeel().getDefaults().getBorder("TitledBorder.border"), 139 }; 140 141 public static void main(String[] args) { 142 Component c = new Component() {}; 143 c.setBackground(Color.WHITE); 144 c.setForeground(Color.BLACK); 145 Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics(); 146 g.setClip(0, 0, 1024, 768); 147 for (Border border : BORDERS) { 148 System.out.println(border.getClass()); 149 border.getBorderInsets(c); 150 border.paintBorder(c, g, 0, 0, 1024, 768); 151 } 152 } 153 154 // This class is used to get the instance of BasicBorders.RolloverMarginBorder 155 private static class ToolBar extends BasicToolBarUI { 156 private Border getRolloverMarginBorder() { 157 JToggleButton button = new JToggleButton(); 158 CompoundBorder border = (CompoundBorder) getNonRolloverBorder(button); 159 return border.getInsideBorder(); 160 } 161 } 162 163 // This class is used to get the instance of MetalComboBoxEditor.EditorBorder 164 private static class MetalEditor extends MetalComboBoxEditor { 165 private Border getEditorBorder() { 166 return editor.getBorder(); 167 } 168 } 169 170 // This class is used to get the instance of SynthFileChooserUI.UIBorder 171 private static class SynthFileChooser extends SynthFileChooserUI { 172 private static final JFileChooser CHOOSER = new JFileChooser(); 173 private String name; 174 175 private SynthFileChooser() { 176 super(CHOOSER); 177 } 178 179 private Border getUIBorder() { 180 new SynthLookAndFeel().initialize(); 181 CHOOSER.setBorder(null); 182 installDefaults(CHOOSER); 183 return CHOOSER.getBorder(); 184 } 185 186 @Override 187 protected ActionMap createActionMap() { 188 return new ActionMapUIResource(); 189 } 190 191 @Override 192 public String getFileName() { 193 return this.name; 194 } 195 196 @Override 197 public void setFileName(String name) { 198 this.name = name; 199 } 200 } 201 }