1 /*
   2  * Copyright (c) 2011, 2013, 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  * @summary <rdar://problem/4533150> [JavaJDK16] CColorPaint throws Exception with Sun2D renderer (creating translucent variants)
  27  * @summary com.apple.junit.java.graphics.color
  28  */
  29 
  30 import junit.framework.*;
  31 import javax.swing.*;
  32 import java.awt.*;
  33 
  34 class Scrap extends JFrame {
  35     private JDesktopPane desktopPane = new JDesktopPane();
  36 
  37     public Scrap() {
  38         super(System.getProperty("java.version"));
  39         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  40         setContentPane(desktopPane);
  41         desktopPane.add(new TransparentFrame(10, 10));
  42         desktopPane.add(new TransparentFrame(100, 100));
  43     }
  44 
  45     public class TransparentFrame extends JInternalFrame {
  46         public TransparentFrame(int positionX, int positionY) {
  47             super("A Transparent Frame", true, true, true, false);
  48 
  49             setSize(400, 300);
  50             setLocation(positionX, positionY);
  51             // setFocusable(true);
  52             setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  53 
  54             JPanel panel = new JPanel();
  55             setContentPane(panel);
  56 
  57             JButton button = new JButton("Test 1");
  58             button.setOpaque(false);
  59             button.setVisible(true);
  60             panel.add(button);
  61 
  62             button = new JButton("Test 2");
  63             button.setOpaque(false);
  64             button.setVisible(true);
  65             panel.add(button);
  66 
  67             panel.add(new JTextField("abcdefg"));
  68 
  69             setVisible(true);
  70         }
  71 
  72         public void paintComponent(Graphics g) {
  73             Graphics2D g2 = (Graphics2D) g;
  74             g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f));
  75             super.paintComponent(g2);
  76         }
  77     }
  78 }
  79 
  80 public class CColorPaint_R4533150 extends TestCase {
  81 
  82     public void testCColorPaint_R4533150() throws Exception {
  83         Scrap instance = new Scrap();
  84         try {
  85             instance.setSize(600, 600);
  86             instance.setVisible(true);
  87         } finally {
  88             instance.dispose();
  89         }
  90     }
  91 
  92     public static Test suite() {
  93         return new TestSuite(CColorPaint_R4533150.class);
  94     }
  95 
  96     public static void main (String[] args) throws RuntimeException {
  97         TestResult tr = junit.textui.TestRunner.run(suite());
  98         if ((tr.errorCount() != 0) || (tr.failureCount() != 0)) {
  99             throw new RuntimeException("### FAILED: unexpected JUnit errors or failures.");
 100         }
 101     }
 102 }