/*
* XGradientBorder.java
*
* Created on 16 January 2007, 16:06
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package net.xoetrope.swing.util;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.RenderingHints;
import java.awt.SystemColor;
import java.awt.geom.Area;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import javax.swing.border.AbstractBorder;
import net.xoetrope.xui.build.BuildProperties;
/**
*
* @author luano
*/
public class XGradientBorder extends AbstractBorder
{
/** Creates a new instance of XGradientBorder */
public XGradientBorder()
{
}
/**
* This default implementation does no painting.
* @param c the component for which this border is being painted
* @param g the paint graphics
* @param x the x position of the painted border
* @param y the y position of the painted border
* @param width the width of the painted border
* @param height the height of the painted border
*/
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height )
{
try {
int fillSize = 1;
if ( !BuildProperties.BUILD_JDK_118 )
((Graphics2D)g).setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
// Robot robot = new Robot();
// Rectangle thisRect = c.getBounds();
// Point topLeft = new Point( 0, 0 );
// SwingUtilities.convertPointToScreen( topLeft, c );
// BufferedImage bi = robot.createScreenCapture ( new Rectangle( topLeft.x -fillSize, topLeft.y, fillSize, fillSize ) );
// g.drawImage( bi, 0, 0, null );
//
// bi = robot.createScreenCapture ( new Rectangle( topLeft.x + thisRect.width + fillSize, topLeft.y, fillSize, fillSize ) );
// g.drawImage( bi, thisRect.width -fillSize, 0, null );
//
// bi = robot.createScreenCapture ( new Rectangle( topLeft.x - fillSize, topLeft.y + thisRect.height, fillSize, fillSize ) );
// g.drawImage( bi, 0, thisRect.height - fillSize, null );
//
// bi = robot.createScreenCapture ( new Rectangle( topLeft.x + thisRect.width + fillSize, topLeft.y + thisRect.height, fillSize, fillSize ) );
// g.drawImage( bi, thisRect.width - fillSize, thisRect.height - fillSize, null );
}
catch ( Exception e ) { e.printStackTrace ();}
Dimension size = c.getSize();
Color color = g.getColor();
g.setColor( SystemColor.activeCaption );
// Construct the border in two parts for different rounding, top and bottom.
Area borderArea = new Area( new RoundRectangle2D.Double( 0, 0, size.width, size.height, 15, 15 ));
borderArea.add( new Area( new RoundRectangle2D.Double( 0, 15, size.width, size.height - 15, 4, 4 )));
borderArea.subtract( new Area( new Rectangle2D.Double( 4.0F, 4.0F, 4.0F, 4.0F )));
// Fill the background
Color bkColor = SystemColor.activeCaption;
g.setColor( bkColor );
if ( g instanceof Graphics2D ) {
Graphics2D g2d = ((Graphics2D)g);
GradientPaint gradient = new GradientPaint( 0.0F, 0.0F, bkColor.brighter(),
(float)size.height/2, (float)size.width/2,
bkColor.darker(), true );
g2d.setPaint( gradient );
g2d.fill( borderArea );
}
else
g.fillRect( 0, 0, size.width, size.height );
g.setColor( color );
}
/**
* This default implementation returns a new <code>Insets</code>
* instance where the <code>top</code>, <code>left</code>,
* <code>bottom</code>, and
* <code>right</code> fields are set to <code>0</code>.
* @param c the component for which this border insets value applies
* @return the new <code>Insets</code> object initialized to 0
*/
public Insets getBorderInsets( Component c )
{
return new Insets( 4, 4, 4, 4 );
}
/**
* Reinitializes the insets parameter with this Border's current Insets.
* @param c the component for which this border insets value applies
* @param insets the object to be reinitialized
* @return the <code>insets</code> object
*/
// public Insets getBorderInsets( Component c, Insets insets )
// {
// insets.left = insets.top = insets.right = insets.bottom = 4;
// return insets;
// }
}