/*
Copyright (c) 2006 Lukasz Szajkowski <http://www.szajkowski.com/>

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/

/** A Vertex class */
Zorya._Vertex = function (vertexModel, vertexView) {
	this.debug = 10;
	this.className = 'Vertex';	
	Zorya.debug().alert(this.className + ' ' + vertexModel.getName(), this.debug);
	
	/** Default construtor
	 *
	 * vertexModel - vertex model
	 * vertexView - vertex view
	 */
	{	
		this.vertexModel = vertexModel;
		this.vertexView = vertexView;
		this.countOutEdges = 0;
		this.countInEdges = 0;
		this.countAllEdges = 0;
		this.outEdges = new Array();
		this.inEdges = new Array();
		this.allEdges = new Array();		
		Zorya.debug().alert(this.className + ' created', this.debug);
	}

	/** The method paints the vertex */
	this.createView = function(canvas){			
	}

	/** The method refreshes the vertex */
	this.refresh = function(){			
		var i;
		//alert('refresh ');
		//Zorya.debug().alert('refresh' , 1);
		//for (i = 0; i < this.countAllEdges; i++ ) {
			//alert('refresh ' + i);
    		this.getView().refresh();
		//}
		
		//for (i = 0; i < this.countAllEdges; i++) {
    		//this.allEdges[i].paint();			    		
		//}
	}
			 	
	/** The vertex drag event handler method */
	this.dragMoveAction =  function(dragEvent){
		var senderVertex = dragEvent.group.subscriber;
		senderVertex.refresh();
	}
					
	/** The initialize method */
	this.initialize = function() {
		this.controller = vertexView.getInternalCanvas().obj.toolManDragGroup;
		this.controller.subscriber = this;
		//this.controller.register('dragend', this.dragedAction);
		this.controller.register('dragmove', this.dragMoveAction);
	}
	
 	/** The method adds edge to inEdges array */
 	this.addInEdge = function(edge) {
 		var idtmp = edge.getId();
 //		this.inEdges[idtmp] = edge;
 		this.allEdges[this.countAllEdges] = edge;
 		this.countAllEdges++;
 		//alert('id = ' + idtmp + ' ' + this.countAllEdges);
 	}

 	/** The method adds edge to outEdges array */
 	this.addOutEdge = function(edge) {
// 		this.outEdges[edge.getId()] = edge;
 		this.allEdges[this.countAllEdges] = edge;
 		this.countAllEdges++
 		//alert('id = ' + this.countAllEdges);
 	}		
 	
	/** The method returns all edges field */
	this.getAllEdges = function() {
		return this.allEdges;
	} 	
	
	/** The method returns view field */
	this.getView = function() {
		return this.vertexView;
	}
		
	Zorya.debug().alert(this.className + ' end', this.debug);		
}
