// HWText.js

/* <p>Title: Plot-Text</p>
 * <p>Description: Plot-Routinen zur Kompatibilität mit alten Sources</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: SiG Software Integration GmbH</p>
 * @author Dr. Horst Walther
 * @version date 08.09.2003
 * @version 0.1 */

  function HWText (p, _s, _x, _y, _fontSize, _color, _fontWeight, _fontName, _anchor) {

  var wordy = false;
  this.LEFT = 'start';
  this.RIGHT = 'end';
  this.CENTER = 'middle';
  this.DOWN = 'sub';
  this.UP ='super';

  _s         = (_s==undefined ? "" : _s);
  _x         = (_x==undefined ? 0.0 : _x);
  _y         = (_y==undefined ? 0.0 : _y);
  _fontSize  = (_fontSize==undefined ? 12 : _fontSize);
  _color     = (_color==undefined ? 'black' : _color);
  _fontWeight = (_fontWeight==undefined ? 'bold' : _fontWeight);
  _fontName  = (_fontName==undefined ? 'Verdana' : _fontName);
  _anchor    = (_anchor==undefined ? 'start' : _anchor);

  var s = _s;
  var x = _x;
  var y = _y;
  var fontSize = _fontSize;
  var color  = _color;
  var fontWeight = _fontWeight;
  var fontName = _fontName;
  var anchor = _anchor; 
  var baseline = null;
  var p2d = p;
  var dx = 0;
  var dy = 0;
  var textPath = null;

  var padding = 8;
  var places = 2;

//  ----------------------------------------------------------------------------
  this.changeValue = function(node, _s, _x, _y, _fontSize, _color, _fontWeight, _fontName, _anchor) {
    this.setValue (_s, _x, _y, _fontSize, _color, _fontWeight, _fontName, _anchor);
    p2d.changeText (node, x, y, s, dx, dy, fontSize, color, anchor);
    return this;
  };

//  ----------------------------------------------------------------------------
  this.setValue = function(_s, _x, _y, _fontSize, _color, _fontWeight, _fontName, _anchor) {
    s = _s==undefined ? s: _s;
    x = _x==undefined ? x: _x;
    y = _y==undefined ? y: _y;
    fontSize = _fontSize==undefined ? fontSize : _fontSize;
    color = _color==undefined ? color : _color;
    fontWeight = _fontWeight==undefined ? fontWeight : _fontWeight;
    fontName = _fontName==undefined ? fontName : _fontName;
    anchor = _anchor==undefined ? anchor : _anchor;
//	if (wordy) alert (this.id+'.HWText.setValue: '+this.toString ());
    return this;
  };

//  ---------------------------------------------------------------------------
  this.draw = function (alignX, alignY) {
    anchor = alignX==undefined ? anchor : alignX;
	baseline = alignY==undefined ? baseline : alignY;
    var yDelta = baseline == this.CENTER ? + fontSize * 0.005 : (baseline == this.DOWN ? +fontSize * 0.01 : 0.0);
    return p2d.drawText (x, y-yDelta, s, dx, dy, fontSize, color, fontWeight, fontName, anchor, textPath);
  };

//  ---------------------------------------------------------------------------
  this.change = function (node, alignX, alignY) {
    if (!node) return this;
    anchor = alignX==undefined ? anchor : alignX;
	baseline = alignY==undefined ? baseline : alignY;
    return p2d.changeText (node, x, y, s, dx, dy, fontSize, color, fontWeight, fontName, anchor);
  };

//  ----------------------------------------------------------------------------
 this.setCenter = function (g) {
   setCenterX (g);
   setCenterY (g);
 };

//  ----------------------------------------------------------------------------
 this.setCenterX = function (g) {
  this.anchor = 'middle';
 };

//  ----------------------------------------------------------------------------
 this.setLeft = function (g) {
  this.anchor = 'start';
 }

//  ----------------------------------------------------------------------------
 this.setRight = function (g) {
  this.anchor = 'end';
 }

//  ----------------------------------------------------------------------------
 this.setCenterY = function (g) {
  alert ('###  HWText, err: setCenterY not yet implemented"');
 }

//  ----------------------------------------------------------------------------
 this.setDown = function (g) {
  baseline = 'sub';
  alert ('###  HWText, err: setDown not yet implemented"');
 }

//  ----------------------------------------------------------------------------
  this.setUp = function (g) {
    baseline = 'super';
    alert ('###  HWText, err: setUp not yet implemented"');
  };

//  ----------------------------------------------------------------------------
  this.changePosition = function (node, _x, _y) {
    if (!node) return this;
    x = _x==undefined ? x : _x;
    y = _y==undefined ? y : _y;
    return p2d.changeText (node, x, y, s, dx, dy, fontSize, color, fontWeight, fontName, anchor);
  };

//  ----------------------------------------------------------------------------
  this.toString = function () {
    return "'" + s + "', pos=(" + x + ", " + y + "), ) fontSize=" + fontSize + ", anchor=" + anchor + ", color=" + color + ", fontName=" +fontName + ", fontWeight=" + fontWeight + ", textPath=" + textPath;
  }

//  --------------------------------------------------------------------------->
  this.addTextPath = function (t) {
    textPath = t;
    return this;
  }

  //  --------------------------------------------------------------------------->
  this.remove = function () {
    if (!this.node) {return null;}
    this.p.removeNode(this.node);
    return this.node = null;
  };

//  ----------------------------------------------------------------------------
  if (p2d == undefined) alert ('###  HWText: p2d='+p2d);
//  ----------------------------------------------------------------------------
}

