01: /*
02: * Created on 26 avr. 2005
03: *
04: * @author Christelle
05: *
06: */
07: package org.openwfe.gpe.figures;
08:
09: import org.eclipse.draw2d.ColorConstants;
10: import org.eclipse.draw2d.Graphics;
11: import org.eclipse.draw2d.Label;
12: import org.eclipse.draw2d.geometry.Insets;
13: import org.eclipse.draw2d.geometry.Rectangle;
14:
15: public class NoChildLabel extends Label {
16:
17: private boolean selected;
18: private boolean hasFocus;
19:
20: private Rectangle getSelectionRectangle() {
21: Rectangle bounds = getTextBounds();
22: bounds.expand(new Insets(4, 4, 0, 0));
23: translateToParent(bounds);
24: bounds.intersect(getBounds());
25: return bounds;
26: }
27:
28: /**
29: * @see org.eclipse.draw2d.Label#paintFigure(org.eclipse.draw2d.Graphics)
30: */
31: protected void paintFigure(Graphics graphics) {
32: if (selected) {
33: graphics.pushState();
34: graphics
35: .setBackgroundColor(ColorConstants.menuBackgroundSelected);
36: graphics.fillRectangle(getSelectionRectangle());
37: graphics.popState();
38: graphics.setForegroundColor(ColorConstants.red);
39: }
40: if (hasFocus) {
41: graphics.pushState();
42: graphics.setXORMode(true);
43: graphics
44: .setForegroundColor(ColorConstants.menuBackgroundSelected);
45: graphics.setBackgroundColor(ColorConstants.red);
46: graphics.drawFocus(getSelectionRectangle().resize(-1, -1));
47: graphics.popState();
48: }
49: super .paintFigure(graphics);
50: }
51:
52: /**
53: * Sets the selection state of this SimpleActivityLabel
54: * @param b true will cause the label to appear selected
55: */
56: public void setSelected(boolean b) {
57: selected = b;
58: repaint();
59: }
60:
61: /**
62: * Sets the focus state of this SimpleActivityLabel
63: * @param b true will cause a focus rectangle to be drawn around the text of the Label
64: */
65: public void setFocus(boolean b) {
66: hasFocus = b;
67: repaint();
68: }
69:
70: }
|