Sidebar.js 133 KB

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