日期:2014-05-17  浏览次数:20965 次

js画图开发库--mxgraph--contexticons-悬停图标.html

?js画图开发库--mxgraph--contexticons-悬停图标.html

?

?

<!Doctype html>
<html xmlns=http://www.w3.org/1999/xhtml>
	<head>
	<meta http-equiv=Content-Type content="text/html;charset=utf-8">
	<title>悬停图标示例 for mxGraph</title>

	<!-- 如果本文件的包与src不是在同一个目录,就要将basepath设置到src目录下 -->
	<script type="text/javascript">
		mxBasePath = '../src';
	</script>

	<!-- 引入支持库文件 -->
	<script type="text/javascript" src="../src/js/mxClient.js"></script>
	<!-- 示例代码 -->
	<script type="text/javascript">
		// Defines a subclass for mxVertexHandler that adds a set of clickable icons to every selected vertex.
		//定义节点处理程序,每个节点在被点击时会显示节点图标。图表是以节点的子类形式存在的。
		function mxVertexToolHandler(state) {
			mxVertexHandler.apply(this, arguments);
		};

		mxVertexToolHandler.prototype = new mxVertexHandler();
		mxVertexToolHandler.prototype.constructor = mxVertexToolHandler;
		
		mxVertexToolHandler.prototype.domNode = null;
		//初始化
		mxVertexToolHandler.prototype.init = function()
		{
			mxVertexHandler.prototype.init.apply(this, arguments);

			//示例中使用div容器显示元素,这样做的目的就是解决IE浏览器中透明度的问题。
			this.domNode = document.createElement('div');
			this.domNode.style.position = 'absolute';
			this.domNode.style.whiteSpace = 'nowrap';
			var md = (mxClient.IS_TOUCH) ? 'touchstart' : 'mousedown';

			// 删除按钮
			var img = mxUtils.createImage('images/delete2.png');
			img.style.cursor = 'pointer';
			img.style.width = '16px';
			img.style.height = '16px';
			mxEvent.addListener(img, md,
				mxUtils.bind(this, function(evt)
				{
					// Disables dragging the image
					mxEvent.consume(evt);
				})
			);
			mxEvent.addListener(img, 'click',
				mxUtils.bind(this, function(evt)
				{
					this.graph.removeCells([this.state.cell]);
					mxEvent.consume(evt);
				})
			);
			this.domNode.appendChild(img);

			// 大小按钮
			var img = mxUtils.createImage('images/fit_to_size.png');
			img.style.cursor = 'se-resize';
			img.style.width = '16px';
			img.style.height = '16px';
			mxEvent.addListener(img, md,
				mxUtils.bind(this, function(evt)
				{
					this.start(mxEvent.getClientX(evt), mxEvent.getClientY(evt), 7);
					this.graph.isMouseDown = true;
					mxEvent.consume(evt);
				})
			);
			this.domNode.appendChild(img);

			// 移动按钮
			var img = mxUtils.createImage('images/connector.gif');
			img.style.cursor = 'move';
			img.style.width = '16px';
			img.style.height = '16px';
			mxEvent.addListener(img, md,
				mxUtils.bind(this, function(evt)
				{
					this.graph.graphHandler.start(this.state.cell,
						mxEvent.getClientX(evt), mxEvent.getClientY(evt));
					this.graph.graphHandler.cellWasClicked = true;
					this.graph.isMouseDown = true;
					mxEvent.consume(evt);
				})
			);
			this.domNode.appendChild(img);

			// 链接按钮
			var img = mxUtils.createImage('images/check.png');
			img.style.cursor = 'pointer';
			img.style.width = '16px';
			img.style.height = '16px';
			mxEvent.addListener(img, md,
				mxUtils.bind(this, function(evt)
				{
					var pt = mxUtils.convertPoint(this.graph.container,
							mxEvent.getClientX(evt), mxEvent.getClientY(evt));
					this.graph.connectionHandler.start(this.state, pt.x, pt.y);
					this.graph.isMouseDown = true;
					mxEvent.consume(evt);
				})
			);
			this.domNode.appendChild(img);
			//将节点添加到容器
			this.graph.container.appendChild(this.domNode);
			this.redrawTools();
		};
		//重绘
		mxVertexToolHandler.prototype.redraw = function()
		{
			mxVertexHandler.prototype.redraw.apply(this);
			this.redrawTools();
		};
		//重绘工具
		mxVertexToolHandler.prototype.redrawTools = function()
		{
			if (this.state != null && this.domNode != null)
			{
				var dy = (mxClient.IS_VML && document.compatMode == 'CSS1Compat') ? 20 : 4;
				this.domNode.style.left = (this.state.x + this.state.width - 56) + 'px';