1/*
2 * Copyright (c) 2005, 2014, 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.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25package javax.swing.plaf.nimbus;
26
27import javax.swing.Painter;
28
29import javax.swing.JComponent;
30import javax.swing.UIManager;
31import javax.swing.plaf.UIResource;
32import java.awt.Graphics;
33import java.awt.Graphics2D;
34import java.awt.Color;
35import java.awt.image.BufferedImage;
36
37/**
38 * TableScrollPaneCorner - A simple component that paints itself using the table
39 * header background painter. It is used to fill the top right corner of
40 * scrollpane.
41 *
42 * @author Created by Jasper Potts (Jan 28, 2008)
43 */
44@SuppressWarnings("serial") // Superclass is not serializable across versions
45class TableScrollPaneCorner extends JComponent implements UIResource{
46
47    /**
48     * Paint the component using the Nimbus Table Header Background Painter
49     */
50    @Override protected void paintComponent(Graphics g) {
51        @SuppressWarnings("unchecked")
52        Painter<JComponent> painter = (Painter) UIManager.get(
53            "TableHeader:\"TableHeader.renderer\"[Enabled].backgroundPainter");
54        if (painter != null){
55            if (g instanceof Graphics2D){
56                painter.paint((Graphics2D)g,this,getWidth()+1,getHeight());
57            } else {
58                // paint using image to not Graphics2D to support
59                // Java 1.1 printing API
60                BufferedImage img =  new BufferedImage(getWidth(),getHeight(),
61                        BufferedImage.TYPE_INT_ARGB);
62                Graphics2D g2 = (Graphics2D)img.getGraphics();
63                painter.paint(g2,this,getWidth()+1,getHeight());
64                g2.dispose();
65                g.drawImage(img,0,0,null);
66                img = null;
67            }
68        }
69    }
70}
71