Sidebar.js 131 KB

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