mxEditor使用(八)—— 增加自定义图元

前面我们通过修改配置文件增加已经存在的图元,这里我们学习如何增加自定义图元。我们希望增加双边线的矩形。首先,我们写一段js代码,实现并注册这个自定义的图元:


function DoubleRectangleShape() { }

DoubleRectangleShape.prototype = new mxActor();
DoubleRectangleShape.prototype.constructor = DoubleRectangleShape;
DoubleRectangleShape.prototype.redrawPath = function (path, x, y, w, h) {
    //alert(x);
    var x1 = 0;
    var y1 = 0;
    path.moveTo(x1, y1);
    path.lineTo(x1+w, y1);
    path.lineTo(x1+w, y1+h);
    path.lineTo(x1, y1+h);
    path.lineTo(x1, y1);
    path.moveTo(x1+5, y1+5);
    path.lineTo(x1+w - 5, y1+5);
    path.lineTo(x1+w - 5, y1+h - 5);
    path.lineTo(x1+5, y1+h - 5);
    path.lineTo(x1+5, y1+5);
    // ...
    path.close();
}

mxCellRenderer.registerShape('doublerectangleshape', DoubleRectangleShape);

然后在html文件中加载这个js文件,注意这个文件加载在mxClient.js后面,在app.js前面:

    <script type="text/javascript" src="../../src/js/mxClient.js"></script>
    <script type="text/javascript" src="js/DoubleRectangleShape.js"></script>
    <script type="text/javascript" src="js/app.js"></script>

接下来的步骤与增加已有图元一样,首先,修改wftoolbar-commands.xml,增加如下代码:

<add as="MyTask" template="mytask"  icon="images/rectangle.gif"/>

第二步,修改wfeditor-commons.xml,增加template,这部分代码如下:

    <add as="mytask">
      <MyTask label="任务" description="" fields="" href="" >
        <mxCell vertex="1" style="doublerectangleshape">
          <mxGeometry as="geometry" width="72" height="32"/>
         </mxCell>
        
      </MyTask>
    </add>

第三步,修改wfgraph-commons.xml,在mxStylesheet 下增加style,这部分代码如下:

    <add as="doublerectangleshape">
      <add as="shape" value="doublerectangleshape"/>,
    </add>

清除浏览器缓存,再次访问示例页面,图标增加了,可以向图形中增加新的图元:


图片.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、简历准备 1、个人技能 (1)自定义控件、UI设计、常用动画特效 自定义控件 ①为什么要自定义控件? Andr...
    lucas777阅读 5,266评论 2 54
  • 一. Java基础部分.................................................
    wy_sure阅读 3,839评论 0 11
  • spring官方文档:http://docs.spring.io/spring/docs/current/spri...
    牛马风情阅读 1,732评论 0 3
  • 点击查看原文 Web SDK 开发手册 SDK 概述 网易云信 SDK 为 Web 应用提供一个完善的 IM 系统...
    layjoy阅读 13,951评论 0 15
  • 1. 简介 1.1 什么是 MyBatis ? MyBatis 是支持定制化 SQL、存储过程以及高级映射的优秀的...
    笨鸟慢飞阅读 5,671评论 0 4