TestAbstractRegionPainter.java revision 13901:b2a69d66dc65
1139749Simp/*
2129449Sscottl * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3129449Sscottl * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4129449Sscottl *
589580Smsmith * This code is free software; you can redistribute it and/or modify it
689580Smsmith * under the terms of the GNU General Public License version 2 only, as
789580Smsmith * published by the Free Software Foundation.
889580Smsmith *
989580Smsmith * This code is distributed in the hope that it will be useful, but WITHOUT
1089580Smsmith * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1189580Smsmith * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1289580Smsmith * version 2 for more details (a copy is included in the LICENSE file that
1389580Smsmith * accompanied this code).
1489580Smsmith *
1589580Smsmith * You should have received a copy of the GNU General Public License version
1689580Smsmith * 2 along with this work; if not, write to the Free Software Foundation,
1789580Smsmith * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1889580Smsmith *
1989580Smsmith * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2089580Smsmith * or visit www.oracle.com if you need additional information or have any
2189580Smsmith * questions.
2289580Smsmith */
2389580Smsmithimport java.awt.Color;
2489580Smsmithimport java.awt.Graphics2D;
2589580Smsmithimport javax.swing.JComponent;
2689580Smsmithimport javax.swing.SwingUtilities;
2789580Smsmithimport javax.swing.plaf.nimbus.AbstractRegionPainter;
2889580Smsmith/*
2989580Smsmith * @test
3089580Smsmith * @bug 8080972
3189580Smsmith * @summary Audit Core Reflection in module java.desktop for places that will
3289580Smsmith *          require changes to work with modules
3389580Smsmith * @author Alexander Scherbatiy
3489580Smsmith */
35120477Sscottl
3689580Smsmithpublic class TestAbstractRegionPainter {
3789580Smsmith
3889580Smsmith    public static void main(String[] args) throws Exception {
3989580Smsmith        SwingUtilities.invokeAndWait(TestAbstractRegionPainter::testAbstractRegionPainter);
4089580Smsmith        System.setSecurityManager(new SecurityManager());
4189580Smsmith        SwingUtilities.invokeAndWait(TestAbstractRegionPainter::testAbstractRegionPainter);
42129449Sscottl    }
4389580Smsmith
4489580Smsmith    private static void testAbstractRegionPainter() {
45119418Sobrien        UserAbstractRegionPainter painter = new UserAbstractRegionPainter();
46119418Sobrien
4789580Smsmith        JComponent userComponent = new UserJComponent();
4889580Smsmith
4989580Smsmith        Color color = painter.getUserComponentColor(userComponent, "UserColor",
5089580Smsmith                Color.yellow, 0, 0, 0);
5189580Smsmith
5289580Smsmith        if (!UserJComponent.USER_COLOR.equals(color)) {
5395533Smike            throw new RuntimeException("Wrong color: " + color);
5489580Smsmith        }
5589580Smsmith    }
5689580Smsmith
5789580Smsmith    public static class UserJComponent extends JComponent {
5889580Smsmith
5989580Smsmith        public static final Color USER_COLOR = new Color(10, 20, 30);
6089580Smsmith        public static final Color TEST_COLOR = new Color(15, 25, 35);
6189580Smsmith
6289580Smsmith        Color color = USER_COLOR;
6389580Smsmith
6489580Smsmith        public UserJComponent() {
6589580Smsmith
6689580Smsmith        }
6789580Smsmith
6889580Smsmith        public Color getUserColor() {
6989580Smsmith            return color;
7089580Smsmith        }
7189580Smsmith
72227293Sed        public void setUserColor(Color color) {
73156139Sscottl            this.color = color;
7489580Smsmith        }
7589580Smsmith    }
7689580Smsmith
7789580Smsmith    public static class UserAbstractRegionPainter extends AbstractRegionPainter {
7889580Smsmith
7989580Smsmith        public Color getUserComponentColor(JComponent c, String property,
8089580Smsmith                Color defaultColor,
8189580Smsmith                float saturationOffset,
8289580Smsmith                float brightnessOffset,
8389580Smsmith                int alphaOffset) {
8489580Smsmith            return getComponentColor(c, property, defaultColor, saturationOffset, brightnessOffset, alphaOffset);
8589580Smsmith        }
8689580Smsmith
8789580Smsmith        @Override
8889580Smsmith        protected AbstractRegionPainter.PaintContext getPaintContext() {
8989580Smsmith            throw new UnsupportedOperationException("Not supported yet.");
9089580Smsmith        }
9189580Smsmith
9289580Smsmith        @Override
9389580Smsmith        protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys) {
9489580Smsmith            throw new UnsupportedOperationException("Not supported yet.");
9589580Smsmith        }
9689580Smsmith    }
9789580Smsmith}
9889580Smsmith