Sidebar.js 130 KB

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