Menus.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. /**
  2. *$id:Action 。JS,V 2017-12-19
  3. *$author shen.zhi
  4. */
  5. /**
  6. * 构建了一种新的图形编辑器
  7. */
  8. var data=null;
  9. Menus = function(editorUi)
  10. {
  11. this.editorUi = editorUi;
  12. this.menus = new Object();
  13. //获取右键菜单 关联设备信息数据
  14. $.post($("#path").val()+"/GetConnIpServlet",function(text){
  15. if(text!=null && text!=""){
  16. data = text;
  17. }
  18. });
  19. this.init();
  20. //预取标记图像
  21. new Image().src = IMAGE_PATH + '/checkmark.gif';
  22. };
  23. /**
  24. *添加标签菜单项给定的菜单和母。
  25. */
  26. Menus.prototype.init = function()
  27. {
  28. var graph = this.editorUi.editor.graph;
  29. this.put('fontFamily', new Menu(mxUtils.bind(this, function(menu, parent)
  30. {
  31. var fonts = ['Helvetica', 'Verdana', 'Times New Roman', 'Garamond', 'Comic Sans MS',
  32. 'Courier New', 'Georgia', 'Lucida Console', 'Tahoma'];
  33. for (var i = 0; i < fonts.length; i++)
  34. {
  35. var tr = this.styleChange(menu, fonts[i], [mxConstants.STYLE_FONTFAMILY], [fonts[i]], null, parent);
  36. tr.firstChild.nextSibling.style.fontFamily = fonts[i];
  37. }
  38. menu.addSeparator(parent);
  39. this.promptChange(menu, mxResources.get('custom'), '', mxConstants.DEFAULT_FONTFAMILY, mxConstants.STYLE_FONTFAMILY, parent);
  40. })));
  41. this.put('fontSize', new Menu(mxUtils.bind(this, function(menu, parent)
  42. {
  43. var sizes = [6, 8, 9, 10, 11, 12, 14, 18, 24, 36, 48, 72];
  44. for (var i = 0; i < sizes.length; i++)
  45. {
  46. this.styleChange(menu, sizes[i], [mxConstants.STYLE_FONTSIZE], [sizes[i]], null, parent);
  47. }
  48. menu.addSeparator(parent);
  49. this.promptChange(menu, mxResources.get('custom'), '(pt)', '12', mxConstants.STYLE_FONTSIZE, parent);
  50. })));
  51. //右键线宽[1px,2px..自定义]
  52. this.put('linewidth', new Menu(mxUtils.bind(this, function(menu, parent)
  53. {
  54. var sizes = [1, 2, 3, 4, 8, 12, 16, 24];
  55. for (var i = 0; i < sizes.length; i++)
  56. {
  57. this.styleChange(menu, sizes[i] + 'px', [mxConstants.STYLE_STROKEWIDTH], [sizes[i]], null, parent);
  58. }
  59. menu.addSeparator(parent);
  60. this.promptChange(menu, mxResources.get('custom'), '(px)', '1', mxConstants.STYLE_STROKEWIDTH, parent);
  61. })));
  62. //右键关联设备信息{二级,三级...菜单}
  63. this.put('connip', new Menu(mxUtils.bind(this, function(menu, parent)
  64. {
  65. var idx=0;
  66. var sizes = data.split("&");
  67. for(var i = 0;i<sizes.length;i++){
  68. if(sizes[i]!="" && sizes[i]!=null){
  69. idx = sizes[i].indexOf("+");
  70. if(idx>0){
  71. this.valueChange(menu, sizes[i].substr(0,idx),sizes[i].substr(sizes[i].indexOf("+")+1), null, parent);
  72. }else{
  73. this.valueChange(menu, sizes[i],"", null, parent);
  74. }
  75. }
  76. }
  77. menu.addSeparator(parent);
  78. })));
  79. this.put('line', new Menu(mxUtils.bind(this, function(menu, parent)
  80. {
  81. this.styleChange(menu, mxResources.get('straight'), [mxConstants.STYLE_EDGE], [null], null, parent);
  82. this.styleChange(menu, mxResources.get('entityRelation'), [mxConstants.STYLE_EDGE], ['entityRelationEdgeStyle'], null, parent);
  83. menu.addSeparator(parent);
  84. this.styleChange(menu, mxResources.get('horizontal'), [mxConstants.STYLE_EDGE, mxConstants.STYLE_ELBOW], ['elbowEdgeStyle', 'horizontal'], null, parent);
  85. this.styleChange(menu, mxResources.get('vertical'), [mxConstants.STYLE_EDGE, mxConstants.STYLE_ELBOW], ['elbowEdgeStyle', 'vertical'], null, parent);
  86. menu.addSeparator(parent);
  87. this.styleChange(menu, mxResources.get('plain'), [mxConstants.STYLE_EDGE], ['segmentEdgeStyle'], null, parent);
  88. this.styleChange(menu, mxResources.get('orthogonal'), [mxConstants.STYLE_EDGE], ['orthogonalEdgeStyle'], null, parent);
  89. })));
  90. this.put('lineend', new Menu(mxUtils.bind(this, function(menu, parent)
  91. {
  92. this.styleChange(menu, mxResources.get('classic'), [mxConstants.STYLE_ENDARROW], [mxConstants.ARROW_CLASSIC], null, parent);
  93. this.styleChange(menu, mxResources.get('openArrow'), [mxConstants.STYLE_ENDARROW], [mxConstants.ARROW_OPEN], null, parent);
  94. this.styleChange(menu, mxResources.get('block') , [mxConstants.STYLE_ENDARROW], [mxConstants.ARROW_BLOCK], null, parent);
  95. menu.addSeparator(parent);
  96. this.styleChange(menu, mxResources.get('oval'), [mxConstants.STYLE_ENDARROW], [mxConstants.ARROW_OVAL], null, parent);
  97. this.styleChange(menu, mxResources.get('diamond'), [mxConstants.STYLE_ENDARROW], [mxConstants.ARROW_DIAMOND], null, parent);
  98. this.styleChange(menu, mxResources.get('diamondThin'), [mxConstants.STYLE_ENDARROW], [mxConstants.ARROW_DIAMOND_THIN], null, parent);
  99. menu.addSeparator(parent);
  100. this.styleChange(menu, mxResources.get('none'), [mxConstants.STYLE_ENDARROW], [mxConstants.NONE], null, parent);
  101. menu.addSeparator(parent);
  102. menu.addItem(mxResources.get('transparent'), null, function() { graph.toggleCellStyles('endFill', true); }, parent, null, true);
  103. menu.addSeparator(parent);
  104. this.promptChange(menu, mxResources.get('size'), '(px)', mxConstants.DEFAULT_MARKERSIZE, mxConstants.STYLE_ENDSIZE, parent);
  105. })));
  106. this.put('linestart', new Menu(mxUtils.bind(this, function(menu, parent)
  107. {
  108. this.styleChange(menu, mxResources.get('classic'), [mxConstants.STYLE_STARTARROW], [mxConstants.ARROW_CLASSIC], null, parent);
  109. this.styleChange(menu, mxResources.get('openArrow'), [mxConstants.STYLE_STARTARROW], [mxConstants.ARROW_OPEN], null, parent);
  110. this.styleChange(menu, mxResources.get('block'), [mxConstants.STYLE_STARTARROW], [mxConstants.ARROW_BLOCK], null, parent);
  111. menu.addSeparator(parent);
  112. this.styleChange(menu, mxResources.get('oval'), [mxConstants.STYLE_STARTARROW], [mxConstants.ARROW_OVAL], null, parent);
  113. this.styleChange(menu, mxResources.get('diamond'), [mxConstants.STYLE_STARTARROW], [mxConstants.ARROW_DIAMOND], null, parent);
  114. this.styleChange(menu, mxResources.get('diamondThin'), [mxConstants.STYLE_STARTARROW], [mxConstants.ARROW_DIAMOND_THIN], null, parent);
  115. menu.addSeparator(parent);
  116. this.styleChange(menu, mxResources.get('none'), [mxConstants.STYLE_STARTARROW], [mxConstants.NONE], null, parent);
  117. menu.addSeparator(parent);
  118. menu.addItem(mxResources.get('transparent'), null, function() { graph.toggleCellStyles('startFill', true); }, parent, null, true);
  119. menu.addSeparator(parent);
  120. this.promptChange(menu, mxResources.get('size'), '(px)', mxConstants.DEFAULT_MARKERSIZE, mxConstants.STYLE_STARTSIZE, parent);
  121. })));
  122. this.put('spacing', new Menu(mxUtils.bind(this, function(menu, parent)
  123. {
  124. // Uses shadow action and line menu to analyze selection
  125. var vertexSelected = this.editorUi.actions.get('shadow').enabled;
  126. var edgeSelected = this.get('line').enabled;
  127. if (vertexSelected || menu.showDisabled)
  128. {
  129. this.promptChange(menu, mxResources.get('top'), '(px)', '0', mxConstants.STYLE_SPACING_TOP, parent, vertexSelected);
  130. this.promptChange(menu, mxResources.get('right'), '(px)', '0', mxConstants.STYLE_SPACING_RIGHT, parent, vertexSelected);
  131. this.promptChange(menu, mxResources.get('bottom'), '(px)', '0', mxConstants.STYLE_SPACING_BOTTOM, parent, vertexSelected);
  132. this.promptChange(menu, mxResources.get('left'), '(px)', '0', mxConstants.STYLE_SPACING_LEFT, parent, vertexSelected);
  133. menu.addSeparator(parent);
  134. this.promptChange(menu, mxResources.get('global'), '(px)', '0', mxConstants.STYLE_SPACING, parent, vertexSelected);
  135. this.promptChange(menu, mxResources.get('perimeter'), '(px)', '0', mxConstants.STYLE_PERIMETER_SPACING, parent, vertexSelected);
  136. }
  137. if (edgeSelected || menu.showDisabled)
  138. {
  139. menu.addSeparator(parent);
  140. this.promptChange(menu, mxResources.get('sourceSpacing'), '(px)', '0', mxConstants.STYLE_SOURCE_PERIMETER_SPACING, parent, edgeSelected);
  141. this.promptChange(menu, mxResources.get('targetSpacing'), '(px)', '0', mxConstants.STYLE_TARGET_PERIMETER_SPACING, parent, edgeSelected);
  142. }
  143. })));
  144. this.put('format', new Menu(mxUtils.bind(this, function(menu, parent)
  145. {
  146. this.addSubmenu('spacing', menu, parent);
  147. this.addMenuItems(menu, ['-', 'fillColor'], parent);
  148. this.addSubmenu('gradient', menu, parent);
  149. this.addMenuItems(menu, ['-', 'shadow'], parent);
  150. this.promptChange(menu, mxResources.get('opacity'), '(%)', '100', mxConstants.STYLE_OPACITY, parent, this.get('format').enabled);
  151. this.addMenuItems(menu, ['-', 'rounded', 'dashed', '-', 'strokeColor'], parent);
  152. this.addSubmenu('linewidth', menu, parent);
  153. this.addMenuItems(menu, ['-'], parent);
  154. this.addSubmenu('line', menu, parent);
  155. this.addMenuItems(menu, ['-'], parent);
  156. this.addSubmenu('linestart', menu, parent);
  157. this.addSubmenu('lineend', menu, parent);
  158. menu.addSeparator(parent);
  159. this.addMenuItem(menu, 'style', parent);
  160. })));
  161. this.put('gradient', new Menu(mxUtils.bind(this, function(menu, parent)
  162. {
  163. this.addMenuItems(menu, ['gradientColor', '-'], parent);
  164. this.styleChange(menu, mxResources.get('north'), [mxConstants.STYLE_GRADIENT_DIRECTION], [mxConstants.DIRECTION_NORTH], null, parent);
  165. this.styleChange(menu, mxResources.get('east'), [mxConstants.STYLE_GRADIENT_DIRECTION], [mxConstants.DIRECTION_EAST], null, parent);
  166. this.styleChange(menu, mxResources.get('south'), [mxConstants.STYLE_GRADIENT_DIRECTION], [mxConstants.DIRECTION_SOUTH], null, parent);
  167. this.styleChange(menu, mxResources.get('west'), [mxConstants.STYLE_GRADIENT_DIRECTION], [mxConstants.DIRECTION_WEST], null, parent);
  168. })));
  169. this.put('text', new Menu(mxUtils.bind(this, function(menu, parent)
  170. {
  171. this.addMenuItem(menu, 'fontColor', parent);
  172. menu.addSeparator(parent);
  173. //this.addSubmenu('fontFamily', menu, parent);
  174. this.addSubmenu('fontSize', menu, parent);
  175. this.addMenuItems(menu, ['-', 'bold', 'italic','-'], parent);
  176. this.addSubmenu('alignment', menu, parent);
  177. this.addSubmenu('position', menu, parent);
  178. this.addMenuItems(menu, ['-', 'backgroundColor', 'borderColor', '-'], parent);
  179. var enabled = this.get('text').enabled;
  180. this.promptChange(menu, mxResources.get('textOpacity'), '(%)', '100', mxConstants.STYLE_TEXT_OPACITY, parent, enabled);
  181. menu.addItem(mxResources.get('hide'), null, function() { graph.toggleCellStyles(mxConstants.STYLE_NOLABEL, false); }, parent, null, enabled);
  182. menu.addItem(mxResources.get('rotate'), null, function() { graph.toggleCellStyles(mxConstants.STYLE_HORIZONTAL, true); }, parent, null, enabled);
  183. })));
  184. this.put('alignment', new Menu(mxUtils.bind(this, function(menu, parent)
  185. {
  186. this.styleChange(menu, mxResources.get('leftAlign'), [mxConstants.STYLE_ALIGN], [mxConstants.ALIGN_LEFT], null, parent);
  187. this.styleChange(menu, mxResources.get('center'), [mxConstants.STYLE_ALIGN], [mxConstants.ALIGN_CENTER], null, parent);
  188. this.styleChange(menu, mxResources.get('rightAlign'), [mxConstants.STYLE_ALIGN], [mxConstants.ALIGN_RIGHT], null, parent);
  189. menu.addSeparator(parent);
  190. this.styleChange(menu, mxResources.get('topAlign'), [mxConstants.STYLE_VERTICAL_ALIGN], [mxConstants.ALIGN_TOP], null, parent);
  191. this.styleChange(menu, mxResources.get('middle'), [mxConstants.STYLE_VERTICAL_ALIGN], [mxConstants.ALIGN_MIDDLE], null, parent);
  192. this.styleChange(menu, mxResources.get('bottomAlign'), [mxConstants.STYLE_VERTICAL_ALIGN], [mxConstants.ALIGN_BOTTOM], null, parent);
  193. })));
  194. this.put('position', new Menu(mxUtils.bind(this, function(menu, parent)
  195. {
  196. this.styleChange(menu, mxResources.get('left'), [mxConstants.STYLE_LABEL_POSITION, mxConstants.STYLE_ALIGN], [mxConstants.ALIGN_LEFT, mxConstants.ALIGN_RIGHT], null, parent);
  197. this.styleChange(menu, mxResources.get('center'), [mxConstants.STYLE_LABEL_POSITION, mxConstants.STYLE_ALIGN], [mxConstants.ALIGN_CENTER, mxConstants.ALIGN_CENTER], null, parent);
  198. this.styleChange(menu, mxResources.get('right'), [mxConstants.STYLE_LABEL_POSITION, mxConstants.STYLE_ALIGN], [mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_LEFT], null, parent);
  199. menu.addSeparator(parent);
  200. this.styleChange(menu, mxResources.get('top'), [mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.STYLE_VERTICAL_ALIGN], [mxConstants.ALIGN_TOP, mxConstants.ALIGN_BOTTOM], null, parent);
  201. this.styleChange(menu, mxResources.get('middle'), [mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.STYLE_VERTICAL_ALIGN], [mxConstants.ALIGN_MIDDLE, mxConstants.ALIGN_MIDDLE], null, parent);
  202. this.styleChange(menu, mxResources.get('bottom'), [mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.STYLE_VERTICAL_ALIGN], [mxConstants.ALIGN_BOTTOM, mxConstants.ALIGN_TOP], null, parent);
  203. })));
  204. this.put('direction', new Menu(mxUtils.bind(this, function(menu, parent)
  205. {
  206. this.styleChange(menu, mxResources.get('north'), [mxConstants.STYLE_DIRECTION], [mxConstants.DIRECTION_NORTH], null, parent);
  207. this.styleChange(menu, mxResources.get('east'), [mxConstants.STYLE_DIRECTION], [mxConstants.DIRECTION_EAST], null, parent);
  208. this.styleChange(menu, mxResources.get('south'), [mxConstants.STYLE_DIRECTION], [mxConstants.DIRECTION_SOUTH], null, parent);
  209. this.styleChange(menu, mxResources.get('west'), [mxConstants.STYLE_DIRECTION], [mxConstants.DIRECTION_WEST], null, parent);
  210. menu.addSeparator(parent);
  211. menu.addItem(mxResources.get('flipH'), null, function()
  212. {
  213. graph.getModel().beginUpdate();
  214. try
  215. {
  216. graph.toggleCellStyles(mxConstants.STYLE_STENCIL_FLIPH, false);
  217. graph.toggleCellStyles(mxConstants.STYLE_IMAGE_FLIPH, false);
  218. }
  219. finally
  220. {
  221. graph.getModel().endUpdate();
  222. }
  223. }, parent);
  224. menu.addItem(mxResources.get('flipV'), null, function()
  225. {
  226. graph.getModel().beginUpdate();
  227. try
  228. {
  229. graph.toggleCellStyles(mxConstants.STYLE_STENCIL_FLIPV, false);
  230. graph.toggleCellStyles(mxConstants.STYLE_IMAGE_FLIPV, false);
  231. }
  232. finally
  233. {
  234. graph.getModel().endUpdate();
  235. }
  236. }, parent);
  237. this.addMenuItem(menu, 'rotation', parent);
  238. })));
  239. this.put('align', new Menu(mxUtils.bind(this, function(menu, parent)
  240. {
  241. menu.addItem(mxResources.get('leftAlign'), null, function() { graph.alignCells(mxConstants.ALIGN_LEFT); }, parent);
  242. menu.addItem(mxResources.get('center'), null, function() { graph.alignCells(mxConstants.ALIGN_CENTER); }, parent);
  243. menu.addItem(mxResources.get('rightAlign'), null, function() { graph.alignCells(mxConstants.ALIGN_RIGHT); }, parent);
  244. menu.addSeparator(parent);
  245. menu.addItem(mxResources.get('topAlign'), null, function() { graph.alignCells(mxConstants.ALIGN_TOP); }, parent);
  246. menu.addItem(mxResources.get('middle'), null, function() { graph.alignCells(mxConstants.ALIGN_MIDDLE); }, parent);
  247. menu.addItem(mxResources.get('bottomAlign'), null, function() { graph.alignCells(mxConstants.ALIGN_BOTTOM); }, parent);
  248. })));
  249. this.put('layout', new Menu(mxUtils.bind(this, function(menu, parent)
  250. {
  251. menu.addItem(mxResources.get('horizontalTree'), null, mxUtils.bind(this, function()
  252. {
  253. if (!graph.isSelectionEmpty())
  254. {
  255. var layout = new mxCompactTreeLayout(graph, true);
  256. layout.edgeRouting = false;
  257. layout.levelDistance = 30;
  258. this.editorUi.executeLayout(layout, true, true);
  259. }
  260. }), parent);
  261. menu.addItem(mxResources.get('verticalTree'), null, mxUtils.bind(this, function()
  262. {
  263. if (!graph.isSelectionEmpty())
  264. {
  265. var layout = new mxCompactTreeLayout(graph, false);
  266. layout.edgeRouting = false;
  267. layout.levelDistance = 30;
  268. this.editorUi.executeLayout(layout, true, true);
  269. }
  270. }), parent);
  271. menu.addSeparator(parent);
  272. menu.addItem(mxResources.get('horizontalFlow'), null, mxUtils.bind(this, function()
  273. {
  274. var layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_WEST);
  275. this.editorUi.executeLayout(layout, true, true);
  276. }), parent);
  277. menu.addItem(mxResources.get('verticalFlow'), null, mxUtils.bind(this, function()
  278. {
  279. var layout = new mxHierarchicalLayout(graph, mxConstants.DIRECTION_NORTH);
  280. this.editorUi.executeLayout(layout, true, true);
  281. }), parent);
  282. menu.addSeparator(parent);
  283. menu.addItem(mxResources.get('organic'), null, mxUtils.bind(this, function()
  284. {
  285. var layout = new mxFastOrganicLayout(graph);
  286. this.editorUi.executeLayout(layout, true, true);
  287. }), parent);
  288. menu.addItem(mxResources.get('circle'), null, mxUtils.bind(this, function()
  289. {
  290. var layout = new mxCircleLayout(graph);
  291. this.editorUi.executeLayout(layout, true, true, graph.getSelectionCells());
  292. }), parent);
  293. })));
  294. this.put('navigation', new Menu(mxUtils.bind(this, function(menu, parent)
  295. {
  296. this.addMenuItems(menu, ['home', '-', 'exitGroup', 'enterGroup', '-', 'expand', 'collapse'], parent);
  297. })));
  298. this.put('arrange', new Menu(mxUtils.bind(this, function(menu, parent)
  299. {
  300. this.addMenuItems(menu, ['toFront', 'toBack', '-'], parent);
  301. this.addSubmenu('direction', menu, parent);
  302. this.addSubmenu('layout', menu, parent);
  303. this.addSubmenu('align', menu, parent);
  304. menu.addSeparator(parent);
  305. this.addSubmenu('navigation', menu, parent);
  306. this.addMenuItems(menu, ['-', 'group', 'ungroup', 'removeFromGroup', '-', 'autosize', 'rotate'], parent);
  307. })));
  308. this.put('view', new Menu(mxUtils.bind(this, function(menu, parent)
  309. {
  310. this.addMenuItems(menu, ['actualSize'], parent);
  311. menu.addSeparator();
  312. var scales = [0.25, 0.5, 0.75, 1, 2, 4];
  313. for (var i = 0; i < scales.length; i++)
  314. {
  315. (function(scale)
  316. {
  317. menu.addItem((scale * 100) + '%', null, function()
  318. {
  319. graph.zoomTo(scale);
  320. }, parent);
  321. })(scales[i]);
  322. }
  323. this.addMenuItems(menu, ['-', 'zoomIn', 'zoomOut', '-', 'fitWindow', 'customZoom', '-', 'fitPage', 'fitPageWidth'], parent);
  324. })));
  325. this.put('file', new Menu(mxUtils.bind(this, function(menu, parent)
  326. {
  327. this.addMenuItems(menu, ['save', '-', 'import', 'editFile', '-', 'pageSetup', 'print'], parent);
  328. })));
  329. this.put('edit', new Menu(mxUtils.bind(this, function(menu, parent)
  330. {
  331. this.addMenuItems(menu, ['undo', 'redo', '-', 'cut', 'copy', 'paste', 'delete', '-', 'duplicate', '-',
  332. /* 'editLink', 'openLink', '-', 取消编辑连接和打开连接*/
  333. 'selectVertices', 'selectEdges', 'selectAll', '-', 'setAsDefaultEdge']);
  334. })));
  335. this.put('options', new Menu(mxUtils.bind(this, function(menu, parent)
  336. {
  337. this.addMenuItems(menu, ['grid', 'guides', 'tooltips', '-', 'connect', 'navigation',
  338. 'scrollbars']);
  339. })));
  340. };
  341. /**
  342. * Adds the label menu items to the given menu and parent.
  343. */
  344. Menus.prototype.put = function(name, menu)
  345. {
  346. this.menus[name] = menu;
  347. };
  348. /**
  349. * Adds the label menu items to the given menu and parent.
  350. */
  351. Menus.prototype.get = function(name)
  352. {
  353. return this.menus[name];
  354. };
  355. /**
  356. * Adds the given submenu.
  357. */
  358. Menus.prototype.addSubmenu = function(name, menu, parent)
  359. {
  360. var enabled = this.get(name).enabled;
  361. if (menu.showDisabled || enabled)
  362. {
  363. var submenu = menu.addItem(mxResources.get(name), null, null, parent, null, enabled);
  364. this.addMenu(name, menu, submenu);
  365. }
  366. };
  367. /**
  368. * Adds the label menu items to the given menu and parent.
  369. */
  370. Menus.prototype.addMenu = function(name, popupMenu, parent)
  371. {
  372. var menu = this.get(name);
  373. if (menu != null && (popupMenu.showDisabled || menu.enabled))
  374. {
  375. this.get(name).execute(popupMenu, parent);
  376. }
  377. };
  378. /**
  379. * Adds a style change item to the given menu.
  380. */
  381. Menus.prototype.styleChange = function(menu, label, keys, values, sprite, parent)
  382. {
  383. return menu.addItem(label, null, mxUtils.bind(this, function()
  384. {
  385. var graph = this.editorUi.editor.graph;
  386. graph.getModel().beginUpdate();
  387. try
  388. {
  389. for (var i = 0; i < keys.length; i++)
  390. {
  391. graph.setCellStyles(keys[i], values[i]);
  392. }
  393. }
  394. finally
  395. {
  396. graph.getModel().endUpdate();
  397. }
  398. }), parent, sprite);
  399. };
  400. Menus.prototype.valueChange = function(menu, label, values, sprite, parent)
  401. {
  402. return menu.addItem(label, null, mxUtils.bind(this, function()
  403. {
  404. var graph = this.editorUi.editor.graph;
  405. graph.getModel().beginUpdate();
  406. try
  407. {
  408. var cels = graph.getSelectionCell();//获取当前选中的cell对象
  409. cels.setValue(label.substr(label.indexOf("—")+1)+"\n通讯:"+label.substr(0,label.indexOf("—")).replace("/","\n业务:"));
  410. cels.setRemark(values);
  411. //cels.setFid(values);
  412. graph.refresh();//刷新整个区域
  413. }
  414. finally
  415. {
  416. graph.getModel().endUpdate();
  417. }
  418. }), parent, sprite);
  419. };
  420. /**
  421. * Adds a style change item with a prompt to the given menu.
  422. */
  423. Menus.prototype.promptChange = function(menu, label, hint, defaultValue, key, parent, enabled)
  424. {
  425. return menu.addItem(label, null, mxUtils.bind(this, function()
  426. {
  427. var graph = this.editorUi.editor.graph;
  428. var value = defaultValue;
  429. var state = graph.getView().getState(graph.getSelectionCell());
  430. if (state != null)
  431. {
  432. value = state.style[key] || value;
  433. }
  434. value = mxUtils.prompt(mxResources.get('enterValue') + ((hint.length > 0) ? (' ' + hint) : ''), value);
  435. if (value != null && value.length > 0)
  436. {
  437. graph.setCellStyles(key, value);
  438. }
  439. }), parent, null, enabled);
  440. };
  441. /**
  442. * Adds a handler for showing a menu in the given element.
  443. */
  444. Menus.prototype.pickColor = function(key)
  445. {
  446. if (this.colorDialog == null)
  447. {
  448. this.colorDialog = new ColorDialog(this.editorUi);
  449. }
  450. this.colorDialog.currentColorKey = key;
  451. var graph = this.editorUi.editor.graph;
  452. var state = graph.getView().getState(graph.getSelectionCell());
  453. var color = 'none';
  454. if (state != null)
  455. {
  456. color = state.style[key] || color;
  457. }
  458. if (color == 'none')
  459. {
  460. color = 'ffffff';
  461. this.colorDialog.picker.fromString('ffffff');
  462. this.colorDialog.colorInput.value = 'none';
  463. }
  464. else
  465. {
  466. this.colorDialog.picker.fromString(color);
  467. }
  468. this.editorUi.showDialog(this.colorDialog.container, 220, 360, true, false);
  469. if (!mxClient.IS_TOUCH)
  470. {
  471. this.colorDialog.colorInput.focus();
  472. }
  473. };
  474. /**
  475. * Creates the keyboard event handler for the current graph and history.
  476. */
  477. Menus.prototype.addMenuItem = function(menu, key, parent)
  478. {
  479. var action = this.editorUi.actions.get(key);
  480. if (action != null && (menu.showDisabled || action.enabled))
  481. {
  482. var item = menu.addItem(action.label, null, action.funct, parent, null, action.enabled);
  483. // Adds checkmark image
  484. if (action.toggleAction && action.isSelected())
  485. {
  486. this.addCheckmark(item);
  487. }
  488. this.addShortcut(item, action);
  489. return item;
  490. }
  491. return null;
  492. };
  493. /**
  494. * Adds a checkmark to the given menuitem.
  495. */
  496. Menus.prototype.addShortcut = function(item, action)
  497. {
  498. if (action.shortcut != null)
  499. {
  500. var td = item.firstChild.nextSibling.nextSibling;
  501. var span = document.createElement('span');
  502. span.style.color = 'gray';
  503. mxUtils.write(span, action.shortcut);
  504. td.appendChild(span);
  505. }
  506. };
  507. /**
  508. * Adds a checkmark to the given menuitem.
  509. */
  510. Menus.prototype.addCheckmark = function(item)
  511. {
  512. var td = item.firstChild.nextSibling;
  513. td.style.backgroundImage = 'url(' + IMAGE_PATH + '/checkmark.gif)';
  514. td.style.backgroundRepeat = 'no-repeat';
  515. td.style.backgroundPosition = '2px 50%';
  516. td.style.width = '20px';
  517. };
  518. /**
  519. * Creates the keyboard event handler for the current graph and history.
  520. */
  521. Menus.prototype.addMenuItems = function(menu, keys, parent)
  522. {
  523. for (var i = 0; i < keys.length; i++)
  524. {
  525. if (keys[i] == '-')
  526. {
  527. menu.addSeparator(parent);
  528. }
  529. else
  530. {
  531. this.addMenuItem(menu, keys[i], parent);
  532. }
  533. }
  534. };
  535. /**
  536. * Creates the keyboard event handler for the current graph and history.
  537. */
  538. Menus.prototype.createPopupMenu = function(menu, cell, evt)
  539. {
  540. var graph = this.editorUi.editor.graph;
  541. menu.smartSeparators = true;
  542. if (graph.isSelectionEmpty())
  543. {
  544. this.addMenuItems(menu, ['undo', 'redo', '-', 'paste', '-']);
  545. }
  546. else
  547. {
  548. this.addMenuItems(menu, ['delete', '-', 'cut', 'copy', '-', 'duplicate','-']);
  549. }
  550. if (graph.getSelectionCount() > 0)
  551. {
  552. this.addMenuItems(menu, ['toFront', 'toBack','-']);
  553. this.addSubmenu('linewidth', menu);
  554. if (graph.getSelectionCount() == 1){//如果选中的数量只有一个
  555. var cel = graph.getSelectionCell();
  556. if(!cel.isEdge()){//如果选中的不是边 则增加关联ip菜单
  557. this.addSubmenu('connip', menu);
  558. }
  559. }
  560. if (graph.getModel().isEdge(graph.getSelectionCell()))
  561. {
  562. this.addSubmenu('line', menu);
  563. menu.addSeparator();
  564. this.addSubmenu('linestart', menu);
  565. this.addSubmenu('lineend', menu);
  566. menu.addSeparator();
  567. this.addMenuItems(menu, ['setAsDefaultEdge']);
  568. }
  569. else if (graph.getSelectionCount() > 1)
  570. {
  571. menu.addSeparator();
  572. this.addMenuItems(menu, ['group']);
  573. }
  574. else
  575. {
  576. this.addSubmenu('layout', menu);
  577. }
  578. menu.addSeparator();
  579. }
  580. else
  581. {
  582. this.addMenuItems(menu, ['-', 'selectVertices', 'selectEdges', '-', 'selectAll']);
  583. }
  584. };
  585. /**
  586. * Creates the keyboard event handler for the current graph and history.
  587. */
  588. Menus.prototype.createMenubar = function(container)
  589. {
  590. var menubar = new Menubar(this.editorUi, container);
  591. var menus = ['file', 'edit', 'view', 'format', 'text', 'arrange', 'options'];
  592. for (var i = 0; i < menus.length; i++)
  593. {
  594. menubar.addMenu(mxResources.get(menus[i]), this.get(menus[i]).funct);
  595. }
  596. return menubar;
  597. };
  598. /**
  599. * Construcs a new menubar for the given editor.
  600. */
  601. function Menubar(editorUi, container)
  602. {
  603. this.editorUi = editorUi;
  604. this.container = container;
  605. // Global handler to hide the current menu
  606. var md = (mxClient.IS_TOUCH) ? 'touchstart' : 'mousedown';
  607. mxEvent.addListener(document, md, mxUtils.bind(this, function(evt)
  608. {
  609. this.hideMenu();
  610. }));
  611. };
  612. /**
  613. * Adds the menubar elements.
  614. */
  615. Menubar.prototype.hideMenu = function()
  616. {
  617. if (this.currentMenu != null)
  618. {
  619. this.currentMenu.hideMenu();
  620. }
  621. };
  622. /**
  623. * Adds a submenu to this menubar.
  624. */
  625. Menubar.prototype.addMenu = function(label, funct)
  626. {
  627. var elt = document.createElement('a');
  628. elt.setAttribute('href', 'javascript:void(0);');
  629. elt.className = 'geItem';
  630. mxUtils.write(elt, label);
  631. this.addMenuHandler(elt, funct);
  632. this.container.appendChild(elt);
  633. return elt;
  634. };
  635. /**
  636. * Adds a handler for showing a menu in the given element.
  637. */
  638. Menubar.prototype.addMenuHandler = function(elt, funct)
  639. {
  640. if (funct != null)
  641. {
  642. var show = true;
  643. var clickHandler = mxUtils.bind(this, function(evt)
  644. {
  645. if (show && elt.enabled == null || elt.enabled)
  646. {
  647. this.editorUi.editor.graph.panningHandler.hideMenu();
  648. var menu = new mxPopupMenu(funct);
  649. menu.div.className += ' geMenubarMenu';
  650. menu.smartSeparators = true;
  651. menu.showDisabled = true;
  652. menu.autoExpand = true;
  653. // Disables autoexpand and destroys menu when hidden
  654. menu.hideMenu = mxUtils.bind(this, function()
  655. {
  656. mxPopupMenu.prototype.hideMenu.apply(menu, arguments);
  657. menu.destroy();
  658. this.currentMenu = null;
  659. this.currentElt = null;
  660. });
  661. menu.popup(elt.offsetLeft + 4, elt.offsetTop + elt.offsetHeight + 4, null, evt);
  662. this.currentMenu = menu;
  663. this.currentElt = elt;
  664. }
  665. show = true;
  666. mxEvent.consume(evt);
  667. });
  668. // Shows menu automatically while in expanded state
  669. mxEvent.addListener(elt, 'click', clickHandler);
  670. }
  671. };
  672. /**
  673. * Constructs a new action for the given parameters.
  674. */
  675. function Menu(funct, enabled)
  676. {
  677. mxEventSource.call(this);
  678. this.funct = funct;
  679. this.enabled = (enabled != null) ? enabled : true;
  680. };
  681. // Menu inherits from mxEventSource
  682. mxUtils.extend(Menu, mxEventSource);
  683. /**
  684. * Sets the enabled state of the action and fires a stateChanged event.
  685. */
  686. Menu.prototype.setEnabled = function(value)
  687. {
  688. if (this.enabled != value)
  689. {
  690. this.enabled = value;
  691. this.fireEvent(new mxEventObject('stateChanged'));
  692. }
  693. };
  694. /**
  695. * Sets the enabled state of the action and fires a stateChanged event.
  696. */
  697. Menu.prototype.execute = function(menu, parent)
  698. {
  699. this.funct(menu, parent);
  700. };