KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > snow > sortabletable > GradientShapeEntity


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   /**
16    * Child of ShapeEntity.
17    * Used by SelfDrawingFileTreeIcon.
18    */

19 public class GradientShapeEntity
20 {
21
22   private GeneralPath shapePath = null;
23
24   //private Color borderDefaultColor;
25
private Color borderSelectedColor;
26
27 // private GradientPaint gradientPaintDefault;
28
private GradientPaint gradientPaintSelected;
29
30  // private int thickness = 1;
31
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.borderDefaultColor = borderDefaultColor;
44
this.borderSelectedColor = borderSelectedColor;
45     //this.thickness = thickness;
46
this.shapeStroke = new BasicStroke( (float) thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND );
47 /* this.gradientPaintDefault = new GradientPaint( 0f,0f,
48                                                    this.getBrighterColor(insideDefaultColor),
49                                                    x_GradientLength,
50                                                    y_GradientLength,
51                                                    this.getDarkerColor(insideDefaultColor) );*/

52     this.gradientPaintSelected = new GradientPaint( 0f,0f,
53                                                     this.getBrighterColor(insideSelectedColor),
54                                                     x_GradientLength,
55                                                     y_GradientLength,
56                                                     this.getDarkerColor(insideSelectedColor) );
57   } // constructor
58

59
60
61
62  /**
63   * Implementation of the ShapeEntity method.
64   */

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   } // paint
77

78
79
80  /**
81   * Implementation of the ShapeEntity method.
82   */

83   public void moveTo( int x, int y )
84   {
85     this.shapePath.moveTo(x,y);
86   }
87
88
89  /**
90   * Implementation of the ShapeEntity method.
91   */

92   public void lineTo( int x, int y )
93   {
94     this.shapePath.lineTo(x,y);
95   }
96
97
98  /**
99   * Implementation of the ShapeEntity method.
100   */

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 } // GradientShapeEntity
Popular Tags