Package net.xoetrope.swing.util

Source Code of net.xoetrope.swing.util.XGradientHeaderPanel

package net.xoetrope.swing.util;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import javax.swing.JLabel;

/**
* A header like panel that paints a gradient fill
* <p>Copyright: Xoetrope Ltd. (c) 2003-2006<br>
* License:      see license.txt</p>
* $Revision: 1.2 $
*/
public class XGradientHeaderPanel extends JLabel
{   
  /** Creates a new instance of XGradientHeaderPanel */
  public XGradientHeaderPanel()
  {
  } 
 
  public Insets getInsets()
  {
    return new Insets( 2, 4, 2, 4 );
  }
 
  public Dimension getPreferredSize()
  {
    Dimension sz = super.getPreferredSize();
    return new Dimension( Math.max( 20, sz.width ), Math.max( 20, sz.height ));
  }

  /**
   * Paint the component
   * @param g the graphics context
   */
  public void paintComponent( Graphics g )
  {
    Rectangle rect = getBounds();

    // Fill the background
    Color bkColor = getBackground();
    g.setColor( bkColor );
    if ( g instanceof Graphics2D ) {
      Graphics2D g2d = ((Graphics2D)g);
      GradientPaint gradient = new GradientPaint( 0.0F, 0.0F, bkColor.brighter(),
                                                  (float)rect.height/2, (float)rect.width/2,
                                                  bkColor.darker(), true );
      g2d.setPaint( gradient );
      g2d.fill( new Rectangle( 0, 0, rect.width, rect.height ));
      g2d.draw3DRect( 0, 0, rect.width-1, rect.height-1, true );
    }
    else
      g.fillRect( 0, 0, rect.width, rect.height );

    super.paintComponent( g );
  }
}
TOP

Related Classes of net.xoetrope.swing.util.XGradientHeaderPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.