Sidebar.js 130 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451
  1. /**
  2. * Copyright (c) 2006-2012, JGraph Ltd
  3. */
  4. /**
  5. * Construcs a new sidebar for the given editor.
  6. */
  7. function Sidebar(editorUi, container)
  8. {
  9. this.editorUi = editorUi;
  10. this.container = container;
  11. this.palettes = new Object();
  12. this.taglist = new Object();
  13. this.showTooltips = true;
  14. this.graph = new Graph(document.createElement('div'), null, null, this.editorUi.editor.graph.getStylesheet());
  15. this.graph.cellRenderer.antiAlias = false;
  16. this.graph.resetViewOnRootChange = false;
  17. this.graph.foldingEnabled = false;
  18. this.graph.setConnectable(false);
  19. this.graph.gridEnabled = false;
  20. this.graph.autoScroll = false;
  21. this.graph.setTooltips(false);
  22. this.graph.setEnabled(false);
  23. // Container must be in the DOM for correct HTML rendering
  24. this.graph.container.style.visibility = 'hidden';
  25. this.graph.container.style.position = 'absolute';
  26. this.graph.container.style.overflow = 'hidden';
  27. this.graph.container.style.height = '1px';
  28. this.graph.container.style.width = '1px';
  29. // Workaround for blank output in IE11-
  30. if (!mxClient.IS_IE && !mxClient.IS_IE11)
  31. {
  32. this.graph.container.style.display = 'none';
  33. }
  34. document.body.appendChild(this.graph.container);
  35. this.pointerUpHandler = mxUtils.bind(this, function()
  36. {
  37. this.showTooltips = true;
  38. });
  39. mxEvent.addListener(document, (mxClient.IS_POINTER) ? 'pointerup' : 'mouseup', this.pointerUpHandler);
  40. this.pointerDownHandler = mxUtils.bind(this, function()
  41. {
  42. this.showTooltips = false;
  43. this.hideTooltip();
  44. });
  45. mxEvent.addListener(document, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown', this.pointerDownHandler);
  46. this.pointerMoveHandler = mxUtils.bind(this, function(evt)
  47. {
  48. var src = mxEvent.getSource(evt);
  49. while (src != null)
  50. {
  51. if (src == this.currentElt)
  52. {
  53. return;
  54. }
  55. src = src.parentNode;
  56. }
  57. this.hideTooltip();
  58. });
  59. mxEvent.addListener(document, (mxClient.IS_POINTER) ? 'pointermove' : 'mousemove', this.pointerMoveHandler);
  60. // Handles mouse leaving the window
  61. this.pointerOutHandler = mxUtils.bind(this, function(evt)
  62. {
  63. if (evt.toElement == null && evt.relatedTarget == null)
  64. {
  65. this.hideTooltip();
  66. }
  67. });
  68. mxEvent.addListener(document, (mxClient.IS_POINTER) ? 'pointerout' : 'mouseout', this.pointerOutHandler);
  69. // Enables tooltips after scroll
  70. mxEvent.addListener(container, 'scroll', mxUtils.bind(this, function()
  71. {
  72. this.showTooltips = true;
  73. }));
  74. this.init();
  75. // Pre-fetches tooltip image
  76. if (!mxClient.IS_SVG)
  77. {
  78. new Image().src = IMAGE_PATH + '/tooltip.png';
  79. }
  80. };
  81. /**
  82. * Adds all palettes to the sidebar.
  83. */
  84. Sidebar.prototype.init = function()
  85. {
  86. var dir = STENCIL_PATH;
  87. this.addSearchPalette(true);
  88. this.addGeneralPalette(true);
  89. this.addMiscPalette(false);
  90. this.addAdvancedPalette(false);
  91. this.addStencilPalette('basic', mxResources.get('basic'), dir + '/basic.xml',
  92. ';whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#000000;strokeWidth=2');
  93. this.addStencilPalette('arrows', mxResources.get('arrows'), dir + '/arrows.xml',
  94. ';whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#000000;strokeWidth=2');
  95. this.addUmlPalette(false);
  96. this.addBpmnPalette(dir, false);
  97. this.addStencilPalette('flowchart', 'Flowchart', dir + '/flowchart.xml',
  98. ';whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#000000;strokeWidth=2');
  99. this.addImagePalette('clipart', mxResources.get('clipart'), dir + '/clipart/', '_128x128.png',
  100. ['Earth_globe', 'Empty_Folder', 'Full_Folder', 'Gear', 'Lock', 'Software', 'Virus', 'Email',
  101. 'Database', 'Router_Icon', 'iPad', 'iMac', 'Laptop', 'MacBook', 'Monitor_Tower', 'Printer',
  102. 'Server_Tower', 'Workstation', 'Firewall_02', 'Wireless_Router_N', 'Credit_Card',
  103. 'Piggy_Bank', 'Graph', 'Safe', 'Shopping_Cart', 'Suit1', 'Suit2', 'Suit3', 'Pilot1',
  104. 'Worker1', 'Soldier1', 'Doctor1', 'Tech1', 'Security1', 'Telesales1'], null,
  105. {'Wireless_Router_N': 'wireless router switch wap wifi access point wlan',
  106. 'Router_Icon': 'router switch'});
  107. };
  108. /**
  109. * Sets the default font size.
  110. */
  111. Sidebar.prototype.collapsedImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/collapsed.gif' : 'data:image/gif;base64,R0lGODlhDQANAIABAJmZmf///yH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS4wLWMwNjAgNjEuMTM0Nzc3LCAyMDEwLzAyLzEyLTE3OjMyOjAwICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozNUQyRTJFNjZGNUYxMUU1QjZEOThCNDYxMDQ2MzNCQiIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozNUQyRTJFNzZGNUYxMUU1QjZEOThCNDYxMDQ2MzNCQiI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjFERjc3MEUxNkY1RjExRTVCNkQ5OEI0NjEwNDYzM0JCIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjFERjc3MEUyNkY1RjExRTVCNkQ5OEI0NjEwNDYzM0JCIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+Af/+/fz7+vn49/b19PPy8fDv7u3s6+rp6Ofm5eTj4uHg397d3Nva2djX1tXU09LR0M/OzczLysnIx8bFxMPCwcC/vr28u7q5uLe2tbSzsrGwr66trKuqqainpqWko6KhoJ+enZybmpmYl5aVlJOSkZCPjo2Mi4qJiIeGhYSDgoGAf359fHt6eXh3dnV0c3JxcG9ubWxramloZ2ZlZGNiYWBfXl1cW1pZWFdWVVRTUlFQT05NTEtKSUhHRkVEQ0JBQD8+PTw7Ojk4NzY1NDMyMTAvLi0sKyopKCcmJSQjIiEgHx4dHBsaGRgXFhUUExIREA8ODQwLCgkIBwYFBAMCAQAAIfkEAQAAAQAsAAAAAA0ADQAAAhSMj6lrwAjcC1GyahV+dcZJgeIIFgA7';
  112. /**
  113. * Sets the default font size.
  114. */
  115. Sidebar.prototype.expandedImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/expanded.gif' : 'data:image/gif;base64,R0lGODlhDQANAIABAJmZmf///yH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS4wLWMwNjAgNjEuMTM0Nzc3LCAyMDEwLzAyLzEyLTE3OjMyOjAwICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDoxREY3NzBERjZGNUYxMUU1QjZEOThCNDYxMDQ2MzNCQiIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDoxREY3NzBFMDZGNUYxMUU1QjZEOThCNDYxMDQ2MzNCQiI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjFERjc3MERENkY1RjExRTVCNkQ5OEI0NjEwNDYzM0JCIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjFERjc3MERFNkY1RjExRTVCNkQ5OEI0NjEwNDYzM0JCIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+Af/+/fz7+vn49/b19PPy8fDv7u3s6+rp6Ofm5eTj4uHg397d3Nva2djX1tXU09LR0M/OzczLysnIx8bFxMPCwcC/vr28u7q5uLe2tbSzsrGwr66trKuqqainpqWko6KhoJ+enZybmpmYl5aVlJOSkZCPjo2Mi4qJiIeGhYSDgoGAf359fHt6eXh3dnV0c3JxcG9ubWxramloZ2ZlZGNiYWBfXl1cW1pZWFdWVVRTUlFQT05NTEtKSUhHRkVEQ0JBQD8+PTw7Ojk4NzY1NDMyMTAvLi0sKyopKCcmJSQjIiEgHx4dHBsaGRgXFhUUExIREA8ODQwLCgkIBwYFBAMCAQAAIfkEAQAAAQAsAAAAAA0ADQAAAhGMj6nL3QAjVHIu6azbvPtWAAA7';
  116. /**
  117. * Sets the default font size.
  118. */
  119. Sidebar.prototype.tooltipImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/tooltip.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAbCAMAAAB7jU7LAAAACVBMVEX///+ZmZn///9Y2COLAAAAA3RSTlP//wDXyg1BAAAAOElEQVR42mXQMQ4AMAgDsWv//+iutcJmIQSk+9dJpVKpVCqVSqVSqZTdncWzF8/NeP7FkxWenPEDOnUBiL3jWx0AAAAASUVORK5CYII=';
  120. /**
  121. *
  122. */
  123. Sidebar.prototype.searchImage = (!mxClient.IS_SVG) ? IMAGE_PATH + '/search.png' : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAAEaSURBVHjabNGxS5VxFIfxz71XaWuQUJCG/gCHhgTD9VpEETg4aMOlQRp0EoezObgcd220KQiXmpretTAHQRBdojlQEJyukPdt+b1ywfvAGc7wnHP4nlZd1yKijQW8xzNc4Su+ZOYfQ3T6/f4YNvEJYzjELXp4VVXVz263+7cR2niBxAFeZ2YPi3iHR/gYERPDwhpOsd6sz8x/mfkNG3iOlWFhFj8y89J9KvzGXER0GuEaD42mgwHqUtoljbcRsTBCeINpfM/MgZLKPpaxFxGbOCqDXmILN7hoJrTKH+axhxmcYRxP0MIDnOBDZv5q1XUNIuJxifJp+UNV7t7BFM6xeic0RMQ4Bpl5W/ol7GISx/eEUUTECrbx+f8A8xhiZht9zsgAAAAASUVORK5CYII=';
  124. /**
  125. * Specifies if tooltips should be visible. Default is true.
  126. */
  127. Sidebar.prototype.enableTooltips = true;
  128. /**
  129. * Specifies the delay for the tooltip. Default is 16 px.
  130. */
  131. Sidebar.prototype.tooltipBorder = 16;
  132. /**
  133. * Specifies the delay for the tooltip. Default is 300 ms.
  134. */
  135. Sidebar.prototype.tooltipDelay = 300;
  136. /**
  137. * Specifies the delay for the drop target icons. Default is 200 ms.
  138. */
  139. Sidebar.prototype.dropTargetDelay = 200;
  140. /**
  141. * Specifies the URL of the gear image.
  142. */
  143. Sidebar.prototype.gearImage = STENCIL_PATH + '/clipart/Gear_128x128.png';
  144. /**
  145. * Specifies the width of the thumbnails.
  146. */
  147. Sidebar.prototype.thumbWidth = 36;
  148. /**
  149. * Specifies the height of the thumbnails.
  150. */
  151. Sidebar.prototype.thumbHeight = 36;
  152. /**
  153. * Specifies the padding for the thumbnails. Default is 3.
  154. */
  155. Sidebar.prototype.thumbPadding = (document.documentMode >= 5) ? 0 : 1;
  156. /**
  157. * Specifies the delay for the tooltip. Default is 2 px.
  158. */
  159. Sidebar.prototype.thumbBorder = 2;
  160. /**
  161. * Specifies the size of the sidebar titles.
  162. */
  163. Sidebar.prototype.sidebarTitleSize = 9;
  164. /**
  165. * Specifies if titles in the sidebar should be enabled.
  166. */
  167. Sidebar.prototype.sidebarTitles = false;
  168. /**
  169. * Specifies if titles in the tooltips should be enabled.
  170. */
  171. Sidebar.prototype.tooltipTitles = true;
  172. /**
  173. * Specifies if titles in the tooltips should be enabled.
  174. */
  175. Sidebar.prototype.maxTooltipWidth = 400;
  176. /**
  177. * Specifies if titles in the tooltips should be enabled.
  178. */
  179. Sidebar.prototype.maxTooltipHeight = 400;
  180. /**
  181. * Specifies if stencil files should be loaded and added to the search index
  182. * when stencil palettes are added. If this is false then the stencil files
  183. * are lazy-loaded when the palette is shown.
  184. */
  185. Sidebar.prototype.addStencilsToIndex = true;
  186. /**
  187. * Specifies the width for clipart images. Default is 80.
  188. */
  189. Sidebar.prototype.defaultImageWidth = 80;
  190. /**
  191. * Specifies the height for clipart images. Default is 80.
  192. */
  193. Sidebar.prototype.defaultImageHeight = 80;
  194. /**
  195. * Adds all palettes to the sidebar.
  196. */
  197. Sidebar.prototype.showTooltip = function(elt, cells, w, h, title, showLabel)
  198. {
  199. if (this.enableTooltips && this.showTooltips)
  200. {
  201. if (this.currentElt != elt)
  202. {
  203. if (this.thread != null)
  204. {
  205. window.clearTimeout(this.thread);
  206. this.thread = null;
  207. }
  208. var show = mxUtils.bind(this, function()
  209. {
  210. // Lazy creation of the DOM nodes and graph instance
  211. if (this.tooltip == null)
  212. {
  213. this.tooltip = document.createElement('div');
  214. this.tooltip.className = 'geSidebarTooltip';
  215. this.tooltip.style.zIndex = mxPopupMenu.prototype.zIndex - 1;
  216. document.body.appendChild(this.tooltip);
  217. this.graph2 = new Graph(this.tooltip, null, null, this.editorUi.editor.graph.getStylesheet());
  218. this.graph2.resetViewOnRootChange = false;
  219. this.graph2.foldingEnabled = false;
  220. this.graph2.gridEnabled = false;
  221. this.graph2.autoScroll = false;
  222. this.graph2.setTooltips(false);
  223. this.graph2.setConnectable(false);
  224. this.graph2.setEnabled(false);
  225. if (!mxClient.IS_SVG)
  226. {
  227. this.graph2.view.canvas.style.position = 'relative';
  228. }
  229. this.tooltipImage = mxUtils.createImage(this.tooltipImage);
  230. this.tooltipImage.className = 'geSidebarTooltipImage';
  231. this.tooltipImage.style.zIndex = mxPopupMenu.prototype.zIndex - 1;
  232. this.tooltipImage.style.position = 'absolute';
  233. this.tooltipImage.style.width = '14px';
  234. this.tooltipImage.style.height = '27px';
  235. document.body.appendChild(this.tooltipImage);
  236. }
  237. this.graph2.model.clear();
  238. this.graph2.view.setTranslate(this.tooltipBorder, this.tooltipBorder);
  239. if (w > this.maxTooltipWidth || h > this.maxTooltipHeight)
  240. {
  241. this.graph2.view.scale = Math.round(Math.min(this.maxTooltipWidth / w, this.maxTooltipHeight / h) * 100) / 100;
  242. }
  243. else
  244. {
  245. this.graph2.view.scale = 1;
  246. }
  247. this.tooltip.style.display = 'block';
  248. this.graph2.labelsVisible = (showLabel == null || showLabel);
  249. this.graph2.addCells(cells);
  250. var bounds = this.graph2.getGraphBounds();
  251. var width = bounds.width + 2 * this.tooltipBorder + 4;
  252. var height = bounds.height + 2 * this.tooltipBorder;
  253. if (mxClient.IS_QUIRKS)
  254. {
  255. height += 4;
  256. this.tooltip.style.overflow = 'hidden';
  257. }
  258. else
  259. {
  260. this.tooltip.style.overflow = 'visible';
  261. }
  262. this.tooltipImage.style.visibility = 'visible';
  263. this.tooltip.style.width = width + 'px';
  264. // Adds title for entry
  265. if (this.tooltipTitles && title != null && title.length > 0)
  266. {
  267. if (this.tooltipTitle == null)
  268. {
  269. this.tooltipTitle = document.createElement('div');
  270. this.tooltipTitle.style.borderTop = '1px solid gray';
  271. this.tooltipTitle.style.textAlign = 'center';
  272. this.tooltipTitle.style.width = '100%';
  273. // Oversize titles are cut-off currently. Should make tooltip wider later.
  274. this.tooltipTitle.style.overflow = 'hidden';
  275. if (mxClient.IS_SVG)
  276. {
  277. this.tooltipTitle.style.paddingTop = '6px';
  278. }
  279. else
  280. {
  281. this.tooltipTitle.style.position = 'absolute';
  282. this.tooltipTitle.style.paddingTop = '6px';
  283. }
  284. this.tooltip.appendChild(this.tooltipTitle);
  285. }
  286. else
  287. {
  288. this.tooltipTitle.innerHTML = '';
  289. }
  290. this.tooltipTitle.style.display = '';
  291. mxUtils.write(this.tooltipTitle, title);
  292. var ddy = this.tooltipTitle.offsetHeight + 10;
  293. height += ddy;
  294. if (mxClient.IS_SVG)
  295. {
  296. this.tooltipTitle.style.marginTop = (2 - ddy) + 'px';
  297. }
  298. else
  299. {
  300. height -= 6;
  301. this.tooltipTitle.style.top = (height - ddy) + 'px';
  302. }
  303. }
  304. else if (this.tooltipTitle != null && this.tooltipTitle.parentNode != null)
  305. {
  306. this.tooltipTitle.style.display = 'none';
  307. }
  308. this.tooltip.style.height = height + 'px';
  309. var x0 = -Math.round(bounds.x - this.tooltipBorder);
  310. var y0 = -Math.round(bounds.y - this.tooltipBorder);
  311. var b = document.body;
  312. var d = document.documentElement;
  313. var bottom = b.clientHeight || d.clientHeight;
  314. var left = this.container.clientWidth + this.editorUi.splitSize + 3 + this.editorUi.container.offsetLeft;
  315. var top = Math.min(bottom - height - 20 /*status bar*/, Math.max(0, (this.editorUi.container.offsetTop +
  316. this.container.offsetTop + elt.offsetTop - this.container.scrollTop - height / 2 + 16)));
  317. if (mxClient.IS_SVG)
  318. {
  319. if (x0 != 0 || y0 != 0)
  320. {
  321. this.graph2.view.canvas.setAttribute('transform', 'translate(' + x0 + ',' + y0 + ')');
  322. }
  323. else
  324. {
  325. this.graph2.view.canvas.removeAttribute('transform');
  326. }
  327. }
  328. else
  329. {
  330. this.graph2.view.drawPane.style.left = x0 + 'px';
  331. this.graph2.view.drawPane.style.top = y0 + 'px';
  332. }
  333. // Workaround for ignored position CSS style in IE9
  334. // (changes to relative without the following line)
  335. this.tooltip.style.position = 'absolute';
  336. this.tooltip.style.left = left + 'px';
  337. this.tooltip.style.top = top + 'px';
  338. this.tooltipImage.style.left = (left - 13) + 'px';
  339. this.tooltipImage.style.top = (top + height / 2 - 13) + 'px';
  340. });
  341. if (this.tooltip != null && this.tooltip.style.display != 'none')
  342. {
  343. show();
  344. }
  345. else
  346. {
  347. this.thread = window.setTimeout(show, this.tooltipDelay);
  348. }
  349. this.currentElt = elt;
  350. }
  351. }
  352. };
  353. /**
  354. * Hides the current tooltip.
  355. */
  356. Sidebar.prototype.hideTooltip = function()
  357. {
  358. if (this.thread != null)
  359. {
  360. window.clearTimeout(this.thread);
  361. this.thread = null;
  362. }
  363. if (this.tooltip != null)
  364. {
  365. this.tooltip.style.display = 'none';
  366. this.tooltipImage.style.visibility = 'hidden';
  367. this.currentElt = null;
  368. }
  369. };
  370. /**
  371. * Hides the current tooltip.
  372. */
  373. Sidebar.prototype.addEntry = function(tags, fn)
  374. {
  375. if (this.taglist != null && tags != null && tags.length > 0)
  376. {
  377. // Replaces special characters
  378. var tmp = tags.toLowerCase().replace(/[\/\,\(\)]/g, ' ').split(' ');
  379. for (var i = 0; i < tmp.length; i++)
  380. {
  381. // Replaces trailing numbers and special characters
  382. tmp[i] = tmp[i].replace(/\.*\d*$/, '');
  383. if (tmp[i].length > 1)
  384. {
  385. var entry = this.taglist[tmp[i]];
  386. if (entry == null)
  387. {
  388. entry = {entries: [], dict: new mxDictionary()};
  389. this.taglist[tmp[i]] = entry;
  390. }
  391. // Ignores duplicates
  392. if (entry.dict.get(fn) == null)
  393. {
  394. entry.dict.put(fn, fn);
  395. entry.entries.push(fn);
  396. }
  397. }
  398. }
  399. }
  400. return fn;
  401. };
  402. /**
  403. * Adds shape search UI.
  404. */
  405. Sidebar.prototype.searchEntries = function(searchTerms, count, page, success, error)
  406. {
  407. if (this.taglist != null && searchTerms != null)
  408. {
  409. var tmp = searchTerms.toLowerCase().split(' ');
  410. var dict = new mxDictionary();
  411. var max = (page + 1) * count;
  412. var results = [];
  413. var index = 0;
  414. for (var i = 0; i < tmp.length; i++)
  415. {
  416. if (tmp[i].length > 0)
  417. {
  418. var entry = this.taglist[tmp[i]];
  419. var tmpDict = new mxDictionary();
  420. if (entry != null)
  421. {
  422. var arr = entry.entries;
  423. results = [];
  424. for (var j = 0; j < arr.length; j++)
  425. {
  426. var entry = arr[j];
  427. // NOTE Array does not contain duplicates
  428. if ((index == 0) == (dict.get(entry) == null))
  429. {
  430. tmpDict.put(entry, entry);
  431. results.push(entry);
  432. if (i == tmp.length - 1 && results.length == max)
  433. {
  434. success(results.slice(page * count, max), max, true);
  435. return;
  436. }
  437. }
  438. }
  439. }
  440. else
  441. {
  442. results = [];
  443. }
  444. dict = tmpDict;
  445. index++;
  446. }
  447. }
  448. var len = results.length;
  449. success(results.slice(page * count, (page + 1) * count), len, false);
  450. }
  451. else
  452. {
  453. success([]);
  454. }
  455. };
  456. /**
  457. * Adds shape search UI.
  458. */
  459. Sidebar.prototype.filterTags = function(tags)
  460. {
  461. if (tags != null)
  462. {
  463. var arr = tags.split(' ');
  464. var result = [];
  465. var hash = {};
  466. // Ignores tags with leading numbers, strips trailing numbers
  467. for (var i = 0; i < arr.length; i++)
  468. {
  469. // Removes duplicates
  470. if (hash[arr[i]] == null)
  471. {
  472. hash[arr[i]] = '1';
  473. result.push(arr[i]);
  474. }
  475. }
  476. return result.join(' ');
  477. }
  478. return null;
  479. };
  480. /**
  481. * Adds the general palette to the sidebar.
  482. */
  483. Sidebar.prototype.cloneCell = function(cell, value)
  484. {
  485. var clone = cell.clone();
  486. if (value != null)
  487. {
  488. clone.value = value;
  489. }
  490. return clone;
  491. };
  492. /**
  493. * Adds shape search UI.
  494. */
  495. Sidebar.prototype.addSearchPalette = function(expand)
  496. {
  497. var elt = document.createElement('div');
  498. elt.style.visibility = 'hidden';
  499. this.container.appendChild(elt);
  500. var div = document.createElement('div');
  501. div.className = 'geSidebar';
  502. div.style.boxSizing = 'border-box';
  503. div.style.overflow = 'hidden';
  504. div.style.width = '100%';
  505. div.style.padding = '8px';
  506. div.style.paddingTop = '14px';
  507. div.style.paddingBottom = '0px';
  508. if (!expand)
  509. {
  510. div.style.display = 'none';
  511. }
  512. var inner = document.createElement('div');
  513. inner.style.whiteSpace = 'nowrap';
  514. inner.style.textOverflow = 'clip';
  515. inner.style.paddingBottom = '8px';
  516. inner.style.cursor = 'default';
  517. var input = document.createElement('input');
  518. input.setAttribute('placeholder', mxResources.get('searchShapes'));
  519. input.setAttribute('type', 'text');
  520. input.style.fontSize = '12px';
  521. input.style.overflow = 'hidden';
  522. input.style.boxSizing = 'border-box';
  523. input.style.border = 'solid 1px #d5d5d5';
  524. input.style.borderRadius = '4px';
  525. input.style.width = '100%';
  526. input.style.outline = 'none';
  527. input.style.padding = '6px';
  528. inner.appendChild(input);
  529. var cross = document.createElement('img');
  530. cross.setAttribute('src', Sidebar.prototype.searchImage);
  531. cross.setAttribute('title', mxResources.get('search'));
  532. cross.style.position = 'relative';
  533. cross.style.left = '-18px';
  534. if (mxClient.IS_QUIRKS)
  535. {
  536. input.style.height = '28px';
  537. cross.style.top = '-4px';
  538. }
  539. else
  540. {
  541. cross.style.top = '2px';
  542. }
  543. // Needed to block event transparency in IE
  544. cross.style.background = 'url(\'' + this.editorUi.editor.transparentImage + '\')';
  545. var find;
  546. inner.appendChild(cross);
  547. div.appendChild(inner);
  548. var center = document.createElement('center');
  549. var button = mxUtils.button(mxResources.get('moreResults'), function()
  550. {
  551. find();
  552. });
  553. button.style.display = 'none';
  554. // Workaround for inherited line-height in quirks mode
  555. button.style.lineHeight = 'normal';
  556. button.style.marginTop = '4px';
  557. button.style.marginBottom = '8px';
  558. center.style.paddingTop = '4px';
  559. center.style.paddingBottom = '8px';
  560. center.appendChild(button);
  561. div.appendChild(center);
  562. var searchTerm = '';
  563. var active = false;
  564. var complete = false;
  565. var page = 0;
  566. var hash = new Object();
  567. // Count is dynamically updated below
  568. var count = 12;
  569. var clearDiv = mxUtils.bind(this, function()
  570. {
  571. active = false;
  572. this.currentSearch = null;
  573. var child = div.firstChild;
  574. while (child != null)
  575. {
  576. var next = child.nextSibling;
  577. if (child != inner && child != center)
  578. {
  579. child.parentNode.removeChild(child);
  580. }
  581. child = next;
  582. }
  583. });
  584. find = mxUtils.bind(this, function()
  585. {
  586. // Shows 4 rows (minimum 4 results)
  587. count = 4 * Math.max(1, Math.floor(this.container.clientWidth / (this.thumbWidth + 10)));
  588. this.hideTooltip();
  589. if (input.value != '')
  590. {
  591. if (center.parentNode != null)
  592. {
  593. if (searchTerm != input.value)
  594. {
  595. clearDiv();
  596. searchTerm = input.value;
  597. hash = new Object();
  598. complete = false;
  599. page = 0;
  600. }
  601. if (!active && !complete)
  602. {
  603. button.setAttribute('disabled', 'true');
  604. button.style.display = '';
  605. button.style.cursor = 'wait';
  606. button.innerHTML = mxResources.get('loading') + '...';
  607. active = true;
  608. // Ignores old results
  609. var current = new Object();
  610. this.currentSearch = current;
  611. this.searchEntries(searchTerm, count, page, mxUtils.bind(this, function(results, len, more)
  612. {
  613. if (this.currentSearch == current)
  614. {
  615. results = (results != null) ? results : [];
  616. active = false;
  617. page++;
  618. center.parentNode.removeChild(center);
  619. for (var i = 0; i < results.length; i++)
  620. {
  621. var elt = results[i]();
  622. // Avoids duplicates in results
  623. if (hash[elt.innerHTML] == null)
  624. {
  625. hash[elt.innerHTML] = '1';
  626. div.appendChild(results[i]());
  627. }
  628. }
  629. if (more)
  630. {
  631. button.removeAttribute('disabled');
  632. button.innerHTML = mxResources.get('moreResults');
  633. }
  634. else
  635. {
  636. button.innerHTML = mxResources.get('reset');
  637. button.style.display = 'none';
  638. complete = true;
  639. }
  640. button.style.cursor = '';
  641. if (results.length == 0 && page == 1)
  642. {
  643. var err = document.createElement('div');
  644. err.className = 'geTitle';
  645. err.style.backgroundColor = 'transparent';
  646. err.style.borderColor = 'transparent';
  647. err.style.color = 'gray';
  648. err.style.padding = '0px';
  649. err.style.margin = '0px 8px 0px 8px';
  650. err.style.paddingTop = '6px';
  651. err.style.textAlign = 'center';
  652. err.style.cursor = 'default';
  653. mxUtils.write(err, mxResources.get('noResultsFor', [searchTerm]));
  654. div.appendChild(err);
  655. }
  656. div.appendChild(center);
  657. }
  658. }), mxUtils.bind(this, function()
  659. {
  660. // TODO: Error handling
  661. button.style.cursor = '';
  662. }));
  663. }
  664. }
  665. }
  666. else
  667. {
  668. clearDiv();
  669. input.value = '';
  670. searchTerm = '';
  671. hash = new Object();
  672. button.style.display = 'none';
  673. complete = false;
  674. input.focus();
  675. }
  676. });
  677. mxEvent.addListener(input, 'keydown', mxUtils.bind(this, function(evt)
  678. {
  679. if (evt.keyCode == 13 /* Enter */)
  680. {
  681. find();
  682. }
  683. }));
  684. mxEvent.addListener(input, 'focus', function()
  685. {
  686. input.style.paddingRight = '';
  687. cross.style.display = 'none';
  688. });
  689. mxEvent.addListener(input, 'blur', function()
  690. {
  691. input.style.paddingRight = '20px';
  692. cross.style.display = '';
  693. });
  694. input.style.paddingRight = '20px';
  695. mxEvent.addListener(input, 'keyup', mxUtils.bind(this, function(evt)
  696. {
  697. if (input.value == '')
  698. {
  699. complete = true;
  700. button.style.display = 'none';
  701. }
  702. else if (input.value != searchTerm)
  703. {
  704. button.style.display = 'none';
  705. complete = false;
  706. }
  707. else if (!active)
  708. {
  709. if (complete)
  710. {
  711. button.style.display = 'none';
  712. }
  713. else
  714. {
  715. button.style.display = '';
  716. }
  717. }
  718. }));
  719. // Workaround for blocked text selection in Editor
  720. mxEvent.addListener(input, 'mousedown', function(evt)
  721. {
  722. if (evt.stopPropagation)
  723. {
  724. evt.stopPropagation();
  725. }
  726. evt.cancelBubble = true;
  727. });
  728. // Workaround for blocked text selection in Editor
  729. mxEvent.addListener(input, 'selectstart', function(evt)
  730. {
  731. if (evt.stopPropagation)
  732. {
  733. evt.stopPropagation();
  734. }
  735. evt.cancelBubble = true;
  736. });
  737. var outer = document.createElement('div');
  738. outer.appendChild(div);
  739. this.container.appendChild(outer);
  740. // Keeps references to the DOM nodes
  741. this.palettes['search'] = [elt, outer];
  742. };
  743. /**
  744. * Adds the general palette to the sidebar.
  745. */
  746. Sidebar.prototype.addGeneralPalette = function(expand)
  747. {
  748. var fns = [
  749. this.createVertexTemplateEntry('whiteSpace=wrap;html=1;', 120, 60, '', 'Rectangle', null, null, 'rect rectangle box'),
  750. this.createVertexTemplateEntry('rounded=1;whiteSpace=wrap;html=1;', 120, 60, '', 'Rounded Rectangle', null, null, 'rounded rect rectangle box'),
  751. this.createVertexTemplateEntry('ellipse;whiteSpace=wrap;html=1;', 120, 80, '', 'Ellipse', null, null, 'circle oval ellipse state'),
  752. // Explicit strokecolor/fillcolor=none is a workaround to maintain transparent background regardless of current style
  753. this.createVertexTemplateEntry('text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;',
  754. 40, 20, 'Text', 'Text', null, null, 'text textbox textarea label'),
  755. this.createVertexTemplateEntry('shape=ext;double=1;whiteSpace=wrap;html=1;', 120, 60, '', 'Double Rectangle', null, null, 'rect rectangle box double'),
  756. this.createVertexTemplateEntry('shape=ext;double=1;rounded=1;whiteSpace=wrap;html=1;', 120, 60, '', 'Double Rounded Rectangle', null, null, 'rounded rect rectangle box double'),
  757. this.createVertexTemplateEntry('ellipse;shape=doubleEllipse;whiteSpace=wrap;html=1;', 120, 80, '', 'Double Ellipse', null, null, 'circle oval ellipse start end state double'),
  758. this.createVertexTemplateEntry('rhombus;whiteSpace=wrap;html=1;', 80, 80, '', 'Diamond', null, null, 'diamond rhombus if condition decision conditional question test'),
  759. this.createVertexTemplateEntry('shape=parallelogram;whiteSpace=wrap;html=1;', 120, 60, '', 'Parallelogram'),
  760. this.createVertexTemplateEntry('triangle;whiteSpace=wrap;html=1;', 60, 80, '', 'Triangle', null, null, 'triangle logic inverter buffer'),
  761. this.createVertexTemplateEntry('shape=cylinder;whiteSpace=wrap;html=1;', 60, 80, '', 'Cylinder', null, null, 'cylinder data database'),
  762. this.createVertexTemplateEntry('shape=hexagon;perimeter=hexagonPerimeter;whiteSpace=wrap;html=1;', 120, 80, '', 'Hexagon', null, null, 'hexagon preparation'),
  763. this.createVertexTemplateEntry('shape=process;whiteSpace=wrap;html=1;', 120, 60, '', 'Process', null, null, 'process task'),
  764. this.createVertexTemplateEntry('ellipse;shape=cloud;whiteSpace=wrap;html=1;', 120, 80, '', 'Cloud', null, null, 'cloud network'),
  765. this.createVertexTemplateEntry('shape=document;whiteSpace=wrap;html=1;', 120, 80, '', 'Document'),
  766. this.createVertexTemplateEntry('shape=internalStorage;whiteSpace=wrap;html=1;', 80, 80, '', 'Internal Storage'),
  767. this.createVertexTemplateEntry('shape=cube;whiteSpace=wrap;html=1;', 120, 80, '', 'Cube'),
  768. this.createVertexTemplateEntry('shape=step;whiteSpace=wrap;html=1;', 120, 80, '', 'Step'),
  769. this.createVertexTemplateEntry('shape=trapezoid;whiteSpace=wrap;html=1;', 120, 60, '', 'Trapezoid'),
  770. this.createVertexTemplateEntry('shape=tape;whiteSpace=wrap;html=1;', 120, 100, '', 'Tape'),
  771. this.createVertexTemplateEntry('shape=note;whiteSpace=wrap;html=1;', 80, 100, '', 'Note'),
  772. this.createVertexTemplateEntry('shape=card;whiteSpace=wrap;html=1;', 80, 100, '', 'Card'),
  773. this.createEdgeTemplateEntry('endArrow=classic;html=1;', 50, 50, '', 'Connection'),
  774. this.createEdgeTemplateEntry('endArrow=classic;startArrow=classic;html=1;', 50, 50, '', 'Connection')
  775. ];
  776. this.addPaletteFunctions('general', mxResources.get('general'), (expand != null) ? expand : true, fns);
  777. };
  778. /**
  779. * Adds the general palette to the sidebar.
  780. */
  781. Sidebar.prototype.addMiscPalette = function(expand)
  782. {
  783. var fns = [
  784. this.createVertexTemplateEntry('text;html=1;fontSize=24;fontStyle=1;verticalAlign=middle;align=center;', 100, 40, 'Title', 'Title', null, null, 'text heading title'),
  785. this.createVertexTemplateEntry('text;html=1;spacing=5;spacingTop=-20;whiteSpace=wrap;overflow=hidden;', 190, 120,
  786. '<h1>Heading</h1><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>',
  787. 'Textbox', null, null, 'text textbox textarea'),
  788. this.createVertexTemplateEntry('text;html=1;whiteSpace=wrap;verticalAlign=middle;overflow=hidden;', 100, 80,
  789. '<ul><li>Value 1</li><li>Value 2</li><li>Value 3</li></ul>', 'Unordered List'),
  790. this.createVertexTemplateEntry('text;html=1;whiteSpace=wrap;verticalAlign=middle;overflow=hidden;', 100, 80,
  791. '<ol><li>Value 1</li><li>Value 2</li><li>Value 3</li></ol>', 'Ordered List'),
  792. this.createVertexTemplateEntry('text;html=1;fillColor=#ffffff;overflow=fill;rounded=0;', 280, 160,
  793. '<table border="1" width="100%" height="100%" cellpadding="4" style="width:100%;height:100%;border-collapse:collapse;">' +
  794. '<tr style="background-color:#A7C942;color:#ffffff;border:1px solid #98bf21;"><th align="left">Title 1</th><th align="left">Title 2</th><th align="left">Title 3</th></tr>' +
  795. '<tr style="border:1px solid #98bf21;"><td>Value 1</td><td>Value 2</td><td>Value 3</td></tr>' +
  796. '<tr style="background-color:#EAF2D3;border:1px solid #98bf21;"><td>Value 4</td><td>Value 5</td><td>Value 6</td></tr>' +
  797. '<tr style="border:1px solid #98bf21;"><td>Value 7</td><td>Value 8</td><td>Value 9</td></tr>' +
  798. '<tr style="background-color:#EAF2D3;border:1px solid #98bf21;"><td>Value 10</td><td>Value 11</td><td>Value 12</td></tr></table>', 'Table 1'),
  799. this.createVertexTemplateEntry('text;html=1;strokeColor=#c0c0c0;overflow=fill;', 180, 140,
  800. '<table border="0" width="100%" height="100%" style="width:100%;height:100%;border-collapse:collapse;">' +
  801. '<tr><td align="center">Value 1</td><td align="center">Value 2</td><td align="center">Value 3</td></tr>' +
  802. '<tr><td align="center">Value 4</td><td align="center">Value 5</td><td align="center">Value 6</td></tr>' +
  803. '<tr><td align="center">Value 7</td><td align="center">Value 8</td><td align="center">Value 9</td></tr></table>', 'Table 2'),
  804. this.createVertexTemplateEntry('text;html=1;overflow=fill;', 180, 140,
  805. '<table border="1" width="100%" height="100%" style="width:100%;height:100%;border-collapse:collapse;">' +
  806. '<tr><td align="center">Value 1</td><td align="center">Value 2</td><td align="center">Value 3</td></tr>' +
  807. '<tr><td align="center">Value 4</td><td align="center">Value 5</td><td align="center">Value 6</td></tr>' +
  808. '<tr><td align="center">Value 7</td><td align="center">Value 8</td><td align="center">Value 9</td></tr></table>', 'Table 3'),
  809. this.createVertexTemplateEntry('text;html=1;overflow=fill;', 160, 140,
  810. '<table border="1" width="100%" height="100%" cellpadding="4" style="width:100%;height:100%;border-collapse:collapse;">' +
  811. '<tr><th align="center"><b>Title</b></th></tr>' +
  812. '<tr><td align="center">Section 1.1\nSection 1.2\nSection 1.3</td></tr>' +
  813. '<tr><td align="center">Section 2.1\nSection 2.2\nSection 2.3</td></tr></table>', 'Table 4'),
  814. this.addEntry('link hyperlink', mxUtils.bind(this, function()
  815. {
  816. var cell = new mxCell('Link', new mxGeometry(0, 0, 60, 40), 'text;html=1;whiteSpace=wrap;align=center;verticalAlign=middle;fontColor=#0000EE;fontStyle=4;');
  817. cell.vertex = true;
  818. this.graph.setLinkForCell(cell, 'https://www.draw.io');
  819. return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Link');
  820. })),
  821. this.addEntry('timestamp date time text label', mxUtils.bind(this, function()
  822. {
  823. var cell = new mxCell('%date{ddd mmm dd yyyy HH:MM:ss}%', new mxGeometry(0, 0, 160, 20), 'text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;overflow=hidden;');
  824. cell.vertex = true;
  825. this.graph.setAttributeForCell(cell, 'placeholders', '1');
  826. return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Timestamp');
  827. })),
  828. this.addEntry('variable placeholder metadata hello world text label', mxUtils.bind(this, function()
  829. {
  830. var cell = new mxCell('%name% Text', new mxGeometry(0, 0, 80, 20), 'text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;overflow=hidden;');
  831. cell.vertex = true;
  832. this.graph.setAttributeForCell(cell, 'placeholders', '1');
  833. this.graph.setAttributeForCell(cell, 'name', 'Variable');
  834. return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Variable');
  835. })),
  836. this.createVertexTemplateEntry('shape=umlActor;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;verticalAlign=top;html=1;', 30, 60, 'Actor', 'Actor', false, null, 'user person human stickman'),
  837. this.createVertexTemplateEntry('html=1;whiteSpace=wrap;comic=1;strokeWidth=2;fontFamily=Comic Sans MS;fontStyle=1;', 120, 60, 'RECTANGLE', 'Comic Rectangle', true, null, 'comic rectangle rect box text retro'),
  838. this.createVertexTemplateEntry('rhombus;html=1;align=center;whiteSpace=wrap;comic=1;strokeWidth=2;fontFamily=Comic Sans MS;fontStyle=1;', 100, 100, 'DIAMOND', 'Comic Diamond', true, null, 'comic diamond rhombus if condition decision conditional question test retro'),
  839. this.createEdgeTemplateEntry('edgeStyle=segmentEdgeStyle;rounded=0;comic=1;strokeWidth=2;endArrow=blockThin;html=1;fontFamily=Comic Sans MS;fontStyle=1;', 50, 50, '', 'Comic Arrow 1'),
  840. this.createEdgeTemplateEntry('rounded=0;comic=1;strokeWidth=2;endArrow=blockThin;html=1;fontFamily=Comic Sans MS;fontStyle=1;', 50, 50, '', 'Comic Arrow 2'),
  841. this.createVertexTemplateEntry('html=1;whiteSpace=wrap;aspect=fixed;shape=isoRectangle;', 150, 90, '', 'Isometric Square', true, null, 'rectangle rect box iso isometric'),
  842. this.createVertexTemplateEntry('html=1;whiteSpace=wrap;aspect=fixed;shape=isoCube;', 90, 100, '', 'Isometric Cube', true, null, 'cube box iso isometric'),
  843. this.createEdgeTemplateEntry('edgeStyle=isometricEdgeStyle;endArrow=none;html=1;', 50, 100, '', 'Isometric Edge 1'),
  844. this.createEdgeTemplateEntry('edgeStyle=isometricEdgeStyle;endArrow=none;html=1;elbow=vertical;', 50, 100, '', 'Isometric Edge 2'),
  845. this.createVertexTemplateEntry('line;html=1;', 160, 10, '', 'Horizontal Line'),
  846. this.createVertexTemplateEntry('line;direction=south;html=1;', 10, 160, '', 'Vertical Line'),
  847. this.createVertexTemplateEntry('line;html=1;perimeter=backbonePerimeter;points=[];outlineConnect=0;', 160, 10, '', 'Horizontal Backbone', false, null, 'network'),
  848. this.createVertexTemplateEntry('line;direction=south;html=1;perimeter=backbonePerimeter;points=[];outlineConnect=0;', 10, 160, '', 'Vertical Backbone', false, null, 'network'),
  849. this.createVertexTemplateEntry('shape=curlyBracket;whiteSpace=wrap;html=1;rounded=1;', 20, 120, '', 'Curly Bracket'),
  850. this.createVertexTemplateEntry('shape=image;html=1;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;verticalAlign=top;imageAspect=1;aspect=fixed;image=' + this.gearImage, 52, 61, '', 'Image (Fixed Aspect)', false, null, 'fixed image icon symbol'),
  851. this.createVertexTemplateEntry('shape=image;html=1;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;verticalAlign=top;imageAspect=0;image=' + this.gearImage, 50, 60, '', 'Image (Variable Aspect)', false, null, 'strechted image icon symbol'),
  852. this.createVertexTemplateEntry('icon;html=1;image=' + this.gearImage, 60, 60, 'Icon', 'Icon', false, null, 'icon image symbol'),
  853. this.createVertexTemplateEntry('label;whiteSpace=wrap;html=1;image=' + this.gearImage, 140, 60, 'Label', 'Label 1', null, null, 'label image icon symbol'),
  854. this.createVertexTemplateEntry('label;whiteSpace=wrap;html=1;align=center;verticalAlign=bottom;spacingLeft=0;spacingBottom=4;imageAlign=center;imageVerticalAlign=top;image=' + this.gearImage, 120, 80, 'Label', 'Label 2', null, null, 'label image icon symbol'),
  855. this.createEdgeTemplateEntry('shape=flexArrow;endArrow=classic;html=1;fillColor=#ffffff;', 50, 50, '', 'Arrow'),
  856. this.createEdgeTemplateEntry('shape=flexArrow;endArrow=classic;startArrow=classic;html=1;fillColor=#ffffff;', 50, 50, '', 'Arrow'),
  857. this.createEdgeTemplateEntry('endArrow=none;html=1;dashed=1;dashPattern=1 4;', 50, 50, '', 'Dotted Line'),
  858. this.createEdgeTemplateEntry('endArrow=none;dashed=1;html=1;', 50, 50, '', 'Dashed Line'),
  859. this.createEdgeTemplateEntry('endArrow=none;html=1;', 50, 50, '', 'Line'),
  860. this.createEdgeTemplateEntry('edgeStyle=segmentEdgeStyle;endArrow=classic;html=1;', 50, 50, '', 'Manual Line'),
  861. this.createEdgeTemplateEntry('edgeStyle=elbowEdgeStyle;elbow=horizontal;endArrow=classic;html=1;', 50, 50, '', 'Horizontal Elbow'),
  862. this.createEdgeTemplateEntry('edgeStyle=elbowEdgeStyle;elbow=vertical;endArrow=classic;html=1;', 50, 50, '', 'Vertical Elbow'),
  863. this.addEntry('curve', mxUtils.bind(this, function()
  864. {
  865. var cell = new mxCell('', new mxGeometry(0, 0, 50, 50), 'curved=1;endArrow=classic;html=1;');
  866. cell.geometry.setTerminalPoint(new mxPoint(0, 50), true);
  867. cell.geometry.setTerminalPoint(new mxPoint(50, 0), false);
  868. cell.geometry.points = [new mxPoint(50, 50), new mxPoint(0, 0)];
  869. cell.geometry.relative = true;
  870. cell.edge = true;
  871. return this.createEdgeTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Curve');
  872. })),
  873. this.createEdgeTemplateEntry('shape=link;html=1;', 50, 50, '', 'Link')
  874. ];
  875. this.addPaletteFunctions('misc', mxResources.get('misc'), (expand != null) ? expand : true, fns);
  876. };
  877. /**
  878. * Adds the container palette to the sidebar.
  879. */
  880. Sidebar.prototype.addAdvancedPalette = function(expand)
  881. {
  882. this.addPaletteFunctions('advanced', mxResources.get('advanced'), (expand != null) ? expand : false, this.createAdvancedShapes());
  883. };
  884. /**
  885. * Adds the container palette to the sidebar.
  886. */
  887. Sidebar.prototype.createAdvancedShapes = function()
  888. {
  889. // Avoids having to bind all functions to "this"
  890. var sb = this;
  891. // Reusable cells
  892. var field = new mxCell('List Item', new mxGeometry(0, 0, 60, 26), 'text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;whiteSpace=wrap;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;');
  893. field.vertex = true;
  894. return [
  895. this.createVertexTemplateEntry('shape=image;html=1;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;verticalAlign=top;imageAspect=0;image=' + this.gearImage, 50, 60, '', 'Stretched Image', false, null, 'strechted image icon symbol'),
  896. this.createVertexTemplateEntry('icon;html=1;image=' + this.gearImage, 60, 60, 'Icon', 'Icon', false, null, 'icon image symbol'),
  897. this.createVertexTemplateEntry('label;whiteSpace=wrap;html=1;image=' + this.gearImage, 140, 60, 'Label', 'Label 1', null, null, 'label image icon symbol'),
  898. this.createVertexTemplateEntry('label;whiteSpace=wrap;html=1;align=center;verticalAlign=bottom;spacingLeft=0;spacingBottom=4;imageAlign=center;imageVerticalAlign=top;image=' + this.gearImage, 120, 80, 'Label', 'Label 2', null, null, 'label image icon symbol'),
  899. this.createVertexTemplateEntry('shape=xor;whiteSpace=wrap;html=1;', 60, 80, '', 'Or', null, null, 'logic or'),
  900. this.createVertexTemplateEntry('shape=or;whiteSpace=wrap;html=1;', 60, 80, '', 'And', null, null, 'logic and'),
  901. this.createVertexTemplateEntry('shape=dataStorage;whiteSpace=wrap;html=1;', 100, 80, '', 'Data Storage'),
  902. this.createVertexTemplateEntry('shape=tapeData;whiteSpace=wrap;html=1;perimeter=ellipsePerimeter;', 80, 80, '', 'Tape Data'),
  903. this.createVertexTemplateEntry('shape=manualInput;whiteSpace=wrap;html=1;', 80, 80, '', 'Manual Input'),
  904. this.createVertexTemplateEntry('shape=loopLimit;whiteSpace=wrap;html=1;', 100, 80, '', 'Loop Limit'),
  905. this.createVertexTemplateEntry('shape=offPageConnector;whiteSpace=wrap;html=1;', 80, 80, '', 'Off Page Connector'),
  906. this.createVertexTemplateEntry('shape=delay;whiteSpace=wrap;html=1;', 80, 40, '', 'Delay'),
  907. this.createVertexTemplateEntry('shape=display;whiteSpace=wrap;html=1;', 80, 40, '', 'Display'),
  908. this.createVertexTemplateEntry('shape=singleArrow;direction=west;whiteSpace=wrap;html=1;', 100, 60, '', 'Arrow Left'),
  909. this.createVertexTemplateEntry('shape=singleArrow;whiteSpace=wrap;html=1;', 100, 60, '', 'Arrow Right'),
  910. this.createVertexTemplateEntry('shape=singleArrow;direction=north;whiteSpace=wrap;html=1;', 60, 100, '', 'Arrow Up'),
  911. this.createVertexTemplateEntry('shape=singleArrow;direction=south;whiteSpace=wrap;html=1;', 60, 100, '', 'Arrow Down'),
  912. this.createVertexTemplateEntry('shape=doubleArrow;whiteSpace=wrap;html=1;', 100, 60, '', 'Double Arrow'),
  913. this.createVertexTemplateEntry('shape=doubleArrow;direction=south;whiteSpace=wrap;html=1;', 60, 100, '', 'Double Arrow Vertical', null, null, 'double arrow'),
  914. this.createVertexTemplateEntry('shape=actor;whiteSpace=wrap;html=1;', 40, 60, '', 'User', null, null, 'user person human'),
  915. this.createVertexTemplateEntry('shape=cross;whiteSpace=wrap;html=1;', 80, 80, '', 'Cross'),
  916. this.createVertexTemplateEntry('shape=corner;whiteSpace=wrap;html=1;', 80, 80, '', 'Corner'),
  917. this.createVertexTemplateEntry('shape=tee;whiteSpace=wrap;html=1;', 80, 80, '', 'Tee'),
  918. this.createVertexTemplateEntry('shape=datastore;whiteSpace=wrap;html=1;', 60, 60, '', 'Data Store', null, null, 'data store cylinder database'),
  919. this.createVertexTemplateEntry('shape=orEllipse;perimeter=ellipsePerimeter;whiteSpace=wrap;html=1;', 80, 80, '', 'Or', null, null, 'or circle oval ellipse'),
  920. this.createVertexTemplateEntry('shape=sumEllipse;perimeter=ellipsePerimeter;whiteSpace=wrap;html=1;', 80, 80, '', 'Sum', null, null, 'sum circle oval ellipse'),
  921. this.createVertexTemplateEntry('shape=lineEllipse;perimeter=ellipsePerimeter;whiteSpace=wrap;html=1;', 80, 80, '', 'Ellipse with horizontal divider', null, null, 'circle oval ellipse'),
  922. this.createVertexTemplateEntry('shape=lineEllipse;line=vertical;perimeter=ellipsePerimeter;whiteSpace=wrap;html=1;', 80, 80, '', 'Ellipse with vertical divider', null, null, 'circle oval ellipse'),
  923. this.createVertexTemplateEntry('shape=sortShape;perimeter=rhombusPerimeter;whiteSpace=wrap;html=1;', 80, 80, '', 'Sort', null, null, 'sort'),
  924. this.createVertexTemplateEntry('shape=collate;whiteSpace=wrap;html=1;', 80, 80, '', 'Collate', null, null, 'collate'),
  925. this.createVertexTemplateEntry('shape=switch;whiteSpace=wrap;html=1;', 60, 60, '', 'Switch', null, null, 'switch router'),
  926. this.createVertexTemplateEntry('shape=dimension;whiteSpace=wrap;html=1;align=center;points=[];verticalAlign=bottom;spacingBottom=-5;labelBackgroundColor=#ffffff', 100, 40, 'Label', 'Horizontal Dimension', null, null, 'horizontal dimension measure'),
  927. this.createVertexTemplateEntry('shape=dimension;direction=north;whiteSpace=wrap;html=1;align=right;points=[];verticalAlign=middle;labelBackgroundColor=#ffffff', 40, 100, 'Label', 'Vertical Dimension', null, null, 'vertical dimension measure'),
  928. this.createVertexTemplateEntry('swimlane;whiteSpace=wrap;html=1;', 200, 200, 'Container', 'Container', null, null, 'container swimlane lane pool'),
  929. this.addEntry('list', function()
  930. {
  931. var cell = new mxCell('List', new mxGeometry(0, 0, 140, 110),
  932. 'swimlane;html=1;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=26;fillColor=none;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;swimlaneFillColor=#ffffff;');
  933. cell.vertex = true;
  934. cell.insert(sb.cloneCell(field, 'Item 1'));
  935. cell.insert(sb.cloneCell(field, 'Item 2'));
  936. cell.insert(sb.cloneCell(field, 'Item 3'));
  937. return sb.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'List');
  938. }),
  939. this.addEntry('list item entry value', function()
  940. {
  941. return sb.createVertexTemplateFromCells([sb.cloneCell(field, 'List Item')], field.geometry.width, field.geometry.height, 'List Item');
  942. })
  943. ];
  944. };
  945. /**
  946. * Adds the general palette to the sidebar.
  947. */
  948. Sidebar.prototype.addUmlPalette = function(expand)
  949. {
  950. // Avoids having to bind all functions to "this"
  951. var sb = this;
  952. // Reusable cells
  953. var field = new mxCell('+ field: type', new mxGeometry(0, 0, 100, 26), 'text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;whiteSpace=wrap;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;');
  954. field.vertex = true;
  955. var divider = new mxCell('', new mxGeometry(0, 0, 40, 8), 'line;html=1;strokeWidth=1;fillColor=none;align=left;verticalAlign=middle;spacingTop=-1;spacingLeft=3;spacingRight=3;rotatable=0;labelPosition=right;points=[];portConstraint=eastwest;');
  956. divider.vertex = true;
  957. // Default tags
  958. var dt = 'uml static class ';
  959. var fns = [
  960. this.createVertexTemplateEntry('html=1;', 110, 50, 'Object', 'Object', null, null, dt + 'object instance'),
  961. this.createVertexTemplateEntry('html=1;', 110, 50, '&laquo;interface&raquo;<br><b>Name</b>', 'Interface', null, null, dt + 'interface object instance annotated annotation'),
  962. this.addEntry(dt + 'object instance', function()
  963. {
  964. var cell = new mxCell('Classname', new mxGeometry(0, 0, 160, 90),
  965. 'swimlane;html=1;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;swimlaneFillColor=#ffffff;');
  966. cell.vertex = true;
  967. cell.insert(field.clone());
  968. cell.insert(divider.clone());
  969. cell.insert(sb.cloneCell(field, '+ method(type): type'));
  970. return sb.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Class');
  971. }),
  972. this.addEntry(dt + 'section subsection', function()
  973. {
  974. var cell = new mxCell('Classname', new mxGeometry(0, 0, 140, 110),
  975. 'swimlane;html=1;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=26;fillColor=none;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;swimlaneFillColor=#ffffff;');
  976. cell.vertex = true;
  977. cell.insert(field.clone());
  978. cell.insert(field.clone());
  979. cell.insert(field.clone());
  980. return sb.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Class 2');
  981. }),
  982. this.addEntry(dt + 'item member method function variable field attribute label', function()
  983. {
  984. return sb.createVertexTemplateFromCells([sb.cloneCell(field, '+ item: attribute')], field.geometry.width, field.geometry.height, 'Item 1');
  985. }),
  986. this.addEntry(dt + 'item member method function variable field attribute label', function()
  987. {
  988. var cell = new mxCell('item: attribute', new mxGeometry(0, 0, 120, field.geometry.height), 'label;html=1;fontStyle=0;strokeColor=none;fillColor=none;align=left;verticalAlign=top;overflow=hidden;' +
  989. 'spacingLeft=28;spacingRight=4;whiteSpace=wrap;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;imageWidth=16;imageHeight=16;image=' + sb.gearImage);
  990. cell.vertex = true;
  991. return sb.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Item 2');
  992. }),
  993. this.addEntry(dt + 'divider hline line separator', function()
  994. {
  995. return sb.createVertexTemplateFromCells([divider.clone()], divider.geometry.width, divider.geometry.height, 'Divider');
  996. }),
  997. this.addEntry(dt + 'spacer space gap separator', function()
  998. {
  999. var cell = new mxCell('', new mxGeometry(0, 0, 20, 14), 'text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;spacingTop=-1;spacingLeft=4;spacingRight=4;rotatable=0;labelPosition=right;points=[];portConstraint=eastwest;');
  1000. cell.vertex = true;
  1001. return sb.createVertexTemplateFromCells([cell.clone()], cell.geometry.width, cell.geometry.height, 'Spacer');
  1002. }),
  1003. this.createVertexTemplateEntry('text;html=1;align=center;fontStyle=1;verticalAlign=middle;spacingLeft=3;spacingRight=3;strokeColor=none;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;',
  1004. 80, 26, 'Title', 'Title', null, null, dt + 'title label'),
  1005. this.addEntry(dt + 'component', function()
  1006. {
  1007. var cell = new mxCell('&laquo;Annotation&raquo;<br/><b>Component</b>', new mxGeometry(0, 0, 180, 90), 'html=1;');
  1008. cell.vertex = true;
  1009. var symbol = new mxCell('', new mxGeometry(1, 0, 20, 20), 'shape=component;jettyWidth=8;jettyHeight=4;');
  1010. symbol.vertex = true;
  1011. symbol.geometry.relative = true;
  1012. symbol.geometry.offset = new mxPoint(-27, 7);
  1013. cell.insert(symbol);
  1014. return sb.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Component');
  1015. }),
  1016. this.addEntry(dt + 'component', function()
  1017. {
  1018. var cell = new mxCell('<p style="margin:0px;margin-top:6px;text-align:center;"><b>Component</b></p>' +
  1019. '<hr/><p style="margin:0px;margin-left:8px;">+ Attribute1: Type<br/>+ Attribute2: Type</p>', new mxGeometry(0, 0, 180, 90),
  1020. 'align=left;overflow=fill;html=1;');
  1021. cell.vertex = true;
  1022. var symbol = new mxCell('', new mxGeometry(1, 0, 20, 20), 'shape=component;jettyWidth=8;jettyHeight=4;');
  1023. symbol.vertex = true;
  1024. symbol.geometry.relative = true;
  1025. symbol.geometry.offset = new mxPoint(-24, 4);
  1026. cell.insert(symbol);
  1027. return sb.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Component with Attributes');
  1028. }),
  1029. this.createVertexTemplateEntry('verticalAlign=top;align=left;spacingTop=8;spacingLeft=2;spacingRight=12;shape=cube;size=10;direction=south;fontStyle=4;html=1;',
  1030. 180, 120, 'Block', 'Block', null, null, dt + 'block'),
  1031. this.createVertexTemplateEntry('shape=component;align=left;spacingLeft=36;', 120, 60, 'Module', 'Module', null, null, dt + 'module'),
  1032. this.createVertexTemplateEntry('shape=folder;fontStyle=1;spacingTop=10;tabWidth=40;tabHeight=14;tabPosition=left;html=1;', 70, 50,
  1033. 'package', 'Package', null, null, dt + 'package'),
  1034. this.createVertexTemplateEntry('verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;',
  1035. 160, 90, '<p style="margin:0px;margin-top:4px;text-align:center;text-decoration:underline;"><b>Object:Type</b></p><hr/>' +
  1036. '<p style="margin:0px;margin-left:8px;">field1 = value1<br/>field2 = value2<br>field3 = value3</p>', 'Object',
  1037. null, null, dt + 'object instance'),
  1038. this.createVertexTemplateEntry('verticalAlign=top;align=left;overflow=fill;html=1;',180, 90,
  1039. '<div style="box-sizing:border-box;width:100%;background:#e4e4e4;padding:2px;">Tablename</div>' +
  1040. '<table style="width:100%;font-size:1em;" cellpadding="2" cellspacing="0">' +
  1041. '<tr><td>PK</td><td>uniqueId</td></tr><tr><td>FK1</td><td>' +
  1042. 'foreignKey</td></tr><tr><td></td><td>fieldname</td></tr></table>', 'Entity', null, null, 'er entity table'),
  1043. this.addEntry(dt + 'object instance', function()
  1044. {
  1045. var cell = new mxCell('<p style="margin:0px;margin-top:4px;text-align:center;">' +
  1046. '<b>Class</b></p>' +
  1047. '<hr size="1"/><div style="height:2px;"></div>', new mxGeometry(0, 0, 140, 60),
  1048. 'verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;');
  1049. cell.vertex = true;
  1050. return sb.createVertexTemplateFromCells([cell.clone()], cell.geometry.width, cell.geometry.height, 'Class 3');
  1051. }),
  1052. this.addEntry(dt + 'object instance', function()
  1053. {
  1054. var cell = new mxCell('<p style="margin:0px;margin-top:4px;text-align:center;">' +
  1055. '<b>Class</b></p>' +
  1056. '<hr size="1"/><div style="height:2px;"></div><hr size="1"/><div style="height:2px;"></div>', new mxGeometry(0, 0, 140, 60),
  1057. 'verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;');
  1058. cell.vertex = true;
  1059. return sb.createVertexTemplateFromCells([cell.clone()], cell.geometry.width, cell.geometry.height, 'Class 4');
  1060. }),
  1061. this.addEntry(dt + 'object instance', function()
  1062. {
  1063. var cell = new mxCell('<p style="margin:0px;margin-top:4px;text-align:center;">' +
  1064. '<b>Class</b></p>' +
  1065. '<hr size="1"/><p style="margin:0px;margin-left:4px;">+ field: Type</p><hr size="1"/>' +
  1066. '<p style="margin:0px;margin-left:4px;">+ method(): Type</p>', new mxGeometry(0, 0, 160, 90),
  1067. 'verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;');
  1068. cell.vertex = true;
  1069. return sb.createVertexTemplateFromCells([cell.clone()], cell.geometry.width, cell.geometry.height, 'Class 5');
  1070. }),
  1071. this.addEntry(dt + 'object instance', function()
  1072. {
  1073. var cell = new mxCell('<p style="margin:0px;margin-top:4px;text-align:center;">' +
  1074. '<i>&lt;&lt;Interface&gt;&gt;</i><br/><b>Interface</b></p>' +
  1075. '<hr size="1"/><p style="margin:0px;margin-left:4px;">+ field1: Type<br/>' +
  1076. '+ field2: Type</p>' +
  1077. '<hr size="1"/><p style="margin:0px;margin-left:4px;">' +
  1078. '+ method1(Type): Type<br/>' +
  1079. '+ method2(Type, Type): Type</p>', new mxGeometry(0, 0, 190, 140),
  1080. 'verticalAlign=top;align=left;overflow=fill;fontSize=12;fontFamily=Helvetica;html=1;');
  1081. cell.vertex = true;
  1082. return sb.createVertexTemplateFromCells([cell.clone()], cell.geometry.width, cell.geometry.height, 'Interface 2');
  1083. }),
  1084. this.createVertexTemplateEntry('shape=lollipop;direction=south;html=1;', 30, 10, '', 'Provided Interface', null, null, dt + 'provided interface'),
  1085. this.createVertexTemplateEntry('shape=requires;direction=north;html=1;', 30, 20, '', 'Required Interface', null, null, dt + 'required interface'),
  1086. this.createVertexTemplateEntry('shape=umlBoundary;whiteSpace=wrap;html=1;', 100, 80, 'Boundary Object', 'Boundary Object', null, null, 'uml boundary object'),
  1087. this.createVertexTemplateEntry('ellipse;shape=umlEntity;whiteSpace=wrap;html=1;', 80, 80, 'Entity Object', 'Entity Object', null, null, 'uml entity object'),
  1088. this.createVertexTemplateEntry('ellipse;shape=umlControl;whiteSpace=wrap;html=1;', 70, 80, 'Control Object', 'Control Object', null, null, 'uml control object'),
  1089. this.createVertexTemplateEntry('shape=umlActor;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;verticalAlign=top;html=1;', 30, 60, 'Actor', 'Actor', false, null, 'uml actor'),
  1090. this.createVertexTemplateEntry('ellipse;whiteSpace=wrap;html=1;', 140, 70, 'Use Case', 'Use Case', null, null, 'uml use case usecase'),
  1091. this.addEntry('uml activity state start', function()
  1092. {
  1093. var cell = new mxCell('', new mxGeometry(0, 0, 30, 30),
  1094. 'ellipse;html=1;shape=startState;fillColor=#000000;strokeColor=#ff0000;');
  1095. cell.vertex = true;
  1096. var edge = new mxCell('', new mxGeometry(0, 0, 0, 0), 'edgeStyle=orthogonalEdgeStyle;html=1;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;');
  1097. edge.geometry.setTerminalPoint(new mxPoint(15, 90), false);
  1098. edge.geometry.relative = true;
  1099. edge.edge = true;
  1100. cell.insertEdge(edge, true);
  1101. return sb.createVertexTemplateFromCells([cell, edge], 30, 90, 'Start');
  1102. }),
  1103. this.addEntry('uml activity state', function()
  1104. {
  1105. var cell = new mxCell('Activity', new mxGeometry(0, 0, 120, 40),
  1106. 'rounded=1;whiteSpace=wrap;html=1;arcSize=40;fillColor=#ffffc0;strokeColor=#ff0000;');
  1107. cell.vertex = true;
  1108. var edge = new mxCell('', new mxGeometry(0, 0, 0, 0), 'edgeStyle=orthogonalEdgeStyle;html=1;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;');
  1109. edge.geometry.setTerminalPoint(new mxPoint(60, 100), false);
  1110. edge.geometry.relative = true;
  1111. edge.edge = true;
  1112. cell.insertEdge(edge, true);
  1113. return sb.createVertexTemplateFromCells([cell, edge], 120, 100, 'Activity');
  1114. }),
  1115. this.addEntry('uml activity composite state', function()
  1116. {
  1117. var cell = new mxCell('Composite State', new mxGeometry(0, 0, 160, 60),
  1118. 'swimlane;html=1;fontStyle=1;align=center;verticalAlign=middle;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=0;resizeLast=1;container=0;collapsible=0;rounded=1;arcSize=30;strokeColor=#ff0000;fillColor=#ffffc0;swimlaneFillColor=#ffffc0;');
  1119. cell.vertex = true;
  1120. var cell1 = new mxCell('Subtitle', new mxGeometry(0, 0, 200, 26), 'text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;spacingLeft=4;spacingRight=4;whiteSpace=wrap;overflow=hidden;rotatable=0;');
  1121. cell1.vertex = true;
  1122. cell.insert(cell1);
  1123. var edge = new mxCell('', new mxGeometry(0, 0, 0, 0), 'edgeStyle=orthogonalEdgeStyle;html=1;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;');
  1124. edge.geometry.setTerminalPoint(new mxPoint(80, 120), false);
  1125. edge.geometry.relative = true;
  1126. edge.edge = true;
  1127. cell.insertEdge(edge, true);
  1128. return sb.createVertexTemplateFromCells([cell, edge], 160, 120, 'Composite State');
  1129. }),
  1130. this.addEntry('uml activity condition', function()
  1131. {
  1132. var cell = new mxCell('Condition', new mxGeometry(0, 0, 80, 40), 'rhombus;whiteSpace=wrap;html=1;fillColor=#ffffc0;strokeColor=#ff0000;');
  1133. cell.vertex = true;
  1134. var edge1 = new mxCell('no', new mxGeometry(0, 0, 0, 0), 'edgeStyle=orthogonalEdgeStyle;html=1;align=left;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;');
  1135. edge1.geometry.setTerminalPoint(new mxPoint(180, 20), false);
  1136. edge1.geometry.relative = true;
  1137. edge1.geometry.x = -1;
  1138. edge1.edge = true;
  1139. cell.insertEdge(edge1, true);
  1140. var edge2 = new mxCell('yes', new mxGeometry(0, 0, 0, 0), 'edgeStyle=orthogonalEdgeStyle;html=1;align=left;verticalAlign=top;endArrow=open;endSize=8;strokeColor=#ff0000;');
  1141. edge2.geometry.setTerminalPoint(new mxPoint(40, 100), false);
  1142. edge2.geometry.relative = true;
  1143. edge2.geometry.x = -1;
  1144. edge2.edge = true;
  1145. cell.insertEdge(edge2, true);
  1146. return sb.createVertexTemplateFromCells([cell, edge1, edge2], 180, 100, 'Condition');
  1147. }),
  1148. this.addEntry('uml activity fork join', function()
  1149. {
  1150. var cell = new mxCell('', new mxGeometry(0, 0, 200, 10), 'shape=line;html=1;strokeWidth=6;strokeColor=#ff0000;');
  1151. cell.vertex = true;
  1152. var edge = new mxCell('', new mxGeometry(0, 0, 0, 0), 'edgeStyle=orthogonalEdgeStyle;html=1;verticalAlign=bottom;endArrow=open;endSize=8;strokeColor=#ff0000;');
  1153. edge.geometry.setTerminalPoint(new mxPoint(100, 80), false);
  1154. edge.geometry.relative = true;
  1155. edge.edge = true;
  1156. cell.insertEdge(edge, true);
  1157. return sb.createVertexTemplateFromCells([cell, edge], 200, 80, 'Fork/Join');
  1158. }),
  1159. this.createVertexTemplateEntry('ellipse;html=1;shape=endState;fillColor=#000000;strokeColor=#ff0000;', 30, 30, '', 'End', null, null, 'uml activity state end'),
  1160. this.createVertexTemplateEntry('shape=umlLifeline;perimeter=lifelinePerimeter;whiteSpace=wrap;html=1;container=1;collapsible=0;recursiveResize=0;outlineConnect=0;', 100, 300, ':Object', 'Lifeline', null, null, 'uml sequence participant lifeline'),
  1161. this.createVertexTemplateEntry('shape=umlLifeline;participant=umlActor;perimeter=lifelinePerimeter;whiteSpace=wrap;html=1;container=1;collapsible=0;recursiveResize=0;verticalAlign=top;spacingTop=36;labelBackgroundColor=#ffffff;outlineConnect=0;',
  1162. 20, 300, '', 'Actor Lifeline', null, null, 'uml sequence participant lifeline actor'),
  1163. this.createVertexTemplateEntry('shape=umlLifeline;participant=umlBoundary;perimeter=lifelinePerimeter;whiteSpace=wrap;html=1;container=1;collapsible=0;recursiveResize=0;verticalAlign=top;spacingTop=36;labelBackgroundColor=#ffffff;outlineConnect=0;',
  1164. 50, 300, '', 'Boundary Lifeline', null, null, 'uml sequence participant lifeline boundary'),
  1165. this.createVertexTemplateEntry('shape=umlLifeline;participant=umlEntity;perimeter=lifelinePerimeter;whiteSpace=wrap;html=1;container=1;collapsible=0;recursiveResize=0;verticalAlign=top;spacingTop=36;labelBackgroundColor=#ffffff;outlineConnect=0;',
  1166. 40, 300, '', 'Entity Lifeline', null, null, 'uml sequence participant lifeline entity'),
  1167. this.createVertexTemplateEntry('shape=umlLifeline;participant=umlControl;perimeter=lifelinePerimeter;whiteSpace=wrap;html=1;container=1;collapsible=0;recursiveResize=0;verticalAlign=top;spacingTop=36;labelBackgroundColor=#ffffff;outlineConnect=0;',
  1168. 40, 300, '', 'Control Lifeline', null, null, 'uml sequence participant lifeline control'),
  1169. this.createVertexTemplateEntry('shape=umlFrame;whiteSpace=wrap;html=1;', 300, 200, 'frame', 'Frame', null, null, 'uml sequence frame'),
  1170. this.createVertexTemplateEntry('shape=umlDestroy;whiteSpace=wrap;html=1;strokeWidth=3;', 30, 30, '', 'Destruction', null, null, 'uml sequence destruction destroy'),
  1171. this.createVertexTemplateEntry('shape=note;whiteSpace=wrap;html=1;size=14;verticalAlign=top;align=left;spacingTop=-6;', 100, 70, 'Note', 'Note', null, null, 'uml note'),
  1172. this.addEntry('uml sequence invoke invocation call activation', function()
  1173. {
  1174. var cell = new mxCell('', new mxGeometry(0, 0, 10, 80), 'html=1;points=[];perimeter=orthogonalPerimeter;');
  1175. cell.vertex = true;
  1176. var edge = new mxCell('dispatch', new mxGeometry(0, 0, 0, 0), 'html=1;verticalAlign=bottom;startArrow=oval;endArrow=block;startSize=8;');
  1177. edge.geometry.setTerminalPoint(new mxPoint(-60, 0), true);
  1178. edge.geometry.relative = true;
  1179. edge.edge = true;
  1180. cell.insertEdge(edge, false);
  1181. return sb.createVertexTemplateFromCells([cell, edge], 10, 80, 'Found Message');
  1182. }),
  1183. this.addEntry('uml sequence invoke call delegation synchronous invocation activation', function()
  1184. {
  1185. var cell = new mxCell('', new mxGeometry(0, 0, 10, 80), 'html=1;points=[];perimeter=orthogonalPerimeter;');
  1186. cell.vertex = true;
  1187. var edge1 = new mxCell('dispatch', new mxGeometry(0, 0, 0, 0), 'html=1;verticalAlign=bottom;endArrow=block;entryX=0;entryY=0;');
  1188. edge1.geometry.setTerminalPoint(new mxPoint(-70, 0), true);
  1189. edge1.geometry.relative = true;
  1190. edge1.edge = true;
  1191. cell.insertEdge(edge1, false);
  1192. var edge2 = new mxCell('return', new mxGeometry(0, 0, 0, 0), 'html=1;verticalAlign=bottom;endArrow=open;dashed=1;endSize=8;exitX=0;exitY=0.95;');
  1193. edge2.geometry.setTerminalPoint(new mxPoint(-70, 76), false);
  1194. edge2.geometry.relative = true;
  1195. edge2.edge = true;
  1196. cell.insertEdge(edge2, true);
  1197. return sb.createVertexTemplateFromCells([cell, edge1, edge2], 10, 80, 'Synchronous Invocation');
  1198. }),
  1199. this.addEntry('uml sequence self call recursion delegation activation', function()
  1200. {
  1201. var cell = new mxCell('', new mxGeometry(0, 20, 10, 40), 'html=1;points=[];perimeter=orthogonalPerimeter;');
  1202. cell.vertex = true;
  1203. var edge = new mxCell('self call', new mxGeometry(0, 0, 0, 0), 'edgeStyle=orthogonalEdgeStyle;html=1;align=left;spacingLeft=2;endArrow=block;rounded=0;entryX=1;entryY=0;');
  1204. edge.geometry.setTerminalPoint(new mxPoint(5, 0), true);
  1205. edge.geometry.points = [new mxPoint(30, 0)];
  1206. edge.geometry.relative = true;
  1207. edge.edge = true;
  1208. cell.insertEdge(edge, false);
  1209. return sb.createVertexTemplateFromCells([cell, edge], 10, 60, 'Self Call');
  1210. }),
  1211. this.addEntry('uml sequence invoke call delegation callback activation', function()
  1212. {
  1213. var cell = new mxCell('', new mxGeometry(0, 0, 10, 60), 'html=1;points=[];perimeter=orthogonalPerimeter;');
  1214. cell.vertex = true;
  1215. var edge1 = new mxCell('callback', new mxGeometry(0, 0, 0, 0), 'html=1;verticalAlign=bottom;endArrow=block;entryX=1;entryY=0;');
  1216. edge1.geometry.setTerminalPoint(new mxPoint(70, 0), true);
  1217. edge1.geometry.relative = true;
  1218. edge1.edge = true;
  1219. cell.insertEdge(edge1, false);
  1220. var edge2 = new mxCell('return', new mxGeometry(0, 0, 0, 0), 'html=1;verticalAlign=bottom;endArrow=open;dashed=1;endSize=8;exitX=1;exitY=0.95;');
  1221. edge2.geometry.setTerminalPoint(new mxPoint(70, 57), false);
  1222. edge2.geometry.relative = true;
  1223. edge2.edge = true;
  1224. cell.insertEdge(edge2, true);
  1225. return sb.createVertexTemplateFromCells([cell, edge1, edge2], 10, 60, 'Callback');
  1226. }),
  1227. this.createVertexTemplateEntry('html=1;points=[];perimeter=orthogonalPerimeter;', 10, 80, '', 'Activation', null, null, 'uml sequence activation'),
  1228. this.createEdgeTemplateEntry('html=1;verticalAlign=bottom;startArrow=oval;startFill=1;endArrow=block;startSize=8;', 60, 0, 'dispatch', 'Found Message 1', null, 'uml sequence message call invoke dispatch'),
  1229. this.createEdgeTemplateEntry('html=1;verticalAlign=bottom;startArrow=circle;startFill=1;endArrow=open;startSize=6;endSize=8;', 80, 0, 'dispatch', 'Found Message 2', null, 'uml sequence message call invoke dispatch'),
  1230. this.createEdgeTemplateEntry('html=1;verticalAlign=bottom;endArrow=block;', 80, 0, 'dispatch', 'Message', null, 'uml sequence message call invoke dispatch'),
  1231. this.addEntry('uml sequence return message', function()
  1232. {
  1233. var edge = new mxCell('return', new mxGeometry(0, 0, 0, 0), 'html=1;verticalAlign=bottom;endArrow=open;dashed=1;endSize=8;');
  1234. edge.geometry.setTerminalPoint(new mxPoint(80, 0), true);
  1235. edge.geometry.setTerminalPoint(new mxPoint(0, 0), false);
  1236. edge.geometry.relative = true;
  1237. edge.edge = true;
  1238. return sb.createEdgeTemplateFromCells([edge], 80, 0, 'Return');
  1239. }),
  1240. this.addEntry('uml relation', function()
  1241. {
  1242. var edge = new mxCell('name', new mxGeometry(0, 0, 0, 0), 'endArrow=block;endFill=1;html=1;edgeStyle=orthogonalEdgeStyle;align=left;verticalAlign=top;');
  1243. edge.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  1244. edge.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  1245. edge.geometry.relative = true;
  1246. edge.geometry.x = -1;
  1247. edge.edge = true;
  1248. var cell = new mxCell('1', new mxGeometry(-1, 0, 0, 0), 'resizable=0;html=1;align=left;verticalAlign=bottom;labelBackgroundColor=#ffffff;fontSize=10;');
  1249. cell.geometry.relative = true;
  1250. cell.setConnectable(false);
  1251. cell.vertex = true;
  1252. edge.insert(cell);
  1253. return sb.createEdgeTemplateFromCells([edge], 160, 0, 'Relation 1');
  1254. }),
  1255. this.addEntry('uml association', function()
  1256. {
  1257. var edge = new mxCell('', new mxGeometry(0, 0, 0, 0), 'endArrow=none;html=1;edgeStyle=orthogonalEdgeStyle;');
  1258. edge.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  1259. edge.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  1260. edge.geometry.relative = true;
  1261. edge.edge = true;
  1262. var cell1 = new mxCell('parent', new mxGeometry(-1, 0, 0, 0), 'resizable=0;html=1;align=left;verticalAlign=bottom;labelBackgroundColor=#ffffff;fontSize=10;');
  1263. cell1.geometry.relative = true;
  1264. cell1.setConnectable(false);
  1265. cell1.vertex = true;
  1266. edge.insert(cell1);
  1267. var cell2 = new mxCell('child', new mxGeometry(1, 0, 0, 0), 'resizable=0;html=1;align=right;verticalAlign=bottom;labelBackgroundColor=#ffffff;fontSize=10;');
  1268. cell2.geometry.relative = true;
  1269. cell2.setConnectable(false);
  1270. cell2.vertex = true;
  1271. edge.insert(cell2);
  1272. return sb.createEdgeTemplateFromCells([edge], 160, 0, 'Association 1');
  1273. }),
  1274. this.addEntry('uml aggregation', function()
  1275. {
  1276. var edge = new mxCell('1', new mxGeometry(0, 0, 0, 0), 'endArrow=open;html=1;endSize=12;startArrow=diamondThin;startSize=14;startFill=0;edgeStyle=orthogonalEdgeStyle;align=left;verticalAlign=bottom;');
  1277. edge.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  1278. edge.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  1279. edge.geometry.relative = true;
  1280. edge.geometry.x = -1;
  1281. edge.geometry.y = 3;
  1282. edge.edge = true;
  1283. return sb.createEdgeTemplateFromCells([edge], 160, 0, 'Aggregation');
  1284. }),
  1285. this.addEntry('uml composition', function()
  1286. {
  1287. var edge = new mxCell('1', new mxGeometry(0, 0, 0, 0), 'endArrow=open;html=1;endSize=12;startArrow=diamondThin;startSize=14;startFill=1;edgeStyle=orthogonalEdgeStyle;align=left;verticalAlign=bottom;');
  1288. edge.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  1289. edge.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  1290. edge.geometry.relative = true;
  1291. edge.geometry.x = -1;
  1292. edge.geometry.y = 3;
  1293. edge.edge = true;
  1294. return sb.createEdgeTemplateFromCells([edge], 160, 0, 'Composition');
  1295. }),
  1296. this.addEntry('uml relation', function()
  1297. {
  1298. var edge = new mxCell('Relation', new mxGeometry(0, 0, 0, 0), 'endArrow=open;html=1;endSize=12;startArrow=diamondThin;startSize=14;startFill=0;edgeStyle=orthogonalEdgeStyle;');
  1299. edge.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  1300. edge.geometry.setTerminalPoint(new mxPoint(160, 0), false);
  1301. edge.geometry.relative = true;
  1302. edge.edge = true;
  1303. var cell1 = new mxCell('0..n', new mxGeometry(-1, 0, 0, 0), 'resizable=0;html=1;align=left;verticalAlign=top;labelBackgroundColor=#ffffff;fontSize=10;');
  1304. cell1.geometry.relative = true;
  1305. cell1.setConnectable(false);
  1306. cell1.vertex = true;
  1307. edge.insert(cell1);
  1308. var cell2 = new mxCell('1', new mxGeometry(1, 0, 0, 0), 'resizable=0;html=1;align=right;verticalAlign=top;labelBackgroundColor=#ffffff;fontSize=10;');
  1309. cell2.geometry.relative = true;
  1310. cell2.setConnectable(false);
  1311. cell2.vertex = true;
  1312. edge.insert(cell2);
  1313. return sb.createEdgeTemplateFromCells([edge], 160, 0, 'Relation 2');
  1314. }),
  1315. this.createEdgeTemplateEntry('endArrow=open;endSize=12;dashed=1;html=1;', 160, 0, 'Use', 'Dependency', null, 'uml dependency use'),
  1316. this.createEdgeTemplateEntry('endArrow=block;endSize=16;endFill=0;html=1;', 160, 0, 'Extends', 'Generalization', null, 'uml generalization extend'),
  1317. this.createEdgeTemplateEntry('endArrow=block;startArrow=block;endFill=1;startFill=1;html=1;', 160, 0, '', 'Association 2', null, 'uml association'),
  1318. this.createEdgeTemplateEntry('endArrow=open;startArrow=circlePlus;endFill=0;startFill=0;endSize=8;html=1;', 160, 0, '', 'Inner Class', null, 'inner class'),
  1319. this.createEdgeTemplateEntry('endArrow=open;startArrow=cross;endFill=0;startFill=0;endSize=8;startSize=10;html=1;', 160, 0, '', 'Terminate', null, 'terminate')
  1320. ];
  1321. this.addPaletteFunctions('uml', mxResources.get('uml'), expand || false, fns);
  1322. };
  1323. /**
  1324. * Adds the BPMN library to the sidebar.
  1325. */
  1326. Sidebar.prototype.addBpmnPalette = function(dir, expand)
  1327. {
  1328. // Avoids having to bind all functions to "this"
  1329. var sb = this;
  1330. var fns =
  1331. [
  1332. this.createVertexTemplateEntry('shape=ext;rounded=1;html=1;whiteSpace=wrap;', 120, 80, 'Task', 'Process', null, null, 'bpmn task process'),
  1333. this.createVertexTemplateEntry('shape=ext;rounded=1;html=1;whiteSpace=wrap;double=1;', 120, 80, 'Transaction', 'Transaction', null, null, 'bpmn transaction'),
  1334. this.createVertexTemplateEntry('shape=ext;rounded=1;html=1;whiteSpace=wrap;dashed=1;dashPattern=1 4;', 120, 80, 'Event\nSub-Process', 'Event Sub-Process', null, null, 'bpmn event subprocess sub process sub-process'),
  1335. this.createVertexTemplateEntry('shape=ext;rounded=1;html=1;whiteSpace=wrap;strokeWidth=3;', 120, 80, 'Call Activity', 'Call Activity', null, null, 'bpmn call activity'),
  1336. this.addEntry('bpmn subprocess sub process sub-process', function()
  1337. {
  1338. var cell = new mxCell('Sub-Process', new mxGeometry(0, 0, 120, 80), 'html=1;whiteSpace=wrap;rounded=1;');
  1339. cell.vertex = true;
  1340. var cell1 = new mxCell('', new mxGeometry(0.5, 1, 14, 14), 'html=1;shape=plus;');
  1341. cell1.vertex = true;
  1342. cell1.geometry.relative = true;
  1343. cell1.geometry.offset = new mxPoint(-7, -14);
  1344. cell.insert(cell1);
  1345. return sb.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Sub-Process');
  1346. }),
  1347. this.addEntry(this.getTagsForStencil('mxgraph.bpmn', 'loop', 'subprocess sub process sub-process looped').join(' '), function()
  1348. {
  1349. var cell = new mxCell('Looped\nSub-Process', new mxGeometry(0, 0, 120, 80), 'html=1;whiteSpace=wrap;rounded=1');
  1350. cell.vertex = true;
  1351. var cell1 = new mxCell('', new mxGeometry(0.5, 1, 14, 14), 'html=1;shape=mxgraph.bpmn.loop;');
  1352. cell1.vertex = true;
  1353. cell1.geometry.relative = true;
  1354. cell1.geometry.offset = new mxPoint(-15, -14);
  1355. cell.insert(cell1);
  1356. var cell2 = new mxCell('', new mxGeometry(0.5, 1, 14, 14), 'html=1;shape=plus;');
  1357. cell2.vertex = true;
  1358. cell2.geometry.relative = true;
  1359. cell2.geometry.offset = new mxPoint(1, -14);
  1360. cell.insert(cell2);
  1361. return sb.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Looped Sub-Process');
  1362. }),
  1363. this.addEntry('bpmn receive task', function()
  1364. {
  1365. var cell = new mxCell('Receive', new mxGeometry(0, 0, 120, 80), 'html=1;whiteSpace=wrap;rounded=1;');
  1366. cell.vertex = true;
  1367. var cell1 = new mxCell('', new mxGeometry(0, 0, 20, 14), 'html=1;shape=message;');
  1368. cell1.vertex = true;
  1369. cell1.geometry.relative = true;
  1370. cell1.geometry.offset = new mxPoint(7, 7);
  1371. cell.insert(cell1);
  1372. return sb.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Receive Task');
  1373. }),
  1374. this.addEntry(this.getTagsForStencil('mxgraph.bpmn', 'user_task').join(' '), function()
  1375. {
  1376. var cell = new mxCell('User', new mxGeometry(0, 0, 120, 80), 'html=1;whiteSpace=wrap;rounded=1;');
  1377. cell.vertex = true;
  1378. var cell1 = new mxCell('', new mxGeometry(0, 0, 14, 14), 'html=1;shape=mxgraph.bpmn.user_task;');
  1379. cell1.vertex = true;
  1380. cell1.geometry.relative = true;
  1381. cell1.geometry.offset = new mxPoint(7, 7);
  1382. cell.insert(cell1);
  1383. var cell2 = new mxCell('', new mxGeometry(0.5, 1, 14, 14), 'html=1;shape=plus;');
  1384. cell2.vertex = true;
  1385. cell2.geometry.relative = true;
  1386. cell2.geometry.offset = new mxPoint(-7, -14);
  1387. cell.insert(cell2);
  1388. return sb.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'User Task');
  1389. }),
  1390. this.addEntry(this.getTagsForStencil('mxgraph.bpmn', 'timer_start', 'attached').join(' '), function()
  1391. {
  1392. var cell = new mxCell('Process', new mxGeometry(0, 0, 120, 80), 'html=1;whiteSpace=wrap;rounded=1;');
  1393. cell.vertex = true;
  1394. var cell1 = new mxCell('', new mxGeometry(1, 1, 30, 30), 'shape=mxgraph.bpmn.timer_start;perimeter=ellipsePerimeter;html=1;verticalLabelPosition=bottom;labelBackgroundColor=#ffffff;verticalAlign=top;');
  1395. cell1.vertex = true;
  1396. cell1.geometry.relative = true;
  1397. cell1.geometry.offset = new mxPoint(-40, -15);
  1398. cell.insert(cell1);
  1399. return sb.createVertexTemplateFromCells([cell], 120, 95, 'Attached Timer Event 1');
  1400. }),
  1401. this.addEntry(this.getTagsForStencil('mxgraph.bpmn', 'timer_start', 'attached').join(' '), function()
  1402. {
  1403. var cell = new mxCell('Process', new mxGeometry(0, 0, 120, 80), 'html=1;whiteSpace=wrap;rounded=1;');
  1404. cell.vertex = true;
  1405. var cell1 = new mxCell('', new mxGeometry(1, 0, 30, 30), 'shape=mxgraph.bpmn.timer_start;perimeter=ellipsePerimeter;html=1;labelPosition=right;labelBackgroundColor=#ffffff;align=left;');
  1406. cell1.vertex = true;
  1407. cell1.geometry.relative = true;
  1408. cell1.geometry.offset = new mxPoint(-15, 10);
  1409. cell.insert(cell1);
  1410. return sb.createVertexTemplateFromCells([cell], 135, 80, 'Attached Timer Event 2');
  1411. }),
  1412. this.createVertexTemplateEntry('swimlane;html=1;horizontal=0;startSize=20;', 320, 240, 'Pool', 'Pool', null, null, 'bpmn pool'),
  1413. this.createVertexTemplateEntry('swimlane;html=1;horizontal=0;swimlaneFillColor=white;swimlaneLine=0;', 300, 120, 'Lane', 'Lane', null, null, 'bpmn lane'),
  1414. this.createVertexTemplateEntry('shape=hexagon;html=1;whiteSpace=wrap;perimeter=hexagonPerimeter;', 60, 50, '', 'Conversation', null, null, 'bpmn conversation'),
  1415. this.createVertexTemplateEntry('shape=hexagon;html=1;whiteSpace=wrap;perimeter=hexagonPerimeter;strokeWidth=4', 60, 50, '', 'Call Conversation', null, null, 'bpmn call conversation'),
  1416. this.addEntry('bpmn subconversation sub conversation sub-conversation', function()
  1417. {
  1418. var cell = new mxCell('', new mxGeometry(0, 0, 60, 50), 'shape=hexagon;whiteSpace=wrap;html=1;perimeter=hexagonPerimeter;');
  1419. cell.vertex = true;
  1420. var cell1 = new mxCell('', new mxGeometry(0.5, 1, 14, 14), 'html=1;shape=plus;');
  1421. cell1.vertex = true;
  1422. cell1.geometry.relative = true;
  1423. cell1.geometry.offset = new mxPoint(-7, -14);
  1424. cell.insert(cell1);
  1425. return sb.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Sub-Conversation');
  1426. }),
  1427. this.addEntry('bpmn data object', function()
  1428. {
  1429. var cell = new mxCell('', new mxGeometry(0, 0, 40, 60), 'shape=note;whiteSpace=wrap;size=16;html=1;');
  1430. cell.vertex = true;
  1431. var cell1 = new mxCell('', new mxGeometry(0, 0, 14, 14), 'html=1;shape=singleArrow;arrowWidth=0.4;arrowSize=0.4;');
  1432. cell1.vertex = true;
  1433. cell1.geometry.relative = true;
  1434. cell1.geometry.offset = new mxPoint(2, 2);
  1435. cell.insert(cell1);
  1436. var cell2 = new mxCell('', new mxGeometry(0.5, 1, 14, 14), 'html=1;whiteSpace=wrap;shape=parallelMarker;');
  1437. cell2.vertex = true;
  1438. cell2.geometry.relative = true;
  1439. cell2.geometry.offset = new mxPoint(-7, -14);
  1440. cell.insert(cell2);
  1441. return sb.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, 'Data Object');
  1442. }),
  1443. this.createVertexTemplateEntry('shape=datastore;whiteSpace=wrap;html=1;', 60, 60, '', 'Data Store', null, null, 'bpmn data store'),
  1444. this.createVertexTemplateEntry('shape=plus;html=1;', 14, 14, '', 'Sub-Process Marker', null, null, 'bpmn subprocess sub process sub-process marker'),
  1445. this.createVertexTemplateEntry('shape=mxgraph.bpmn.loop;html=1;', 14, 14, '', 'Loop Marker', null, null, 'bpmn loop marker'),
  1446. this.createVertexTemplateEntry('shape=parallelMarker;html=1;', 14, 14, '', 'Parallel MI Marker', null, null, 'bpmn parallel mi marker'),
  1447. this.createVertexTemplateEntry('shape=parallelMarker;direction=south;html=1;', 14, 14, '', 'Sequential MI Marker', null, null, 'bpmn sequential mi marker'),
  1448. this.createVertexTemplateEntry('shape=mxgraph.bpmn.ad_hoc;fillColor=#000000;html=1;', 14, 14, '', 'Ad Hoc Marker', null, null, 'bpmn ad hoc marker'),
  1449. this.createVertexTemplateEntry('shape=mxgraph.bpmn.compensation;html=1;', 14, 14, '', 'Compensation Marker', null, null, 'bpmn compensation marker'),
  1450. this.createVertexTemplateEntry('shape=message;whiteSpace=wrap;html=1;fillColor=#000000;strokeColor=#ffffff;strokeWidth=2;', 40, 30, '', 'Send Task', null, null, 'bpmn send task'),
  1451. this.createVertexTemplateEntry('shape=message;whiteSpace=wrap;html=1;', 40, 30, '', 'Receive Task', null, null, 'bpmn receive task'),
  1452. this.createVertexTemplateEntry('shape=mxgraph.bpmn.user_task;html=1;', 14, 14, '', 'User Task', null, null, this.getTagsForStencil('mxgraph.bpmn', 'user_task').join(' ')),
  1453. this.createVertexTemplateEntry('shape=mxgraph.bpmn.manual_task;html=1;', 14, 14, '', 'Manual Task', null, null, this.getTagsForStencil('mxgraph.bpmn', 'user_task').join(' ')),
  1454. this.createVertexTemplateEntry('shape=mxgraph.bpmn.business_rule_task;html=1;', 14, 14, '', 'Business Rule Task', null, null, this.getTagsForStencil('mxgraph.bpmn', 'business_rule_task').join(' ')),
  1455. this.createVertexTemplateEntry('shape=mxgraph.bpmn.service_task;html=1;', 14, 14, '', 'Service Task', null, null, this.getTagsForStencil('mxgraph.bpmn', 'service_task').join(' ')),
  1456. this.createVertexTemplateEntry('shape=mxgraph.bpmn.script_task;html=1;', 14, 14, '', 'Script Task', null, null, this.getTagsForStencil('mxgraph.bpmn', 'script_task').join(' ')),
  1457. this.createEdgeTemplateEntry('endArrow=block;endFill=1;endSize=6;html=1;', 100, 0, '', 'Sequence Flow', null, 'bpmn sequence flow'),
  1458. this.createEdgeTemplateEntry('startArrow=dash;startSize=8;endArrow=block;endFill=1;endSize=6;html=1;', 100, 0, '', 'Default Flow', null, 'bpmn default flow'),
  1459. this.createEdgeTemplateEntry('startArrow=diamondThin;startFill=0;startSize=14;endArrow=block;endFill=1;endSize=6;html=1;', 100, 0, '', 'Conditional Flow', null, 'bpmn conditional flow'),
  1460. this.createEdgeTemplateEntry('startArrow=oval;startFill=0;startSize=7;endArrow=block;endFill=0;endSize=10;dashed=1;html=1;', 100, 0, '', 'Message Flow 1', null, 'bpmn message flow'),
  1461. this.addEntry('bpmn message flow', function()
  1462. {
  1463. var edge = new mxCell('', new mxGeometry(0, 0, 0, 0), 'startArrow=oval;startFill=0;startSize=7;endArrow=block;endFill=0;endSize=10;dashed=1;html=1;');
  1464. edge.geometry.setTerminalPoint(new mxPoint(0, 0), true);
  1465. edge.geometry.setTerminalPoint(new mxPoint(100, 0), false);
  1466. edge.geometry.relative = true;
  1467. edge.edge = true;
  1468. var cell = new mxCell('', new mxGeometry(0, 0, 20, 14), 'shape=message;html=1;');
  1469. cell.geometry.relative = true;
  1470. cell.setConnectable(false);
  1471. cell.vertex = true;
  1472. cell.geometry.offset = new mxPoint(-10, -7);
  1473. edge.insert(cell);
  1474. return sb.createEdgeTemplateFromCells([edge], 100, 0, 'Message Flow 2');
  1475. }),
  1476. this.createEdgeTemplateEntry('shape=link;html=1;', 100, 0, '', 'Link', null, 'bpmn link')
  1477. ];
  1478. this.addPaletteFunctions('bpmn', 'BPMN ' + mxResources.get('general'), false, fns);
  1479. };
  1480. /**
  1481. * Creates and returns the given title element.
  1482. */
  1483. Sidebar.prototype.createTitle = function(label)
  1484. {
  1485. var elt = document.createElement('a');
  1486. elt.setAttribute('href', 'javascript:void(0);');
  1487. elt.setAttribute('title', mxResources.get('sidebarTooltip'));
  1488. elt.className = 'geTitle';
  1489. mxUtils.write(elt, label);
  1490. return elt;
  1491. };
  1492. /**
  1493. * Creates a thumbnail for the given cells.
  1494. */
  1495. Sidebar.prototype.createThumb = function(cells, width, height, parent, title, showLabel, showTitle, realWidth, realHeight)
  1496. {
  1497. this.graph.labelsVisible = (showLabel == null || showLabel);
  1498. var fo = mxClient.NO_FO;
  1499. mxClient.NO_FO = Editor.prototype.originalNoForeignObject;
  1500. this.graph.view.scaleAndTranslate(1, 0, 0);
  1501. this.graph.addCells(cells);
  1502. var bounds = this.graph.getGraphBounds();
  1503. var s = Math.floor(Math.min((width - 2 * this.thumbBorder) / bounds.width, (height - 2 * this.thumbBorder)
  1504. / bounds.height) * 100) / 100;
  1505. this.graph.view.scaleAndTranslate(s, Math.floor((width - bounds.width * s) / 2 / s - bounds.x),
  1506. Math.floor((height - bounds.height * s) / 2 / s - bounds.y));
  1507. var node = null;
  1508. // For supporting HTML labels in IE9 standards mode the container is cloned instead
  1509. if (this.graph.dialect == mxConstants.DIALECT_SVG && !mxClient.NO_FO)
  1510. {
  1511. node = this.graph.view.getCanvas().ownerSVGElement.cloneNode(true);
  1512. }
  1513. // LATER: Check if deep clone can be used for quirks if container in DOM
  1514. else
  1515. {
  1516. node = this.graph.container.cloneNode(false);
  1517. node.innerHTML = this.graph.container.innerHTML;
  1518. }
  1519. this.graph.getModel().clear();
  1520. mxClient.NO_FO = fo;
  1521. // Catch-all event handling
  1522. if (mxClient.IS_IE6)
  1523. {
  1524. parent.style.backgroundImage = 'url(' + this.editorUi.editor.transparentImage + ')';
  1525. }
  1526. node.style.position = 'relative';
  1527. node.style.overflow = 'hidden';
  1528. node.style.cursor = 'move';
  1529. node.style.left = this.thumbBorder + 'px';
  1530. node.style.top = this.thumbBorder + 'px';
  1531. node.style.width = width + 'px';
  1532. node.style.height = height + 'px';
  1533. node.style.visibility = '';
  1534. node.style.minWidth = '';
  1535. node.style.minHeight = '';
  1536. parent.appendChild(node);
  1537. // Adds title for sidebar entries
  1538. if (this.sidebarTitles && title != null && showTitle != false)
  1539. {
  1540. var border = (mxClient.IS_QUIRKS) ? 2 * this.thumbPadding + 2: 0;
  1541. parent.style.height = (this.thumbHeight + border + this.sidebarTitleSize + 8) + 'px';
  1542. var div = document.createElement('div');
  1543. div.style.fontSize = this.sidebarTitleSize + 'px';
  1544. div.style.color = '#303030';
  1545. div.style.textAlign = 'center';
  1546. div.style.whiteSpace = 'nowrap';
  1547. if (mxClient.IS_IE)
  1548. {
  1549. div.style.height = (this.sidebarTitleSize + 12) + 'px';
  1550. }
  1551. div.style.paddingTop = '4px';
  1552. mxUtils.write(div, title);
  1553. parent.appendChild(div);
  1554. }
  1555. return bounds;
  1556. };
  1557. /**
  1558. * Creates and returns a new palette item for the given image.
  1559. */
  1560. Sidebar.prototype.createItem = function(cells, title, showLabel, showTitle, width, height, allowCellsInserted)
  1561. {
  1562. var elt = document.createElement('a');
  1563. elt.setAttribute('href', 'javascript:void(0);');
  1564. elt.className = 'geItem';
  1565. elt.style.overflow = 'hidden';
  1566. var border = (mxClient.IS_QUIRKS) ? 8 + 2 * this.thumbPadding : 2 * this.thumbBorder;
  1567. elt.style.width = (this.thumbWidth + border) + 'px';
  1568. elt.style.height = (this.thumbHeight + border) + 'px';
  1569. elt.style.padding = this.thumbPadding + 'px';
  1570. // Blocks default click action
  1571. mxEvent.addListener(elt, 'click', function(evt)
  1572. {
  1573. mxEvent.consume(evt);
  1574. });
  1575. this.createThumb(cells, this.thumbWidth, this.thumbHeight, elt, title, showLabel, showTitle, width, height);
  1576. var bounds = new mxRectangle(0, 0, width, height);
  1577. if (cells.length > 1 || cells[0].vertex)
  1578. {
  1579. var ds = this.createDragSource(elt, this.createDropHandler(cells, true, allowCellsInserted,
  1580. bounds), this.createDragPreview(width, height), cells, bounds);
  1581. this.addClickHandler(elt, ds, cells);
  1582. // Uses guides for vertices only if enabled in graph
  1583. ds.isGuidesEnabled = mxUtils.bind(this, function()
  1584. {
  1585. return this.editorUi.editor.graph.graphHandler.guidesEnabled;
  1586. });
  1587. }
  1588. else if (cells[0] != null && cells[0].edge)
  1589. {
  1590. var ds = this.createDragSource(elt, this.createDropHandler(cells, false, allowCellsInserted,
  1591. bounds), this.createDragPreview(width, height), cells, bounds);
  1592. this.addClickHandler(elt, ds, cells);
  1593. }
  1594. // Shows a tooltip with the rendered cell
  1595. if (!mxClient.IS_IOS)
  1596. {
  1597. mxEvent.addGestureListeners(elt, null, mxUtils.bind(this, function(evt)
  1598. {
  1599. if (mxEvent.isMouseEvent(evt))
  1600. {
  1601. this.showTooltip(elt, cells, bounds.width, bounds.height, title, showLabel);
  1602. }
  1603. }));
  1604. }
  1605. return elt;
  1606. };
  1607. /**
  1608. * Creates a drop handler for inserting the given cells.
  1609. */
  1610. Sidebar.prototype.updateShapes = function(source, targets)
  1611. {
  1612. var graph = this.editorUi.editor.graph;
  1613. var sourceCellStyle = graph.getCellStyle(source);
  1614. var result = [];
  1615. graph.model.beginUpdate();
  1616. try
  1617. {
  1618. var cellStyle = graph.getModel().getStyle(source);
  1619. // Lists the styles to carry over from the existing shape
  1620. var styles = ['shadow', 'dashed', 'dashPattern', 'fontFamily', 'fontSize', 'fontColor', 'align', 'startFill',
  1621. 'startSize', 'endFill', 'endSize', 'strokeColor', 'strokeWidth', 'fillColor', 'gradientColor',
  1622. 'html', 'part', 'noEdgeStyle', 'edgeStyle', 'elbow', 'childLayout'];
  1623. for (var i = 0; i < targets.length; i++)
  1624. {
  1625. var targetCell = targets[i];
  1626. if ((graph.getModel().isVertex(targetCell) == graph.getModel().isVertex(source)) ||
  1627. (graph.getModel().isEdge(targetCell) == graph.getModel().isEdge(source)))
  1628. {
  1629. var state = graph.view.getState(targetCell);
  1630. var style = (state != null) ? state.style : graph.getCellStyle(targets[i]);
  1631. graph.getModel().setStyle(targetCell, cellStyle);
  1632. // Removes all children of composite cells
  1633. if (state != null && mxUtils.getValue(state.style, 'composite', '0') == '1')
  1634. {
  1635. var childCount = graph.model.getChildCount(targetCell);
  1636. for (var j = childCount; j >= 0; j--)
  1637. {
  1638. graph.model.remove(graph.model.getChildAt(targetCell, j));
  1639. }
  1640. }
  1641. if (style != null)
  1642. {
  1643. // Replaces the participant style in the lifeline shape with the target shape
  1644. if (style[mxConstants.STYLE_SHAPE] == 'umlLifeline' &&
  1645. sourceCellStyle[mxConstants.STYLE_SHAPE] != 'umlLifeline')
  1646. {
  1647. graph.setCellStyles(mxConstants.STYLE_SHAPE, 'umlLifeline', [targetCell]);
  1648. graph.setCellStyles('participant', sourceCellStyle[mxConstants.STYLE_SHAPE], [targetCell]);
  1649. }
  1650. for (var j = 0; j < styles.length; j++)
  1651. {
  1652. var value = style[styles[j]];
  1653. if (value != null)
  1654. {
  1655. graph.setCellStyles(styles[j], value, [targetCell]);
  1656. }
  1657. }
  1658. }
  1659. result.push(targetCell);
  1660. }
  1661. }
  1662. }
  1663. finally
  1664. {
  1665. graph.model.endUpdate();
  1666. }
  1667. return result;
  1668. };
  1669. /**
  1670. * Creates a drop handler for inserting the given cells.
  1671. */
  1672. Sidebar.prototype.createDropHandler = function(cells, allowSplit, allowCellsInserted, bounds)
  1673. {
  1674. allowCellsInserted = (allowCellsInserted != null) ? allowCellsInserted : true;
  1675. return mxUtils.bind(this, function(graph, evt, target, x, y)
  1676. {
  1677. if (graph.isEnabled())
  1678. {
  1679. cells = graph.getImportableCells(cells);
  1680. if (cells.length > 0)
  1681. {
  1682. graph.stopEditing();
  1683. var validDropTarget = (target != null) ? graph.isValidDropTarget(target, cells, evt) : false;
  1684. var select = null;
  1685. if (target != null && !validDropTarget)
  1686. {
  1687. target = null;
  1688. }
  1689. if (!graph.isCellLocked(target || graph.getDefaultParent()))
  1690. {
  1691. graph.model.beginUpdate();
  1692. try
  1693. {
  1694. x = Math.round(x);
  1695. y = Math.round(y);
  1696. // Splits the target edge or inserts into target group
  1697. if (allowSplit && graph.isSplitTarget(target, cells, evt))
  1698. {
  1699. var clones = graph.cloneCells(cells);
  1700. graph.splitEdge(target, clones, null,
  1701. x - bounds.width / 2, y - bounds.height / 2);
  1702. select = clones;
  1703. }
  1704. else if (cells.length > 0)
  1705. {
  1706. select = graph.importCells(cells, x, y, target);
  1707. }
  1708. // Executes parent layout hooks for position/order
  1709. if (graph.layoutManager != null)
  1710. {
  1711. var layout = graph.layoutManager.getLayout(target);
  1712. if (layout != null)
  1713. {
  1714. var s = graph.view.scale;
  1715. var tr = graph.view.translate;
  1716. var tx = (x + tr.x) * s;
  1717. var ty = (y + tr.y) * s;
  1718. for (var i = 0; i < select.length; i++)
  1719. {
  1720. layout.moveCell(select[i], tx, ty);
  1721. }
  1722. }
  1723. }
  1724. if (allowCellsInserted)
  1725. {
  1726. graph.fireEvent(new mxEventObject('cellsInserted', 'cells', select));
  1727. }
  1728. }
  1729. finally
  1730. {
  1731. graph.model.endUpdate();
  1732. }
  1733. if (select != null && select.length > 0)
  1734. {
  1735. graph.scrollCellToVisible(select[0]);
  1736. graph.setSelectionCells(select);
  1737. }
  1738. }
  1739. }
  1740. mxEvent.consume(evt);
  1741. }
  1742. });
  1743. };
  1744. /**
  1745. * Creates and returns a preview element for the given width and height.
  1746. */
  1747. Sidebar.prototype.createDragPreview = function(width, height)
  1748. {
  1749. var elt = document.createElement('div');
  1750. elt.style.border = '1px dashed black';
  1751. elt.style.width = width + 'px';
  1752. elt.style.height = height + 'px';
  1753. return elt;
  1754. };
  1755. /**
  1756. * Creates a drag source for the given element.
  1757. */
  1758. Sidebar.prototype.dropAndConnect = function(source, targets, direction, dropCellIndex)
  1759. {
  1760. var geo = this.getDropAndConnectGeometry(source, targets[dropCellIndex], direction, targets);
  1761. if (geo != null)
  1762. {
  1763. var graph = this.editorUi.editor.graph;
  1764. // Targets without the new edge for selection
  1765. var tmp = [];
  1766. graph.model.beginUpdate();
  1767. try
  1768. {
  1769. var sourceGeo = graph.getCellGeometry(source);
  1770. var geo2 = graph.getCellGeometry(targets[dropCellIndex]);
  1771. // Handles special case where target should be ignored for stack layouts
  1772. var targetParent = graph.model.getParent(source);
  1773. var validLayout = true;
  1774. // Ignores parent if it has a stack layout
  1775. if (graph.layoutManager != null)
  1776. {
  1777. var layout = graph.layoutManager.getLayout(targetParent);
  1778. // LATER: Use parent of parent if valid layout
  1779. if (layout != null && layout.constructor == mxStackLayout)
  1780. {
  1781. validLayout = false;
  1782. var tmp = graph.view.getState(targetParent);
  1783. // Offsets by parent position
  1784. if (tmp != null)
  1785. {
  1786. var offset = new mxPoint((tmp.x / graph.view.scale - graph.view.translate.x),
  1787. (tmp.y / graph.view.scale - graph.view.translate.y));
  1788. geo.x += offset.x;
  1789. geo.y += offset.y;
  1790. var pt = geo.getTerminalPoint(false);
  1791. if (pt != null)
  1792. {
  1793. pt.x += offset.x;
  1794. pt.y += offset.y;
  1795. }
  1796. }
  1797. }
  1798. }
  1799. var dx = geo2.x;
  1800. var dy = geo2.y;
  1801. // Ignores geometry of edges
  1802. if (graph.model.isEdge(targets[dropCellIndex]))
  1803. {
  1804. dx = 0;
  1805. dy = 0;
  1806. }
  1807. var useParent = graph.model.isEdge(source) || (sourceGeo != null && !sourceGeo.relative && validLayout);
  1808. targets = graph.importCells(targets, (geo.x - (useParent ? dx : 0)),
  1809. (geo.y - (useParent ? dy : 0)), (useParent) ? targetParent : null);
  1810. tmp = targets;
  1811. if (graph.model.isEdge(source))
  1812. {
  1813. // Adds new terminal to edge
  1814. // LATER: Push new terminal out radially from edge start point
  1815. graph.model.setTerminal(source, targets[dropCellIndex], direction == mxConstants.DIRECTION_NORTH);
  1816. }
  1817. else if (graph.model.isEdge(targets[dropCellIndex]))
  1818. {
  1819. // Adds new outgoing connection to vertex and clears points
  1820. graph.model.setTerminal(targets[dropCellIndex], source, true);
  1821. var geo3 = graph.getCellGeometry(targets[dropCellIndex]);
  1822. geo3.points = null;
  1823. if (geo3.getTerminalPoint(false) != null)
  1824. {
  1825. geo3.setTerminalPoint(geo.getTerminalPoint(false), false);
  1826. }
  1827. else if (useParent && graph.model.isVertex(targetParent))
  1828. {
  1829. // Adds parent offset to other nodes
  1830. var tmpState = graph.view.getState(targetParent);
  1831. var offset = new mxPoint((tmpState.x / graph.view.scale - graph.view.translate.x),
  1832. (tmpState.y / graph.view.scale - graph.view.translate.y));
  1833. graph.cellsMoved(targets, offset.x, offset.y, null, null, true);
  1834. }
  1835. }
  1836. else
  1837. {
  1838. geo2 = graph.getCellGeometry(targets[dropCellIndex]);
  1839. dx = geo.x - Math.round(geo2.x);
  1840. dy = geo.y - Math.round(geo2.y);
  1841. geo.x = Math.round(geo2.x);
  1842. geo.y = Math.round(geo2.y);
  1843. graph.model.setGeometry(targets[dropCellIndex], geo);
  1844. graph.cellsMoved(targets, dx, dy, null, null, true);
  1845. tmp = targets.slice();
  1846. targets.push(graph.insertEdge(null, null, '', source, targets[dropCellIndex],
  1847. graph.createCurrentEdgeStyle()));
  1848. }
  1849. graph.fireEvent(new mxEventObject('cellsInserted', 'cells', targets));
  1850. }
  1851. finally
  1852. {
  1853. graph.model.endUpdate();
  1854. }
  1855. graph.setSelectionCells(tmp);
  1856. }
  1857. };
  1858. /**
  1859. * Creates a drag source for the given element.
  1860. */
  1861. Sidebar.prototype.getDropAndConnectGeometry = function(source, target, direction, targets)
  1862. {
  1863. var graph = this.editorUi.editor.graph;
  1864. var view = graph.view;
  1865. var keepSize = targets.length > 1;
  1866. var geo = graph.getCellGeometry(source);
  1867. var geo2 = graph.getCellGeometry(target);
  1868. if (geo != null && geo2 != null)
  1869. {
  1870. geo2 = geo2.clone();
  1871. if (graph.model.isEdge(source))
  1872. {
  1873. var state = graph.view.getState(source);
  1874. var pts = state.absolutePoints;
  1875. var p0 = pts[0];
  1876. var pe = pts[pts.length - 1];
  1877. if (direction == mxConstants.DIRECTION_NORTH)
  1878. {
  1879. geo2.x = p0.x / view.scale - view.translate.x - geo2.width / 2;
  1880. geo2.y = p0.y / view.scale - view.translate.y - geo2.height / 2;
  1881. }
  1882. else
  1883. {
  1884. geo2.x = pe.x / view.scale - view.translate.x - geo2.width / 2;
  1885. geo2.y = pe.y / view.scale - view.translate.y - geo2.height / 2;
  1886. }
  1887. }
  1888. else
  1889. {
  1890. if (geo.relative)
  1891. {
  1892. var state = graph.view.getState(source);
  1893. geo = geo.clone();
  1894. geo.x = (state.x - view.translate.x) / view.scale;
  1895. geo.y = (state.y - view.translate.y) / view.scale;
  1896. }
  1897. var length = graph.defaultEdgeLength;
  1898. // Maintains edge length
  1899. if (graph.model.isEdge(target) && geo2.getTerminalPoint(true) != null && geo2.getTerminalPoint(false) != null)
  1900. {
  1901. var p0 = geo2.getTerminalPoint(true);
  1902. var pe = geo2.getTerminalPoint(false);
  1903. var dx = pe.x - p0.x;
  1904. var dy = pe.y - p0.y;
  1905. length = Math.sqrt(dx * dx + dy * dy);
  1906. geo2.x = geo.getCenterX();
  1907. geo2.y = geo.getCenterY();
  1908. geo2.width = 1;
  1909. geo2.height = 1;
  1910. if (direction == mxConstants.DIRECTION_NORTH)
  1911. {
  1912. geo2.height = length
  1913. geo2.y = geo.y - length;
  1914. geo2.setTerminalPoint(new mxPoint(geo2.x, geo2.y), false);
  1915. }
  1916. else if (direction == mxConstants.DIRECTION_EAST)
  1917. {
  1918. geo2.width = length
  1919. geo2.x = geo.x + geo.width;
  1920. geo2.setTerminalPoint(new mxPoint(geo2.x + geo2.width, geo2.y), false);
  1921. }
  1922. else if (direction == mxConstants.DIRECTION_SOUTH)
  1923. {
  1924. geo2.height = length
  1925. geo2.y = geo.y + geo.height;
  1926. geo2.setTerminalPoint(new mxPoint(geo2.x, geo2.y + geo2.height), false);
  1927. }
  1928. else if (direction == mxConstants.DIRECTION_WEST)
  1929. {
  1930. geo2.width = length
  1931. geo2.x = geo.x - length;
  1932. geo2.setTerminalPoint(new mxPoint(geo2.x, geo2.y), false);
  1933. }
  1934. }
  1935. else
  1936. {
  1937. // Try match size or ignore if width or height < 45 which
  1938. // is considered special enough to be ignored here
  1939. if (!keepSize && geo2.width > 45 && geo2.height > 45 &&
  1940. geo.width > 45 && geo.height > 45)
  1941. {
  1942. geo2.width = geo2.width * (geo.height / geo2.height);
  1943. geo2.height = geo.height;
  1944. }
  1945. geo2.x = geo.x + geo.width / 2 - geo2.width / 2;
  1946. geo2.y = geo.y + geo.height / 2 - geo2.height / 2;
  1947. if (direction == mxConstants.DIRECTION_NORTH)
  1948. {
  1949. geo2.y = geo2.y - geo.height / 2 - geo2.height / 2 - length;
  1950. }
  1951. else if (direction == mxConstants.DIRECTION_EAST)
  1952. {
  1953. geo2.x = geo2.x + geo.width / 2 + geo2.width / 2 + length;
  1954. }
  1955. else if (direction == mxConstants.DIRECTION_SOUTH)
  1956. {
  1957. geo2.y = geo2.y + geo.height / 2 + geo2.height / 2 + length;
  1958. }
  1959. else if (direction == mxConstants.DIRECTION_WEST)
  1960. {
  1961. geo2.x = geo2.x - geo.width / 2 - geo2.width / 2 - length;
  1962. }
  1963. // Adds offset to match cells without connecting edge
  1964. if (graph.model.isEdge(target) && geo2.getTerminalPoint(true) != null && target.getTerminal(false) != null)
  1965. {
  1966. var targetGeo = graph.getCellGeometry(target.getTerminal(false));
  1967. if (targetGeo != null)
  1968. {
  1969. if (direction == mxConstants.DIRECTION_NORTH)
  1970. {
  1971. geo2.x -= targetGeo.getCenterX();
  1972. geo2.y -= targetGeo.getCenterY() + targetGeo.height / 2;
  1973. }
  1974. else if (direction == mxConstants.DIRECTION_EAST)
  1975. {
  1976. geo2.x -= targetGeo.getCenterX() - targetGeo.width / 2;
  1977. geo2.y -= targetGeo.getCenterY();
  1978. }
  1979. else if (direction == mxConstants.DIRECTION_SOUTH)
  1980. {
  1981. geo2.x -= targetGeo.getCenterX();
  1982. geo2.y -= targetGeo.getCenterY() - targetGeo.height / 2;
  1983. }
  1984. else if (direction == mxConstants.DIRECTION_WEST)
  1985. {
  1986. geo2.x -= targetGeo.getCenterX() + targetGeo.width / 2;
  1987. geo2.y -= targetGeo.getCenterY();
  1988. }
  1989. }
  1990. }
  1991. }
  1992. }
  1993. }
  1994. return geo2;
  1995. };
  1996. /**
  1997. * Creates a drag source for the given element.
  1998. */
  1999. Sidebar.prototype.createDragSource = function(elt, dropHandler, preview, cells, bounds)
  2000. {
  2001. // Checks if the cells contain any vertices
  2002. var ui = this.editorUi;
  2003. var graph = ui.editor.graph;
  2004. var freeSourceEdge = null;
  2005. var firstVertex = null;
  2006. var sidebar = this;
  2007. for (var i = 0; i < cells.length; i++)
  2008. {
  2009. if (firstVertex == null && this.editorUi.editor.graph.model.isVertex(cells[i]))
  2010. {
  2011. firstVertex = i;
  2012. }
  2013. else if (freeSourceEdge == null && this.editorUi.editor.graph.model.isEdge(cells[i]) &&
  2014. this.editorUi.editor.graph.model.getTerminal(cells[i], true) == null)
  2015. {
  2016. freeSourceEdge = i;
  2017. }
  2018. if (firstVertex != null && freeSourceEdge != null)
  2019. {
  2020. break;
  2021. }
  2022. }
  2023. var dragSource = mxUtils.makeDraggable(elt, this.editorUi.editor.graph, mxUtils.bind(this, function(graph, evt, target, x, y)
  2024. {
  2025. if (this.updateThread != null)
  2026. {
  2027. window.clearTimeout(this.updateThread);
  2028. }
  2029. if (cells != null && currentStyleTarget != null && activeArrow == styleTarget)
  2030. {
  2031. var tmp = graph.isCellSelected(currentStyleTarget.cell) ? graph.getSelectionCells() : [currentStyleTarget.cell];
  2032. var updatedCells = this.updateShapes((graph.model.isEdge(currentStyleTarget.cell)) ? cells[0] : cells[firstVertex], tmp);
  2033. graph.setSelectionCells(updatedCells);
  2034. }
  2035. else if (cells != null && activeArrow != null && currentTargetState != null && activeArrow != styleTarget)
  2036. {
  2037. var index = (graph.model.isEdge(currentTargetState.cell) || freeSourceEdge == null) ? firstVertex : freeSourceEdge;
  2038. this.dropAndConnect(currentTargetState.cell, cells, direction, index);
  2039. }
  2040. else
  2041. {
  2042. dropHandler.apply(this, arguments);
  2043. }
  2044. if (this.editorUi.hoverIcons != null)
  2045. {
  2046. this.editorUi.hoverIcons.update(graph.view.getState(graph.getSelectionCell()));
  2047. }
  2048. }),
  2049. preview, 0, 0, this.editorUi.editor.graph.autoscroll, true, true);
  2050. // Stops dragging if cancel is pressed
  2051. this.editorUi.editor.graph.addListener(mxEvent.ESCAPE, function(sender, evt)
  2052. {
  2053. if (dragSource.isActive())
  2054. {
  2055. dragSource.reset();
  2056. }
  2057. });
  2058. // Overrides mouseDown to ignore popup triggers
  2059. var mouseDown = dragSource.mouseDown;
  2060. dragSource.mouseDown = function(evt)
  2061. {
  2062. if (!mxEvent.isPopupTrigger(evt) && !mxEvent.isMultiTouchEvent(evt))
  2063. {
  2064. graph.stopEditing();
  2065. mouseDown.apply(this, arguments);
  2066. }
  2067. };
  2068. // Workaround for event redirection via image tag in quirks and IE8
  2069. function createArrow(img, tooltip)
  2070. {
  2071. var arrow = null;
  2072. if (mxClient.IS_IE && !mxClient.IS_SVG)
  2073. {
  2074. // Workaround for PNG images in IE6
  2075. if (mxClient.IS_IE6 && document.compatMode != 'CSS1Compat')
  2076. {
  2077. arrow = document.createElement(mxClient.VML_PREFIX + ':image');
  2078. arrow.setAttribute('src', img.src);
  2079. arrow.style.borderStyle = 'none';
  2080. }
  2081. else
  2082. {
  2083. arrow = document.createElement('div');
  2084. arrow.style.backgroundImage = 'url(' + img.src + ')';
  2085. arrow.style.backgroundPosition = 'center';
  2086. arrow.style.backgroundRepeat = 'no-repeat';
  2087. }
  2088. arrow.style.width = (img.width + 4) + 'px';
  2089. arrow.style.height = (img.height + 4) + 'px';
  2090. arrow.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  2091. }
  2092. else
  2093. {
  2094. arrow = mxUtils.createImage(img.src);
  2095. arrow.style.width = img.width + 'px';
  2096. arrow.style.height = img.height + 'px';
  2097. }
  2098. if (tooltip != null)
  2099. {
  2100. arrow.setAttribute('title', tooltip);
  2101. }
  2102. mxUtils.setOpacity(arrow, (img == this.refreshTarget) ? 30 : 20);
  2103. arrow.style.position = 'absolute';
  2104. arrow.style.cursor = 'crosshair';
  2105. return arrow;
  2106. };
  2107. var currentTargetState = null;
  2108. var currentStateHandle = null;
  2109. var currentStyleTarget = null;
  2110. var activeTarget = false;
  2111. var arrowUp = createArrow(this.triangleUp, mxResources.get('connect'));
  2112. var arrowRight = createArrow(this.triangleRight, mxResources.get('connect'));
  2113. var arrowDown = createArrow(this.triangleDown, mxResources.get('connect'));
  2114. var arrowLeft = createArrow(this.triangleLeft, mxResources.get('connect'));
  2115. var styleTarget = createArrow(this.refreshTarget, mxResources.get('replace'));
  2116. // Workaround for actual parentNode not being updated in old IE
  2117. var styleTargetParent = null;
  2118. var roundSource = createArrow(this.roundDrop);
  2119. var roundTarget = createArrow(this.roundDrop);
  2120. var direction = mxConstants.DIRECTION_NORTH;
  2121. var activeArrow = null;
  2122. function checkArrow(x, y, bounds, arrow)
  2123. {
  2124. if (arrow.parentNode != null)
  2125. {
  2126. if (mxUtils.contains(bounds, x, y))
  2127. {
  2128. mxUtils.setOpacity(arrow, 100);
  2129. activeArrow = arrow;
  2130. }
  2131. else
  2132. {
  2133. mxUtils.setOpacity(arrow, (arrow == styleTarget) ? 30 : 20);
  2134. }
  2135. }
  2136. return bounds;
  2137. };
  2138. // Hides guides and preview if target is active
  2139. var dsCreatePreviewElement = dragSource.createPreviewElement;
  2140. // Stores initial size of preview element
  2141. dragSource.createPreviewElement = function(graph)
  2142. {
  2143. var elt = dsCreatePreviewElement.apply(this, arguments);
  2144. // Pass-through events required to tooltip on replace shape
  2145. if (mxClient.IS_SVG)
  2146. {
  2147. elt.style.pointerEvents = 'none';
  2148. }
  2149. this.previewElementWidth = elt.style.width;
  2150. this.previewElementHeight = elt.style.height;
  2151. return elt;
  2152. };
  2153. // Shows/hides hover icons
  2154. var dragEnter = dragSource.dragEnter;
  2155. dragSource.dragEnter = function(graph, evt)
  2156. {
  2157. if (ui.hoverIcons != null)
  2158. {
  2159. ui.hoverIcons.setDisplay('none');
  2160. }
  2161. dragEnter.apply(this, arguments);
  2162. };
  2163. var dragExit = dragSource.dragExit;
  2164. dragSource.dragExit = function(graph, evt)
  2165. {
  2166. if (ui.hoverIcons != null)
  2167. {
  2168. ui.hoverIcons.setDisplay('');
  2169. }
  2170. dragExit.apply(this, arguments);
  2171. };
  2172. dragSource.dragOver = function(graph, evt)
  2173. {
  2174. mxDragSource.prototype.dragOver.apply(this, arguments);
  2175. if (this.currentGuide != null && activeArrow != null)
  2176. {
  2177. this.currentGuide.hide();
  2178. }
  2179. if (this.previewElement != null)
  2180. {
  2181. var view = graph.view;
  2182. if (currentStyleTarget != null && activeArrow == styleTarget)
  2183. {
  2184. this.previewElement.style.display = (graph.model.isEdge(currentStyleTarget.cell)) ? 'none' : '';
  2185. this.previewElement.style.left = currentStyleTarget.x + 'px';
  2186. this.previewElement.style.top = currentStyleTarget.y + 'px';
  2187. this.previewElement.style.width = currentStyleTarget.width + 'px';
  2188. this.previewElement.style.height = currentStyleTarget.height + 'px';
  2189. }
  2190. else if (currentTargetState != null && activeArrow != null)
  2191. {
  2192. var index = (graph.model.isEdge(currentTargetState.cell) || freeSourceEdge == null) ? firstVertex : freeSourceEdge;
  2193. var geo = sidebar.getDropAndConnectGeometry(currentTargetState.cell, cells[index], direction, cells);
  2194. var geo2 = (!graph.model.isEdge(currentTargetState.cell)) ? graph.getCellGeometry(currentTargetState.cell) : null;
  2195. var geo3 = graph.getCellGeometry(cells[index]);
  2196. var parent = graph.model.getParent(currentTargetState.cell);
  2197. var dx = view.translate.x * view.scale;
  2198. var dy = view.translate.y * view.scale;
  2199. if (geo2 != null && !geo2.relative && graph.model.isVertex(parent))
  2200. {
  2201. var pState = view.getState(parent);
  2202. dx = pState.x;
  2203. dy = pState.y;
  2204. }
  2205. var dx2 = geo3.x;
  2206. var dy2 = geo3.y;
  2207. // Ignores geometry of edges
  2208. if (graph.model.isEdge(cells[index]))
  2209. {
  2210. dx2 = 0;
  2211. dy2 = 0;
  2212. }
  2213. // Shows preview at drop location
  2214. this.previewElement.style.left = ((geo.x - dx2) * view.scale + dx) + 'px';
  2215. this.previewElement.style.top = ((geo.y - dy2) * view.scale + dy) + 'px';
  2216. if (cells.length == 1)
  2217. {
  2218. this.previewElement.style.width = (geo.width * view.scale) + 'px';
  2219. this.previewElement.style.height = (geo.height * view.scale) + 'px';
  2220. }
  2221. this.previewElement.style.display = '';
  2222. }
  2223. else if (dragSource.currentHighlight.state != null &&
  2224. graph.model.isEdge(dragSource.currentHighlight.state.cell))
  2225. {
  2226. // Centers drop cells when splitting edges
  2227. this.previewElement.style.left = Math.round(parseInt(this.previewElement.style.left) -
  2228. bounds.width * view.scale / 2) + 'px';
  2229. this.previewElement.style.top = Math.round(parseInt(this.previewElement.style.top) -
  2230. bounds.height * view.scale / 2) + 'px';
  2231. }
  2232. else
  2233. {
  2234. this.previewElement.style.width = this.previewElementWidth;
  2235. this.previewElement.style.height = this.previewElementHeight;
  2236. this.previewElement.style.display = '';
  2237. }
  2238. }
  2239. };
  2240. var startTime = new Date().getTime();
  2241. var timeOnTarget = 0;
  2242. var prev = null;
  2243. // Gets source cell style to compare shape below
  2244. var sourceCellStyle = this.editorUi.editor.graph.getCellStyle(cells[0]);
  2245. // Allows drop into cell only if target is a valid root
  2246. dragSource.getDropTarget = mxUtils.bind(this, function(graph, x, y, evt)
  2247. {
  2248. // Alt means no targets at all
  2249. // LATER: Show preview where result will go
  2250. var cell = (!mxEvent.isAltDown(evt) && cells != null) ? graph.getCellAt(x, y) : null;
  2251. // Uses connectable parent vertex if one exists
  2252. if (cell != null && !this.graph.isCellConnectable(cell))
  2253. {
  2254. var parent = this.graph.getModel().getParent(cell);
  2255. if (this.graph.getModel().isVertex(parent) && this.graph.isCellConnectable(parent))
  2256. {
  2257. cell = parent;
  2258. }
  2259. }
  2260. // Ignores locked cells
  2261. if (graph.isCellLocked(cell))
  2262. {
  2263. cell = null;
  2264. }
  2265. var state = graph.view.getState(cell);
  2266. activeArrow = null;
  2267. var bbox = null;
  2268. // Time on target
  2269. if (prev != state)
  2270. {
  2271. prev = state;
  2272. startTime = new Date().getTime();
  2273. timeOnTarget = 0;
  2274. if (this.updateThread != null)
  2275. {
  2276. window.clearTimeout(this.updateThread);
  2277. }
  2278. if (state != null)
  2279. {
  2280. this.updateThread = window.setTimeout(function()
  2281. {
  2282. if (activeArrow == null)
  2283. {
  2284. prev = state;
  2285. dragSource.getDropTarget(graph, x, y, evt);
  2286. }
  2287. }, this.dropTargetDelay + 10);
  2288. }
  2289. }
  2290. else
  2291. {
  2292. timeOnTarget = new Date().getTime() - startTime;
  2293. }
  2294. // Shift means disabled, delayed on cells with children, shows after this.dropTargetDelay, hides after 2500ms
  2295. if (timeOnTarget < 2500 && state != null && !mxEvent.isShiftDown(evt) &&
  2296. // If shape is equal or target has no stroke then add long delay except for images
  2297. (((mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE) != mxUtils.getValue(sourceCellStyle, mxConstants.STYLE_SHAPE) &&
  2298. mxUtils.getValue(state.style, mxConstants.STYLE_STROKECOLOR, mxConstants.NONE) != mxConstants.NONE) ||
  2299. mxUtils.getValue(sourceCellStyle, mxConstants.STYLE_SHAPE) == 'image') ||
  2300. timeOnTarget > 1500 || graph.model.isEdge(state.cell)) && (timeOnTarget > this.dropTargetDelay) &&
  2301. ((graph.model.isVertex(state.cell) && firstVertex != null) ||
  2302. (graph.model.isEdge(state.cell) && graph.model.isEdge(cells[0]))))
  2303. {
  2304. currentStyleTarget = state;
  2305. var tmp = (graph.model.isEdge(state.cell)) ? graph.view.getPoint(state) :
  2306. new mxPoint(state.getCenterX(), state.getCenterY());
  2307. tmp = new mxRectangle(tmp.x - this.refreshTarget.width / 2, tmp.y - this.refreshTarget.height / 2,
  2308. this.refreshTarget.width, this.refreshTarget.height);
  2309. styleTarget.style.left = Math.floor(tmp.x) + 'px';
  2310. styleTarget.style.top = Math.floor(tmp.y) + 'px';
  2311. if (styleTargetParent == null)
  2312. {
  2313. graph.container.appendChild(styleTarget);
  2314. styleTargetParent = styleTarget.parentNode;
  2315. }
  2316. checkArrow(x, y, tmp, styleTarget);
  2317. }
  2318. // Does not reset on ignored edges
  2319. else if (currentStyleTarget == null || !mxUtils.contains(currentStyleTarget, x, y) ||
  2320. (timeOnTarget > 1500 && !mxEvent.isShiftDown(evt)))
  2321. {
  2322. currentStyleTarget = null;
  2323. if (styleTargetParent != null)
  2324. {
  2325. styleTarget.parentNode.removeChild(styleTarget);
  2326. styleTargetParent = null;
  2327. }
  2328. }
  2329. else if (currentStyleTarget != null && styleTargetParent != null)
  2330. {
  2331. // Sets active Arrow as side effect
  2332. var tmp = (graph.model.isEdge(currentStyleTarget.cell)) ? graph.view.getPoint(currentStyleTarget) : new mxPoint(currentStyleTarget.getCenterX(), currentStyleTarget.getCenterY());
  2333. tmp = new mxRectangle(tmp.x - this.refreshTarget.width / 2, tmp.y - this.refreshTarget.height / 2,
  2334. this.refreshTarget.width, this.refreshTarget.height);
  2335. checkArrow(x, y, tmp, styleTarget);
  2336. }
  2337. // Checks if inside bounds
  2338. if (activeTarget && currentTargetState != null && !mxEvent.isAltDown(evt) && activeArrow == null)
  2339. {
  2340. // LATER: Use hit-detection for edges
  2341. bbox = mxRectangle.fromRectangle(currentTargetState);
  2342. if (graph.model.isEdge(currentTargetState.cell))
  2343. {
  2344. var pts = currentTargetState.absolutePoints;
  2345. if (roundSource.parentNode != null)
  2346. {
  2347. var p0 = pts[0];
  2348. bbox.add(checkArrow(x, y, new mxRectangle(p0.x - this.roundDrop.width / 2,
  2349. p0.y - this.roundDrop.height / 2, this.roundDrop.width, this.roundDrop.height), roundSource));
  2350. }
  2351. if (roundTarget.parentNode != null)
  2352. {
  2353. var pe = pts[pts.length - 1];
  2354. bbox.add(checkArrow(x, y, new mxRectangle(pe.x - this.roundDrop.width / 2,
  2355. pe.y - this.roundDrop.height / 2,
  2356. this.roundDrop.width, this.roundDrop.height), roundTarget));
  2357. }
  2358. }
  2359. else
  2360. {
  2361. var bds = mxRectangle.fromRectangle(currentTargetState);
  2362. // Uses outer bounding box to take rotation into account
  2363. if (currentTargetState.shape != null && currentTargetState.shape.boundingBox != null)
  2364. {
  2365. bds = mxRectangle.fromRectangle(currentTargetState.shape.boundingBox);
  2366. }
  2367. bds.grow(this.graph.tolerance);
  2368. bds.grow(HoverIcons.prototype.arrowSpacing);
  2369. var handler = this.graph.selectionCellsHandler.getHandler(currentTargetState.cell);
  2370. if (handler != null)
  2371. {
  2372. bds.x -= handler.horizontalOffset / 2;
  2373. bds.y -= handler.verticalOffset / 2;
  2374. bds.width += handler.horizontalOffset;
  2375. bds.height += handler.verticalOffset;
  2376. // Adds bounding box of rotation handle to avoid overlap
  2377. if (handler.rotationShape != null && handler.rotationShape.node != null &&
  2378. handler.rotationShape.node.style.visibility != 'hidden' &&
  2379. handler.rotationShape.node.style.display != 'none' &&
  2380. handler.rotationShape.boundingBox != null)
  2381. {
  2382. bds.add(handler.rotationShape.boundingBox);
  2383. }
  2384. }
  2385. bbox.add(checkArrow(x, y, new mxRectangle(currentTargetState.getCenterX() - this.triangleUp.width / 2,
  2386. bds.y - this.triangleUp.height, this.triangleUp.width, this.triangleUp.height), arrowUp));
  2387. bbox.add(checkArrow(x, y, new mxRectangle(bds.x + bds.width,
  2388. currentTargetState.getCenterY() - this.triangleRight.height / 2,
  2389. this.triangleRight.width, this.triangleRight.height), arrowRight));
  2390. bbox.add(checkArrow(x, y, new mxRectangle(currentTargetState.getCenterX() - this.triangleDown.width / 2,
  2391. bds.y + bds.height, this.triangleDown.width, this.triangleDown.height), arrowDown));
  2392. bbox.add(checkArrow(x, y, new mxRectangle(bds.x - this.triangleLeft.width,
  2393. currentTargetState.getCenterY() - this.triangleLeft.height / 2,
  2394. this.triangleLeft.width, this.triangleLeft.height), arrowLeft));
  2395. }
  2396. // Adds tolerance
  2397. if (bbox != null)
  2398. {
  2399. bbox.grow(10);
  2400. }
  2401. }
  2402. direction = mxConstants.DIRECTION_NORTH;
  2403. if (activeArrow == arrowRight)
  2404. {
  2405. direction = mxConstants.DIRECTION_EAST;
  2406. }
  2407. else if (activeArrow == arrowDown || activeArrow == roundTarget)
  2408. {
  2409. direction = mxConstants.DIRECTION_SOUTH;
  2410. }
  2411. else if (activeArrow == arrowLeft)
  2412. {
  2413. direction = mxConstants.DIRECTION_WEST;
  2414. }
  2415. if (currentStyleTarget != null && activeArrow == styleTarget)
  2416. {
  2417. state = currentStyleTarget;
  2418. }
  2419. var validTarget = (firstVertex == null || graph.isCellConnectable(cells[firstVertex])) &&
  2420. ((graph.model.isEdge(cell) && firstVertex != null) ||
  2421. (graph.model.isVertex(cell) && graph.isCellConnectable(cell)));
  2422. // Drop arrows shown after this.dropTargetDelay, hidden after 5 secs, switches arrows after 500ms
  2423. if ((currentTargetState != null && timeOnTarget >= 5000) ||
  2424. (currentTargetState != state &&
  2425. (bbox == null || !mxUtils.contains(bbox, x, y) ||
  2426. (timeOnTarget > 500 && activeArrow == null && validTarget))))
  2427. {
  2428. activeTarget = false;
  2429. currentTargetState = ((timeOnTarget < 5000 && timeOnTarget > this.dropTargetDelay) || graph.model.isEdge(cell)) ? state : null;
  2430. if (currentTargetState != null && validTarget)
  2431. {
  2432. var elts = [roundSource, roundTarget, arrowUp, arrowRight, arrowDown, arrowLeft];
  2433. for (var i = 0; i < elts.length; i++)
  2434. {
  2435. if (elts[i].parentNode != null)
  2436. {
  2437. elts[i].parentNode.removeChild(elts[i]);
  2438. }
  2439. }
  2440. if (graph.model.isEdge(cell))
  2441. {
  2442. var pts = state.absolutePoints;
  2443. if (pts != null)
  2444. {
  2445. var p0 = pts[0];
  2446. var pe = pts[pts.length - 1];
  2447. var tol = graph.tolerance;
  2448. var box = new mxRectangle(x - tol, y - tol, 2 * tol, 2 * tol);
  2449. roundSource.style.left = Math.floor(p0.x - this.roundDrop.width / 2) + 'px';
  2450. roundSource.style.top = Math.floor(p0.y - this.roundDrop.height / 2) + 'px';
  2451. roundTarget.style.left = Math.floor(pe.x - this.roundDrop.width / 2) + 'px';
  2452. roundTarget.style.top = Math.floor(pe.y - this.roundDrop.height / 2) + 'px';
  2453. if (graph.model.getTerminal(cell, true) == null)
  2454. {
  2455. graph.container.appendChild(roundSource);
  2456. }
  2457. if (graph.model.getTerminal(cell, false) == null)
  2458. {
  2459. graph.container.appendChild(roundTarget);
  2460. }
  2461. }
  2462. }
  2463. else
  2464. {
  2465. var bds = mxRectangle.fromRectangle(state);
  2466. // Uses outer bounding box to take rotation into account
  2467. if (state.shape != null && state.shape.boundingBox != null)
  2468. {
  2469. bds = mxRectangle.fromRectangle(state.shape.boundingBox);
  2470. }
  2471. bds.grow(this.graph.tolerance);
  2472. bds.grow(HoverIcons.prototype.arrowSpacing);
  2473. var handler = this.graph.selectionCellsHandler.getHandler(state.cell);
  2474. if (handler != null)
  2475. {
  2476. bds.x -= handler.horizontalOffset / 2;
  2477. bds.y -= handler.verticalOffset / 2;
  2478. bds.width += handler.horizontalOffset;
  2479. bds.height += handler.verticalOffset;
  2480. // Adds bounding box of rotation handle to avoid overlap
  2481. if (handler.rotationShape != null && handler.rotationShape.node != null &&
  2482. handler.rotationShape.node.style.visibility != 'hidden' &&
  2483. handler.rotationShape.node.style.display != 'none' &&
  2484. handler.rotationShape.boundingBox != null)
  2485. {
  2486. bds.add(handler.rotationShape.boundingBox);
  2487. }
  2488. }
  2489. arrowUp.style.left = Math.floor(state.getCenterX() - this.triangleUp.width / 2) + 'px';
  2490. arrowUp.style.top = Math.floor(bds.y - this.triangleUp.height) + 'px';
  2491. arrowRight.style.left = Math.floor(bds.x + bds.width) + 'px';
  2492. arrowRight.style.top = Math.floor(state.getCenterY() - this.triangleRight.height / 2) + 'px';
  2493. arrowDown.style.left = arrowUp.style.left
  2494. arrowDown.style.top = Math.floor(bds.y + bds.height) + 'px';
  2495. arrowLeft.style.left = Math.floor(bds.x - this.triangleLeft.width) + 'px';
  2496. arrowLeft.style.top = arrowRight.style.top;
  2497. if (state.style['portConstraint'] != 'eastwest')
  2498. {
  2499. graph.container.appendChild(arrowUp);
  2500. graph.container.appendChild(arrowDown);
  2501. }
  2502. graph.container.appendChild(arrowRight);
  2503. graph.container.appendChild(arrowLeft);
  2504. }
  2505. // Hides handle for cell under mouse
  2506. if (state != null)
  2507. {
  2508. currentStateHandle = graph.selectionCellsHandler.getHandler(state.cell);
  2509. if (currentStateHandle != null && currentStateHandle.setHandlesVisible != null)
  2510. {
  2511. currentStateHandle.setHandlesVisible(false);
  2512. }
  2513. }
  2514. activeTarget = true;
  2515. }
  2516. else
  2517. {
  2518. var elts = [roundSource, roundTarget, arrowUp, arrowRight, arrowDown, arrowLeft];
  2519. for (var i = 0; i < elts.length; i++)
  2520. {
  2521. if (elts[i].parentNode != null)
  2522. {
  2523. elts[i].parentNode.removeChild(elts[i]);
  2524. }
  2525. }
  2526. }
  2527. }
  2528. if (!activeTarget && currentStateHandle != null)
  2529. {
  2530. currentStateHandle.setHandlesVisible(true);
  2531. }
  2532. // Handles drop target
  2533. var target = ((!mxEvent.isAltDown(evt) || mxEvent.isShiftDown(evt)) &&
  2534. !(currentStyleTarget != null && activeArrow == styleTarget)) ?
  2535. mxDragSource.prototype.getDropTarget.apply(this, arguments) : null;
  2536. var model = graph.getModel();
  2537. if (target != null)
  2538. {
  2539. if (activeArrow != null || !graph.isSplitTarget(target, cells, evt))
  2540. {
  2541. // Selects parent group as drop target
  2542. while (target != null && !graph.isValidDropTarget(target, cells, evt) && model.isVertex(model.getParent(target)))
  2543. {
  2544. target = model.getParent(target);
  2545. }
  2546. if (graph.view.currentRoot == target || (!graph.isValidRoot(target) &&
  2547. graph.getModel().getChildCount(target) == 0) ||
  2548. graph.isCellLocked(target) || model.isEdge(target))
  2549. {
  2550. target = null;
  2551. }
  2552. }
  2553. }
  2554. return target;
  2555. });
  2556. dragSource.stopDrag = function()
  2557. {
  2558. mxDragSource.prototype.stopDrag.apply(this, arguments);
  2559. var elts = [roundSource, roundTarget, styleTarget, arrowUp, arrowRight, arrowDown, arrowLeft];
  2560. for (var i = 0; i < elts.length; i++)
  2561. {
  2562. if (elts[i].parentNode != null)
  2563. {
  2564. elts[i].parentNode.removeChild(elts[i]);
  2565. }
  2566. }
  2567. if (currentTargetState != null && currentStateHandle != null)
  2568. {
  2569. currentStateHandle.reset();
  2570. }
  2571. currentStateHandle = null;
  2572. currentTargetState = null;
  2573. currentStyleTarget = null;
  2574. styleTargetParent = null;
  2575. activeArrow = null;
  2576. };
  2577. return dragSource;
  2578. };
  2579. /**
  2580. * Adds a handler for inserting the cell with a single click.
  2581. */
  2582. Sidebar.prototype.itemClicked = function(cells, ds, evt, elt)
  2583. {
  2584. var graph = this.editorUi.editor.graph;
  2585. // Alt+Click inserts and connects
  2586. if (mxEvent.isAltDown(evt))
  2587. {
  2588. if (graph.getSelectionCount() == 1 && graph.model.isVertex(graph.getSelectionCell()))
  2589. {
  2590. var firstVertex = null;
  2591. for (var i = 0; i < cells.length && firstVertex == null; i++)
  2592. {
  2593. if (graph.model.isVertex(cells[i]))
  2594. {
  2595. firstVertex = i;
  2596. }
  2597. }
  2598. if (firstVertex != null)
  2599. {
  2600. this.dropAndConnect(graph.getSelectionCell(), cells, (mxEvent.isMetaDown(evt) || mxEvent.isControlDown(evt)) ?
  2601. (mxEvent.isShiftDown(evt) ? mxConstants.DIRECTION_WEST : mxConstants.DIRECTION_NORTH) :
  2602. (mxEvent.isShiftDown(evt) ? mxConstants.DIRECTION_EAST : mxConstants.DIRECTION_SOUTH), firstVertex);
  2603. graph.scrollCellToVisible(graph.getSelectionCell());
  2604. }
  2605. }
  2606. }
  2607. // Shift+Click updates shape
  2608. else if (mxEvent.isShiftDown(evt))
  2609. {
  2610. if (!graph.isSelectionEmpty())
  2611. {
  2612. this.updateShapes(cells[0], graph.getSelectionCells());
  2613. graph.scrollCellToVisible(graph.getSelectionCell());
  2614. }
  2615. }
  2616. else
  2617. {
  2618. var pt = graph.getInsertPoint();
  2619. ds.drop(graph, evt, null, pt.x, pt.y);
  2620. if (this.editorUi.hoverIcons != null && mxEvent.isTouchEvent(evt))
  2621. {
  2622. this.editorUi.hoverIcons.update(graph.view.getState(graph.getSelectionCell()));
  2623. }
  2624. }
  2625. };
  2626. /**
  2627. * Adds a handler for inserting the cell with a single click.
  2628. */
  2629. Sidebar.prototype.addClickHandler = function(elt, ds, cells)
  2630. {
  2631. var graph = this.editorUi.editor.graph;
  2632. var oldMouseUp = ds.mouseUp;
  2633. var first = null;
  2634. mxEvent.addGestureListeners(elt, function(evt)
  2635. {
  2636. first = new mxPoint(mxEvent.getClientX(evt), mxEvent.getClientY(evt));
  2637. });
  2638. ds.mouseUp = mxUtils.bind(this, function(evt)
  2639. {
  2640. if (!mxEvent.isPopupTrigger(evt) && this.currentGraph == null && first != null)
  2641. {
  2642. var tol = graph.tolerance;
  2643. if (Math.abs(first.x - mxEvent.getClientX(evt)) <= tol &&
  2644. Math.abs(first.y - mxEvent.getClientY(evt)) <= tol)
  2645. {
  2646. this.itemClicked(cells, ds, evt, elt);
  2647. }
  2648. }
  2649. oldMouseUp.apply(ds, arguments);
  2650. first = null;
  2651. // Blocks tooltips on this element after single click
  2652. this.currentElt = elt;
  2653. });
  2654. };
  2655. /**
  2656. * Creates a drop handler for inserting the given cells.
  2657. */
  2658. Sidebar.prototype.createVertexTemplateEntry = function(style, width, height, value, title, showLabel, showTitle, tags)
  2659. {
  2660. tags = (tags != null && tags.length > 0) ? tags : title.toLowerCase();
  2661. return this.addEntry(tags, mxUtils.bind(this, function()
  2662. {
  2663. return this.createVertexTemplate(style, width, height, value, title, showLabel, showTitle);
  2664. }));
  2665. }
  2666. /**
  2667. * Creates a drop handler for inserting the given cells.
  2668. */
  2669. Sidebar.prototype.createVertexTemplate = function(style, width, height, value, title, showLabel, showTitle, allowCellsInserted)
  2670. {
  2671. var cells = [new mxCell((value != null) ? value : '', new mxGeometry(0, 0, width, height), style)];
  2672. cells[0].vertex = true;
  2673. return this.createVertexTemplateFromCells(cells, width, height, title, showLabel, showTitle, allowCellsInserted);
  2674. };
  2675. /**
  2676. * Creates a drop handler for inserting the given cells.
  2677. */
  2678. Sidebar.prototype.createVertexTemplateFromCells = function(cells, width, height, title, showLabel, showTitle, allowCellsInserted)
  2679. {
  2680. return this.createItem(cells, title, showLabel, showTitle, width, height, allowCellsInserted);
  2681. };
  2682. /**
  2683. *
  2684. */
  2685. Sidebar.prototype.createEdgeTemplateEntry = function(style, width, height, value, title, showLabel, tags, allowCellsInserted)
  2686. {
  2687. tags = (tags != null && tags.length > 0) ? tags : title.toLowerCase();
  2688. return this.addEntry(tags, mxUtils.bind(this, function()
  2689. {
  2690. return this.createEdgeTemplate(style, width, height, value, title, showLabel, allowCellsInserted);
  2691. }));
  2692. };
  2693. /**
  2694. * Creates a drop handler for inserting the given cells.
  2695. */
  2696. Sidebar.prototype.createEdgeTemplate = function(style, width, height, value, title, showLabel, allowCellsInserted)
  2697. {
  2698. var cell = new mxCell((value != null) ? value : '', new mxGeometry(0, 0, width, height), style);
  2699. cell.geometry.setTerminalPoint(new mxPoint(0, height), true);
  2700. cell.geometry.setTerminalPoint(new mxPoint(width, 0), false);
  2701. cell.geometry.relative = true;
  2702. cell.edge = true;
  2703. return this.createEdgeTemplateFromCells([cell], width, height, title, showLabel, allowCellsInserted);
  2704. };
  2705. /**
  2706. * Creates a drop handler for inserting the given cells.
  2707. */
  2708. Sidebar.prototype.createEdgeTemplateFromCells = function(cells, width, height, title, showLabel, allowCellsInserted)
  2709. {
  2710. return this.createItem(cells, title, showLabel, true, width, height, allowCellsInserted);
  2711. };
  2712. /**
  2713. * Adds the given palette.
  2714. */
  2715. Sidebar.prototype.addPaletteFunctions = function(id, title, expanded, fns)
  2716. {
  2717. this.addPalette(id, title, expanded, mxUtils.bind(this, function(content)
  2718. {
  2719. for (var i = 0; i < fns.length; i++)
  2720. {
  2721. content.appendChild(fns[i](content));
  2722. }
  2723. }));
  2724. };
  2725. /**
  2726. * Adds the given palette.
  2727. */
  2728. Sidebar.prototype.addPalette = function(id, title, expanded, onInit)
  2729. {
  2730. var elt = this.createTitle(title);
  2731. this.container.appendChild(elt);
  2732. var div = document.createElement('div');
  2733. div.className = 'geSidebar';
  2734. // Disables built-in pan and zoom in IE10 and later
  2735. if (mxClient.IS_POINTER)
  2736. {
  2737. div.style.touchAction = 'none';
  2738. }
  2739. // Shows tooltip if mouse over background
  2740. mxEvent.addListener(div, 'mousemove', mxUtils.bind(this, function(evt)
  2741. {
  2742. if (mxEvent.getSource(evt) == div)
  2743. {
  2744. div.setAttribute('title', mxResources.get('sidebarTooltip'));
  2745. }
  2746. else
  2747. {
  2748. div.removeAttribute('title');
  2749. }
  2750. }));
  2751. if (expanded)
  2752. {
  2753. onInit(div);
  2754. onInit = null;
  2755. }
  2756. else
  2757. {
  2758. div.style.display = 'none';
  2759. }
  2760. this.addFoldingHandler(elt, div, onInit);
  2761. var outer = document.createElement('div');
  2762. outer.appendChild(div);
  2763. this.container.appendChild(outer);
  2764. // Keeps references to the DOM nodes
  2765. if (id != null)
  2766. {
  2767. this.palettes[id] = [elt, outer];
  2768. }
  2769. return div;
  2770. };
  2771. /**
  2772. * Create the given title element.
  2773. */
  2774. Sidebar.prototype.addFoldingHandler = function(title, content, funct)
  2775. {
  2776. var initialized = false;
  2777. // Avoids mixed content warning in IE6-8
  2778. if (!mxClient.IS_IE || document.documentMode >= 8)
  2779. {
  2780. title.style.backgroundImage = (content.style.display == 'none') ?
  2781. 'url(\'' + this.collapsedImage + '\')' : 'url(\'' + this.expandedImage + '\')';
  2782. }
  2783. title.style.backgroundRepeat = 'no-repeat';
  2784. title.style.backgroundPosition = '0% 50%';
  2785. mxEvent.addListener(title, 'click', mxUtils.bind(this, function(evt)
  2786. {
  2787. if (content.style.display == 'none')
  2788. {
  2789. if (!initialized)
  2790. {
  2791. initialized = true;
  2792. if (funct != null)
  2793. {
  2794. // Wait cursor does not show up on Mac
  2795. title.style.cursor = 'wait';
  2796. var prev = title.innerHTML;
  2797. title.innerHTML = mxResources.get('loading') + '...';
  2798. window.setTimeout(function()
  2799. {
  2800. var fo = mxClient.NO_FO;
  2801. mxClient.NO_FO = Editor.prototype.originalNoForeignObject;
  2802. funct(content);
  2803. mxClient.NO_FO = fo;
  2804. content.style.display = 'block';
  2805. title.style.cursor = '';
  2806. title.innerHTML = prev;
  2807. }, 0);
  2808. }
  2809. else
  2810. {
  2811. content.style.display = 'block';
  2812. }
  2813. }
  2814. else
  2815. {
  2816. content.style.display = 'block';
  2817. }
  2818. title.style.backgroundImage = 'url(\'' + this.expandedImage + '\')';
  2819. }
  2820. else
  2821. {
  2822. title.style.backgroundImage = 'url(\'' + this.collapsedImage + '\')';
  2823. content.style.display = 'none';
  2824. }
  2825. mxEvent.consume(evt);
  2826. }));
  2827. };
  2828. /**
  2829. * Removes the palette for the given ID.
  2830. */
  2831. Sidebar.prototype.removePalette = function(id)
  2832. {
  2833. var elts = this.palettes[id];
  2834. if (elts != null)
  2835. {
  2836. this.palettes[id] = null;
  2837. for (var i = 0; i < elts.length; i++)
  2838. {
  2839. this.container.removeChild(elts[i]);
  2840. }
  2841. return true;
  2842. }
  2843. return false;
  2844. };
  2845. /**
  2846. * Adds the given image palette.
  2847. */
  2848. Sidebar.prototype.addImagePalette = function(id, title, prefix, postfix, items, titles, tags)
  2849. {
  2850. var showTitles = titles != null;
  2851. var fns = [];
  2852. for (var i = 0; i < items.length; i++)
  2853. {
  2854. (mxUtils.bind(this, function(item, title, tmpTags)
  2855. {
  2856. if (tmpTags == null)
  2857. {
  2858. var slash = item.lastIndexOf('/');
  2859. var dot = item.lastIndexOf('.');
  2860. tmpTags = item.substring((slash >= 0) ? slash + 1 : 0, (dot >= 0) ? dot : item.length).replace(/[-_]/g, ' ');
  2861. }
  2862. fns.push(this.createVertexTemplateEntry('image;html=1;labelBackgroundColor=#ffffff;image=' + prefix + item + postfix,
  2863. this.defaultImageWidth, this.defaultImageHeight, '', title, title != null, null, this.filterTags(tmpTags)));
  2864. }))(items[i], (titles != null) ? titles[i] : null, (tags != null) ? tags[items[i]] : null);
  2865. }
  2866. this.addPaletteFunctions(id, title, false, fns);
  2867. };
  2868. /**
  2869. * Creates the array of tags for the given stencil. Duplicates are allowed and will be filtered out later.
  2870. */
  2871. Sidebar.prototype.getTagsForStencil = function(packageName, stencilName, moreTags)
  2872. {
  2873. var tags = packageName.split('.');
  2874. for (var i = 1; i < tags.length; i++)
  2875. {
  2876. tags[i] = tags[i].replace(/_/g, ' ')
  2877. }
  2878. tags.push(stencilName.replace(/_/g, ' '));
  2879. if (moreTags != null)
  2880. {
  2881. tags.push(moreTags);
  2882. }
  2883. return tags.slice(1, tags.length);
  2884. };
  2885. /**
  2886. * Adds the given stencil palette.
  2887. */
  2888. Sidebar.prototype.addStencilPalette = function(id, title, stencilFile, style, ignore, onInit, scale, tags)
  2889. {
  2890. scale = (scale != null) ? scale : 1;
  2891. if (this.addStencilsToIndex)
  2892. {
  2893. // LATER: Handle asynchronous loading dependency
  2894. var fns = [];
  2895. mxStencilRegistry.loadStencilSet(stencilFile, mxUtils.bind(this, function(packageName, stencilName, displayName, w, h)
  2896. {
  2897. if (ignore == null || mxUtils.indexOf(ignore, stencilName) < 0)
  2898. {
  2899. var tmp = this.getTagsForStencil(packageName, stencilName);
  2900. var tmpTags = (tags != null) ? tags[stencilName] : null;
  2901. if (tmpTags != null)
  2902. {
  2903. tmp.push(tmpTags);
  2904. }
  2905. fns.push(this.createVertexTemplateEntry('shape=' + packageName + stencilName.toLowerCase() + style,
  2906. Math.round(w * scale), Math.round(h * scale), '', stencilName.replace(/_/g, ' '), null, null,
  2907. this.filterTags(tmp.join(' '))));
  2908. }
  2909. }), true, true);
  2910. this.addPaletteFunctions(id, title, false, fns);
  2911. }
  2912. else
  2913. {
  2914. this.addPalette(id, title, false, mxUtils.bind(this, function(content)
  2915. {
  2916. if (style == null)
  2917. {
  2918. style = '';
  2919. }
  2920. if (onInit != null)
  2921. {
  2922. onInit.call(this, content);
  2923. }
  2924. mxStencilRegistry.loadStencilSet(stencilFile, mxUtils.bind(this, function(packageName, stencilName, displayName, w, h)
  2925. {
  2926. if (ignore == null || mxUtils.indexOf(ignore, stencilName) < 0)
  2927. {
  2928. content.appendChild(this.createVertexTemplate('shape=' + packageName + stencilName.toLowerCase() + style,
  2929. Math.round(w * scale), Math.round(h * scale), '', stencilName.replace(/_/g, ' '), true));
  2930. }
  2931. }), true);
  2932. }));
  2933. }
  2934. };
  2935. /**
  2936. * Adds the given stencil palette.
  2937. */
  2938. Sidebar.prototype.destroy = function()
  2939. {
  2940. if (this.graph != null)
  2941. {
  2942. if (this.graph.container != null && this.graph.container.parentNode != null)
  2943. {
  2944. this.graph.container.parentNode.removeChild(this.graph.container);
  2945. }
  2946. this.graph.destroy();
  2947. this.graph = null;
  2948. }
  2949. if (this.pointerUpHandler != null)
  2950. {
  2951. mxEvent.removeListener(document, (mxClient.IS_POINTER) ? 'pointerup' : 'mouseup', this.pointerUpHandler);
  2952. this.pointerUpHandler = null;
  2953. }
  2954. if (this.pointerDownHandler != null)
  2955. {
  2956. mxEvent.removeListener(document, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown', this.pointerDownHandler);
  2957. this.pointerDownHandler = null;
  2958. }
  2959. if (this.pointerMoveHandler != null)
  2960. {
  2961. mxEvent.removeListener(document, (mxClient.IS_POINTER) ? 'pointermove' : 'mousemove', this.pointerMoveHandler);
  2962. this.pointerMoveHandler = null;
  2963. }
  2964. if (this.pointerOutHandler != null)
  2965. {
  2966. mxEvent.removeListener(document, (mxClient.IS_POINTER) ? 'pointerout' : 'mouseout', this.pointerOutHandler);
  2967. this.pointerOutHandler = null;
  2968. }
  2969. };