/*****************************
  File: TextTool.js
  Created by Hawkeye
  Created: 9.5.2002

  I make and edit text.  Yay!

  I am a drawing tool, although I suppose a text thing is more like a simpleShape than a complexObjectGroup.  So I'll be make one of those!

  So what do I do?  I'll pop up a dialog box to allow user input.  There'll be a textarea for entering some text.  There'll also be a couple of select boxes to choose your font, font size, etc.  So you'll enter your stuff, hit the button, and **SHAZZAM** Text!

****************************/

TextTool.prototype = new DrawingTool(); 
TextTool.prototype.constructor = TextTool;
TextTool.superclass = DrawingTool.prototype;
function TextTool(){}
TextTool.prototype.initTool = function(){ 
  //debug("initing TextTool");
  useCanvas();
  eventCatcher.addEventListener("mouseup", this, false);
  this.actionState = "click0";
}





TextTool.prototype.drawer =  '<html>\n';
TextTool.prototype.drawer += '<head><meta http-equiv="content-type" content="text/html; charset=UTF-8"></head>\n';
TextTool.prototype.drawer +=  '<script language="javascript">\n';
TextTool.prototype.drawer +=  '  var updateNode = null;\n';
TextTool.prototype.drawer +=  '  function goGoText(){\n';
TextTool.prototype.drawer +=  '    var str  = window.document.getElementById("newText").value;\n';
TextTool.prototype.drawer +=  '    var size = window.document.getElementById("fontSize").value;\n';
TextTool.prototype.drawer +=  '    var color = window.document.getElementById("fontColor").value;\n';
TextTool.prototype.drawer +=  '    opener.textTool.runText( str, size, color, updateNode );\n';
TextTool.prototype.drawer +=  '  }\n';
TextTool.prototype.drawer +=  '</script>\n';
TextTool.prototype.drawer += '<body>\n';

TextTool.prototype.drawer += ' <h4>入力してください</h4>\n';
TextTool.prototype.drawer += ' <textarea id="newtext" cols="40" rows="5"></textarea>\n';
TextTool.prototype.drawer += ' <select id="fontSize">\n';

TextTool.prototype.drawer += '  <option value=10>10</option>\n';
TextTool.prototype.drawer += '  <option value=11>11</option>\n';
TextTool.prototype.drawer += '  <option value=12>12</option>\n';
TextTool.prototype.drawer += '  <option value=13>13</option>\n';
TextTool.prototype.drawer += '  <option value=14>14</option>\n';
TextTool.prototype.drawer += '  <option value=16>16</option>\n';
TextTool.prototype.drawer += '  <option value=18 selected>18</option>\n';
TextTool.prototype.drawer += '  <option value=20>20</option>\n';
TextTool.prototype.drawer += '  <option value=24>24</option>\n';
TextTool.prototype.drawer += '  <option value=28>28</option>\n';
TextTool.prototype.drawer += '  <option value=30>30</option>\n';
TextTool.prototype.drawer += '  <option value=34>34</option>\n';
TextTool.prototype.drawer += '  <option value=38>48</option>';
TextTool.prototype.drawer += ' </select>';
TextTool.prototype.drawer += ' <select id="fontColor">';
TextTool.prototype.drawer += '  <option value="black" style="color:black">黒</option>\n';
TextTool.prototype.drawer += '  <option value="red" style="color:red">赤</option>\n';
TextTool.prototype.drawer += '  <option value="orange" style="color:orange">オレンジ</option>\n';
TextTool.prototype.drawer += '  <option value="yellow" style="color:yellow">黄</option>\n';
TextTool.prototype.drawer += '  <option value="green" style="color:green">緑</option>\n';
TextTool.prototype.drawer += '  <option value="blue" style="color:blue">青</option>\n';
TextTool.prototype.drawer += '  <option value="purple" style="color:purple">紫</option>\n';
TextTool.prototype.drawer+= '</select>\n';
TextTool.prototype.drawer += ' <input type="button" value="テキスト作成" onclick="goGoText()">\n';
TextTool.prototype.drawer+= '</body></html>\n';



TextTool.prototype.mouseup = function(evt){
  this.x = getX(evt);
  this.y = getY(evt);
  windowPlease("","testo","scrollbars=no, menubar=yes,height=200,width=400",this.drawer);
}

var bob;

TextTool.prototype.runText = function( textData, size, color, updateObj ){
  popupwin.close();
  popupwin = null

  if ( updateObj == null ){
    this.svgTextNode = new TextObject( this.x, this.y, textData, size, color, true);

  } else {
    updateObj.textData = textData;
    updateObj.size = size;
    updateObj.color = color;
    updateObj.updateData();
  }
}
TextTool.prototype.deactivate = function(){
  // debug("deactivate textTool");
  if (popupwin){
    popupwin.close();
    popupwin = null;
  }
  eventCatcher.removeEventListener("mouseup", this, false);
}

TextTool.prototype.copyconstructor = function(svgNode){
  if ( svgNode.localName!="text" ){
    alert("I've got a :"+svgNode.localName+": but I wanted a text");
    return 0;
  }
  //  alert("copyconstrucText");
  this.x = Number( svgNode.getAttribute("x"));
  this.y = Number( svgNode.getAttribute("y"));
  var svgNode = svgNode;
  var textData = svgNode.firstChild.firstChild.data;
  var style = svgNode.getStyle();
  var size = style.font-size;
  var color = style.fill;
  //  var data = this.span.firstChild;
  this.svgTextNode = new TextObject( this.x, this.y, textData, size, color, false);
  this.svgTextNode.copyconstructor(svgNode);
  return this.svgTextNode;
}
TextTool.prototype.editText = function( txtObj){
  windowPlease("","testo","scrollbars=no, menubar=yes,height=200,width=400",this.drawer);
  with( popupwin.document.getElementById("fontSize") ){
    for (var i=0;i<options.length;i++){
      if (options[i].text==txtObj.size){ 
	options[i].selected=true;
	break;
      }
    }
  }
  with( popupwin.document.getElementById("fontColor") ){
    for (var i=0;i<options.length;i++){
      if (options[i].text==txtObj.color){ 
	options[i].selected=true;
	break;
      }
    }
  }
  popupwin.document.getElementById("newText").value = txtObj.textData;
  popupwin.updateNode = txtObj;
}
var textTool = new TextTool();

function tspanTool(){}
tspanTool.copyconstructor = function(){ return 0;}
