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