Sidebar.js 138 KB

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