1 /*
   2  * Copyright (c) 2005, 2006, 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 class TableScrollPaneCorner extends JComponent implements UIResource{
  45 
  46     /**
  47      * Paint the component using the Nimbus Table Header Background Painter
  48      */
  49     @Override protected void paintComponent(Graphics g) {
  50         Painter painter = (Painter) UIManager.get(
  51             "TableHeader:\"TableHeader.renderer\"[Enabled].backgroundPainter");
  52         if (painter != null){
  53             if (g instanceof Graphics2D){
  54                 painter.paint((Graphics2D)g,this,getWidth()+1,getHeight());
  55             } else {
  56                 // paint using image to not Graphics2D to support
  57                 // Java 1.1 printing API
  58                 BufferedImage img =  new BufferedImage(getWidth(),getHeight(),
  59                         BufferedImage.TYPE_INT_ARGB);
  60                 Graphics2D g2 = (Graphics2D)img.getGraphics();
  61                 painter.paint(g2,this,getWidth()+1,getHeight());
  62                 g2.dispose();
  63                 g.drawImage(img,0,0,null);
  64                 img = null;
  65             }
  66         }
  67     }
  68 }