Sidebar.js 132 KB

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