NoChildLabel.java :  » Workflow-Engines » OpenWFE » org » openwfe » gpe » figures » Java Open Source

Java Open Source » Workflow Engines » OpenWFE 
OpenWFE » org » openwfe » gpe » figures » NoChildLabel.java
/*
 * Created on 26 avr. 2005
 *
 * @author Christelle
 *
 */
package org.openwfe.gpe.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Rectangle;


public class NoChildLabel extends Label{

  private boolean selected;
  private boolean hasFocus;

  private Rectangle getSelectionRectangle() {
    Rectangle bounds = getTextBounds();
    bounds.expand(new Insets(4,4,0,0));
    translateToParent(bounds);
    bounds.intersect(getBounds());
    return bounds;
  }

  /**
   * @see org.eclipse.draw2d.Label#paintFigure(org.eclipse.draw2d.Graphics)
   */
  protected void paintFigure(Graphics graphics) {
    if (selected) {
      graphics.pushState();
      graphics.setBackgroundColor(ColorConstants.menuBackgroundSelected);
      graphics.fillRectangle(getSelectionRectangle());
      graphics.popState();
      graphics.setForegroundColor(ColorConstants.red);
    }
    if (hasFocus) {
      graphics.pushState();
      graphics.setXORMode(true);
      graphics.setForegroundColor(ColorConstants.menuBackgroundSelected);
      graphics.setBackgroundColor(ColorConstants.red);
      graphics.drawFocus(getSelectionRectangle().resize(-1, -1));
      graphics.popState();
    }
    super.paintFigure(graphics);
  }

  /**
   * Sets the selection state of this SimpleActivityLabel
   * @param b true will cause the label to appear selected
   */
  public void setSelected(boolean b) {
    selected = b;
    repaint();
  }

  /**
   * Sets the focus state of this SimpleActivityLabel
   * @param b true will cause a focus rectangle to be drawn around the text of the Label
   */
  public void setFocus(boolean b) {
    hasFocus = b;
    repaint();
  }


}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.