01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: // This file is part of KeY - Integrated Deductive Software Design
10: // Copyright (C) 2001-2004 Universitaet Karlsruhe, Germany
11: // Universitaet Koblenz-Landau, Germany
12: // Chalmers University of Technology, Sweden
13: //
14: // The KeY system is protected by the GNU General Public License.
15: // See LICENSE.TXT for details.
16:
17: package de.uka.ilkd.key.gui;
18:
19: import java.awt.*;
20: import java.awt.image.BufferedImage;
21:
22: import javax.swing.Icon;
23: import javax.swing.plaf.metal.MetalIconFactory.TreeControlIcon;
24:
25: class KeYControlIcon extends TreeControlIcon {
26:
27: private static final Icon collapsedIcon = new KeYControlIcon(true);
28: private static final Icon expandedIcon = new KeYControlIcon(false);
29:
30: private boolean collapsed;
31:
32: public static Icon getKeYCollapsedIcon() {
33: return collapsedIcon;
34: }
35:
36: public static Icon getKeYExpandedIcon() {
37: return expandedIcon;
38: }
39:
40: public KeYControlIcon(boolean collapsed) {
41: super (collapsed);
42: this .collapsed = collapsed;
43:
44: }
45:
46: public void paintIcon(Component c, Graphics g, int x, int y) {
47: GraphicsConfiguration gc = c.getGraphicsConfiguration();
48: Image image;
49: if (gc != null) {
50: image = gc.createCompatibleImage(getIconWidth(),
51: getIconHeight(), Transparency.BITMASK);
52: } else {
53: image = new BufferedImage(getIconWidth(), getIconHeight(),
54: BufferedImage.TYPE_INT_ARGB);
55: }
56: Graphics imageG = image.getGraphics();
57: paintMe(c, imageG);
58: imageG.dispose();
59:
60: g.drawImage(image, x, y, null);
61: }
62:
63: private void paintMe(Component c, Graphics g) {
64: // Draw tab top
65: g.setColor(c.getBackground());
66: g.fillRect(0, 0, getIconWidth(), getIconHeight());
67:
68: int midx = getIconWidth() / 2;
69: int midy = getIconHeight() / 2;
70:
71: int min = getIconWidth() < getIconHeight() ? getIconWidth()
72: : getIconHeight();
73:
74: g.setColor(c.getGraphics().getColor());
75: g.drawRect(midx - (min / 4), midy - (min / 4), (min / 2) - 1,
76: (min / 2) - 1);
77:
78: g.drawLine(midx - (min / 4 - 2), midy, midx + (min / 4 - 2),
79: midy);
80: if (collapsed) {
81: g.drawLine(midx, midy - (min / 4 - 2), midx, midy
82: + (min / 4 - 2));
83: }
84: }
85: }
|