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  */
  25 package javax.swing.plaf.nimbus;
  26 
  27 import javax.swing.Painter;
  28 
  29 import javax.swing.JComponent;
  30 import javax.swing.UIManager;
  31 import javax.swing.plaf.UIResource;
  32 import java.awt.Graphics;
  33 import java.awt.Graphics2D;
  34 import java.awt.Color;
  35 import 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
  45 class 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         Painter painter = (Painter) UIManager.get(
  52             "TableHeader:\"TableHeader.renderer\"[Enabled].backgroundPainter");
  53         if (painter != null){
  54             if (g instanceof Graphics2D){
  55                 painter.paint((Graphics2D)g,this,getWidth()+1,getHeight());
  56             } else {
  57                 // paint using image to not Graphics2D to support
  58                 // Java 1.1 printing API
  59                 BufferedImage img =  new BufferedImage(getWidth(),getHeight(),
  60                         BufferedImage.TYPE_INT_ARGB);
  61                 Graphics2D g2 = (Graphics2D)img.getGraphics();
  62                 painter.paint(g2,this,getWidth()+1,getHeight());
  63                 g2.dispose();
  64                 g.drawImage(img,0,0,null);
  65                 img = null;
  66             }
  67         }
  68     }
  69 }