forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.3 KiB
78 lines
2.3 KiB
package leaf.ui;
|
|
|
|
import java.awt.Color;
|
|
import java.awt.GradientPaint;
|
|
import java.awt.Graphics;
|
|
import java.awt.Graphics2D;
|
|
import java.awt.RenderingHints;
|
|
|
|
import javax.swing.ImageIcon;
|
|
import javax.swing.JButton;
|
|
|
|
public class LeafButton extends JButton
|
|
{
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private ImageIcon icon = null;
|
|
|
|
public LeafButton(String text)
|
|
{
|
|
super( text );
|
|
setOpaque( false );
|
|
}
|
|
|
|
public LeafButton( ImageIcon icon )
|
|
{
|
|
super( icon );
|
|
this.icon = icon;
|
|
setOpaque( false );
|
|
}
|
|
|
|
protected void paintComponent( Graphics g )
|
|
{
|
|
if( icon == null )
|
|
{
|
|
boolean pushed = getModel().isPressed();
|
|
// Color borderColor = getBackground();
|
|
// Color highlightColor = getBackground();
|
|
Color textColor = isEnabled() ? getForeground() : getForeground().brighter().brighter().brighter();
|
|
Color textAccent = getBackground();
|
|
Color textAccentHot = getBackground();
|
|
GradientPaint topGradientUp = new GradientPaint( 0, 0, getBackground().brighter(), 0, getHeight() / 2, getBackground() );
|
|
GradientPaint topGradientDown = new GradientPaint( 0, 0, getBackground().brighter(), 0, getHeight() / 2, getBackground() );
|
|
GradientPaint bottomGradientDown = new GradientPaint( 0, getHeight() / 2, getBackground(), 0, getHeight(), getBackground().darker() );
|
|
GradientPaint bottomGradientUp = new GradientPaint( 0, getHeight() / 2, getBackground(), 0, getHeight(), getBackground().darker().darker() );
|
|
Graphics2D g2 = (Graphics2D) g;
|
|
g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
|
|
|
|
int height = getHeight() / 2;
|
|
|
|
g2.setPaint( pushed ? topGradientDown : topGradientUp );
|
|
g2.fillRect( 0, 0, getWidth(), height );
|
|
|
|
g2.setPaint( pushed ? bottomGradientDown : bottomGradientUp );
|
|
g2.fillRect( 0, height, getWidth(), height );
|
|
|
|
// g2.setColor( borderColor );
|
|
// g2.drawRect( 0, 0, getWidth() - 1, getHeight() - 1 );
|
|
//
|
|
// g2.setColor( highlightColor );
|
|
// g2.drawRect( 1, 1, getWidth() - 3, getHeight() - 3 );
|
|
|
|
int x = (getWidth() - g2.getFontMetrics().stringWidth( getText() )) / 2;
|
|
int y = getHeight() - ((getHeight() - g2.getFontMetrics().getHeight()) / 2) - 3;
|
|
|
|
y += 1;
|
|
g2.setColor( pushed ? textAccentHot : textAccent );
|
|
g2.drawString( getText(), x, y );
|
|
|
|
y -= 1;
|
|
g2.setColor( textColor );
|
|
g2.drawString( getText(), x, y );
|
|
}
|
|
else
|
|
{
|
|
super.paintComponent( g );
|
|
}
|
|
}
|
|
} |