01: package tide.syntaxtree;
02:
03: import snow.utils.gui.Icons;
04: import snow.utils.gui.Icons;
05: import snow.lookandfeel.ThemesManager;
06: import javax.swing.*;
07: import java.awt.*;
08: import java.awt.geom.*;
09:
10: public class SyntaxTreeIcon implements Icon {
11: public String text = "?";
12: int size = 18;
13: public int width = 18;
14:
15: public Font letterFont = UIManager.getFont("Label.font");
16:
17: // set from outside
18: public Color letterColor = ThemesManager.getInstance().getBlack();
19: Color gradColor1 = ThemesManager.getInstance().getWhite();
20: Color gradColor2 = ThemesManager.getInstance().getWhite();
21:
22: private static final Icon startIcon = new Icons.StartIcon(9, 9,
23: true);
24: public boolean isMain = false;
25:
26: public SyntaxTreeIcon() {
27: //gradColor1 = new Color(letterColor.getRed()*5/6, letterColor.getGreen()*5/6, letterColor.getBlue()*5/6);
28: gradColor1 = new Color(200, 200, 200); //Color.lightGray;
29: }
30:
31: public int getIconHeight() {
32: return size;
33: }
34:
35: public int getIconWidth() {
36: return width; //(int)(size*text.length()/1.7);
37: }
38:
39: public void paintIcon(Component c, Graphics g, int x, int y) {
40: Graphics2D g2 = (Graphics2D) g;
41: Color oldColor = g.getColor();
42:
43: g.translate(x, y);
44:
45: Paint oldPaint = g2.getPaint();
46: //g2.setPaint(new GradientPaint(0f,0f,Color.gray.brighter(), (float) getIconWidth(), 0f, Color.LIGHT_GRAY.brighter()));
47: g2.setPaint(new GradientPaint(0f, 0f, gradColor1,
48: (float) getIconWidth(), 0f, gradColor2));
49: g2.fill(new Rectangle2D.Double(0, 1, getIconWidth(),
50: getIconHeight()));
51: g2.setPaint(oldPaint);
52:
53: if (text != null) {
54: Font oldFont = g2.getFont();
55:
56: g2.setColor(letterColor);
57: g2.setFont(letterFont);
58: g2.drawString(text, size / 4, size * 7 / 8);
59:
60: g2.setFont(oldFont);
61: }
62:
63: g2.setColor(oldColor);
64:
65: if (isMain) {
66: startIcon.paintIcon(c, g, 21, 6);
67: }
68: }
69:
70: }
|