1 package snow.sortabletable; 2 3 4 5 import java.awt.*; 6 import java.awt.event.*; 7 import java.awt.font.*; 8 import java.awt.geom.*; 9 10 import javax.swing.*; 11 import javax.swing.plaf.*; 12 import javax.swing.plaf.metal.*; 13 14 15 19 public class GradientShapeEntity 20 { 21 22 private GeneralPath shapePath = null; 23 24 private Color borderSelectedColor; 26 27 private GradientPaint gradientPaintSelected; 29 30 private BasicStroke shapeStroke; 32 33 34 public GradientShapeEntity( Color borderDefaultColor, 35 Color borderSelectedColor, 36 Color insideDefaultColor, 37 Color insideSelectedColor, 38 float x_GradientLength, 39 float y_GradientLength, 40 int thickness ) 41 { 42 this.shapePath = new GeneralPath( GeneralPath.WIND_NON_ZERO ); 43 this.borderSelectedColor = borderSelectedColor; 45 this.shapeStroke = new BasicStroke( (float) thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND ); 47 52 this.gradientPaintSelected = new GradientPaint( 0f,0f, 53 this.getBrighterColor(insideSelectedColor), 54 x_GradientLength, 55 y_GradientLength, 56 this.getDarkerColor(insideSelectedColor) ); 57 } 59 60 61 62 65 public void paint( Graphics2D graphics2D) 66 { 67 Color borderColor = this.borderSelectedColor; 68 GradientPaint gradientPaint = gradientPaintSelected ; 69 70 graphics2D.setPaint( gradientPaint ); 71 graphics2D.fill( this.shapePath ); 72 73 graphics2D.setColor( borderColor ); 74 graphics2D.setStroke( this.shapeStroke ); 75 graphics2D.draw( this.shapePath ); 76 } 78 79 80 83 public void moveTo( int x, int y ) 84 { 85 this.shapePath.moveTo(x,y); 86 } 87 88 89 92 public void lineTo( int x, int y ) 93 { 94 this.shapePath.lineTo(x,y); 95 } 96 97 98 101 public void closePath() 102 { 103 this.shapePath.closePath(); 104 } 105 106 107 108 private Color getBrighterColor( Color c ) 109 { 110 int r = c.getRed() + 48; if( r > 255 ) r = 255; 111 int g = c.getGreen() + 48; if( g > 255 ) g = 255; 112 int b = c.getBlue() + 48; if( b > 255 ) b = 255; 113 return new Color(r,g,b); 114 } 115 116 private Color getDarkerColor( Color c ) 117 { 118 int r = c.getRed() - 48; if( r < 0 ) r = 0; 119 int g = c.getGreen() - 48; if( g < 0 ) g = 0; 120 int b = c.getBlue() - 48; if( b < 0 ) b = 0; 121 return new Color(r,g,b); 122 } 123 124 125 126 } | Popular Tags |