Sidebar.js 130 KB

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