Sidebar.js 134 KB

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