01: package snow.sortabletable;
02:
03: import java.awt.*;
04: import java.awt.event.*;
05: import java.awt.font.*;
06: import java.awt.geom.*;
07: import javax.swing.*;
08: import javax.swing.plaf.*;
09: import javax.swing.plaf.metal.*;
10:
11: /**
12: * Child of ShapeEntity.
13: * Used by SelfDrawingFileTreeIcon.
14: */
15: public class GradientShapeEntity {
16: private GeneralPath shapePath = null;
17: private Color borderSelectedColor;
18: private GradientPaint gradientPaintSelected;
19: private BasicStroke shapeStroke;
20:
21: public GradientShapeEntity(Color borderDefaultColor,
22: Color borderSelectedColor, Color insideDefaultColor,
23: Color insideSelectedColor, float x_GradientLength,
24: float y_GradientLength, int thickness) {
25: this .shapePath = new GeneralPath(GeneralPath.WIND_NON_ZERO);
26: this .borderSelectedColor = borderSelectedColor;
27: this .shapeStroke = new BasicStroke((float) thickness,
28: BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
29: this .gradientPaintSelected = new GradientPaint(0f, 0f, this
30: .getBrighterColor(insideSelectedColor),
31: x_GradientLength, y_GradientLength, this
32: .getDarkerColor(insideSelectedColor));
33: }
34:
35: /**
36: * Implementation of the ShapeEntity method.
37: */
38: public void paint(Graphics2D graphics2D) {
39: Color borderColor = this .borderSelectedColor;
40: GradientPaint gradientPaint = gradientPaintSelected;
41:
42: graphics2D.setPaint(gradientPaint);
43: graphics2D.fill(this .shapePath);
44:
45: graphics2D.setColor(borderColor);
46: graphics2D.setStroke(this .shapeStroke);
47: graphics2D.draw(this .shapePath);
48: }
49:
50: /**
51: * Implementation of the ShapeEntity method.
52: */
53: public void moveTo(int x, int y) {
54: this .shapePath.moveTo(x, y);
55: }
56:
57: /**
58: * Implementation of the ShapeEntity method.
59: */
60: public void lineTo(int x, int y) {
61: this .shapePath.lineTo(x, y);
62: }
63:
64: /**
65: * Implementation of the ShapeEntity method.
66: */
67: public void closePath() {
68: this .shapePath.closePath();
69: }
70:
71: private Color getBrighterColor(Color c) {
72: int r = c.getRed() + 48;
73: if (r > 255)
74: r = 255;
75: int g = c.getGreen() + 48;
76: if (g > 255)
77: g = 255;
78: int b = c.getBlue() + 48;
79: if (b > 255)
80: b = 255;
81: return new Color(r, g, b);
82: }
83:
84: private Color getDarkerColor(Color c) {
85: int r = c.getRed() - 48;
86: if (r < 0)
87: r = 0;
88: int g = c.getGreen() - 48;
89: if (g < 0)
90: g = 0;
91: int b = c.getBlue() - 48;
92: if (b < 0)
93: b = 0;
94: return new Color(r, g, b);
95: }
96:
97: }
|