/*
 * Licensed Materials - Property of Rogue Wave Software, Inc. 
 * © Copyright Rogue Wave Software, Inc. 2014, 2015 
 * © Copyright IBM Corp. 2009, 2014
 * © Copyright ILOG 1996, 2009
 * All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:
 * The Software and Documentation were developed at private expense and
 * are "Commercial Items" as that term is defined at 48 CFR 2.101,
 * consisting of "Commercial Computer Software" and
 * "Commercial Computer Software Documentation", as such terms are
 * used in 48 CFR 12.212 or 48 CFR 227.7202-1 through 227.7202-4,
 * as applicable.
 */

package xmlgrapher;

import ilog.views.*;
import ilog.views.graphic.*;
import java.awt.*;

/**
 * A Graphic object with a rectangular base
 * and a label underneath.
 */
public class GrapherNode extends IlvGraphicSet
{
  IlvGraphic _base;
  IlvRect _rect;
  String _label;
  IlvZoomableLabel _labelg;
  String description;

  public GrapherNode(IlvRect rect, String label) 
  {  
    _rect = new IlvRect(rect);
    _base = new IlvReliefRectangle(_rect);
    _label = label;
    _labelg = new IlvZoomableLabel(new IlvPoint(_rect.x, _rect.y), label);
    _labelg.setAntialiasing(true);
    addObject(_base,false);
    addObject(_labelg,false);
    centerlabel(); 
  }

  public IlvGraphic getBase() 
  {
    return _base;
  }

  public IlvGraphic getLabelNode() 
  {
    return _labelg;
  }

  public String getLabel() 
  {
    return _labelg.getLabel();
  }

  public String getDescription() 
  {
    return description != null ? description : "";
  }

  public void setDescription(String description) 
  {
    this.description = description;
  }


  private void centerlabel()
  {
    IlvRect rect = _base.boundingBox(null);
    IlvRect l = _labelg.boundingBox(null);
    _labelg.moveResize(new IlvRect(rect.x+rect.width/2-l.width/2 , rect.y+rect.height,l.width, l.height));
  }

  public IlvGraphic copy()
  {
    return null;
  }

  public void setBackground(Color c) 
  {
    _base.setBackground(c);
  }

  public void setFont(Font f) 
  {
    _labelg.setFont(f);
    centerlabel();
  }

  public void setFontSize(int size) 
  {
    Font f = _labelg.getFont();
    Font newfont = new Font(f.getFamily(), f.getStyle(), size);
    setFont(newfont);
  }

  public void applyTransform(IlvTransformer t)
  {
    _base.applyTransform(t);
    centerlabel();
  }

}