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