/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */

if(!dojo._hasResource["esri.toolbars._VertexMover"]){dojo._hasResource["esri.toolbars._VertexMover"]=true;dojo.provide("esri.toolbars._VertexMover");dojo.require("dojox.gfx.move");dojo.declare("esri.toolbars.VertexMover",null,{constructor:function(_1,_2,_3,_4,_5,_6,_7,_8){this.point=_1;this.symbol=_2;this.relatedGraphic=_3;this.segIndex=_4;this.ptIndex=_5;this.segLength=_6;this.editor=_7;this.map=_7.map;this._scratchGL=_7.toolbar._scratchGL;this._placeholder=_8||false;this._type=_3.geometry.type;this._init();this._enable();},refresh:function(_9){if(_9||this._needRefresh()){this._disable();this._enable();}},destroy:function(){this._disable();if(this.graphic){this._scratchGL.remove(this.graphic);}this.point=this.symbol=this.graphic=this.relatedGraphic=this.segIndex=this.ptIndex=this.segLength=this.editor=this.map=this._scratchGL=null;},_init:function(){var _a=new esri.geometry.Point(this.point.toJson());var _b=new esri.Graphic(_a,this.symbol);switch(this._type){case "multipoint":_b._shape=this.relatedGraphic.getDojoShape().children[this.ptIndex];break;case "polyline":case "polygon":this._scratchGL.add(_b);break;}this.graphic=_b;},_enable:function(){var _c=this.graphic.getDojoShape();if(_c){_c._hasMover=true;this._moveable=this._getMoveable(_c);var _d=_c.getEventSource();if(_d){dojo.style(_d,"cursor",this.editor.toolbar._cursors[this._placeholder?"move-gv":"move-v"]);}}},_disable:function(){var _e=this._moveable;if(_e){dojo.disconnect(this._startHandle);dojo.disconnect(this._firstHandle);dojo.disconnect(this._movingHandle);dojo.disconnect(this._stopHandle);var _f=_e.shape;if(_f){var _10=_f.getEventSource();if(_10){dojo.style(_10,"cursor",null);}}_e.destroy();this._moveable=null;}},_needRefresh:function(){var _11=this.graphic.getDojoShape(),_12=false;if(_11){switch(this._type){case "multipoint":var _13=this.relatedGraphic.getDojoShape();if(_13){var _14=_13.children[this.ptIndex];if(_11!==_14){_11=_14;this.graphic._shape=_11;_12=true;}}break;case "polyline":case "polygon":_12=!_11._hasMover;break;}}return _12;},_getMoveable:function(_15){var _16=new dojox.gfx.Moveable(_15,dojo.isMac&&dojo.isFF&&!esri.isTouchEnabled&&{leftButtonOnly:true});this._startHandle=dojo.connect(_16,"onMoveStart",this,this._moveStartHandler);this._firstHandle=dojo.connect(_16,"onFirstMove",this,this._firstMoveHandler);this._movingHandle=dojo.connect(_16,"onMoving",this,this._movingHandler);this._stopHandle=dojo.connect(_16,"onMoveStop",this,this._moveStopHandler);return _16;},_getPtIndex:function(){return this.ptIndex+(this._placeholder?1:0);},_getInfo:function(){return {graphic:this.graphic,isGhost:this._placeholder,segmentIndex:this.segIndex,pointIndex:this._getPtIndex()};},_moveStartHandler:function(_17){var map=this.map;if(map.snappingManager){map.snappingManager._setUpSnapping();}_17.shape.moveToFront();this.constructor.onMoveStart(this);this.editor.toolbar.onVertexMoveStart(this.relatedGraphic,this._getInfo());},_firstMoveHandler:function(_18){var _19=_18.shape;var _1a=this._getControlEdges();var _1b=this._scratchGL._div;var i,_1c=[],_1d=_18.host.shape._wrapOffsets[0]||0;for(i=0;i<_1a.length;i++){var _1e=_1a[i];_1e.x1+=_1d;_1e.x2+=_1d;_1c.push([_1b.createLine({x1:_1e.x1,y1:_1e.y1,x2:_1e.x2,y2:_1e.y2}).setStroke(this.editor._lineStroke),_1e.x1,_1e.y1,_1e.x2,_1e.y2]);}_19._lines=_1c;_18.shape.moveToFront();this.constructor.onFirstMove(this);this.editor.toolbar.onVertexFirstMove(this.relatedGraphic,this._getInfo());},_movingHandler:function(_1f){var _20=_1f.shape,tx=_20.getTransform();var i,_21=_20._lines;for(i=0;i<_21.length;i++){var _22=_21[i];_22[0].setShape({x1:_22[1]+tx.dx,y1:_22[2]+tx.dy,x2:_22[3],y2:_22[4]});}this.editor.toolbar.onVertexMove(this.relatedGraphic,this._getInfo(),tx);},_moveStopHandler:function(_23){var _24=_23.shape,tx=_24.getTransform(),map=this.map;var _25=this.graphic;var i,_26=_24._lines;if(_26){for(i=0;i<_26.length;i++){_26[i][0].removeShape();}_24._lines=null;}var ph=false,_27=true,_28=this._getInfo();if(tx&&(tx.dx||tx.dy)){if(this._placeholder){this._placeholder=false;ph=true;}}else{_27=false;}var _29;if(this.map.snappingManager){_29=this.map.snappingManager._snappingPoint;}var _2a=_29||map.toMap(map.toScreen(_25.geometry).offset(tx.dx,tx.dy));if(this.map.snappingManager){this.map.snappingManager._killOffSnapping();}_24.setTransform(null);_25.setGeometry(_2a);this.constructor.onMoveStop(this,tx);this.editor.toolbar.onVertexMoveStop(this.relatedGraphic,_28,tx);if(!_27){this.editor.toolbar.onVertexClick(this.relatedGraphic,_28);}if(ph){this.editor.toolbar.onVertexAdd(this.relatedGraphic,this._getInfo());}},_getControlEdges:function(){var map=this.map;var _2b=this.relatedGraphic.geometry;var _2c=this.segIndex,_2d=this.ptIndex,_2e=this.segLength;var _2f=this._scratchGL._div;var _30=_2f.getTransform();var sdx=_30.dx,sdy=_30.dy;var pt=map.toScreen(this.graphic.geometry);var x=pt.x-sdx,y=pt.y-sdy;var _31=[];var _32=this.editor._getControlPoints(this,_2b,_2c,_2d,_2e);if(_32[0]){_31.push({x1:x,y1:y,x2:_32[0].x-sdx,y2:_32[0].y-sdy});}if(_32[1]){_31.push({x1:x,y1:y,x2:_32[1].x-sdx,y2:_32[1].y-sdy});}return _31;}});dojo.mixin(esri.toolbars.VertexMover,{onMoveStart:function(){},onFirstMove:function(){},onMoveStop:function(){}});}