Format.js 152 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211
  1. /**
  2. * Copyright (c) 2006-2012, JGraph Ltd
  3. */
  4. Format = function(editorUi, container)
  5. {
  6. this.editorUi = editorUi;
  7. this.container = container;
  8. };
  9. /**
  10. * Returns information about the current selection.
  11. */
  12. Format.prototype.labelIndex = 0;
  13. /**
  14. * Returns information about the current selection.
  15. */
  16. Format.prototype.currentIndex = 0;
  17. /**
  18. * Returns information about the current selection.
  19. */
  20. Format.prototype.showCloseButton = true;
  21. /**
  22. * Background color for inactive tabs.
  23. */
  24. Format.prototype.inactiveTabBackgroundColor = '#d7d7d7';
  25. /**
  26. * Adds the label menu items to the given menu and parent.
  27. */
  28. Format.prototype.init = function()
  29. {
  30. var ui = this.editorUi;
  31. var editor = ui.editor;
  32. var graph = editor.graph;
  33. this.update = mxUtils.bind(this, function(sender, evt)
  34. {
  35. this.clearSelectionState();
  36. this.refresh();
  37. });
  38. graph.getSelectionModel().addListener(mxEvent.CHANGE, this.update);
  39. graph.addListener(mxEvent.EDITING_STARTED, this.update);
  40. graph.addListener(mxEvent.EDITING_STOPPED, this.update);
  41. graph.getModel().addListener(mxEvent.CHANGE, this.update);
  42. graph.addListener(mxEvent.ROOT, mxUtils.bind(this, function()
  43. {
  44. this.refresh();
  45. }));
  46. this.refresh();
  47. };
  48. /**
  49. * Returns information about the current selection.
  50. */
  51. Format.prototype.clearSelectionState = function()
  52. {
  53. this.selectionState = null;
  54. };
  55. /**
  56. * Returns information about the current selection.
  57. */
  58. Format.prototype.getSelectionState = function()
  59. {
  60. if (this.selectionState == null)
  61. {
  62. this.selectionState = this.createSelectionState();
  63. }
  64. return this.selectionState;
  65. };
  66. /**
  67. * Returns information about the current selection.
  68. */
  69. Format.prototype.createSelectionState = function()
  70. {
  71. var cells = this.editorUi.editor.graph.getSelectionCells();
  72. var result = this.initSelectionState();
  73. for (var i = 0; i < cells.length; i++)
  74. {
  75. this.updateSelectionStateForCell(result, cells[i], cells);
  76. }
  77. return result;
  78. };
  79. /**
  80. * Returns information about the current selection.
  81. */
  82. Format.prototype.initSelectionState = function()
  83. {
  84. return {vertices: [], edges: [], x: null, y: null, width: null, height: null, style: {},
  85. containsImage: false, containsLabel: false, fill: true, glass: true, rounded: true,
  86. comic: true, autoSize: false, image: true, shadow: true, lineJumps: true};
  87. };
  88. /**
  89. * Returns information about the current selection.
  90. */
  91. Format.prototype.updateSelectionStateForCell = function(result, cell, cells)
  92. {
  93. var graph = this.editorUi.editor.graph;
  94. if (graph.getModel().isVertex(cell))
  95. {
  96. result.vertices.push(cell);
  97. var geo = graph.getCellGeometry(cell);
  98. if (geo != null)
  99. {
  100. if (geo.width > 0)
  101. {
  102. if (result.width == null)
  103. {
  104. result.width = geo.width;
  105. }
  106. else if (result.width != geo.width)
  107. {
  108. result.width = '';
  109. }
  110. }
  111. else
  112. {
  113. result.containsLabel = true;
  114. }
  115. if (geo.height > 0)
  116. {
  117. if (result.height == null)
  118. {
  119. result.height = geo.height;
  120. }
  121. else if (result.height != geo.height)
  122. {
  123. result.height = '';
  124. }
  125. }
  126. else
  127. {
  128. result.containsLabel = true;
  129. }
  130. if (!geo.relative || geo.offset != null)
  131. {
  132. var x = (geo.relative) ? geo.offset.x : geo.x;
  133. var y = (geo.relative) ? geo.offset.y : geo.y;
  134. if (result.x == null)
  135. {
  136. result.x = x;
  137. }
  138. else if (result.x != x)
  139. {
  140. result.x = '';
  141. }
  142. if (result.y == null)
  143. {
  144. result.y = y;
  145. }
  146. else if (result.y != y)
  147. {
  148. result.y = '';
  149. }
  150. }
  151. }
  152. }
  153. else if (graph.getModel().isEdge(cell))
  154. {
  155. result.edges.push(cell);
  156. }
  157. var state = graph.view.getState(cell);
  158. if (state != null)
  159. {
  160. result.autoSize = result.autoSize || this.isAutoSizeState(state);
  161. result.glass = result.glass && this.isGlassState(state);
  162. result.rounded = result.rounded && this.isRoundedState(state);
  163. result.lineJumps = result.lineJumps && this.isLineJumpState(state);
  164. result.comic = result.comic && this.isComicState(state);
  165. result.image = result.image && this.isImageState(state);
  166. result.shadow = result.shadow && this.isShadowState(state);
  167. result.fill = result.fill && this.isFillState(state);
  168. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  169. result.containsImage = result.containsImage || shape == 'image';
  170. for (var key in state.style)
  171. {
  172. var value = state.style[key];
  173. if (value != null)
  174. {
  175. if (result.style[key] == null)
  176. {
  177. result.style[key] = value;
  178. }
  179. else if (result.style[key] != value)
  180. {
  181. result.style[key] = '';
  182. }
  183. }
  184. }
  185. }
  186. };
  187. /**
  188. * Returns information about the current selection.
  189. */
  190. Format.prototype.isFillState = function(state)
  191. {
  192. return state.view.graph.model.isVertex(state.cell) ||
  193. mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null) == 'arrow' ||
  194. mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null) == 'filledEdge' ||
  195. mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null) == 'flexArrow';
  196. };
  197. /**
  198. * Returns information about the current selection.
  199. */
  200. Format.prototype.isGlassState = function(state)
  201. {
  202. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  203. return (shape == 'label' || shape == 'rectangle' || shape == 'internalStorage' ||
  204. shape == 'ext' || shape == 'umlLifeline' || shape == 'swimlane' ||
  205. shape == 'process');
  206. };
  207. /**
  208. * Returns information about the current selection.
  209. */
  210. Format.prototype.isRoundedState = function(state)
  211. {
  212. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  213. return (shape == 'label' || shape == 'rectangle' || shape == 'internalStorage' || shape == 'corner' ||
  214. shape == 'parallelogram' || shape == 'swimlane' || shape == 'triangle' || shape == 'trapezoid' ||
  215. shape == 'ext' || shape == 'step' || shape == 'tee' || shape == 'process' || shape == 'link' ||
  216. shape == 'rhombus' || shape == 'offPageConnector' || shape == 'loopLimit' || shape == 'hexagon' ||
  217. shape == 'manualInput' || shape == 'curlyBracket' || shape == 'singleArrow' || shape == 'callout' ||
  218. shape == 'doubleArrow' || shape == 'flexArrow' || shape == 'card' || shape == 'umlLifeline');
  219. };
  220. /**
  221. * Returns information about the current selection.
  222. */
  223. Format.prototype.isLineJumpState = function(state)
  224. {
  225. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  226. return shape == 'connector' || shape == 'filledEdge';
  227. };
  228. /**
  229. * Returns information about the current selection.
  230. */
  231. Format.prototype.isComicState = function(state)
  232. {
  233. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  234. return mxUtils.indexOf(['label', 'rectangle', 'internalStorage', 'corner', 'parallelogram', 'note', 'collate',
  235. 'swimlane', 'triangle', 'trapezoid', 'ext', 'step', 'tee', 'process', 'link', 'rhombus',
  236. 'offPageConnector', 'loopLimit', 'hexagon', 'manualInput', 'singleArrow', 'doubleArrow',
  237. 'flexArrow', 'filledEdge', 'card', 'umlLifeline', 'connector', 'folder', 'component', 'sortShape',
  238. 'cross', 'umlFrame', 'cube', 'isoCube', 'isoRectangle', 'partialRectangle'], shape) >= 0;
  239. };
  240. /**
  241. * Returns information about the current selection.
  242. */
  243. Format.prototype.isAutoSizeState = function(state)
  244. {
  245. return mxUtils.getValue(state.style, mxConstants.STYLE_AUTOSIZE, null) == '1';
  246. };
  247. /**
  248. * Returns information about the current selection.
  249. */
  250. Format.prototype.isImageState = function(state)
  251. {
  252. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  253. return (shape == 'label' || shape == 'image');
  254. };
  255. /**
  256. * Returns information about the current selection.
  257. */
  258. Format.prototype.isShadowState = function(state)
  259. {
  260. var shape = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  261. return (shape != 'image');
  262. };
  263. /**
  264. * Adds the label menu items to the given menu and parent.
  265. */
  266. Format.prototype.clear = function()
  267. {
  268. this.container.innerHTML = '';
  269. // Destroy existing panels
  270. if (this.panels != null)
  271. {
  272. for (var i = 0; i < this.panels.length; i++)
  273. {
  274. this.panels[i].destroy();
  275. }
  276. }
  277. this.panels = [];
  278. };
  279. /**
  280. * Adds the label menu items to the given menu and parent.
  281. */
  282. Format.prototype.refresh = function()
  283. {
  284. // Performance tweak: No refresh needed if not visible
  285. if (this.container.style.width == '0px')
  286. {
  287. return;
  288. }
  289. this.clear();
  290. var ui = this.editorUi;
  291. var graph = ui.editor.graph;
  292. var div = document.createElement('div');
  293. div.style.whiteSpace = 'nowrap';
  294. div.style.color = 'rgb(112, 112, 112)';
  295. div.style.textAlign = 'left';
  296. div.style.cursor = 'default';
  297. var label = document.createElement('div');
  298. label.style.border = '1px solid #c0c0c0';
  299. label.style.borderWidth = '0px 0px 1px 0px';
  300. label.style.textAlign = 'center';
  301. label.style.fontWeight = 'bold';
  302. label.style.overflow = 'hidden';
  303. label.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  304. label.style.paddingTop = '8px';
  305. label.style.height = (mxClient.IS_QUIRKS) ? '34px' : '25px';
  306. label.style.width = '100%';
  307. this.container.appendChild(div);
  308. if (graph.isSelectionEmpty())
  309. {
  310. mxUtils.write(label, mxResources.get('diagram'));
  311. // Adds button to hide the format panel since
  312. // people don't seem to find the toolbar button
  313. // and the menu item in the format menu
  314. if (this.showCloseButton)
  315. {
  316. var img = document.createElement('img');
  317. img.setAttribute('border', '0');
  318. img.setAttribute('src', Dialog.prototype.closeImage);
  319. img.setAttribute('title', mxResources.get('hide'));
  320. img.style.position = 'absolute';
  321. img.style.display = 'block';
  322. img.style.right = '0px';
  323. img.style.top = '8px';
  324. img.style.cursor = 'pointer';
  325. img.style.marginTop = '1px';
  326. img.style.marginRight = '17px';
  327. img.style.border = '1px solid transparent';
  328. img.style.padding = '1px';
  329. img.style.opacity = 0.5;
  330. label.appendChild(img)
  331. mxEvent.addListener(img, 'click', function()
  332. {
  333. ui.actions.get('formatPanel').funct();
  334. });
  335. }
  336. div.appendChild(label);
  337. this.panels.push(new DiagramFormatPanel(this, ui, div));
  338. }
  339. else if (graph.isEditing())
  340. {
  341. mxUtils.write(label, mxResources.get('text'));
  342. div.appendChild(label);
  343. this.panels.push(new TextFormatPanel(this, ui, div));
  344. }
  345. else
  346. {
  347. var containsLabel = this.getSelectionState().containsLabel;
  348. var currentLabel = null;
  349. var currentPanel = null;
  350. var addClickHandler = mxUtils.bind(this, function(elt, panel, index)
  351. {
  352. var clickHandler = mxUtils.bind(this, function(evt)
  353. {
  354. if (currentLabel != elt)
  355. {
  356. if (containsLabel)
  357. {
  358. this.labelIndex = index;
  359. }
  360. else
  361. {
  362. this.currentIndex = index;
  363. }
  364. if (currentLabel != null)
  365. {
  366. currentLabel.style.backgroundColor = this.inactiveTabBackgroundColor;
  367. currentLabel.style.borderBottomWidth = '1px';
  368. }
  369. currentLabel = elt;
  370. currentLabel.style.backgroundColor = '';
  371. currentLabel.style.borderBottomWidth = '0px';
  372. if (currentPanel != panel)
  373. {
  374. if (currentPanel != null)
  375. {
  376. currentPanel.style.display = 'none';
  377. }
  378. currentPanel = panel;
  379. currentPanel.style.display = '';
  380. }
  381. }
  382. });
  383. mxEvent.addListener(elt, 'click', clickHandler);
  384. if (index == ((containsLabel) ? this.labelIndex : this.currentIndex))
  385. {
  386. // Invokes handler directly as a workaround for no click on DIV in KHTML.
  387. clickHandler();
  388. }
  389. });
  390. var idx = 0;
  391. label.style.backgroundColor = this.inactiveTabBackgroundColor;
  392. label.style.borderLeftWidth = '1px';
  393. label.style.width = (containsLabel) ? '50%' : '33.3%';
  394. label.style.width = (containsLabel) ? '50%' : '33.3%';
  395. var label2 = label.cloneNode(false);
  396. var label3 = label2.cloneNode(false);
  397. // Workaround for ignored background in IE
  398. label2.style.backgroundColor = this.inactiveTabBackgroundColor;
  399. label3.style.backgroundColor = this.inactiveTabBackgroundColor;
  400. // Style
  401. if (containsLabel)
  402. {
  403. label2.style.borderLeftWidth = '0px';
  404. }
  405. else
  406. {
  407. label.style.borderLeftWidth = '0px';
  408. mxUtils.write(label, mxResources.get('style'));
  409. div.appendChild(label);
  410. var stylePanel = div.cloneNode(false);
  411. stylePanel.style.display = 'none';
  412. this.panels.push(new StyleFormatPanel(this, ui, stylePanel));
  413. this.container.appendChild(stylePanel);
  414. addClickHandler(label, stylePanel, idx++);
  415. }
  416. // Text
  417. mxUtils.write(label2, mxResources.get('text'));
  418. div.appendChild(label2);
  419. var textPanel = div.cloneNode(false);
  420. textPanel.style.display = 'none';
  421. this.panels.push(new TextFormatPanel(this, ui, textPanel));
  422. this.container.appendChild(textPanel);
  423. // Arrange
  424. mxUtils.write(label3, mxResources.get('arrange'));
  425. div.appendChild(label3);
  426. var arrangePanel = div.cloneNode(false);
  427. arrangePanel.style.display = 'none';
  428. this.panels.push(new ArrangePanel(this, ui, arrangePanel));
  429. this.container.appendChild(arrangePanel);
  430. addClickHandler(label2, textPanel, idx++);
  431. addClickHandler(label3, arrangePanel, idx++);
  432. }
  433. };
  434. /**
  435. * Base class for format panels.
  436. */
  437. BaseFormatPanel = function(format, editorUi, container)
  438. {
  439. this.format = format;
  440. this.editorUi = editorUi;
  441. this.container = container;
  442. this.listeners = [];
  443. };
  444. /**
  445. * Adds the given color option.
  446. */
  447. BaseFormatPanel.prototype.getSelectionState = function()
  448. {
  449. var graph = this.editorUi.editor.graph;
  450. var cells = graph.getSelectionCells();
  451. var shape = null;
  452. for (var i = 0; i < cells.length; i++)
  453. {
  454. var state = graph.view.getState(cells[i]);
  455. if (state != null)
  456. {
  457. var tmp = mxUtils.getValue(state.style, mxConstants.STYLE_SHAPE, null);
  458. if (tmp != null)
  459. {
  460. if (shape == null)
  461. {
  462. shape = tmp;
  463. }
  464. else if (shape != tmp)
  465. {
  466. return null;
  467. }
  468. }
  469. }
  470. }
  471. return shape;
  472. };
  473. /**
  474. * Install input handler.
  475. */
  476. BaseFormatPanel.prototype.installInputHandler = function(input, key, defaultValue, min, max, unit, textEditFallback, isFloat)
  477. {
  478. unit = (unit != null) ? unit : '';
  479. isFloat = (isFloat != null) ? isFloat : false;
  480. var ui = this.editorUi;
  481. var graph = ui.editor.graph;
  482. min = (min != null) ? min : 1;
  483. max = (max != null) ? max : 999;
  484. var selState = null;
  485. var updating = false;
  486. var update = mxUtils.bind(this, function(evt)
  487. {
  488. var value = (isFloat) ? parseFloat(input.value) : parseInt(input.value);
  489. // Special case: angle mod 360
  490. if (!isNaN(value) && key == mxConstants.STYLE_ROTATION)
  491. {
  492. // Workaround for decimal rounding errors in floats is to
  493. // use integer and round all numbers to two decimal point
  494. value = mxUtils.mod(Math.round(value * 100), 36000) / 100;
  495. }
  496. value = Math.min(max, Math.max(min, (isNaN(value)) ? defaultValue : value));
  497. if (graph.cellEditor.isContentEditing() && textEditFallback)
  498. {
  499. if (!updating)
  500. {
  501. updating = true;
  502. if (selState != null)
  503. {
  504. graph.cellEditor.restoreSelection(selState);
  505. selState = null;
  506. }
  507. textEditFallback(value);
  508. input.value = value + unit;
  509. // Restore focus and selection in input
  510. updating = false;
  511. }
  512. }
  513. else if (value != mxUtils.getValue(this.format.getSelectionState().style, key, defaultValue))
  514. {
  515. if (graph.isEditing())
  516. {
  517. graph.stopEditing(true);
  518. }
  519. graph.getModel().beginUpdate();
  520. try
  521. {
  522. graph.setCellStyles(key, value, graph.getSelectionCells());
  523. // Handles special case for fontSize where HTML labels are parsed and updated
  524. if (key == mxConstants.STYLE_FONTSIZE)
  525. {
  526. var cells = graph.getSelectionCells();
  527. for (var i = 0; i < cells.length; i++)
  528. {
  529. var cell = cells[i];
  530. // Changes font tags inside HTML labels
  531. if (graph.isHtmlLabel(cell))
  532. {
  533. var div = document.createElement('div');
  534. div.innerHTML = graph.convertValueToString(cell);
  535. var elts = div.getElementsByTagName('font');
  536. for (var j = 0; j < elts.length; j++)
  537. {
  538. elts[j].removeAttribute('size');
  539. elts[j].style.fontSize = value + 'px';
  540. }
  541. graph.cellLabelChanged(cell, div.innerHTML)
  542. }
  543. }
  544. }
  545. }
  546. finally
  547. {
  548. graph.getModel().endUpdate();
  549. }
  550. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [key],
  551. 'values', [value], 'cells', graph.getSelectionCells()));
  552. }
  553. input.value = value + unit;
  554. mxEvent.consume(evt);
  555. });
  556. if (textEditFallback && graph.cellEditor.isContentEditing())
  557. {
  558. // KNOWN: Arrow up/down clear selection text in quirks/IE 8
  559. // Text size via arrow button limits to 16 in IE11. Why?
  560. mxEvent.addListener(input, 'mousedown', function()
  561. {
  562. if (document.activeElement == graph.cellEditor.textarea)
  563. {
  564. selState = graph.cellEditor.saveSelection();
  565. }
  566. });
  567. mxEvent.addListener(input, 'touchstart', function()
  568. {
  569. if (document.activeElement == graph.cellEditor.textarea)
  570. {
  571. selState = graph.cellEditor.saveSelection();
  572. }
  573. });
  574. }
  575. mxEvent.addListener(input, 'change', update);
  576. mxEvent.addListener(input, 'blur', update);
  577. return update;
  578. };
  579. /**
  580. * Adds the given option.
  581. */
  582. BaseFormatPanel.prototype.createPanel = function()
  583. {
  584. var div = document.createElement('div');
  585. div.style.padding = '12px 0px 12px 18px';
  586. div.style.borderBottom = '1px solid #c0c0c0';
  587. return div;
  588. };
  589. /**
  590. * Adds the given option.
  591. */
  592. BaseFormatPanel.prototype.createTitle = function(title)
  593. {
  594. var div = document.createElement('div');
  595. div.style.padding = '0px 0px 6px 0px';
  596. div.style.whiteSpace = 'nowrap';
  597. div.style.overflow = 'hidden';
  598. div.style.width = '200px';
  599. div.style.fontWeight = 'bold';
  600. mxUtils.write(div, title);
  601. return div;
  602. };
  603. /**
  604. *
  605. */
  606. BaseFormatPanel.prototype.createStepper = function(input, update, step, height, disableFocus, defaultValue)
  607. {
  608. step = (step != null) ? step : 1;
  609. height = (height != null) ? height : 8;
  610. if (mxClient.IS_QUIRKS)
  611. {
  612. height = height - 2;
  613. }
  614. else if (mxClient.IS_MT || document.documentMode >= 8)
  615. {
  616. height = height + 1;
  617. }
  618. var stepper = document.createElement('div');
  619. mxUtils.setPrefixedStyle(stepper.style, 'borderRadius', '3px');
  620. stepper.style.border = '1px solid rgb(192, 192, 192)';
  621. stepper.style.position = 'absolute';
  622. var up = document.createElement('div');
  623. up.style.borderBottom = '1px solid rgb(192, 192, 192)';
  624. up.style.position = 'relative';
  625. up.style.height = height + 'px';
  626. up.style.width = '10px';
  627. up.className = 'geBtnUp';
  628. stepper.appendChild(up);
  629. var down = up.cloneNode(false);
  630. down.style.border = 'none';
  631. down.style.height = height + 'px';
  632. down.className = 'geBtnDown';
  633. stepper.appendChild(down);
  634. mxEvent.addListener(down, 'click', function(evt)
  635. {
  636. if (input.value == '')
  637. {
  638. input.value = defaultValue || '2';
  639. }
  640. var val = parseInt(input.value);
  641. if (!isNaN(val))
  642. {
  643. input.value = val - step;
  644. if (update != null)
  645. {
  646. update(evt);
  647. }
  648. }
  649. mxEvent.consume(evt);
  650. });
  651. mxEvent.addListener(up, 'click', function(evt)
  652. {
  653. if (input.value == '')
  654. {
  655. input.value = defaultValue || '0';
  656. }
  657. var val = parseInt(input.value);
  658. if (!isNaN(val))
  659. {
  660. input.value = val + step;
  661. if (update != null)
  662. {
  663. update(evt);
  664. }
  665. }
  666. mxEvent.consume(evt);
  667. });
  668. // Disables transfer of focus to DIV but also :active CSS
  669. // so it's only used for fontSize where the focus should
  670. // stay on the selected text, but not for any other input.
  671. if (disableFocus)
  672. {
  673. var currentSelection = null;
  674. mxEvent.addGestureListeners(stepper,
  675. function(evt)
  676. {
  677. // Workaround for lost current selection in page because of focus in IE
  678. if (mxClient.IS_QUIRKS || document.documentMode == 8)
  679. {
  680. currentSelection = document.selection.createRange();
  681. }
  682. mxEvent.consume(evt);
  683. },
  684. null,
  685. function(evt)
  686. {
  687. // Workaround for lost current selection in page because of focus in IE
  688. if (currentSelection != null)
  689. {
  690. try
  691. {
  692. currentSelection.select();
  693. }
  694. catch (e)
  695. {
  696. // ignore
  697. }
  698. currentSelection = null;
  699. mxEvent.consume(evt);
  700. }
  701. }
  702. );
  703. }
  704. return stepper;
  705. };
  706. /**
  707. * Adds the given option.
  708. */
  709. BaseFormatPanel.prototype.createOption = function(label, isCheckedFn, setCheckedFn, listener)
  710. {
  711. var div = document.createElement('div');
  712. div.style.padding = '6px 0px 1px 0px';
  713. div.style.whiteSpace = 'nowrap';
  714. div.style.overflow = 'hidden';
  715. div.style.width = '200px';
  716. div.style.height = (mxClient.IS_QUIRKS) ? '27px' : '18px';
  717. var cb = document.createElement('input');
  718. cb.setAttribute('type', 'checkbox');
  719. cb.style.margin = '0px 6px 0px 0px';
  720. div.appendChild(cb);
  721. var span = document.createElement('span');
  722. mxUtils.write(span, label);
  723. div.appendChild(span);
  724. var applying = false;
  725. var value = isCheckedFn();
  726. var apply = function(newValue)
  727. {
  728. if (!applying)
  729. {
  730. applying = true;
  731. if (newValue)
  732. {
  733. cb.setAttribute('checked', 'checked');
  734. cb.defaultChecked = true;
  735. cb.checked = true;
  736. }
  737. else
  738. {
  739. cb.removeAttribute('checked');
  740. cb.defaultChecked = false;
  741. cb.checked = false;
  742. }
  743. if (value != newValue)
  744. {
  745. value = newValue;
  746. // Checks if the color value needs to be updated in the model
  747. if (isCheckedFn() != value)
  748. {
  749. setCheckedFn(value);
  750. }
  751. }
  752. applying = false;
  753. }
  754. };
  755. mxEvent.addListener(div, 'click', function(evt)
  756. {
  757. // Toggles checkbox state for click on label
  758. var source = mxEvent.getSource(evt);
  759. if (source == div || source == span)
  760. {
  761. cb.checked = !cb.checked;
  762. }
  763. apply(cb.checked);
  764. });
  765. apply(value);
  766. if (listener != null)
  767. {
  768. listener.install(apply);
  769. this.listeners.push(listener);
  770. }
  771. return div;
  772. };
  773. /**
  774. * The string 'null' means use null in values.
  775. */
  776. BaseFormatPanel.prototype.createCellOption = function(label, key, defaultValue, enabledValue, disabledValue, fn, action, stopEditing)
  777. {
  778. enabledValue = (enabledValue != null) ? ((enabledValue == 'null') ? null : enabledValue) : '1';
  779. disabledValue = (disabledValue != null) ? ((disabledValue == 'null') ? null : disabledValue) : '0';
  780. var ui = this.editorUi;
  781. var editor = ui.editor;
  782. var graph = editor.graph;
  783. return this.createOption(label, function()
  784. {
  785. // Seems to be null sometimes, not sure why...
  786. var state = graph.view.getState(graph.getSelectionCell());
  787. if (state != null)
  788. {
  789. return mxUtils.getValue(state.style, key, defaultValue) != disabledValue;
  790. }
  791. return null;
  792. }, function(checked)
  793. {
  794. if (stopEditing)
  795. {
  796. graph.stopEditing();
  797. }
  798. if (action != null)
  799. {
  800. action.funct();
  801. }
  802. else
  803. {
  804. graph.getModel().beginUpdate();
  805. try
  806. {
  807. var value = (checked) ? enabledValue : disabledValue;
  808. graph.setCellStyles(key, value, graph.getSelectionCells());
  809. if (fn != null)
  810. {
  811. fn(graph.getSelectionCells(), value);
  812. }
  813. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [key],
  814. 'values', [value], 'cells', graph.getSelectionCells()));
  815. }
  816. finally
  817. {
  818. graph.getModel().endUpdate();
  819. }
  820. }
  821. },
  822. {
  823. install: function(apply)
  824. {
  825. this.listener = function()
  826. {
  827. // Seems to be null sometimes, not sure why...
  828. var state = graph.view.getState(graph.getSelectionCell());
  829. if (state != null)
  830. {
  831. apply(mxUtils.getValue(state.style, key, defaultValue) != disabledValue);
  832. }
  833. };
  834. graph.getModel().addListener(mxEvent.CHANGE, this.listener);
  835. },
  836. destroy: function()
  837. {
  838. graph.getModel().removeListener(this.listener);
  839. }
  840. });
  841. };
  842. /**
  843. * Adds the given color option.
  844. */
  845. BaseFormatPanel.prototype.createColorOption = function(label, getColorFn, setColorFn, defaultColor, listener, callbackFn, hideCheckbox)
  846. {
  847. var div = document.createElement('div');
  848. div.style.padding = '6px 0px 1px 0px';
  849. div.style.whiteSpace = 'nowrap';
  850. div.style.overflow = 'hidden';
  851. div.style.width = '200px';
  852. div.style.height = (mxClient.IS_QUIRKS) ? '27px' : '18px';
  853. var cb = document.createElement('input');
  854. cb.setAttribute('type', 'checkbox');
  855. cb.style.margin = '0px 6px 0px 0px';
  856. if (!hideCheckbox)
  857. {
  858. div.appendChild(cb);
  859. }
  860. var span = document.createElement('span');
  861. mxUtils.write(span, label);
  862. div.appendChild(span);
  863. var applying = false;
  864. var value = getColorFn();
  865. var btn = null;
  866. var apply = function(color, disableUpdate)
  867. {
  868. if (!applying)
  869. {
  870. applying = true;
  871. btn.innerHTML = '<div style="width:' + ((mxClient.IS_QUIRKS) ? '30' : '36') +
  872. 'px;height:12px;margin:3px;border:1px solid black;background-color:' +
  873. ((color != null && color != mxConstants.NONE) ? color : defaultColor) + ';"></div>';
  874. // Fine-tuning in Firefox, quirks mode and IE8 standards
  875. if (mxClient.IS_QUIRKS || document.documentMode == 8)
  876. {
  877. btn.firstChild.style.margin = '0px';
  878. }
  879. if (color != null && color != mxConstants.NONE)
  880. {
  881. cb.setAttribute('checked', 'checked');
  882. cb.defaultChecked = true;
  883. cb.checked = true;
  884. }
  885. else
  886. {
  887. cb.removeAttribute('checked');
  888. cb.defaultChecked = false;
  889. cb.checked = false;
  890. }
  891. btn.style.display = (cb.checked || hideCheckbox) ? '' : 'none';
  892. if (callbackFn != null)
  893. {
  894. callbackFn(color);
  895. }
  896. if (!disableUpdate && (hideCheckbox || value != color))
  897. {
  898. value = color;
  899. // Checks if the color value needs to be updated in the model
  900. if (hideCheckbox || getColorFn() != value)
  901. {
  902. setColorFn(value);
  903. }
  904. }
  905. applying = false;
  906. }
  907. };
  908. btn = mxUtils.button('', mxUtils.bind(this, function(evt)
  909. {
  910. this.editorUi.pickColor(value, apply);
  911. mxEvent.consume(evt);
  912. }));
  913. btn.style.position = 'absolute';
  914. btn.style.marginTop = '-4px';
  915. btn.style.right = (mxClient.IS_QUIRKS) ? '0px' : '20px';
  916. btn.style.height = '22px';
  917. btn.className = 'geColorBtn';
  918. btn.style.display = (cb.checked || hideCheckbox) ? '' : 'none';
  919. div.appendChild(btn);
  920. mxEvent.addListener(div, 'click', function(evt)
  921. {
  922. var source = mxEvent.getSource(evt);
  923. if (source == cb || source.nodeName != 'INPUT')
  924. {
  925. // Toggles checkbox state for click on label
  926. if (source != cb)
  927. {
  928. cb.checked = !cb.checked;
  929. }
  930. // Overrides default value with current value to make it easier
  931. // to restore previous value if the checkbox is clicked twice
  932. if (!cb.checked && value != null && value != mxConstants.NONE &&
  933. defaultColor != mxConstants.NONE)
  934. {
  935. defaultColor = value;
  936. }
  937. apply((cb.checked) ? defaultColor : mxConstants.NONE);
  938. }
  939. });
  940. apply(value, true);
  941. if (listener != null)
  942. {
  943. listener.install(apply);
  944. this.listeners.push(listener);
  945. }
  946. return div;
  947. };
  948. /**
  949. *
  950. */
  951. BaseFormatPanel.prototype.createCellColorOption = function(label, colorKey, defaultColor, callbackFn, setStyleFn)
  952. {
  953. var ui = this.editorUi;
  954. var editor = ui.editor;
  955. var graph = editor.graph;
  956. return this.createColorOption(label, function()
  957. {
  958. // Seems to be null sometimes, not sure why...
  959. var state = graph.view.getState(graph.getSelectionCell());
  960. if (state != null)
  961. {
  962. return mxUtils.getValue(state.style, colorKey, null);
  963. }
  964. return null;
  965. }, function(color)
  966. {
  967. graph.getModel().beginUpdate();
  968. try
  969. {
  970. if (setStyleFn != null)
  971. {
  972. setStyleFn(color);
  973. }
  974. graph.setCellStyles(colorKey, color, graph.getSelectionCells());
  975. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [colorKey],
  976. 'values', [color], 'cells', graph.getSelectionCells()));
  977. }
  978. finally
  979. {
  980. graph.getModel().endUpdate();
  981. }
  982. }, defaultColor || mxConstants.NONE,
  983. {
  984. install: function(apply)
  985. {
  986. this.listener = function()
  987. {
  988. // Seems to be null sometimes, not sure why...
  989. var state = graph.view.getState(graph.getSelectionCell());
  990. if (state != null)
  991. {
  992. apply(mxUtils.getValue(state.style, colorKey, null));
  993. }
  994. };
  995. graph.getModel().addListener(mxEvent.CHANGE, this.listener);
  996. },
  997. destroy: function()
  998. {
  999. graph.getModel().removeListener(this.listener);
  1000. }
  1001. }, callbackFn);
  1002. };
  1003. /**
  1004. *
  1005. */
  1006. BaseFormatPanel.prototype.addArrow = function(elt, height)
  1007. {
  1008. height = (height != null) ? height : 10;
  1009. var arrow = document.createElement('div');
  1010. arrow.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  1011. arrow.style.padding = '6px';
  1012. arrow.style.paddingRight = '4px';
  1013. var m = (10 - height);
  1014. if (m == 2)
  1015. {
  1016. arrow.style.paddingTop = 6 + 'px';
  1017. }
  1018. else if (m > 0)
  1019. {
  1020. arrow.style.paddingTop = (6 - m) + 'px';
  1021. }
  1022. else
  1023. {
  1024. arrow.style.marginTop = '-2px';
  1025. }
  1026. arrow.style.height = height + 'px';
  1027. arrow.style.borderLeft = '1px solid #a0a0a0';
  1028. arrow.innerHTML = '<img border="0" src="' + ((mxClient.IS_SVG) ? 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHBJREFUeNpidHB2ZyAGsACxDRBPIKCuA6TwCBB/h2rABu4A8SYmKCcXiP/iUFgAxL9gCi8A8SwsirZCMQMTkmANEH9E4v+CmsaArvAdyNFI/FlQ92EoBIE+qCRIUz168DBgsU4OqhinQpgHMABAgAEALY4XLIsJ20oAAAAASUVORK5CYII=' :
  1029. IMAGE_PATH + '/dropdown.png') + '" style="margin-bottom:4px;">';
  1030. mxUtils.setOpacity(arrow, 70);
  1031. var symbol = elt.getElementsByTagName('div')[0];
  1032. if (symbol != null)
  1033. {
  1034. symbol.style.paddingRight = '6px';
  1035. symbol.style.marginLeft = '4px';
  1036. symbol.style.marginTop = '-1px';
  1037. symbol.style.display = (mxClient.IS_QUIRKS) ? 'inline' : 'inline-block';
  1038. mxUtils.setOpacity(symbol, 60);
  1039. }
  1040. mxUtils.setOpacity(elt, 100);
  1041. elt.style.border = '1px solid #a0a0a0';
  1042. elt.style.backgroundColor = 'white';
  1043. elt.style.backgroundImage = 'none';
  1044. elt.style.width = 'auto';
  1045. elt.className += ' geColorBtn';
  1046. mxUtils.setPrefixedStyle(elt.style, 'borderRadius', '3px');
  1047. elt.appendChild(arrow);
  1048. return symbol;
  1049. };
  1050. /**
  1051. *
  1052. */
  1053. BaseFormatPanel.prototype.addUnitInput = function(container, unit, right, width, update, step, marginTop, disableFocus)
  1054. {
  1055. marginTop = (marginTop != null) ? marginTop : 0;
  1056. var input = document.createElement('input');
  1057. input.style.position = 'absolute';
  1058. input.style.textAlign = 'right';
  1059. input.style.marginTop = '-2px';
  1060. input.style.right = (right + 12) + 'px';
  1061. input.style.width = width + 'px';
  1062. container.appendChild(input);
  1063. var stepper = this.createStepper(input, update, step, null, disableFocus);
  1064. stepper.style.marginTop = (marginTop - 2) + 'px';
  1065. stepper.style.right = right + 'px';
  1066. container.appendChild(stepper);
  1067. return input;
  1068. };
  1069. /**
  1070. *
  1071. */
  1072. BaseFormatPanel.prototype.createRelativeOption = function(label, key, width, handler, init)
  1073. {
  1074. width = (width != null) ? width : 44;
  1075. var graph = this.editorUi.editor.graph;
  1076. var div = this.createPanel();
  1077. div.style.paddingTop = '10px';
  1078. div.style.paddingBottom = '10px';
  1079. mxUtils.write(div, label);
  1080. div.style.fontWeight = 'bold';
  1081. function update(evt)
  1082. {
  1083. if (handler != null)
  1084. {
  1085. handler(input);
  1086. }
  1087. else
  1088. {
  1089. var value = parseInt(input.value);
  1090. value = Math.min(100, Math.max(0, (isNaN(value)) ? 100 : value));
  1091. var state = graph.view.getState(graph.getSelectionCell());
  1092. if (state != null && value != mxUtils.getValue(state.style, key, 100))
  1093. {
  1094. // Removes entry in style (assumes 100 is default for relative values)
  1095. if (value == 100)
  1096. {
  1097. value = null;
  1098. }
  1099. graph.setCellStyles(key, value, graph.getSelectionCells());
  1100. }
  1101. input.value = ((value != null) ? value : '100') + ' %';
  1102. }
  1103. mxEvent.consume(evt);
  1104. };
  1105. var input = this.addUnitInput(div, '%', 20, width, update, 10, -15, handler != null);
  1106. if (key != null)
  1107. {
  1108. var listener = mxUtils.bind(this, function(sender, evt, force)
  1109. {
  1110. if (force || input != document.activeElement)
  1111. {
  1112. var ss = this.format.getSelectionState();
  1113. var tmp = parseInt(mxUtils.getValue(ss.style, key, 100));
  1114. input.value = (isNaN(tmp)) ? '' : tmp + ' %';
  1115. }
  1116. });
  1117. mxEvent.addListener(input, 'keydown', function(e)
  1118. {
  1119. if (e.keyCode == 13)
  1120. {
  1121. graph.container.focus();
  1122. mxEvent.consume(e);
  1123. }
  1124. else if (e.keyCode == 27)
  1125. {
  1126. listener(null, null, true);
  1127. graph.container.focus();
  1128. mxEvent.consume(e);
  1129. }
  1130. });
  1131. graph.getModel().addListener(mxEvent.CHANGE, listener);
  1132. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  1133. listener();
  1134. }
  1135. mxEvent.addListener(input, 'blur', update);
  1136. mxEvent.addListener(input, 'change', update);
  1137. if (init != null)
  1138. {
  1139. init(input);
  1140. }
  1141. return div;
  1142. };
  1143. /**
  1144. *
  1145. */
  1146. BaseFormatPanel.prototype.addLabel = function(div, title, right, width)
  1147. {
  1148. width = (width != null) ? width : 61;
  1149. var label = document.createElement('div');
  1150. mxUtils.write(label, title);
  1151. label.style.position = 'absolute';
  1152. label.style.right = right + 'px';
  1153. label.style.width = width + 'px';
  1154. label.style.marginTop = '6px';
  1155. label.style.textAlign = 'center';
  1156. div.appendChild(label);
  1157. };
  1158. /**
  1159. *
  1160. */
  1161. BaseFormatPanel.prototype.addKeyHandler = function(input, listener)
  1162. {
  1163. mxEvent.addListener(input, 'keydown', mxUtils.bind(this, function(e)
  1164. {
  1165. if (e.keyCode == 13)
  1166. {
  1167. this.editorUi.editor.graph.container.focus();
  1168. mxEvent.consume(e);
  1169. }
  1170. else if (e.keyCode == 27)
  1171. {
  1172. if (listener != null)
  1173. {
  1174. listener(null, null, true);
  1175. }
  1176. this.editorUi.editor.graph.container.focus();
  1177. mxEvent.consume(e);
  1178. }
  1179. }));
  1180. };
  1181. /**
  1182. *
  1183. */
  1184. BaseFormatPanel.prototype.styleButtons = function(elts)
  1185. {
  1186. for (var i = 0; i < elts.length; i++)
  1187. {
  1188. mxUtils.setPrefixedStyle(elts[i].style, 'borderRadius', '3px');
  1189. mxUtils.setOpacity(elts[i], 100);
  1190. elts[i].style.border = '1px solid #a0a0a0';
  1191. elts[i].style.padding = '4px';
  1192. elts[i].style.paddingTop = '3px';
  1193. elts[i].style.paddingRight = '1px';
  1194. elts[i].style.margin = '1px';
  1195. elts[i].style.width = '24px';
  1196. elts[i].style.height = '20px';
  1197. elts[i].className += ' geColorBtn';
  1198. }
  1199. };
  1200. /**
  1201. * Adds the label menu items to the given menu and parent.
  1202. */
  1203. BaseFormatPanel.prototype.destroy = function()
  1204. {
  1205. if (this.listeners != null)
  1206. {
  1207. for (var i = 0; i < this.listeners.length; i++)
  1208. {
  1209. this.listeners[i].destroy();
  1210. }
  1211. this.listeners = null;
  1212. }
  1213. };
  1214. /**
  1215. * Adds the label menu items to the given menu and parent.
  1216. */
  1217. ArrangePanel = function(format, editorUi, container)
  1218. {
  1219. BaseFormatPanel.call(this, format, editorUi, container);
  1220. this.init();
  1221. };
  1222. mxUtils.extend(ArrangePanel, BaseFormatPanel);
  1223. /**
  1224. * Adds the label menu items to the given menu and parent.
  1225. */
  1226. ArrangePanel.prototype.init = function()
  1227. {
  1228. var graph = this.editorUi.editor.graph;
  1229. var ss = this.format.getSelectionState();
  1230. this.container.appendChild(this.addLayerOps(this.createPanel()));
  1231. // Special case that adds two panels
  1232. this.addGeometry(this.container);
  1233. this.addEdgeGeometry(this.container);
  1234. if (!ss.containsLabel || ss.edges.length == 0)
  1235. {
  1236. this.container.appendChild(this.addAngle(this.createPanel()));
  1237. }
  1238. if (!ss.containsLabel && ss.edges.length == 0)
  1239. {
  1240. this.container.appendChild(this.addFlip(this.createPanel()));
  1241. }
  1242. if (ss.vertices.length > 1)
  1243. {
  1244. this.container.appendChild(this.addAlign(this.createPanel()));
  1245. this.container.appendChild(this.addDistribute(this.createPanel()));
  1246. }
  1247. this.container.appendChild(this.addGroupOps(this.createPanel()));
  1248. };
  1249. /**
  1250. *
  1251. */
  1252. ArrangePanel.prototype.addLayerOps = function(div)
  1253. {
  1254. var ui = this.editorUi;
  1255. var btn = mxUtils.button(mxResources.get('toFront'), function(evt)
  1256. {
  1257. ui.actions.get('toFront').funct();
  1258. })
  1259. btn.setAttribute('title', mxResources.get('toFront') + ' (' + this.editorUi.actions.get('toFront').shortcut + ')');
  1260. btn.style.width = '100px';
  1261. btn.style.marginRight = '2px';
  1262. div.appendChild(btn);
  1263. var btn = mxUtils.button(mxResources.get('toBack'), function(evt)
  1264. {
  1265. ui.actions.get('toBack').funct();
  1266. })
  1267. btn.setAttribute('title', mxResources.get('toBack') + ' (' + this.editorUi.actions.get('toBack').shortcut + ')');
  1268. btn.style.width = '100px';
  1269. div.appendChild(btn);
  1270. return div;
  1271. };
  1272. /**
  1273. *
  1274. */
  1275. ArrangePanel.prototype.addGroupOps = function(div)
  1276. {
  1277. var ui = this.editorUi;
  1278. var graph = ui.editor.graph;
  1279. var cell = graph.getSelectionCell();
  1280. var ss = this.format.getSelectionState();
  1281. var count = 0;
  1282. var btn = null;
  1283. div.style.paddingTop = '8px';
  1284. div.style.paddingBottom = '6px';
  1285. if (graph.getSelectionCount() > 1)
  1286. {
  1287. btn = mxUtils.button(mxResources.get('group'), function(evt)
  1288. {
  1289. ui.actions.get('group').funct();
  1290. })
  1291. btn.setAttribute('title', mxResources.get('group') + ' (' + this.editorUi.actions.get('group').shortcut + ')');
  1292. btn.style.width = '202px';
  1293. btn.style.marginBottom = '2px';
  1294. div.appendChild(btn);
  1295. count++;
  1296. }
  1297. else if (graph.getSelectionCount() == 1 && !graph.getModel().isEdge(cell) && !graph.isSwimlane(cell) &&
  1298. graph.getModel().getChildCount(cell) > 0)
  1299. {
  1300. btn = mxUtils.button(mxResources.get('ungroup'), function(evt)
  1301. {
  1302. ui.actions.get('ungroup').funct();
  1303. })
  1304. btn.setAttribute('title', mxResources.get('ungroup') + ' (' + this.editorUi.actions.get('ungroup').shortcut + ')');
  1305. btn.style.width = '202px';
  1306. btn.style.marginBottom = '2px';
  1307. div.appendChild(btn);
  1308. count++;
  1309. }
  1310. if (graph.getSelectionCount() == 1 && graph.getModel().isVertex(cell) &&
  1311. graph.getModel().isVertex(graph.getModel().getParent(cell)))
  1312. {
  1313. if (count > 0)
  1314. {
  1315. mxUtils.br(div);
  1316. }
  1317. btn = mxUtils.button(mxResources.get('removeFromGroup'), function(evt)
  1318. {
  1319. ui.actions.get('removeFromGroup').funct();
  1320. })
  1321. btn.setAttribute('title', mxResources.get('removeFromGroup'));
  1322. btn.style.width = '202px';
  1323. btn.style.marginBottom = '2px';
  1324. div.appendChild(btn);
  1325. count++;
  1326. }
  1327. else if (graph.getSelectionCount() > 0)
  1328. {
  1329. if (count > 0)
  1330. {
  1331. mxUtils.br(div);
  1332. }
  1333. btn = mxUtils.button(mxResources.get('clearWaypoints'), mxUtils.bind(this, function(evt)
  1334. {
  1335. this.editorUi.actions.get('clearWaypoints').funct();
  1336. }));
  1337. btn.setAttribute('title', mxResources.get('clearWaypoints') + ' (' + this.editorUi.actions.get('clearWaypoints').shortcut + ')');
  1338. btn.style.width = '202px';
  1339. btn.style.marginBottom = '2px';
  1340. div.appendChild(btn);
  1341. count++;
  1342. }
  1343. if (graph.getSelectionCount() == 1)
  1344. {
  1345. if (count > 0)
  1346. {
  1347. mxUtils.br(div);
  1348. }
  1349. btn = mxUtils.button(mxResources.get('editData'), mxUtils.bind(this, function(evt)
  1350. {
  1351. this.editorUi.actions.get('editData').funct();
  1352. }));
  1353. btn.setAttribute('title', mxResources.get('editData') + ' (' + this.editorUi.actions.get('editData').shortcut + ')');
  1354. btn.style.width = '100px';
  1355. btn.style.marginBottom = '2px';
  1356. div.appendChild(btn);
  1357. count++;
  1358. btn = mxUtils.button(mxResources.get('editLink'), mxUtils.bind(this, function(evt)
  1359. {
  1360. this.editorUi.actions.get('editLink').funct();
  1361. }));
  1362. btn.setAttribute('title', mxResources.get('editLink'));
  1363. btn.style.width = '100px';
  1364. btn.style.marginLeft = '2px';
  1365. btn.style.marginBottom = '2px';
  1366. div.appendChild(btn);
  1367. count++;
  1368. }
  1369. if (count == 0)
  1370. {
  1371. div.style.display = 'none';
  1372. }
  1373. return div;
  1374. };
  1375. /**
  1376. *
  1377. */
  1378. ArrangePanel.prototype.addAlign = function(div)
  1379. {
  1380. var graph = this.editorUi.editor.graph;
  1381. div.style.paddingTop = '6px';
  1382. div.style.paddingBottom = '12px';
  1383. div.appendChild(this.createTitle(mxResources.get('align')));
  1384. var stylePanel = document.createElement('div');
  1385. stylePanel.style.position = 'relative';
  1386. stylePanel.style.paddingLeft = '0px';
  1387. stylePanel.style.borderWidth = '0px';
  1388. stylePanel.className = 'geToolbarContainer';
  1389. if (mxClient.IS_QUIRKS)
  1390. {
  1391. div.style.height = '60px';
  1392. }
  1393. var left = this.editorUi.toolbar.addButton('geSprite-alignleft', mxResources.get('left'),
  1394. function() { graph.alignCells(mxConstants.ALIGN_LEFT); }, stylePanel);
  1395. var center = this.editorUi.toolbar.addButton('geSprite-aligncenter', mxResources.get('center'),
  1396. function() { graph.alignCells(mxConstants.ALIGN_CENTER); }, stylePanel);
  1397. var right = this.editorUi.toolbar.addButton('geSprite-alignright', mxResources.get('right'),
  1398. function() { graph.alignCells(mxConstants.ALIGN_RIGHT); }, stylePanel);
  1399. var top = this.editorUi.toolbar.addButton('geSprite-aligntop', mxResources.get('top'),
  1400. function() { graph.alignCells(mxConstants.ALIGN_TOP); }, stylePanel);
  1401. var middle = this.editorUi.toolbar.addButton('geSprite-alignmiddle', mxResources.get('middle'),
  1402. function() { graph.alignCells(mxConstants.ALIGN_MIDDLE); }, stylePanel);
  1403. var bottom = this.editorUi.toolbar.addButton('geSprite-alignbottom', mxResources.get('bottom'),
  1404. function() { graph.alignCells(mxConstants.ALIGN_BOTTOM); }, stylePanel);
  1405. this.styleButtons([left, center, right, top, middle, bottom]);
  1406. right.style.marginRight = '6px';
  1407. div.appendChild(stylePanel);
  1408. return div;
  1409. };
  1410. /**
  1411. *
  1412. */
  1413. ArrangePanel.prototype.addFlip = function(div)
  1414. {
  1415. var ui = this.editorUi;
  1416. var editor = ui.editor;
  1417. var graph = editor.graph;
  1418. div.style.paddingTop = '6px';
  1419. div.style.paddingBottom = '10px';
  1420. var span = document.createElement('div');
  1421. span.style.marginTop = '2px';
  1422. span.style.marginBottom = '8px';
  1423. span.style.fontWeight = 'bold';
  1424. mxUtils.write(span, mxResources.get('flip'));
  1425. div.appendChild(span);
  1426. var btn = mxUtils.button(mxResources.get('horizontal'), function(evt)
  1427. {
  1428. graph.toggleCellStyles(mxConstants.STYLE_FLIPH, false);
  1429. })
  1430. btn.setAttribute('title', mxResources.get('horizontal'));
  1431. btn.style.width = '100px';
  1432. btn.style.marginRight = '2px';
  1433. div.appendChild(btn);
  1434. var btn = mxUtils.button(mxResources.get('vertical'), function(evt)
  1435. {
  1436. graph.toggleCellStyles(mxConstants.STYLE_FLIPV, false);
  1437. })
  1438. btn.setAttribute('title', mxResources.get('vertical'));
  1439. btn.style.width = '100px';
  1440. div.appendChild(btn);
  1441. return div;
  1442. };
  1443. /**
  1444. *
  1445. */
  1446. ArrangePanel.prototype.addDistribute = function(div)
  1447. {
  1448. var ui = this.editorUi;
  1449. var editor = ui.editor;
  1450. var graph = editor.graph;
  1451. div.style.paddingTop = '6px';
  1452. div.style.paddingBottom = '12px';
  1453. div.appendChild(this.createTitle(mxResources.get('distribute')));
  1454. var btn = mxUtils.button(mxResources.get('horizontal'), function(evt)
  1455. {
  1456. graph.distributeCells(true);
  1457. })
  1458. btn.setAttribute('title', mxResources.get('horizontal'));
  1459. btn.style.width = '100px';
  1460. btn.style.marginRight = '2px';
  1461. div.appendChild(btn);
  1462. var btn = mxUtils.button(mxResources.get('vertical'), function(evt)
  1463. {
  1464. graph.distributeCells(false);
  1465. })
  1466. btn.setAttribute('title', mxResources.get('vertical'));
  1467. btn.style.width = '100px';
  1468. div.appendChild(btn);
  1469. return div;
  1470. };
  1471. /**
  1472. *
  1473. */
  1474. ArrangePanel.prototype.addAngle = function(div)
  1475. {
  1476. var ui = this.editorUi;
  1477. var editor = ui.editor;
  1478. var graph = editor.graph;
  1479. var ss = this.format.getSelectionState();
  1480. div.style.paddingBottom = '8px';
  1481. var span = document.createElement('div');
  1482. span.style.position = 'absolute';
  1483. span.style.width = '70px';
  1484. span.style.marginTop = '0px';
  1485. span.style.fontWeight = 'bold';
  1486. var input = null;
  1487. var update = null;
  1488. var btn = null;
  1489. if (ss.edges.length == 0)
  1490. {
  1491. mxUtils.write(span, mxResources.get('angle'));
  1492. div.appendChild(span);
  1493. input = this.addUnitInput(div, '°', 20, 44, function()
  1494. {
  1495. update.apply(this, arguments);
  1496. });
  1497. mxUtils.br(div);
  1498. div.style.paddingTop = '10px';
  1499. }
  1500. else
  1501. {
  1502. div.style.paddingTop = '8px';
  1503. }
  1504. if (!ss.containsLabel)
  1505. {
  1506. var label = mxResources.get('reverse');
  1507. if (ss.vertices.length > 0 && ss.edges.length > 0)
  1508. {
  1509. label = mxResources.get('turn') + ' / ' + label;
  1510. }
  1511. else if (ss.vertices.length > 0)
  1512. {
  1513. label = mxResources.get('turn');
  1514. }
  1515. btn = mxUtils.button(label, function(evt)
  1516. {
  1517. ui.actions.get('turn').funct();
  1518. })
  1519. btn.setAttribute('title', label + ' (' + this.editorUi.actions.get('turn').shortcut + ')');
  1520. btn.style.width = '202px';
  1521. div.appendChild(btn);
  1522. if (input != null)
  1523. {
  1524. btn.style.marginTop = '8px';
  1525. }
  1526. }
  1527. if (input != null)
  1528. {
  1529. var listener = mxUtils.bind(this, function(sender, evt, force)
  1530. {
  1531. if (force || document.activeElement != input)
  1532. {
  1533. ss = this.format.getSelectionState();
  1534. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_ROTATION, 0));
  1535. input.value = (isNaN(tmp)) ? '' : tmp + '°';
  1536. }
  1537. });
  1538. update = this.installInputHandler(input, mxConstants.STYLE_ROTATION, 0, 0, 360, '°', null, true);
  1539. this.addKeyHandler(input, listener);
  1540. graph.getModel().addListener(mxEvent.CHANGE, listener);
  1541. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  1542. listener();
  1543. }
  1544. return div;
  1545. };
  1546. /**
  1547. *
  1548. */
  1549. ArrangePanel.prototype.addGeometry = function(container)
  1550. {
  1551. var ui = this.editorUi;
  1552. var graph = ui.editor.graph;
  1553. var rect = this.format.getSelectionState();
  1554. var div = this.createPanel();
  1555. div.style.paddingBottom = '8px';
  1556. var span = document.createElement('div');
  1557. span.style.position = 'absolute';
  1558. span.style.width = '50px';
  1559. span.style.marginTop = '0px';
  1560. span.style.fontWeight = 'bold';
  1561. mxUtils.write(span, mxResources.get('size'));
  1562. div.appendChild(span);
  1563. var widthUpdate, heightUpdate, leftUpdate, topUpdate;
  1564. var width = this.addUnitInput(div, 'pt', 84, 44, function()
  1565. {
  1566. widthUpdate.apply(this, arguments);
  1567. });
  1568. var height = this.addUnitInput(div, 'pt', 20, 44, function()
  1569. {
  1570. heightUpdate.apply(this, arguments);
  1571. });
  1572. var autosizeBtn = document.createElement('div');
  1573. autosizeBtn.className = 'geSprite geSprite-fit';
  1574. autosizeBtn.setAttribute('title', mxResources.get('autosize') + ' (' + this.editorUi.actions.get('autosize').shortcut + ')');
  1575. autosizeBtn.style.position = 'relative';
  1576. autosizeBtn.style.cursor = 'pointer';
  1577. autosizeBtn.style.marginTop = '-3px';
  1578. autosizeBtn.style.border = '0px';
  1579. autosizeBtn.style.left = '52px';
  1580. mxUtils.setOpacity(autosizeBtn, 50);
  1581. mxEvent.addListener(autosizeBtn, 'mouseenter', function()
  1582. {
  1583. mxUtils.setOpacity(autosizeBtn, 100);
  1584. });
  1585. mxEvent.addListener(autosizeBtn, 'mouseleave', function()
  1586. {
  1587. mxUtils.setOpacity(autosizeBtn, 50);
  1588. });
  1589. mxEvent.addListener(autosizeBtn, 'click', function()
  1590. {
  1591. ui.actions.get('autosize').funct();
  1592. });
  1593. div.appendChild(autosizeBtn);
  1594. this.addLabel(div, mxResources.get('width'), 84);
  1595. this.addLabel(div, mxResources.get('height'), 20);
  1596. mxUtils.br(div);
  1597. var wrapper = document.createElement('div');
  1598. wrapper.style.paddingTop = '8px';
  1599. wrapper.style.paddingRight = '20px';
  1600. wrapper.style.whiteSpace = 'nowrap';
  1601. wrapper.style.textAlign = 'right';
  1602. var opt = this.createCellOption(mxResources.get('constrainProportions'),
  1603. mxConstants.STYLE_ASPECT, null, 'fixed', 'null');
  1604. opt.style.width = '100%';
  1605. wrapper.appendChild(opt);
  1606. div.appendChild(wrapper);
  1607. this.addKeyHandler(width, listener);
  1608. this.addKeyHandler(height, listener);
  1609. widthUpdate = this.addGeometryHandler(width, function(geo, value)
  1610. {
  1611. if (geo.width > 0)
  1612. {
  1613. geo.width = Math.max(1, value);
  1614. }
  1615. });
  1616. heightUpdate = this.addGeometryHandler(height, function(geo, value)
  1617. {
  1618. if (geo.height > 0)
  1619. {
  1620. geo.height = Math.max(1, value);
  1621. }
  1622. });
  1623. container.appendChild(div);
  1624. var div2 = this.createPanel();
  1625. div2.style.paddingBottom = '30px';
  1626. var span = document.createElement('div');
  1627. span.style.position = 'absolute';
  1628. span.style.width = '70px';
  1629. span.style.marginTop = '0px';
  1630. span.style.fontWeight = 'bold';
  1631. mxUtils.write(span, mxResources.get('position'));
  1632. div2.appendChild(span);
  1633. var left = this.addUnitInput(div2, 'pt', 84, 44, function()
  1634. {
  1635. leftUpdate.apply(this, arguments);
  1636. });
  1637. var top = this.addUnitInput(div2, 'pt', 20, 44, function()
  1638. {
  1639. topUpdate.apply(this, arguments);
  1640. });
  1641. mxUtils.br(div2);
  1642. this.addLabel(div2, mxResources.get('left'), 84);
  1643. this.addLabel(div2, mxResources.get('top'), 20);
  1644. var listener = mxUtils.bind(this, function(sender, evt, force)
  1645. {
  1646. rect = this.format.getSelectionState();
  1647. if (!rect.containsLabel && rect.vertices.length == graph.getSelectionCount() &&
  1648. rect.width != null && rect.height != null)
  1649. {
  1650. div.style.display = '';
  1651. if (force || document.activeElement != width)
  1652. {
  1653. width.value = rect.width + ((rect.width == '') ? '' : ' pt');
  1654. }
  1655. if (force || document.activeElement != height)
  1656. {
  1657. height.value = rect.height + ((rect.height == '') ? '' : ' pt');
  1658. }
  1659. }
  1660. else
  1661. {
  1662. div.style.display = 'none';
  1663. }
  1664. if (rect.vertices.length == graph.getSelectionCount() &&
  1665. rect.x != null && rect.y != null)
  1666. {
  1667. div2.style.display = '';
  1668. if (force || document.activeElement != left)
  1669. {
  1670. left.value = rect.x + ((rect.x == '') ? '' : ' pt');
  1671. }
  1672. if (force || document.activeElement != top)
  1673. {
  1674. top.value = rect.y + ((rect.y == '') ? '' : ' pt');
  1675. }
  1676. }
  1677. else
  1678. {
  1679. div2.style.display = 'none';
  1680. }
  1681. });
  1682. this.addKeyHandler(left, listener);
  1683. this.addKeyHandler(top, listener);
  1684. graph.getModel().addListener(mxEvent.CHANGE, listener);
  1685. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  1686. listener();
  1687. leftUpdate = this.addGeometryHandler(left, function(geo, value)
  1688. {
  1689. if (geo.relative)
  1690. {
  1691. geo.offset.x = value;
  1692. }
  1693. else
  1694. {
  1695. geo.x = value;
  1696. }
  1697. });
  1698. topUpdate = this.addGeometryHandler(top, function(geo, value)
  1699. {
  1700. if (geo.relative)
  1701. {
  1702. geo.offset.y = value;
  1703. }
  1704. else
  1705. {
  1706. geo.y = value;
  1707. }
  1708. });
  1709. container.appendChild(div2);
  1710. };
  1711. /**
  1712. *
  1713. */
  1714. ArrangePanel.prototype.addGeometryHandler = function(input, fn)
  1715. {
  1716. var ui = this.editorUi;
  1717. var graph = ui.editor.graph;
  1718. var initialValue = null;
  1719. function update(evt)
  1720. {
  1721. if (input.value != '')
  1722. {
  1723. var value = parseFloat(input.value);
  1724. if (value != initialValue)
  1725. {
  1726. graph.getModel().beginUpdate();
  1727. try
  1728. {
  1729. var cells = graph.getSelectionCells();
  1730. for (var i = 0; i < cells.length; i++)
  1731. {
  1732. if (graph.getModel().isVertex(cells[i]))
  1733. {
  1734. var geo = graph.getCellGeometry(cells[i]);
  1735. if (geo != null)
  1736. {
  1737. geo = geo.clone();
  1738. fn(geo, value);
  1739. graph.getModel().setGeometry(cells[i], geo);
  1740. }
  1741. }
  1742. }
  1743. }
  1744. finally
  1745. {
  1746. graph.getModel().endUpdate();
  1747. }
  1748. initialValue = value;
  1749. input.value = value + ' pt';
  1750. }
  1751. else if (isNaN(value))
  1752. {
  1753. input.value = initialValue + ' pt';
  1754. }
  1755. }
  1756. mxEvent.consume(evt);
  1757. };
  1758. mxEvent.addListener(input, 'blur', update);
  1759. mxEvent.addListener(input, 'change', update);
  1760. mxEvent.addListener(input, 'focus', function()
  1761. {
  1762. initialValue = input.value;
  1763. });
  1764. return update;
  1765. };
  1766. ArrangePanel.prototype.addEdgeGeometryHandler = function(input, fn)
  1767. {
  1768. var ui = this.editorUi;
  1769. var graph = ui.editor.graph;
  1770. var initialValue = null;
  1771. function update(evt)
  1772. {
  1773. if (input.value != '')
  1774. {
  1775. var value = parseFloat(input.value);
  1776. if (isNaN(value))
  1777. {
  1778. input.value = initialValue + ' pt';
  1779. }
  1780. else if (value != initialValue)
  1781. {
  1782. graph.getModel().beginUpdate();
  1783. try
  1784. {
  1785. var cells = graph.getSelectionCells();
  1786. for (var i = 0; i < cells.length; i++)
  1787. {
  1788. if (graph.getModel().isEdge(cells[i]))
  1789. {
  1790. var geo = graph.getCellGeometry(cells[i]);
  1791. if (geo != null)
  1792. {
  1793. geo = geo.clone();
  1794. fn(geo, value);
  1795. graph.getModel().setGeometry(cells[i], geo);
  1796. }
  1797. }
  1798. }
  1799. }
  1800. finally
  1801. {
  1802. graph.getModel().endUpdate();
  1803. }
  1804. initialValue = value;
  1805. input.value = value + ' pt';
  1806. }
  1807. }
  1808. mxEvent.consume(evt);
  1809. };
  1810. mxEvent.addListener(input, 'blur', update);
  1811. mxEvent.addListener(input, 'change', update);
  1812. mxEvent.addListener(input, 'focus', function()
  1813. {
  1814. initialValue = input.value;
  1815. });
  1816. return update;
  1817. };
  1818. /**
  1819. *
  1820. */
  1821. ArrangePanel.prototype.addEdgeGeometry = function(container)
  1822. {
  1823. var ui = this.editorUi;
  1824. var graph = ui.editor.graph;
  1825. var rect = this.format.getSelectionState();
  1826. var div = this.createPanel();
  1827. var span = document.createElement('div');
  1828. span.style.position = 'absolute';
  1829. span.style.width = '70px';
  1830. span.style.marginTop = '0px';
  1831. span.style.fontWeight = 'bold';
  1832. mxUtils.write(span, mxResources.get('width'));
  1833. div.appendChild(span);
  1834. var widthUpdate, xtUpdate, ytUpdate, xsUpdate, ysUpdate;
  1835. var width = this.addUnitInput(div, 'pt', 20, 44, function()
  1836. {
  1837. widthUpdate.apply(this, arguments);
  1838. });
  1839. mxUtils.br(div);
  1840. this.addKeyHandler(width, listener);
  1841. function widthUpdate(evt)
  1842. {
  1843. // Maximum stroke width is 999
  1844. var value = parseInt(width.value);
  1845. value = Math.min(999, Math.max(1, (isNaN(value)) ? 1 : value));
  1846. if (value != mxUtils.getValue(rect.style, 'width', mxCellRenderer.defaultShapes['flexArrow'].prototype.defaultWidth))
  1847. {
  1848. graph.setCellStyles('width', value, graph.getSelectionCells());
  1849. ui.fireEvent(new mxEventObject('styleChanged', 'keys', ['width'],
  1850. 'values', [value], 'cells', graph.getSelectionCells()));
  1851. }
  1852. width.value = value + ' pt';
  1853. mxEvent.consume(evt);
  1854. };
  1855. mxEvent.addListener(width, 'blur', widthUpdate);
  1856. mxEvent.addListener(width, 'change', widthUpdate);
  1857. container.appendChild(div);
  1858. var divs = this.createPanel();
  1859. divs.style.paddingBottom = '30px';
  1860. var span = document.createElement('div');
  1861. span.style.position = 'absolute';
  1862. span.style.width = '70px';
  1863. span.style.marginTop = '0px';
  1864. span.style.fontWeight = 'bold';
  1865. mxUtils.write(span, 'Start');
  1866. divs.appendChild(span);
  1867. var xs = this.addUnitInput(divs, 'pt', 84, 44, function()
  1868. {
  1869. xsUpdate.apply(this, arguments);
  1870. });
  1871. var ys = this.addUnitInput(divs, 'pt', 20, 44, function()
  1872. {
  1873. ysUpdate.apply(this, arguments);
  1874. });
  1875. mxUtils.br(divs);
  1876. this.addLabel(divs, mxResources.get('left'), 84);
  1877. this.addLabel(divs, mxResources.get('top'), 20);
  1878. container.appendChild(divs);
  1879. this.addKeyHandler(xs, listener);
  1880. this.addKeyHandler(ys, listener);
  1881. var divt = this.createPanel();
  1882. divt.style.paddingBottom = '30px';
  1883. var span = document.createElement('div');
  1884. span.style.position = 'absolute';
  1885. span.style.width = '70px';
  1886. span.style.marginTop = '0px';
  1887. span.style.fontWeight = 'bold';
  1888. mxUtils.write(span, 'End');
  1889. divt.appendChild(span);
  1890. var xt = this.addUnitInput(divt, 'pt', 84, 44, function()
  1891. {
  1892. xtUpdate.apply(this, arguments);
  1893. });
  1894. var yt = this.addUnitInput(divt, 'pt', 20, 44, function()
  1895. {
  1896. ytUpdate.apply(this, arguments);
  1897. });
  1898. mxUtils.br(divt);
  1899. this.addLabel(divt, mxResources.get('left'), 84);
  1900. this.addLabel(divt, mxResources.get('top'), 20);
  1901. container.appendChild(divt);
  1902. this.addKeyHandler(xt, listener);
  1903. this.addKeyHandler(yt, listener);
  1904. var listener = mxUtils.bind(this, function(sender, evt, force)
  1905. {
  1906. rect = this.format.getSelectionState();
  1907. var cell = graph.getSelectionCell();
  1908. if (rect.style.shape == 'link' || rect.style.shape == 'flexArrow')
  1909. {
  1910. div.style.display = '';
  1911. if (force || document.activeElement != width)
  1912. {
  1913. var value = mxUtils.getValue(rect.style, 'width',
  1914. mxCellRenderer.defaultShapes['flexArrow'].prototype.defaultWidth);
  1915. width.value = value + ' pt';
  1916. }
  1917. }
  1918. else
  1919. {
  1920. div.style.display = 'none';
  1921. }
  1922. if (graph.getSelectionCount() == 1 && graph.model.isEdge(cell))
  1923. {
  1924. var geo = graph.model.getGeometry(cell);
  1925. if (geo.sourcePoint != null && graph.model.getTerminal(cell, true) == null)
  1926. {
  1927. xs.value = geo.sourcePoint.x;
  1928. ys.value = geo.sourcePoint.y;
  1929. }
  1930. else
  1931. {
  1932. divs.style.display = 'none';
  1933. }
  1934. if (geo.targetPoint != null && graph.model.getTerminal(cell, false) == null)
  1935. {
  1936. xt.value = geo.targetPoint.x;
  1937. yt.value = geo.targetPoint.y;
  1938. }
  1939. else
  1940. {
  1941. divt.style.display = 'none';
  1942. }
  1943. }
  1944. else
  1945. {
  1946. divs.style.display = 'none';
  1947. divt.style.display = 'none';
  1948. }
  1949. });
  1950. xsUpdate = this.addEdgeGeometryHandler(xs, function(geo, value)
  1951. {
  1952. geo.sourcePoint.x = value;
  1953. });
  1954. ysUpdate = this.addEdgeGeometryHandler(ys, function(geo, value)
  1955. {
  1956. geo.sourcePoint.y = value;
  1957. });
  1958. xtUpdate = this.addEdgeGeometryHandler(xt, function(geo, value)
  1959. {
  1960. geo.targetPoint.x = value;
  1961. });
  1962. ytUpdate = this.addEdgeGeometryHandler(yt, function(geo, value)
  1963. {
  1964. geo.targetPoint.y = value;
  1965. });
  1966. graph.getModel().addListener(mxEvent.CHANGE, listener);
  1967. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  1968. listener();
  1969. };
  1970. /**
  1971. * Adds the label menu items to the given menu and parent.
  1972. */
  1973. TextFormatPanel = function(format, editorUi, container)
  1974. {
  1975. BaseFormatPanel.call(this, format, editorUi, container);
  1976. this.init();
  1977. };
  1978. mxUtils.extend(TextFormatPanel, BaseFormatPanel);
  1979. /**
  1980. * Adds the label menu items to the given menu and parent.
  1981. */
  1982. TextFormatPanel.prototype.init = function()
  1983. {
  1984. this.container.style.borderBottom = 'none';
  1985. this.addFont(this.container);
  1986. };
  1987. /**
  1988. * Adds the label menu items to the given menu and parent.
  1989. */
  1990. TextFormatPanel.prototype.addFont = function(container)
  1991. {
  1992. var ui = this.editorUi;
  1993. var editor = ui.editor;
  1994. var graph = editor.graph;
  1995. var ss = this.format.getSelectionState();
  1996. var title = this.createTitle(mxResources.get('font'));
  1997. title.style.paddingLeft = '18px';
  1998. title.style.paddingTop = '10px';
  1999. title.style.paddingBottom = '6px';
  2000. container.appendChild(title);
  2001. var stylePanel = this.createPanel();
  2002. stylePanel.style.paddingTop = '2px';
  2003. stylePanel.style.paddingBottom = '2px';
  2004. stylePanel.style.position = 'relative';
  2005. stylePanel.style.marginLeft = '-2px';
  2006. stylePanel.style.borderWidth = '0px';
  2007. stylePanel.className = 'geToolbarContainer';
  2008. if (mxClient.IS_QUIRKS)
  2009. {
  2010. stylePanel.style.display = 'block';
  2011. }
  2012. if (graph.cellEditor.isContentEditing())
  2013. {
  2014. var cssPanel = stylePanel.cloneNode();
  2015. var cssMenu = this.editorUi.toolbar.addMenu(mxResources.get('style'),
  2016. mxResources.get('style'), true, 'formatBlock', cssPanel);
  2017. cssMenu.style.color = 'rgb(112, 112, 112)';
  2018. cssMenu.style.whiteSpace = 'nowrap';
  2019. cssMenu.style.overflow = 'hidden';
  2020. cssMenu.style.margin = '0px';
  2021. this.addArrow(cssMenu);
  2022. cssMenu.style.width = '192px';
  2023. cssMenu.style.height = '15px';
  2024. var arrow = cssMenu.getElementsByTagName('div')[0];
  2025. arrow.style.cssFloat = 'right';
  2026. container.appendChild(cssPanel);
  2027. // Workaround for offset in FF
  2028. if (mxClient.IS_FF)
  2029. {
  2030. cssMenu.getElementsByTagName('div')[0].style.marginTop = '-18px';
  2031. }
  2032. }
  2033. container.appendChild(stylePanel);
  2034. var colorPanel = this.createPanel();
  2035. colorPanel.style.marginTop = '8px';
  2036. colorPanel.style.borderTop = '1px solid #c0c0c0';
  2037. colorPanel.style.paddingTop = '6px';
  2038. colorPanel.style.paddingBottom = '6px';
  2039. var fontMenu = this.editorUi.toolbar.addMenu('Helvetica', mxResources.get('fontFamily'), true, 'fontFamily', stylePanel);
  2040. fontMenu.style.color = 'rgb(112, 112, 112)';
  2041. fontMenu.style.whiteSpace = 'nowrap';
  2042. fontMenu.style.overflow = 'hidden';
  2043. fontMenu.style.margin = '0px';
  2044. this.addArrow(fontMenu);
  2045. fontMenu.style.width = '192px';
  2046. fontMenu.style.height = '15px';
  2047. // Workaround for offset in FF
  2048. if (mxClient.IS_FF)
  2049. {
  2050. fontMenu.getElementsByTagName('div')[0].style.marginTop = '-18px';
  2051. }
  2052. var stylePanel2 = stylePanel.cloneNode(false);
  2053. stylePanel2.style.marginLeft = '-3px';
  2054. var fontStyleItems = this.editorUi.toolbar.addItems(['bold', 'italic', 'underline'], stylePanel2, true);
  2055. fontStyleItems[0].setAttribute('title', mxResources.get('bold') + ' (' + this.editorUi.actions.get('bold').shortcut + ')');
  2056. fontStyleItems[1].setAttribute('title', mxResources.get('italic') + ' (' + this.editorUi.actions.get('italic').shortcut + ')');
  2057. fontStyleItems[2].setAttribute('title', mxResources.get('underline') + ' (' + this.editorUi.actions.get('underline').shortcut + ')');
  2058. var verticalItem = this.editorUi.toolbar.addItems(['vertical'], stylePanel2, true)[0];
  2059. if (mxClient.IS_QUIRKS)
  2060. {
  2061. mxUtils.br(container);
  2062. }
  2063. container.appendChild(stylePanel2);
  2064. this.styleButtons(fontStyleItems);
  2065. this.styleButtons([verticalItem]);
  2066. var stylePanel3 = stylePanel.cloneNode(false);
  2067. stylePanel3.style.marginLeft = '-3px';
  2068. stylePanel3.style.paddingBottom = '0px';
  2069. var left = this.editorUi.toolbar.addButton('geSprite-left', mxResources.get('left'),
  2070. (graph.cellEditor.isContentEditing()) ?
  2071. function()
  2072. {
  2073. document.execCommand('justifyleft', false, null);
  2074. } : this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_ALIGN], [mxConstants.ALIGN_LEFT]), stylePanel3);
  2075. var center = this.editorUi.toolbar.addButton('geSprite-center', mxResources.get('center'),
  2076. (graph.cellEditor.isContentEditing()) ?
  2077. function()
  2078. {
  2079. document.execCommand('justifycenter', false, null);
  2080. } : this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_ALIGN], [mxConstants.ALIGN_CENTER]), stylePanel3);
  2081. var right = this.editorUi.toolbar.addButton('geSprite-right', mxResources.get('right'),
  2082. (graph.cellEditor.isContentEditing()) ?
  2083. function()
  2084. {
  2085. document.execCommand('justifyright', false, null);
  2086. } : this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_ALIGN], [mxConstants.ALIGN_RIGHT]), stylePanel3);
  2087. this.styleButtons([left, center, right]);
  2088. if (graph.cellEditor.isContentEditing())
  2089. {
  2090. var clear = this.editorUi.toolbar.addButton('geSprite-removeformat', mxResources.get('removeFormat'),
  2091. function()
  2092. {
  2093. document.execCommand('removeformat', false, null);
  2094. }, stylePanel2);
  2095. this.styleButtons([clear]);
  2096. }
  2097. var top = this.editorUi.toolbar.addButton('geSprite-top', mxResources.get('top'),
  2098. this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_VERTICAL_ALIGN], [mxConstants.ALIGN_TOP]), stylePanel3);
  2099. var middle = this.editorUi.toolbar.addButton('geSprite-middle', mxResources.get('middle'),
  2100. this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_VERTICAL_ALIGN], [mxConstants.ALIGN_MIDDLE]), stylePanel3);
  2101. var bottom = this.editorUi.toolbar.addButton('geSprite-bottom', mxResources.get('bottom'),
  2102. this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_VERTICAL_ALIGN], [mxConstants.ALIGN_BOTTOM]), stylePanel3);
  2103. this.styleButtons([top, middle, bottom]);
  2104. if (mxClient.IS_QUIRKS)
  2105. {
  2106. mxUtils.br(container);
  2107. }
  2108. container.appendChild(stylePanel3);
  2109. // Hack for updating UI state below based on current text selection
  2110. // currentTable is the current selected DOM table updated below
  2111. var sub, sup, full, tableWrapper, currentTable, tableCell, tableRow;
  2112. if (graph.cellEditor.isContentEditing())
  2113. {
  2114. top.style.display = 'none';
  2115. middle.style.display = 'none';
  2116. bottom.style.display = 'none';
  2117. verticalItem.style.display = 'none';
  2118. full = this.editorUi.toolbar.addButton('geSprite-justifyfull', null,
  2119. function()
  2120. {
  2121. document.execCommand('justifyfull', false, null);
  2122. }, stylePanel3);
  2123. this.styleButtons([full,
  2124. sub = this.editorUi.toolbar.addButton('geSprite-subscript',
  2125. mxResources.get('subscript') + ' (' + Editor.ctrlKey + '+,)',
  2126. function()
  2127. {
  2128. document.execCommand('subscript', false, null);
  2129. }, stylePanel3), sup = this.editorUi.toolbar.addButton('geSprite-superscript',
  2130. mxResources.get('superscript') + ' (' + Editor.ctrlKey + '+.)',
  2131. function()
  2132. {
  2133. document.execCommand('superscript', false, null);
  2134. }, stylePanel3)]);
  2135. full.style.marginRight = '9px';
  2136. var tmp = stylePanel3.cloneNode(false);
  2137. tmp.style.paddingTop = '4px';
  2138. var btns = [this.editorUi.toolbar.addButton('geSprite-orderedlist', mxResources.get('numberedList'),
  2139. function()
  2140. {
  2141. document.execCommand('insertorderedlist', false, null);
  2142. }, tmp),
  2143. this.editorUi.toolbar.addButton('geSprite-unorderedlist', mxResources.get('bulletedList'),
  2144. function()
  2145. {
  2146. document.execCommand('insertunorderedlist', false, null);
  2147. }, tmp),
  2148. this.editorUi.toolbar.addButton('geSprite-outdent', mxResources.get('decreaseIndent'),
  2149. function()
  2150. {
  2151. document.execCommand('outdent', false, null);
  2152. }, tmp),
  2153. this.editorUi.toolbar.addButton('geSprite-indent', mxResources.get('increaseIndent'),
  2154. function()
  2155. {
  2156. document.execCommand('indent', false, null);
  2157. }, tmp),
  2158. this.editorUi.toolbar.addButton('geSprite-code', mxResources.get('html'),
  2159. function()
  2160. {
  2161. graph.cellEditor.toggleViewMode();
  2162. }, tmp)];
  2163. this.styleButtons(btns);
  2164. btns[btns.length - 1].style.marginLeft = '9px';
  2165. if (mxClient.IS_QUIRKS)
  2166. {
  2167. mxUtils.br(container);
  2168. tmp.style.height = '40';
  2169. }
  2170. container.appendChild(tmp);
  2171. }
  2172. else
  2173. {
  2174. fontStyleItems[2].style.marginRight = '9px';
  2175. right.style.marginRight = '9px';
  2176. }
  2177. // Label position
  2178. var stylePanel4 = stylePanel.cloneNode(false);
  2179. stylePanel4.style.marginLeft = '0px';
  2180. stylePanel4.style.paddingTop = '8px';
  2181. stylePanel4.style.paddingBottom = '4px';
  2182. stylePanel4.style.fontWeight = 'normal';
  2183. mxUtils.write(stylePanel4, mxResources.get('position'));
  2184. // Adds label position options
  2185. var positionSelect = document.createElement('select');
  2186. positionSelect.style.position = 'absolute';
  2187. positionSelect.style.right = '20px';
  2188. positionSelect.style.width = '97px';
  2189. positionSelect.style.marginTop = '-2px';
  2190. var directions = ['topLeft', 'top', 'topRight', 'left', 'center', 'right', 'bottomLeft', 'bottom', 'bottomRight'];
  2191. var lset = {'topLeft': [mxConstants.ALIGN_LEFT, mxConstants.ALIGN_TOP, mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_BOTTOM],
  2192. 'top': [mxConstants.ALIGN_CENTER, mxConstants.ALIGN_TOP, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_BOTTOM],
  2193. 'topRight': [mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_TOP, mxConstants.ALIGN_LEFT, mxConstants.ALIGN_BOTTOM],
  2194. 'left': [mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_MIDDLE],
  2195. 'center': [mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE],
  2196. 'right': [mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_MIDDLE, mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE],
  2197. 'bottomLeft': [mxConstants.ALIGN_LEFT, mxConstants.ALIGN_BOTTOM, mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_TOP],
  2198. 'bottom': [mxConstants.ALIGN_CENTER, mxConstants.ALIGN_BOTTOM, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_TOP],
  2199. 'bottomRight': [mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_BOTTOM, mxConstants.ALIGN_LEFT, mxConstants.ALIGN_TOP]};
  2200. for (var i = 0; i < directions.length; i++)
  2201. {
  2202. var positionOption = document.createElement('option');
  2203. positionOption.setAttribute('value', directions[i]);
  2204. mxUtils.write(positionOption, mxResources.get(directions[i]));
  2205. positionSelect.appendChild(positionOption);
  2206. }
  2207. stylePanel4.appendChild(positionSelect);
  2208. // Writing direction
  2209. var stylePanel5 = stylePanel.cloneNode(false);
  2210. stylePanel5.style.marginLeft = '0px';
  2211. stylePanel5.style.paddingTop = '4px';
  2212. stylePanel5.style.paddingBottom = '4px';
  2213. stylePanel5.style.fontWeight = 'normal';
  2214. mxUtils.write(stylePanel5, mxResources.get('writingDirection'));
  2215. // Adds writing direction options
  2216. // LATER: Handle reselect of same option in all selects (change event
  2217. // is not fired for same option so have opened state on click) and
  2218. // handle multiple different styles for current selection
  2219. var dirSelect = document.createElement('select');
  2220. dirSelect.style.position = 'absolute';
  2221. dirSelect.style.right = '20px';
  2222. dirSelect.style.width = '97px';
  2223. dirSelect.style.marginTop = '-2px';
  2224. // NOTE: For automatic we use the value null since automatic
  2225. // requires the text to be non formatted and non-wrapped
  2226. var dirs = ['automatic', 'leftToRight', 'rightToLeft'];
  2227. var dirSet = {'automatic': null,
  2228. 'leftToRight': mxConstants.TEXT_DIRECTION_LTR,
  2229. 'rightToLeft': mxConstants.TEXT_DIRECTION_RTL};
  2230. for (var i = 0; i < dirs.length; i++)
  2231. {
  2232. var dirOption = document.createElement('option');
  2233. dirOption.setAttribute('value', dirs[i]);
  2234. mxUtils.write(dirOption, mxResources.get(dirs[i]));
  2235. dirSelect.appendChild(dirOption);
  2236. }
  2237. stylePanel5.appendChild(dirSelect);
  2238. if (!graph.isEditing())
  2239. {
  2240. container.appendChild(stylePanel4);
  2241. mxEvent.addListener(positionSelect, 'change', function(evt)
  2242. {
  2243. graph.getModel().beginUpdate();
  2244. try
  2245. {
  2246. var vals = lset[positionSelect.value];
  2247. if (vals != null)
  2248. {
  2249. graph.setCellStyles(mxConstants.STYLE_LABEL_POSITION, vals[0], graph.getSelectionCells());
  2250. graph.setCellStyles(mxConstants.STYLE_VERTICAL_LABEL_POSITION, vals[1], graph.getSelectionCells());
  2251. graph.setCellStyles(mxConstants.STYLE_ALIGN, vals[2], graph.getSelectionCells());
  2252. graph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, vals[3], graph.getSelectionCells());
  2253. }
  2254. }
  2255. finally
  2256. {
  2257. graph.getModel().endUpdate();
  2258. }
  2259. mxEvent.consume(evt);
  2260. });
  2261. // LATER: Update dir in text editor while editing and update style with label
  2262. // NOTE: The tricky part is handling and passing on the auto value
  2263. container.appendChild(stylePanel5);
  2264. mxEvent.addListener(dirSelect, 'change', function(evt)
  2265. {
  2266. graph.setCellStyles(mxConstants.STYLE_TEXT_DIRECTION, dirSet[dirSelect.value], graph.getSelectionCells());
  2267. mxEvent.consume(evt);
  2268. });
  2269. }
  2270. // Font size
  2271. var input = document.createElement('input');
  2272. input.style.textAlign = 'right';
  2273. input.style.marginTop = '4px';
  2274. if (!mxClient.IS_QUIRKS)
  2275. {
  2276. input.style.position = 'absolute';
  2277. input.style.right = '32px';
  2278. }
  2279. input.style.width = '46px';
  2280. input.style.height = (mxClient.IS_QUIRKS) ? '21px' : '17px';
  2281. stylePanel2.appendChild(input);
  2282. // Workaround for font size 4 if no text is selected is update font size below
  2283. // after first character was entered (as the font element is lazy created)
  2284. var pendingFontSize = null;
  2285. var inputUpdate = this.installInputHandler(input, mxConstants.STYLE_FONTSIZE, Menus.prototype.defaultFontSize, 1, 999, ' pt',
  2286. function(fontSize)
  2287. {
  2288. // IE does not support containsNode
  2289. // KNOWN: Fixes font size issues but bypasses undo
  2290. if (window.getSelection && !mxClient.IS_IE && !mxClient.IS_IE11)
  2291. {
  2292. var selection = window.getSelection();
  2293. var container = (selection.rangeCount > 0) ? selection.getRangeAt(0).commonAncestorContainer :
  2294. graph.cellEditor.textarea;
  2295. function updateSize(elt, ignoreContains)
  2296. {
  2297. if (elt != graph.cellEditor.textarea && (ignoreContains || selection.containsNode(elt, true)))
  2298. {
  2299. if (elt.nodeName == 'FONT')
  2300. {
  2301. elt.removeAttribute('size');
  2302. elt.style.fontSize = fontSize + 'px';
  2303. }
  2304. else
  2305. {
  2306. var css = mxUtils.getCurrentStyle(elt);
  2307. if (css.fontSize != fontSize + 'px')
  2308. {
  2309. if (mxUtils.getCurrentStyle(elt.parentNode).fontSize != fontSize + 'px')
  2310. {
  2311. elt.style.fontSize = fontSize + 'px';
  2312. }
  2313. else
  2314. {
  2315. elt.style.fontSize = '';
  2316. }
  2317. }
  2318. }
  2319. }
  2320. };
  2321. // Wraps text node or mixed selection with leading text in a font element
  2322. if (container == graph.cellEditor.textarea ||
  2323. container.nodeType != mxConstants.NODETYPE_ELEMENT)
  2324. {
  2325. document.execCommand('fontSize', false, '1');
  2326. }
  2327. if (container != graph.cellEditor.textarea)
  2328. {
  2329. container = container.parentNode;
  2330. }
  2331. if (container.nodeType == mxConstants.NODETYPE_ELEMENT)
  2332. {
  2333. var elts = container.getElementsByTagName('*');
  2334. updateSize(container);
  2335. for (var i = 0; i < elts.length; i++)
  2336. {
  2337. updateSize(elts[i]);
  2338. }
  2339. }
  2340. input.value = fontSize + ' pt';
  2341. }
  2342. else
  2343. {
  2344. pendingFontSize = fontSize;
  2345. // Workaround for can't set font size in px is to change font size afterwards
  2346. document.execCommand('fontSize', false, '4');
  2347. var elts = graph.cellEditor.textarea.getElementsByTagName('font');
  2348. for (var i = 0; i < elts.length; i++)
  2349. {
  2350. if (elts[i].getAttribute('size') == '4')
  2351. {
  2352. elts[i].removeAttribute('size');
  2353. elts[i].style.fontSize = pendingFontSize + 'px';
  2354. // Overrides fontSize in input with the one just assigned as a workaround
  2355. // for potential fontSize values of parent elements that don't match
  2356. window.setTimeout(function()
  2357. {
  2358. input.value = pendingFontSize + ' pt';
  2359. pendingFontSize = null;
  2360. }, 0);
  2361. break;
  2362. }
  2363. }
  2364. }
  2365. }, true);
  2366. var stepper = this.createStepper(input, inputUpdate, 1, 10, true, Menus.prototype.defaultFontSize);
  2367. stepper.style.display = input.style.display;
  2368. stepper.style.marginTop = '4px';
  2369. if (!mxClient.IS_QUIRKS)
  2370. {
  2371. stepper.style.right = '20px';
  2372. }
  2373. stylePanel2.appendChild(stepper);
  2374. var arrow = fontMenu.getElementsByTagName('div')[0];
  2375. arrow.style.cssFloat = 'right';
  2376. var bgColorApply = null;
  2377. var currentBgColor = '#ffffff';
  2378. var fontColorApply = null;
  2379. var currentFontColor = '#000000';
  2380. var bgPanel = (graph.cellEditor.isContentEditing()) ? this.createColorOption(mxResources.get('backgroundColor'), function()
  2381. {
  2382. return currentBgColor;
  2383. }, function(color)
  2384. {
  2385. document.execCommand('backcolor', false, (color != mxConstants.NONE) ? color : 'transparent');
  2386. }, '#ffffff',
  2387. {
  2388. install: function(apply) { bgColorApply = apply; },
  2389. destroy: function() { bgColorApply = null; }
  2390. }, null, true) : this.createCellColorOption(mxResources.get('backgroundColor'), mxConstants.STYLE_LABEL_BACKGROUNDCOLOR, '#ffffff');
  2391. bgPanel.style.fontWeight = 'bold';
  2392. var borderPanel = this.createCellColorOption(mxResources.get('borderColor'), mxConstants.STYLE_LABEL_BORDERCOLOR, '#000000');
  2393. borderPanel.style.fontWeight = 'bold';
  2394. var panel = (graph.cellEditor.isContentEditing()) ? this.createColorOption(mxResources.get('fontColor'), function()
  2395. {
  2396. return currentFontColor;
  2397. }, function(color)
  2398. {
  2399. document.execCommand('forecolor', false, (color != mxConstants.NONE) ? color : 'transparent');
  2400. }, '#000000',
  2401. {
  2402. install: function(apply) { fontColorApply = apply; },
  2403. destroy: function() { fontColorApply = null; }
  2404. }, null, true) : this.createCellColorOption(mxResources.get('fontColor'), mxConstants.STYLE_FONTCOLOR, '#000000', function(color)
  2405. {
  2406. if (color == null || color == mxConstants.NONE)
  2407. {
  2408. bgPanel.style.display = 'none';
  2409. }
  2410. else
  2411. {
  2412. bgPanel.style.display = '';
  2413. }
  2414. borderPanel.style.display = bgPanel.style.display;
  2415. }, function(color)
  2416. {
  2417. if (color == null || color == mxConstants.NONE)
  2418. {
  2419. graph.setCellStyles(mxConstants.STYLE_NOLABEL, '1', graph.getSelectionCells());
  2420. }
  2421. else
  2422. {
  2423. graph.setCellStyles(mxConstants.STYLE_NOLABEL, null, graph.getSelectionCells());
  2424. }
  2425. });
  2426. panel.style.fontWeight = 'bold';
  2427. colorPanel.appendChild(panel);
  2428. colorPanel.appendChild(bgPanel);
  2429. if (!graph.cellEditor.isContentEditing())
  2430. {
  2431. colorPanel.appendChild(borderPanel);
  2432. }
  2433. container.appendChild(colorPanel);
  2434. var extraPanel = this.createPanel();
  2435. extraPanel.style.paddingTop = '2px';
  2436. extraPanel.style.paddingBottom = '4px';
  2437. // LATER: Fix toggle using '' instead of 'null'
  2438. var wwOpt = this.createCellOption(mxResources.get('wordWrap'), mxConstants.STYLE_WHITE_SPACE, null, 'wrap', 'null', null, null, true);
  2439. wwOpt.style.fontWeight = 'bold';
  2440. // Word wrap in edge labels only supported via labelWidth style
  2441. if (!ss.containsLabel && !ss.autoSize && ss.edges.length == 0)
  2442. {
  2443. extraPanel.appendChild(wwOpt);
  2444. }
  2445. // Delegates switch of style to formattedText action as it also convertes newlines
  2446. var htmlOpt = this.createCellOption(mxResources.get('formattedText'), 'html', '0',
  2447. null, null, null, ui.actions.get('formattedText'));
  2448. htmlOpt.style.fontWeight = 'bold';
  2449. extraPanel.appendChild(htmlOpt);
  2450. var spacingPanel = this.createPanel();
  2451. spacingPanel.style.paddingTop = '10px';
  2452. spacingPanel.style.paddingBottom = '28px';
  2453. spacingPanel.style.fontWeight = 'normal';
  2454. var span = document.createElement('div');
  2455. span.style.position = 'absolute';
  2456. span.style.width = '70px';
  2457. span.style.marginTop = '0px';
  2458. span.style.fontWeight = 'bold';
  2459. mxUtils.write(span, mxResources.get('spacing'));
  2460. spacingPanel.appendChild(span);
  2461. var topUpdate, globalUpdate, leftUpdate, bottomUpdate, rightUpdate;
  2462. var topSpacing = this.addUnitInput(spacingPanel, 'pt', 91, 44, function()
  2463. {
  2464. topUpdate.apply(this, arguments);
  2465. });
  2466. var globalSpacing = this.addUnitInput(spacingPanel, 'pt', 20, 44, function()
  2467. {
  2468. globalUpdate.apply(this, arguments);
  2469. });
  2470. mxUtils.br(spacingPanel);
  2471. this.addLabel(spacingPanel, mxResources.get('top'), 91);
  2472. this.addLabel(spacingPanel, mxResources.get('global'), 20);
  2473. mxUtils.br(spacingPanel);
  2474. mxUtils.br(spacingPanel);
  2475. var leftSpacing = this.addUnitInput(spacingPanel, 'pt', 162, 44, function()
  2476. {
  2477. leftUpdate.apply(this, arguments);
  2478. });
  2479. var bottomSpacing = this.addUnitInput(spacingPanel, 'pt', 91, 44, function()
  2480. {
  2481. bottomUpdate.apply(this, arguments);
  2482. });
  2483. var rightSpacing = this.addUnitInput(spacingPanel, 'pt', 20, 44, function()
  2484. {
  2485. rightUpdate.apply(this, arguments);
  2486. });
  2487. mxUtils.br(spacingPanel);
  2488. this.addLabel(spacingPanel, mxResources.get('left'), 162);
  2489. this.addLabel(spacingPanel, mxResources.get('bottom'), 91);
  2490. this.addLabel(spacingPanel, mxResources.get('right'), 20);
  2491. if (!graph.cellEditor.isContentEditing())
  2492. {
  2493. container.appendChild(extraPanel);
  2494. container.appendChild(this.createRelativeOption(mxResources.get('opacity'), mxConstants.STYLE_TEXT_OPACITY));
  2495. container.appendChild(spacingPanel);
  2496. }
  2497. else
  2498. {
  2499. var selState = null;
  2500. var lineHeightInput = null;
  2501. container.appendChild(this.createRelativeOption(mxResources.get('lineheight'), null, null, function(input)
  2502. {
  2503. var value = (input.value == '') ? 120 : parseInt(input.value);
  2504. value = Math.max(0, (isNaN(value)) ? 120 : value);
  2505. if (selState != null)
  2506. {
  2507. graph.cellEditor.restoreSelection(selState);
  2508. selState = null;
  2509. }
  2510. var selectedElement = graph.getSelectedElement();
  2511. var node = selectedElement;
  2512. while (node != null && node.nodeType != mxConstants.NODETYPE_ELEMENT)
  2513. {
  2514. node = node.parentNode;
  2515. }
  2516. if (node != null && node == graph.cellEditor.textarea && graph.cellEditor.textarea.firstChild != null)
  2517. {
  2518. if (graph.cellEditor.textarea.firstChild.nodeName != 'P')
  2519. {
  2520. graph.cellEditor.textarea.innerHTML = '<p>' + graph.cellEditor.textarea.innerHTML + '</p>';
  2521. }
  2522. node = graph.cellEditor.textarea.firstChild;
  2523. }
  2524. if (node != null && node != graph.cellEditor.textarea)
  2525. {
  2526. node.style.lineHeight = value + '%';
  2527. }
  2528. input.value = value + ' %';
  2529. }, function(input)
  2530. {
  2531. // Used in CSS handler to update current value
  2532. lineHeightInput = input;
  2533. // KNOWN: Arrow up/down clear selection text in quirks/IE 8
  2534. // Text size via arrow button limits to 16 in IE11. Why?
  2535. mxEvent.addListener(input, 'mousedown', function()
  2536. {
  2537. if (document.activeElement == graph.cellEditor.textarea)
  2538. {
  2539. selState = graph.cellEditor.saveSelection();
  2540. }
  2541. });
  2542. mxEvent.addListener(input, 'touchstart', function()
  2543. {
  2544. if (document.activeElement == graph.cellEditor.textarea)
  2545. {
  2546. selState = graph.cellEditor.saveSelection();
  2547. }
  2548. });
  2549. input.value = '120 %';
  2550. }));
  2551. var insertPanel = stylePanel.cloneNode(false);
  2552. insertPanel.style.paddingLeft = '0px';
  2553. var insertBtns = this.editorUi.toolbar.addItems(['link', 'image'], insertPanel, true);
  2554. var btns = [
  2555. this.editorUi.toolbar.addButton('geSprite-horizontalrule', mxResources.get('insertHorizontalRule'),
  2556. function()
  2557. {
  2558. document.execCommand('inserthorizontalrule', false, null);
  2559. }, insertPanel),
  2560. this.editorUi.toolbar.addMenuFunctionInContainer(insertPanel, 'geSprite-table', mxResources.get('table'), false, mxUtils.bind(this, function(menu)
  2561. {
  2562. this.editorUi.menus.addInsertTableItem(menu);
  2563. }))];
  2564. this.styleButtons(insertBtns);
  2565. this.styleButtons(btns);
  2566. var wrapper2 = this.createPanel();
  2567. wrapper2.style.paddingTop = '10px';
  2568. wrapper2.style.paddingBottom = '10px';
  2569. wrapper2.appendChild(this.createTitle(mxResources.get('insert')));
  2570. wrapper2.appendChild(insertPanel);
  2571. container.appendChild(wrapper2);
  2572. if (mxClient.IS_QUIRKS)
  2573. {
  2574. wrapper2.style.height = '70';
  2575. }
  2576. var tablePanel = stylePanel.cloneNode(false);
  2577. tablePanel.style.paddingLeft = '0px';
  2578. var btns = [
  2579. this.editorUi.toolbar.addButton('geSprite-insertcolumnbefore', mxResources.get('insertColumnBefore'),
  2580. function()
  2581. {
  2582. try
  2583. {
  2584. if (currentTable != null)
  2585. {
  2586. graph.selectNode(graph.insertColumn(currentTable, (tableCell != null) ? tableCell.cellIndex : 0));
  2587. }
  2588. }
  2589. catch (e)
  2590. {
  2591. alert(e);
  2592. }
  2593. }, tablePanel),
  2594. this.editorUi.toolbar.addButton('geSprite-insertcolumnafter', mxResources.get('insertColumnAfter'),
  2595. function()
  2596. {
  2597. try
  2598. {
  2599. if (currentTable != null)
  2600. {
  2601. graph.selectNode(graph.insertColumn(currentTable, (tableCell != null) ? tableCell.cellIndex + 1 : -1));
  2602. }
  2603. }
  2604. catch (e)
  2605. {
  2606. alert(e);
  2607. }
  2608. }, tablePanel),
  2609. this.editorUi.toolbar.addButton('geSprite-deletecolumn', mxResources.get('deleteColumn'),
  2610. function()
  2611. {
  2612. try
  2613. {
  2614. if (currentTable != null && tableCell != null)
  2615. {
  2616. graph.deleteColumn(currentTable, tableCell.cellIndex);
  2617. }
  2618. }
  2619. catch (e)
  2620. {
  2621. alert(e);
  2622. }
  2623. }, tablePanel),
  2624. this.editorUi.toolbar.addButton('geSprite-insertrowbefore', mxResources.get('insertRowBefore'),
  2625. function()
  2626. {
  2627. try
  2628. {
  2629. if (currentTable != null && tableRow != null)
  2630. {
  2631. graph.selectNode(graph.insertRow(currentTable, tableRow.sectionRowIndex));
  2632. }
  2633. }
  2634. catch (e)
  2635. {
  2636. alert(e);
  2637. }
  2638. }, tablePanel),
  2639. this.editorUi.toolbar.addButton('geSprite-insertrowafter', mxResources.get('insertRowAfter'),
  2640. function()
  2641. {
  2642. try
  2643. {
  2644. if (currentTable != null && tableRow != null)
  2645. {
  2646. graph.selectNode(graph.insertRow(currentTable, tableRow.sectionRowIndex + 1));
  2647. }
  2648. }
  2649. catch (e)
  2650. {
  2651. alert(e);
  2652. }
  2653. }, tablePanel),
  2654. this.editorUi.toolbar.addButton('geSprite-deleterow', mxResources.get('deleteRow'),
  2655. function()
  2656. {
  2657. try
  2658. {
  2659. if (currentTable != null && tableRow != null)
  2660. {
  2661. graph.deleteRow(currentTable, tableRow.sectionRowIndex);
  2662. }
  2663. }
  2664. catch (e)
  2665. {
  2666. alert(e);
  2667. }
  2668. }, tablePanel)];
  2669. this.styleButtons(btns);
  2670. btns[2].style.marginRight = '9px';
  2671. var wrapper3 = this.createPanel();
  2672. wrapper3.style.paddingTop = '10px';
  2673. wrapper3.style.paddingBottom = '10px';
  2674. wrapper3.appendChild(this.createTitle(mxResources.get('table')));
  2675. wrapper3.appendChild(tablePanel);
  2676. if (mxClient.IS_QUIRKS)
  2677. {
  2678. mxUtils.br(container);
  2679. wrapper3.style.height = '70';
  2680. }
  2681. var tablePanel2 = stylePanel.cloneNode(false);
  2682. tablePanel2.style.paddingLeft = '0px';
  2683. var btns = [
  2684. this.editorUi.toolbar.addButton('geSprite-strokecolor', mxResources.get('borderColor'),
  2685. mxUtils.bind(this, function()
  2686. {
  2687. if (currentTable != null)
  2688. {
  2689. // Converts rgb(r,g,b) values
  2690. var color = currentTable.style.borderColor.replace(
  2691. /\brgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/g,
  2692. function($0, $1, $2, $3) {
  2693. return "#" + ("0"+Number($1).toString(16)).substr(-2) + ("0"+Number($2).toString(16)).substr(-2) + ("0"+Number($3).toString(16)).substr(-2);
  2694. });
  2695. this.editorUi.pickColor(color, function(newColor)
  2696. {
  2697. if (newColor == null || newColor == mxConstants.NONE)
  2698. {
  2699. currentTable.removeAttribute('border');
  2700. currentTable.style.border = '';
  2701. currentTable.style.borderCollapse = '';
  2702. }
  2703. else
  2704. {
  2705. currentTable.setAttribute('border', '1');
  2706. currentTable.style.border = '1px solid ' + newColor;
  2707. currentTable.style.borderCollapse = 'collapse';
  2708. }
  2709. });
  2710. }
  2711. }), tablePanel2),
  2712. this.editorUi.toolbar.addButton('geSprite-fillcolor', mxResources.get('backgroundColor'),
  2713. mxUtils.bind(this, function()
  2714. {
  2715. // Converts rgb(r,g,b) values
  2716. if (currentTable != null)
  2717. {
  2718. var color = currentTable.style.backgroundColor.replace(
  2719. /\brgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/g,
  2720. function($0, $1, $2, $3) {
  2721. return "#" + ("0"+Number($1).toString(16)).substr(-2) + ("0"+Number($2).toString(16)).substr(-2) + ("0"+Number($3).toString(16)).substr(-2);
  2722. });
  2723. this.editorUi.pickColor(color, function(newColor)
  2724. {
  2725. if (newColor == null || newColor == mxConstants.NONE)
  2726. {
  2727. currentTable.style.backgroundColor = '';
  2728. }
  2729. else
  2730. {
  2731. currentTable.style.backgroundColor = newColor;
  2732. }
  2733. });
  2734. }
  2735. }), tablePanel2),
  2736. this.editorUi.toolbar.addButton('geSprite-fit', mxResources.get('spacing'),
  2737. function()
  2738. {
  2739. if (currentTable != null)
  2740. {
  2741. var value = currentTable.getAttribute('cellPadding') || 0;
  2742. var dlg = new FilenameDialog(ui, value, mxResources.get('apply'), mxUtils.bind(this, function(newValue)
  2743. {
  2744. if (newValue != null && newValue.length > 0)
  2745. {
  2746. currentTable.setAttribute('cellPadding', newValue);
  2747. }
  2748. else
  2749. {
  2750. currentTable.removeAttribute('cellPadding');
  2751. }
  2752. }), mxResources.get('spacing'));
  2753. ui.showDialog(dlg.container, 300, 80, true, true);
  2754. dlg.init();
  2755. }
  2756. }, tablePanel2),
  2757. this.editorUi.toolbar.addButton('geSprite-left', mxResources.get('left'),
  2758. function()
  2759. {
  2760. if (currentTable != null)
  2761. {
  2762. currentTable.setAttribute('align', 'left');
  2763. }
  2764. }, tablePanel2),
  2765. this.editorUi.toolbar.addButton('geSprite-center', mxResources.get('center'),
  2766. function()
  2767. {
  2768. if (currentTable != null)
  2769. {
  2770. currentTable.setAttribute('align', 'center');
  2771. }
  2772. }, tablePanel2),
  2773. this.editorUi.toolbar.addButton('geSprite-right', mxResources.get('right'),
  2774. function()
  2775. {
  2776. if (currentTable != null)
  2777. {
  2778. currentTable.setAttribute('align', 'right');
  2779. }
  2780. }, tablePanel2)];
  2781. this.styleButtons(btns);
  2782. btns[2].style.marginRight = '9px';
  2783. if (mxClient.IS_QUIRKS)
  2784. {
  2785. mxUtils.br(wrapper3);
  2786. mxUtils.br(wrapper3);
  2787. }
  2788. wrapper3.appendChild(tablePanel2);
  2789. container.appendChild(wrapper3);
  2790. tableWrapper = wrapper3;
  2791. }
  2792. function setSelected(elt, selected)
  2793. {
  2794. if (mxClient.IS_IE && (mxClient.IS_QUIRKS || document.documentMode < 10))
  2795. {
  2796. elt.style.filter = (selected) ? 'progid:DXImageTransform.Microsoft.Gradient('+
  2797. 'StartColorStr=\'#c5ecff\', EndColorStr=\'#87d4fb\', GradientType=0)' : '';
  2798. }
  2799. else
  2800. {
  2801. elt.style.backgroundImage = (selected) ? 'linear-gradient(#c5ecff 0px,#87d4fb 100%)' : '';
  2802. }
  2803. };
  2804. var listener = mxUtils.bind(this, function(sender, evt, force)
  2805. {
  2806. ss = this.format.getSelectionState();
  2807. var fontStyle = mxUtils.getValue(ss.style, mxConstants.STYLE_FONTSTYLE, 0);
  2808. setSelected(fontStyleItems[0], (fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD);
  2809. setSelected(fontStyleItems[1], (fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC);
  2810. setSelected(fontStyleItems[2], (fontStyle & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE);
  2811. fontMenu.firstChild.nodeValue = mxUtils.htmlEntities(mxUtils.getValue(ss.style, mxConstants.STYLE_FONTFAMILY, Menus.prototype.defaultFont));
  2812. setSelected(verticalItem, mxUtils.getValue(ss.style, mxConstants.STYLE_HORIZONTAL, '1') == '0');
  2813. if (force || document.activeElement != input)
  2814. {
  2815. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_FONTSIZE, Menus.prototype.defaultFontSize));
  2816. input.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  2817. }
  2818. var align = mxUtils.getValue(ss.style, mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER);
  2819. setSelected(left, align == mxConstants.ALIGN_LEFT);
  2820. setSelected(center, align == mxConstants.ALIGN_CENTER);
  2821. setSelected(right, align == mxConstants.ALIGN_RIGHT);
  2822. var valign = mxUtils.getValue(ss.style, mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE);
  2823. setSelected(top, valign == mxConstants.ALIGN_TOP);
  2824. setSelected(middle, valign == mxConstants.ALIGN_MIDDLE);
  2825. setSelected(bottom, valign == mxConstants.ALIGN_BOTTOM);
  2826. var pos = mxUtils.getValue(ss.style, mxConstants.STYLE_LABEL_POSITION, mxConstants.ALIGN_CENTER);
  2827. var vpos = mxUtils.getValue(ss.style, mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_MIDDLE);
  2828. if (pos == mxConstants.ALIGN_LEFT && vpos == mxConstants.ALIGN_TOP)
  2829. {
  2830. positionSelect.value = 'topLeft';
  2831. }
  2832. else if (pos == mxConstants.ALIGN_CENTER && vpos == mxConstants.ALIGN_TOP)
  2833. {
  2834. positionSelect.value = 'top';
  2835. }
  2836. else if (pos == mxConstants.ALIGN_RIGHT && vpos == mxConstants.ALIGN_TOP)
  2837. {
  2838. positionSelect.value = 'topRight';
  2839. }
  2840. else if (pos == mxConstants.ALIGN_LEFT && vpos == mxConstants.ALIGN_BOTTOM)
  2841. {
  2842. positionSelect.value = 'bottomLeft';
  2843. }
  2844. else if (pos == mxConstants.ALIGN_CENTER && vpos == mxConstants.ALIGN_BOTTOM)
  2845. {
  2846. positionSelect.value = 'bottom';
  2847. }
  2848. else if (pos == mxConstants.ALIGN_RIGHT && vpos == mxConstants.ALIGN_BOTTOM)
  2849. {
  2850. positionSelect.value = 'bottomRight';
  2851. }
  2852. else if (pos == mxConstants.ALIGN_LEFT)
  2853. {
  2854. positionSelect.value = 'left';
  2855. }
  2856. else if (pos == mxConstants.ALIGN_RIGHT)
  2857. {
  2858. positionSelect.value = 'right';
  2859. }
  2860. else
  2861. {
  2862. positionSelect.value = 'center';
  2863. }
  2864. var dir = mxUtils.getValue(ss.style, mxConstants.STYLE_TEXT_DIRECTION, mxConstants.DEFAULT_TEXT_DIRECTION);
  2865. if (dir == mxConstants.TEXT_DIRECTION_RTL)
  2866. {
  2867. dirSelect.value = 'rightToLeft';
  2868. }
  2869. else if (dir == mxConstants.TEXT_DIRECTION_LTR)
  2870. {
  2871. dirSelect.value = 'leftToRight';
  2872. }
  2873. else if (dir == mxConstants.TEXT_DIRECTION_AUTO)
  2874. {
  2875. dirSelect.value = 'automatic';
  2876. }
  2877. if (force || document.activeElement != globalSpacing)
  2878. {
  2879. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_SPACING, 2));
  2880. globalSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  2881. }
  2882. if (force || document.activeElement != topSpacing)
  2883. {
  2884. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_SPACING_TOP, 0));
  2885. topSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  2886. }
  2887. if (force || document.activeElement != rightSpacing)
  2888. {
  2889. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_SPACING_RIGHT, 0));
  2890. rightSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  2891. }
  2892. if (force || document.activeElement != bottomSpacing)
  2893. {
  2894. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_SPACING_BOTTOM, 0));
  2895. bottomSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  2896. }
  2897. if (force || document.activeElement != leftSpacing)
  2898. {
  2899. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_SPACING_LEFT, 0));
  2900. leftSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  2901. }
  2902. });
  2903. globalUpdate = this.installInputHandler(globalSpacing, mxConstants.STYLE_SPACING, 2, -999, 999, ' pt');
  2904. topUpdate = this.installInputHandler(topSpacing, mxConstants.STYLE_SPACING_TOP, 0, -999, 999, ' pt');
  2905. rightUpdate = this.installInputHandler(rightSpacing, mxConstants.STYLE_SPACING_RIGHT, 0, -999, 999, ' pt');
  2906. bottomUpdate = this.installInputHandler(bottomSpacing, mxConstants.STYLE_SPACING_BOTTOM, 0, -999, 999, ' pt');
  2907. leftUpdate = this.installInputHandler(leftSpacing, mxConstants.STYLE_SPACING_LEFT, 0, -999, 999, ' pt');
  2908. this.addKeyHandler(input, listener);
  2909. this.addKeyHandler(globalSpacing, listener);
  2910. this.addKeyHandler(topSpacing, listener);
  2911. this.addKeyHandler(rightSpacing, listener);
  2912. this.addKeyHandler(bottomSpacing, listener);
  2913. this.addKeyHandler(leftSpacing, listener);
  2914. graph.getModel().addListener(mxEvent.CHANGE, listener);
  2915. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  2916. listener();
  2917. if (graph.cellEditor.isContentEditing())
  2918. {
  2919. var updating = false;
  2920. var updateCssHandler = function()
  2921. {
  2922. if (!updating)
  2923. {
  2924. updating = true;
  2925. window.setTimeout(function()
  2926. {
  2927. var selectedElement = graph.getSelectedElement();
  2928. var node = selectedElement;
  2929. while (node != null && node.nodeType != mxConstants.NODETYPE_ELEMENT)
  2930. {
  2931. node = node.parentNode;
  2932. }
  2933. if (node != null)
  2934. {
  2935. // Workaround for commonAncestor on range in IE11 returning parent of common ancestor
  2936. if (node == graph.cellEditor.textarea && graph.cellEditor.textarea.children.length == 1 &&
  2937. graph.cellEditor.textarea.firstChild.nodeType == mxConstants.NODETYPE_ELEMENT)
  2938. {
  2939. node = graph.cellEditor.textarea.firstChild;
  2940. }
  2941. function getRelativeLineHeight(fontSize, lineHeight, elt)
  2942. {
  2943. if (elt.style.lineHeight.substring(elt.style.lineHeight.length - 1) == '%')
  2944. {
  2945. return parseInt(elt.style.lineHeight) / 100;
  2946. }
  2947. else
  2948. {
  2949. return (lineHeight.substring(lineHeight.length - 2) == 'px') ?
  2950. parseFloat(lineHeight) / fontSize : parseInt(lineHeight);
  2951. }
  2952. };
  2953. function getAbsoluteFontSize(fontSize)
  2954. {
  2955. if (fontSize.substring(fontSize.length - 2) == 'px')
  2956. {
  2957. return parseFloat(fontSize);
  2958. }
  2959. else
  2960. {
  2961. return mxConstants.DEFAULT_FONTSIZE;
  2962. }
  2963. }
  2964. //var realCss = mxUtils.getCurrentStyle(selectedElement);
  2965. var css = mxUtils.getCurrentStyle(node);
  2966. var fontSize = getAbsoluteFontSize(css.fontSize);
  2967. var lineHeight = getRelativeLineHeight(fontSize, css.lineHeight, node);
  2968. // Finds common font size
  2969. var elts = node.getElementsByTagName('*');
  2970. // IE does not support containsNode
  2971. if (elts.length > 0 && window.getSelection && !mxClient.IS_IE && !mxClient.IS_IE11)
  2972. {
  2973. var selection = window.getSelection();
  2974. for (var i = 0; i < elts.length; i++)
  2975. {
  2976. if (selection.containsNode(elts[i], true))
  2977. {
  2978. temp = mxUtils.getCurrentStyle(elts[i]);
  2979. fontSize = Math.max(getAbsoluteFontSize(temp.fontSize), fontSize);
  2980. var lh = getRelativeLineHeight(fontSize, temp.lineHeight, elts[i]);
  2981. if (lh != lineHeight || isNaN(lh))
  2982. {
  2983. lineHeight = '';
  2984. }
  2985. }
  2986. }
  2987. }
  2988. if (css != null)
  2989. {
  2990. setSelected(fontStyleItems[0], css.fontWeight == 'bold' || graph.getParentByName(node, 'B', graph.cellEditor.textarea) != null);
  2991. setSelected(fontStyleItems[1], css.fontStyle == 'italic' || graph.getParentByName(node, 'I', graph.cellEditor.textarea) != null);
  2992. setSelected(fontStyleItems[2], graph.getParentByName(node, 'U', graph.cellEditor.textarea) != null);
  2993. setSelected(left, css.textAlign == 'left');
  2994. setSelected(center, css.textAlign == 'center');
  2995. setSelected(right, css.textAlign == 'right');
  2996. setSelected(full, css.textAlign == 'justify');
  2997. setSelected(sup, graph.getParentByName(node, 'SUP', graph.cellEditor.textarea) != null);
  2998. setSelected(sub, graph.getParentByName(node, 'SUB', graph.cellEditor.textarea) != null);
  2999. currentTable = graph.getParentByName(node, 'TABLE', graph.cellEditor.textarea);
  3000. tableRow = (currentTable == null) ? null : graph.getParentByName(node, 'TR', currentTable);
  3001. tableCell = (currentTable == null) ? null : graph.getParentByName(node, 'TD', currentTable);
  3002. tableWrapper.style.display = (currentTable != null) ? '' : 'none';
  3003. if (document.activeElement != input)
  3004. {
  3005. if (node.nodeName == 'FONT' && node.getAttribute('size') == '4' &&
  3006. pendingFontSize != null)
  3007. {
  3008. node.removeAttribute('size');
  3009. node.style.fontSize = pendingFontSize + ' pt';
  3010. pendingFontSize = null;
  3011. }
  3012. else
  3013. {
  3014. input.value = (isNaN(fontSize)) ? '' : fontSize + ' pt';
  3015. }
  3016. var lh = parseFloat(lineHeight);
  3017. if (!isNaN(lh))
  3018. {
  3019. lineHeightInput.value = Math.round(lh * 100) + ' %';
  3020. }
  3021. else
  3022. {
  3023. lineHeightInput.value = '100 %';
  3024. }
  3025. }
  3026. // Converts rgb(r,g,b) values
  3027. var color = css.color.replace(
  3028. /\brgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/g,
  3029. function($0, $1, $2, $3) {
  3030. return "#" + ("0"+Number($1).toString(16)).substr(-2) + ("0"+Number($2).toString(16)).substr(-2) + ("0"+Number($3).toString(16)).substr(-2);
  3031. });
  3032. var color2 = css.backgroundColor.replace(
  3033. /\brgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/g,
  3034. function($0, $1, $2, $3) {
  3035. return "#" + ("0"+Number($1).toString(16)).substr(-2) + ("0"+Number($2).toString(16)).substr(-2) + ("0"+Number($3).toString(16)).substr(-2);
  3036. });
  3037. // Updates the color picker for the current font
  3038. if (fontColorApply != null)
  3039. {
  3040. if (color.charAt(0) == '#')
  3041. {
  3042. currentFontColor = color;
  3043. }
  3044. else
  3045. {
  3046. currentFontColor = '#000000';
  3047. }
  3048. fontColorApply(currentFontColor, true);
  3049. }
  3050. if (bgColorApply != null)
  3051. {
  3052. if (color2.charAt(0) == '#')
  3053. {
  3054. currentBgColor = color2;
  3055. }
  3056. else
  3057. {
  3058. currentBgColor = null;
  3059. }
  3060. bgColorApply(currentBgColor, true);
  3061. }
  3062. // Workaround for firstChild is null or not an object
  3063. // in the log which seems to be IE8- only / 29.01.15
  3064. if (fontMenu.firstChild != null)
  3065. {
  3066. // Strips leading and trailing quotes
  3067. var ff = css.fontFamily;
  3068. if (ff.charAt(0) == '\'')
  3069. {
  3070. ff = ff.substring(1);
  3071. }
  3072. if (ff.charAt(ff.length - 1) == '\'')
  3073. {
  3074. ff = ff.substring(0, ff.length - 1);
  3075. }
  3076. if (ff.charAt(0) == '"')
  3077. {
  3078. ff = ff.substring(1);
  3079. }
  3080. if (ff.charAt(ff.length - 1) == '"')
  3081. {
  3082. ff = ff.substring(0, ff.length - 1);
  3083. }
  3084. fontMenu.firstChild.nodeValue = ff;
  3085. }
  3086. }
  3087. }
  3088. updating = false;
  3089. }, 0);
  3090. }
  3091. };
  3092. mxEvent.addListener(graph.cellEditor.textarea, 'input', updateCssHandler)
  3093. mxEvent.addListener(graph.cellEditor.textarea, 'touchend', updateCssHandler);
  3094. mxEvent.addListener(graph.cellEditor.textarea, 'mouseup', updateCssHandler);
  3095. mxEvent.addListener(graph.cellEditor.textarea, 'keyup', updateCssHandler);
  3096. this.listeners.push({destroy: function()
  3097. {
  3098. // No need to remove listener since textarea is destroyed after edit
  3099. }});
  3100. updateCssHandler();
  3101. }
  3102. return container;
  3103. };
  3104. /**
  3105. * Adds the label menu items to the given menu and parent.
  3106. */
  3107. StyleFormatPanel = function(format, editorUi, container)
  3108. {
  3109. BaseFormatPanel.call(this, format, editorUi, container);
  3110. this.init();
  3111. };
  3112. mxUtils.extend(StyleFormatPanel, BaseFormatPanel);
  3113. /**
  3114. * Adds the label menu items to the given menu and parent.
  3115. */
  3116. StyleFormatPanel.prototype.init = function()
  3117. {
  3118. var ui = this.editorUi;
  3119. var editor = ui.editor;
  3120. var graph = editor.graph;
  3121. var ss = this.format.getSelectionState();
  3122. if (!ss.containsImage || ss.style.shape == 'image')
  3123. {
  3124. this.container.appendChild(this.addFill(this.createPanel()));
  3125. }
  3126. this.container.appendChild(this.addStroke(this.createPanel()));
  3127. this.container.appendChild(this.addLineJumps(this.createPanel()));
  3128. var opacityPanel = this.createRelativeOption(mxResources.get('opacity'), mxConstants.STYLE_OPACITY, 41);
  3129. opacityPanel.style.paddingTop = '8px';
  3130. opacityPanel.style.paddingBottom = '8px';
  3131. this.container.appendChild(opacityPanel);
  3132. this.container.appendChild(this.addEffects(this.createPanel()));
  3133. var opsPanel = this.addEditOps(this.createPanel());
  3134. if (opsPanel.firstChild != null)
  3135. {
  3136. mxUtils.br(opsPanel);
  3137. }
  3138. this.container.appendChild(this.addStyleOps(opsPanel));
  3139. };
  3140. /**
  3141. * Adds the label menu items to the given menu and parent.
  3142. */
  3143. StyleFormatPanel.prototype.addEditOps = function(div)
  3144. {
  3145. var ss = this.format.getSelectionState();
  3146. var btn = null;
  3147. if (this.editorUi.editor.graph.getSelectionCount() == 1)
  3148. {
  3149. btn = mxUtils.button(mxResources.get('editStyle'), mxUtils.bind(this, function(evt)
  3150. {
  3151. this.editorUi.actions.get('editStyle').funct();
  3152. }));
  3153. btn.setAttribute('title', mxResources.get('editStyle') + ' (' + this.editorUi.actions.get('editStyle').shortcut + ')');
  3154. btn.style.width = '202px';
  3155. btn.style.marginBottom = '2px';
  3156. div.appendChild(btn);
  3157. }
  3158. if (ss.image)
  3159. {
  3160. var btn2 = mxUtils.button(mxResources.get('editImage'), mxUtils.bind(this, function(evt)
  3161. {
  3162. this.editorUi.actions.get('image').funct();
  3163. }));
  3164. btn2.setAttribute('title', mxResources.get('editImage'));
  3165. btn2.style.marginBottom = '2px';
  3166. if (btn == null)
  3167. {
  3168. btn2.style.width = '202px';
  3169. }
  3170. else
  3171. {
  3172. btn.style.width = '100px';
  3173. btn2.style.width = '100px';
  3174. btn2.style.marginLeft = '2px';
  3175. }
  3176. div.appendChild(btn2);
  3177. }
  3178. return div;
  3179. };
  3180. /**
  3181. * Adds the label menu items to the given menu and parent.
  3182. */
  3183. StyleFormatPanel.prototype.addFill = function(container)
  3184. {
  3185. var ui = this.editorUi;
  3186. var graph = ui.editor.graph;
  3187. var ss = this.format.getSelectionState();
  3188. container.style.paddingTop = '6px';
  3189. container.style.paddingBottom = '6px';
  3190. // Adds gradient direction option
  3191. var gradientSelect = document.createElement('select');
  3192. gradientSelect.style.position = 'absolute';
  3193. gradientSelect.style.marginTop = '-2px';
  3194. gradientSelect.style.right = (mxClient.IS_QUIRKS) ? '52px' : '72px';
  3195. gradientSelect.style.width = '70px';
  3196. // Stops events from bubbling to color option event handler
  3197. mxEvent.addListener(gradientSelect, 'click', function(evt)
  3198. {
  3199. mxEvent.consume(evt);
  3200. });
  3201. var gradientPanel = this.createCellColorOption(mxResources.get('gradient'), mxConstants.STYLE_GRADIENTCOLOR, '#ffffff', function(color)
  3202. {
  3203. if (color == null || color == mxConstants.NONE)
  3204. {
  3205. gradientSelect.style.display = 'none';
  3206. }
  3207. else
  3208. {
  3209. gradientSelect.style.display = '';
  3210. }
  3211. });
  3212. var fillKey = (ss.style.shape == 'image') ? mxConstants.STYLE_IMAGE_BACKGROUND : mxConstants.STYLE_FILLCOLOR;
  3213. var fillPanel = this.createCellColorOption(mxResources.get('fill'), fillKey, '#ffffff');
  3214. fillPanel.style.fontWeight = 'bold';
  3215. var tmpColor = mxUtils.getValue(ss.style, fillKey, null);
  3216. gradientPanel.style.display = (tmpColor != null && tmpColor != mxConstants.NONE &&
  3217. ss.fill && ss.style.shape != 'image') ? '' : 'none';
  3218. var directions = [mxConstants.DIRECTION_NORTH, mxConstants.DIRECTION_EAST,
  3219. mxConstants.DIRECTION_SOUTH, mxConstants.DIRECTION_WEST];
  3220. for (var i = 0; i < directions.length; i++)
  3221. {
  3222. var gradientOption = document.createElement('option');
  3223. gradientOption.setAttribute('value', directions[i]);
  3224. mxUtils.write(gradientOption, mxResources.get(directions[i]));
  3225. gradientSelect.appendChild(gradientOption);
  3226. }
  3227. gradientPanel.appendChild(gradientSelect);
  3228. var listener = mxUtils.bind(this, function()
  3229. {
  3230. ss = this.format.getSelectionState();
  3231. var value = mxUtils.getValue(ss.style, mxConstants.STYLE_GRADIENT_DIRECTION, mxConstants.DIRECTION_SOUTH);
  3232. // Handles empty string which is not allowed as a value
  3233. if (value == '')
  3234. {
  3235. value = mxConstants.DIRECTION_SOUTH;
  3236. }
  3237. gradientSelect.value = value;
  3238. container.style.display = (ss.fill) ? '' : 'none';
  3239. var fillColor = mxUtils.getValue(ss.style, mxConstants.STYLE_FILLCOLOR, null);
  3240. if (!ss.fill || ss.containsImage || fillColor == null || fillColor == mxConstants.NONE || ss.style.shape == 'filledEdge')
  3241. {
  3242. gradientPanel.style.display = 'none';
  3243. }
  3244. else
  3245. {
  3246. gradientPanel.style.display = '';
  3247. }
  3248. });
  3249. graph.getModel().addListener(mxEvent.CHANGE, listener);
  3250. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  3251. listener();
  3252. mxEvent.addListener(gradientSelect, 'change', function(evt)
  3253. {
  3254. graph.setCellStyles(mxConstants.STYLE_GRADIENT_DIRECTION, gradientSelect.value, graph.getSelectionCells());
  3255. mxEvent.consume(evt);
  3256. });
  3257. container.appendChild(fillPanel);
  3258. container.appendChild(gradientPanel);
  3259. if (ss.style.shape == 'swimlane')
  3260. {
  3261. container.appendChild(this.createCellColorOption(mxResources.get('laneColor'), 'swimlaneFillColor', '#ffffff'));
  3262. }
  3263. return container;
  3264. };
  3265. /**
  3266. * Adds the label menu items to the given menu and parent.
  3267. */
  3268. StyleFormatPanel.prototype.addStroke = function(container)
  3269. {
  3270. var ui = this.editorUi;
  3271. var graph = ui.editor.graph;
  3272. var ss = this.format.getSelectionState();
  3273. container.style.paddingTop = '4px';
  3274. container.style.paddingBottom = '4px';
  3275. container.style.whiteSpace = 'normal';
  3276. var colorPanel = document.createElement('div');
  3277. colorPanel.style.fontWeight = 'bold';
  3278. // Adds gradient direction option
  3279. var styleSelect = document.createElement('select');
  3280. styleSelect.style.position = 'absolute';
  3281. styleSelect.style.marginTop = '-2px';
  3282. styleSelect.style.right = '72px';
  3283. styleSelect.style.width = '80px';
  3284. var styles = ['sharp', 'rounded', 'curved'];
  3285. for (var i = 0; i < styles.length; i++)
  3286. {
  3287. var styleOption = document.createElement('option');
  3288. styleOption.setAttribute('value', styles[i]);
  3289. mxUtils.write(styleOption, mxResources.get(styles[i]));
  3290. styleSelect.appendChild(styleOption);
  3291. }
  3292. mxEvent.addListener(styleSelect, 'change', function(evt)
  3293. {
  3294. graph.getModel().beginUpdate();
  3295. try
  3296. {
  3297. var keys = [mxConstants.STYLE_ROUNDED, mxConstants.STYLE_CURVED];
  3298. // Default for rounded is 1
  3299. var values = ['0', null];
  3300. if (styleSelect.value == 'rounded')
  3301. {
  3302. values = ['1', null];
  3303. }
  3304. else if (styleSelect.value == 'curved')
  3305. {
  3306. values = [null, '1'];
  3307. }
  3308. for (var i = 0; i < keys.length; i++)
  3309. {
  3310. graph.setCellStyles(keys[i], values[i], graph.getSelectionCells());
  3311. }
  3312. ui.fireEvent(new mxEventObject('styleChanged', 'keys', keys,
  3313. 'values', values, 'cells', graph.getSelectionCells()));
  3314. }
  3315. finally
  3316. {
  3317. graph.getModel().endUpdate();
  3318. }
  3319. mxEvent.consume(evt);
  3320. });
  3321. // Stops events from bubbling to color option event handler
  3322. mxEvent.addListener(styleSelect, 'click', function(evt)
  3323. {
  3324. mxEvent.consume(evt);
  3325. });
  3326. var strokeKey = (ss.style.shape == 'image') ? mxConstants.STYLE_IMAGE_BORDER : mxConstants.STYLE_STROKECOLOR;
  3327. var lineColor = this.createCellColorOption(mxResources.get('line'), strokeKey, '#000000');
  3328. lineColor.appendChild(styleSelect);
  3329. colorPanel.appendChild(lineColor);
  3330. // Used if only edges selected
  3331. var stylePanel = colorPanel.cloneNode(false);
  3332. stylePanel.style.fontWeight = 'normal';
  3333. stylePanel.style.whiteSpace = 'nowrap';
  3334. stylePanel.style.position = 'relative';
  3335. stylePanel.style.paddingLeft = '16px'
  3336. stylePanel.style.marginBottom = '2px';
  3337. stylePanel.style.marginTop = '2px';
  3338. stylePanel.className = 'geToolbarContainer';
  3339. var addItem = mxUtils.bind(this, function(menu, width, cssName, keys, values)
  3340. {
  3341. var item = this.editorUi.menus.styleChange(menu, '', keys, values, 'geIcon', null);
  3342. var pat = document.createElement('div');
  3343. pat.style.width = width + 'px';
  3344. pat.style.height = '1px';
  3345. pat.style.borderBottom = '1px ' + cssName + ' black';
  3346. pat.style.paddingTop = '6px';
  3347. item.firstChild.firstChild.style.padding = '0px 4px 0px 4px';
  3348. item.firstChild.firstChild.style.width = width + 'px';
  3349. item.firstChild.firstChild.appendChild(pat);
  3350. return item;
  3351. });
  3352. var pattern = this.editorUi.toolbar.addMenuFunctionInContainer(stylePanel, 'geSprite-orthogonal', mxResources.get('pattern'), false, mxUtils.bind(this, function(menu)
  3353. {
  3354. addItem(menu, 75, 'solid', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], [null, null]).setAttribute('title', mxResources.get('solid'));
  3355. addItem(menu, 75, 'dashed', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', null]).setAttribute('title', mxResources.get('dashed'));
  3356. addItem(menu, 75, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 1']).setAttribute('title', mxResources.get('dotted') + ' (1)');
  3357. addItem(menu, 75, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 2']).setAttribute('title', mxResources.get('dotted') + ' (2)');
  3358. addItem(menu, 75, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 4']).setAttribute('title', mxResources.get('dotted') + ' (3)');
  3359. }));
  3360. // Used for mixed selection (vertices and edges)
  3361. var altStylePanel = stylePanel.cloneNode(false);
  3362. var edgeShape = this.editorUi.toolbar.addMenuFunctionInContainer(altStylePanel, 'geSprite-connection', mxResources.get('connection'), false, mxUtils.bind(this, function(menu)
  3363. {
  3364. this.editorUi.menus.styleChange(menu, '', [mxConstants.STYLE_SHAPE, mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE, 'width'], [null, null, null, null], 'geIcon geSprite geSprite-connection', null, true).setAttribute('title', mxResources.get('line'));
  3365. this.editorUi.menus.styleChange(menu, '', [mxConstants.STYLE_SHAPE, mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE, 'width'], ['link', null, null, null], 'geIcon geSprite geSprite-linkedge', null, true).setAttribute('title', mxResources.get('link'));
  3366. this.editorUi.menus.styleChange(menu, '', [mxConstants.STYLE_SHAPE, mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE, 'width'], ['flexArrow', null, null, null], 'geIcon geSprite geSprite-arrow', null, true).setAttribute('title', mxResources.get('arrow'));
  3367. this.editorUi.menus.styleChange(menu, '', [mxConstants.STYLE_SHAPE, mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE, 'width'], ['arrow', null, null, null], 'geIcon geSprite geSprite-simplearrow', null, true).setAttribute('title', mxResources.get('simpleArrow'));
  3368. }));
  3369. var altPattern = this.editorUi.toolbar.addMenuFunctionInContainer(altStylePanel, 'geSprite-orthogonal', mxResources.get('pattern'), false, mxUtils.bind(this, function(menu)
  3370. {
  3371. addItem(menu, 33, 'solid', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], [null, null]).setAttribute('title', mxResources.get('solid'));
  3372. addItem(menu, 33, 'dashed', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', null]).setAttribute('title', mxResources.get('dashed'));
  3373. addItem(menu, 33, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 1']).setAttribute('title', mxResources.get('dotted') + ' (1)');
  3374. addItem(menu, 33, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 2']).setAttribute('title', mxResources.get('dotted') + ' (2)');
  3375. addItem(menu, 33, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 4']).setAttribute('title', mxResources.get('dotted') + ' (3)');
  3376. }));
  3377. var stylePanel2 = stylePanel.cloneNode(false);
  3378. // Stroke width
  3379. var input = document.createElement('input');
  3380. input.style.textAlign = 'right';
  3381. input.style.marginTop = '2px';
  3382. input.style.width = '41px';
  3383. input.setAttribute('title', mxResources.get('linewidth'));
  3384. stylePanel.appendChild(input);
  3385. var altInput = input.cloneNode(true);
  3386. altStylePanel.appendChild(altInput);
  3387. function update(evt)
  3388. {
  3389. // Maximum stroke width is 999
  3390. var value = parseInt(input.value);
  3391. value = Math.min(999, Math.max(1, (isNaN(value)) ? 1 : value));
  3392. if (value != mxUtils.getValue(ss.style, mxConstants.STYLE_STROKEWIDTH, 1))
  3393. {
  3394. graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, value, graph.getSelectionCells());
  3395. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_STROKEWIDTH],
  3396. 'values', [value], 'cells', graph.getSelectionCells()));
  3397. }
  3398. input.value = value + ' pt';
  3399. mxEvent.consume(evt);
  3400. };
  3401. function altUpdate(evt)
  3402. {
  3403. // Maximum stroke width is 999
  3404. var value = parseInt(altInput.value);
  3405. value = Math.min(999, Math.max(1, (isNaN(value)) ? 1 : value));
  3406. if (value != mxUtils.getValue(ss.style, mxConstants.STYLE_STROKEWIDTH, 1))
  3407. {
  3408. graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, value, graph.getSelectionCells());
  3409. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_STROKEWIDTH],
  3410. 'values', [value], 'cells', graph.getSelectionCells()));
  3411. }
  3412. altInput.value = value + ' pt';
  3413. mxEvent.consume(evt);
  3414. };
  3415. var stepper = this.createStepper(input, update, 1, 9);
  3416. stepper.style.display = input.style.display;
  3417. stepper.style.marginTop = '2px';
  3418. stylePanel.appendChild(stepper);
  3419. var altStepper = this.createStepper(altInput, altUpdate, 1, 9);
  3420. altStepper.style.display = altInput.style.display;
  3421. altStepper.style.marginTop = '2px';
  3422. altStylePanel.appendChild(altStepper);
  3423. if (!mxClient.IS_QUIRKS)
  3424. {
  3425. input.style.position = 'absolute';
  3426. input.style.right = '32px';
  3427. input.style.height = '15px';
  3428. stepper.style.right = '20px';
  3429. altInput.style.position = 'absolute';
  3430. altInput.style.right = '32px';
  3431. altInput.style.height = '15px';
  3432. altStepper.style.right = '20px';
  3433. }
  3434. else
  3435. {
  3436. input.style.height = '17px';
  3437. altInput.style.height = '17px';
  3438. }
  3439. mxEvent.addListener(input, 'blur', update);
  3440. mxEvent.addListener(input, 'change', update);
  3441. mxEvent.addListener(altInput, 'blur', altUpdate);
  3442. mxEvent.addListener(altInput, 'change', altUpdate);
  3443. if (mxClient.IS_QUIRKS)
  3444. {
  3445. mxUtils.br(stylePanel2);
  3446. mxUtils.br(stylePanel2);
  3447. }
  3448. var edgeStyle = this.editorUi.toolbar.addMenuFunctionInContainer(stylePanel2, 'geSprite-orthogonal', mxResources.get('waypoints'), false, mxUtils.bind(this, function(menu)
  3449. {
  3450. if (ss.style.shape != 'arrow')
  3451. {
  3452. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], [null, null, null], 'geIcon geSprite geSprite-straight', null, true).setAttribute('title', mxResources.get('straight'));
  3453. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['orthogonalEdgeStyle', null, null], 'geIcon geSprite geSprite-orthogonal', null, true).setAttribute('title', mxResources.get('orthogonal'));
  3454. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_ELBOW, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['elbowEdgeStyle', null, null, null], 'geIcon geSprite geSprite-horizontalelbow', null, true).setAttribute('title', mxResources.get('simple'));
  3455. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_ELBOW, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['elbowEdgeStyle', 'vertical', null, null], 'geIcon geSprite geSprite-verticalelbow', null, true).setAttribute('title', mxResources.get('simple'));
  3456. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_ELBOW, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['isometricEdgeStyle', null, null, null], 'geIcon geSprite geSprite-horizontalisometric', null, true).setAttribute('title', mxResources.get('isometric'));
  3457. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_ELBOW, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['isometricEdgeStyle', 'vertical', null, null], 'geIcon geSprite geSprite-verticalisometric', null, true).setAttribute('title', mxResources.get('isometric'));
  3458. if (ss.style.shape == 'connector')
  3459. {
  3460. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['orthogonalEdgeStyle', '1', null], 'geIcon geSprite geSprite-curved', null, true).setAttribute('title', mxResources.get('curved'));
  3461. }
  3462. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_EDGE, mxConstants.STYLE_CURVED, mxConstants.STYLE_NOEDGESTYLE], ['entityRelationEdgeStyle', null, null], 'geIcon geSprite geSprite-entity', null, true).setAttribute('title', mxResources.get('entityRelation'));
  3463. }
  3464. }));
  3465. var lineStart = this.editorUi.toolbar.addMenuFunctionInContainer(stylePanel2, 'geSprite-startclassic', mxResources.get('linestart'), false, mxUtils.bind(this, function(menu)
  3466. {
  3467. if (ss.style.shape == 'connector' || ss.style.shape == 'flexArrow' || ss.style.shape == 'filledEdge')
  3468. {
  3469. var item = this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.NONE, 0], 'geIcon', null, false);
  3470. item.setAttribute('title', mxResources.get('none'));
  3471. item.firstChild.firstChild.innerHTML = '<font style="font-size:10px;">' + mxUtils.htmlEntities(mxResources.get('none')) + '</font>';
  3472. if (ss.style.shape == 'connector' || ss.style.shape == 'filledEdge')
  3473. {
  3474. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_CLASSIC, 1], 'geIcon geSprite geSprite-startclassic', null, false).setAttribute('title', mxResources.get('classic'));
  3475. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_CLASSIC_THIN, 1], 'geIcon geSprite geSprite-startclassicthin', null, false);
  3476. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_OPEN, 0], 'geIcon geSprite geSprite-startopen', null, false).setAttribute('title', mxResources.get('openArrow'));
  3477. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_OPEN_THIN, 0], 'geIcon geSprite geSprite-startopenthin', null, false);
  3478. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['openAsync', 0], 'geIcon geSprite geSprite-startopenasync', null, false);
  3479. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_BLOCK, 1], 'geIcon geSprite geSprite-startblock', null, false).setAttribute('title', mxResources.get('block'));
  3480. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_BLOCK_THIN, 1], 'geIcon geSprite geSprite-startblockthin', null, false);
  3481. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['async', 1], 'geIcon geSprite geSprite-startasync', null, false);
  3482. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_OVAL, 1], 'geIcon geSprite geSprite-startoval', null, false).setAttribute('title', mxResources.get('oval'));
  3483. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_DIAMOND, 1], 'geIcon geSprite geSprite-startdiamond', null, false).setAttribute('title', mxResources.get('diamond'));
  3484. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_DIAMOND_THIN, 1], 'geIcon geSprite geSprite-startthindiamond', null, false).setAttribute('title', mxResources.get('diamondThin'));
  3485. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_CLASSIC, 0], 'geIcon geSprite geSprite-startclassictrans', null, false).setAttribute('title', mxResources.get('classic'));
  3486. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_CLASSIC_THIN, 0], 'geIcon geSprite geSprite-startclassicthintrans', null, false);
  3487. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_BLOCK, 0], 'geIcon geSprite geSprite-startblocktrans', null, false).setAttribute('title', mxResources.get('block'));
  3488. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_BLOCK_THIN, 0], 'geIcon geSprite geSprite-startblockthintrans', null, false);
  3489. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['async', 0], 'geIcon geSprite geSprite-startasynctrans', null, false);
  3490. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_OVAL, 0], 'geIcon geSprite geSprite-startovaltrans', null, false).setAttribute('title', mxResources.get('oval'));
  3491. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_DIAMOND, 0], 'geIcon geSprite geSprite-startdiamondtrans', null, false).setAttribute('title', mxResources.get('diamond'));
  3492. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_DIAMOND_THIN, 0], 'geIcon geSprite geSprite-startthindiamondtrans', null, false).setAttribute('title', mxResources.get('diamondThin'));
  3493. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['dash', 0], 'geIcon geSprite geSprite-startdash', null, false);
  3494. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['cross', 0], 'geIcon geSprite geSprite-startcross', null, false);
  3495. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['circlePlus', 0], 'geIcon geSprite geSprite-startcircleplus', null, false);
  3496. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['circle', 1], 'geIcon geSprite geSprite-startcircle', null, false);
  3497. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERone', 0], 'geIcon geSprite geSprite-starterone', null, false);
  3498. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERmandOne', 0], 'geIcon geSprite geSprite-starteronetoone', null, false);
  3499. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERmany', 0], 'geIcon geSprite geSprite-startermany', null, false);
  3500. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERoneToMany', 0], 'geIcon geSprite geSprite-starteronetomany', null, false);
  3501. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERzeroToOne', 1], 'geIcon geSprite geSprite-starteroneopt', null, false);
  3502. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERzeroToMany', 1], 'geIcon geSprite geSprite-startermanyopt', null, false);
  3503. }
  3504. else
  3505. {
  3506. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW], [mxConstants.ARROW_BLOCK], 'geIcon geSprite geSprite-startblocktrans', null, false).setAttribute('title', mxResources.get('block'));
  3507. }
  3508. }
  3509. }));
  3510. var lineEnd = this.editorUi.toolbar.addMenuFunctionInContainer(stylePanel2, 'geSprite-endclassic', mxResources.get('lineend'), false, mxUtils.bind(this, function(menu)
  3511. {
  3512. if (ss.style.shape == 'connector' || ss.style.shape == 'flexArrow' || ss.style.shape == 'filledEdge')
  3513. {
  3514. var item = this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.NONE, 0], 'geIcon', null, false);
  3515. item.setAttribute('title', mxResources.get('none'));
  3516. item.firstChild.firstChild.innerHTML = '<font style="font-size:10px;">' + mxUtils.htmlEntities(mxResources.get('none')) + '</font>';
  3517. if (ss.style.shape == 'connector' || ss.style.shape == 'filledEdge')
  3518. {
  3519. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_CLASSIC, 1], 'geIcon geSprite geSprite-endclassic', null, false).setAttribute('title', mxResources.get('classic'));
  3520. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_CLASSIC_THIN, 1], 'geIcon geSprite geSprite-endclassicthin', null, false);
  3521. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_OPEN, 0], 'geIcon geSprite geSprite-endopen', null, false).setAttribute('title', mxResources.get('openArrow'));
  3522. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_OPEN_THIN, 0], 'geIcon geSprite geSprite-endopenthin', null, false);
  3523. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['openAsync', 0], 'geIcon geSprite geSprite-endopenasync', null, false);
  3524. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_BLOCK, 1], 'geIcon geSprite geSprite-endblock', null, false).setAttribute('title', mxResources.get('block'));
  3525. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_BLOCK_THIN, 1], 'geIcon geSprite geSprite-endblockthin', null, false);
  3526. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['async', 1], 'geIcon geSprite geSprite-endasync', null, false);
  3527. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_OVAL, 1], 'geIcon geSprite geSprite-endoval', null, false).setAttribute('title', mxResources.get('oval'));
  3528. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_DIAMOND, 1], 'geIcon geSprite geSprite-enddiamond', null, false).setAttribute('title', mxResources.get('diamond'));
  3529. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_DIAMOND_THIN, 1], 'geIcon geSprite geSprite-endthindiamond', null, false).setAttribute('title', mxResources.get('diamondThin'));
  3530. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_CLASSIC, 0], 'geIcon geSprite geSprite-endclassictrans', null, false).setAttribute('title', mxResources.get('classic'));
  3531. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_CLASSIC_THIN, 0], 'geIcon geSprite geSprite-endclassicthintrans', null, false);
  3532. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_BLOCK, 0], 'geIcon geSprite geSprite-endblocktrans', null, false).setAttribute('title', mxResources.get('block'));
  3533. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_BLOCK_THIN, 0], 'geIcon geSprite geSprite-endblockthintrans', null, false);
  3534. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['async', 0], 'geIcon geSprite geSprite-endasynctrans', null, false);
  3535. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_OVAL, 0], 'geIcon geSprite geSprite-endovaltrans', null, false).setAttribute('title', mxResources.get('oval'));
  3536. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_DIAMOND, 0], 'geIcon geSprite geSprite-enddiamondtrans', null, false).setAttribute('title', mxResources.get('diamond'));
  3537. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_DIAMOND_THIN, 0], 'geIcon geSprite geSprite-endthindiamondtrans', null, false).setAttribute('title', mxResources.get('diamondThin'));
  3538. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['dash', 0], 'geIcon geSprite geSprite-enddash', null, false);
  3539. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['cross', 0], 'geIcon geSprite geSprite-endcross', null, false);
  3540. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['circlePlus', 0], 'geIcon geSprite geSprite-endcircleplus', null, false);
  3541. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['circle', 1], 'geIcon geSprite geSprite-endcircle', null, false);
  3542. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERone', 0], 'geIcon geSprite geSprite-enderone', null, false);
  3543. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERmandOne', 0], 'geIcon geSprite geSprite-enderonetoone', null, false);
  3544. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERmany', 0], 'geIcon geSprite geSprite-endermany', null, false);
  3545. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERoneToMany', 0], 'geIcon geSprite geSprite-enderonetomany', null, false);
  3546. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERzeroToOne', 1], 'geIcon geSprite geSprite-enderoneopt', null, false);
  3547. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERzeroToMany', 1], 'geIcon geSprite geSprite-endermanyopt', null, false);
  3548. }
  3549. else
  3550. {
  3551. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW], [mxConstants.ARROW_BLOCK], 'geIcon geSprite geSprite-endblocktrans', null, false).setAttribute('title', mxResources.get('block'));
  3552. }
  3553. }
  3554. }));
  3555. this.addArrow(edgeShape, 8);
  3556. this.addArrow(edgeStyle);
  3557. this.addArrow(lineStart);
  3558. this.addArrow(lineEnd);
  3559. var symbol = this.addArrow(pattern, 9);
  3560. symbol.className = 'geIcon';
  3561. symbol.style.width = '84px';
  3562. var altSymbol = this.addArrow(altPattern, 9);
  3563. altSymbol.className = 'geIcon';
  3564. altSymbol.style.width = '22px';
  3565. var solid = document.createElement('div');
  3566. solid.style.width = '85px';
  3567. solid.style.height = '1px';
  3568. solid.style.borderBottom = '1px solid black';
  3569. solid.style.marginBottom = '9px';
  3570. symbol.appendChild(solid);
  3571. var altSolid = document.createElement('div');
  3572. altSolid.style.width = '23px';
  3573. altSolid.style.height = '1px';
  3574. altSolid.style.borderBottom = '1px solid black';
  3575. altSolid.style.marginBottom = '9px';
  3576. altSymbol.appendChild(altSolid);
  3577. pattern.style.height = '15px';
  3578. altPattern.style.height = '15px';
  3579. edgeShape.style.height = '15px';
  3580. edgeStyle.style.height = '17px';
  3581. lineStart.style.marginLeft = '3px';
  3582. lineStart.style.height = '17px';
  3583. lineEnd.style.marginLeft = '3px';
  3584. lineEnd.style.height = '17px';
  3585. container.appendChild(colorPanel);
  3586. container.appendChild(altStylePanel);
  3587. container.appendChild(stylePanel);
  3588. var arrowPanel = stylePanel.cloneNode(false);
  3589. arrowPanel.style.paddingBottom = '6px';
  3590. arrowPanel.style.paddingTop = '4px';
  3591. arrowPanel.style.fontWeight = 'normal';
  3592. var span = document.createElement('div');
  3593. span.style.position = 'absolute';
  3594. span.style.marginLeft = '3px';
  3595. span.style.marginBottom = '12px';
  3596. span.style.marginTop = '2px';
  3597. span.style.fontWeight = 'normal';
  3598. span.style.width = '76px';
  3599. mxUtils.write(span, mxResources.get('lineend'));
  3600. arrowPanel.appendChild(span);
  3601. var endSpacingUpdate, endSizeUpdate;
  3602. var endSpacing = this.addUnitInput(arrowPanel, 'pt', 74, 33, function()
  3603. {
  3604. endSpacingUpdate.apply(this, arguments);
  3605. });
  3606. var endSize = this.addUnitInput(arrowPanel, 'pt', 20, 33, function()
  3607. {
  3608. endSizeUpdate.apply(this, arguments);
  3609. });
  3610. mxUtils.br(arrowPanel);
  3611. var spacer = document.createElement('div');
  3612. spacer.style.height = '8px';
  3613. arrowPanel.appendChild(spacer);
  3614. span = span.cloneNode(false);
  3615. mxUtils.write(span, mxResources.get('linestart'));
  3616. arrowPanel.appendChild(span);
  3617. var startSpacingUpdate, startSizeUpdate;
  3618. var startSpacing = this.addUnitInput(arrowPanel, 'pt', 74, 33, function()
  3619. {
  3620. startSpacingUpdate.apply(this, arguments);
  3621. });
  3622. var startSize = this.addUnitInput(arrowPanel, 'pt', 20, 33, function()
  3623. {
  3624. startSizeUpdate.apply(this, arguments);
  3625. });
  3626. mxUtils.br(arrowPanel);
  3627. this.addLabel(arrowPanel, mxResources.get('spacing'), 74, 50);
  3628. this.addLabel(arrowPanel, mxResources.get('size'), 20, 50);
  3629. mxUtils.br(arrowPanel);
  3630. var perimeterPanel = colorPanel.cloneNode(false);
  3631. perimeterPanel.style.fontWeight = 'normal';
  3632. perimeterPanel.style.position = 'relative';
  3633. perimeterPanel.style.paddingLeft = '16px'
  3634. perimeterPanel.style.marginBottom = '2px';
  3635. perimeterPanel.style.marginTop = '6px';
  3636. perimeterPanel.style.borderWidth = '0px';
  3637. perimeterPanel.style.paddingBottom = '18px';
  3638. var span = document.createElement('div');
  3639. span.style.position = 'absolute';
  3640. span.style.marginLeft = '3px';
  3641. span.style.marginBottom = '12px';
  3642. span.style.marginTop = '1px';
  3643. span.style.fontWeight = 'normal';
  3644. span.style.width = '120px';
  3645. mxUtils.write(span, mxResources.get('perimeter'));
  3646. perimeterPanel.appendChild(span);
  3647. var perimeterUpdate;
  3648. var perimeterSpacing = this.addUnitInput(perimeterPanel, 'pt', 20, 41, function()
  3649. {
  3650. perimeterUpdate.apply(this, arguments);
  3651. });
  3652. if (ss.edges.length == graph.getSelectionCount())
  3653. {
  3654. container.appendChild(stylePanel2);
  3655. if (mxClient.IS_QUIRKS)
  3656. {
  3657. mxUtils.br(container);
  3658. mxUtils.br(container);
  3659. }
  3660. container.appendChild(arrowPanel);
  3661. }
  3662. else if (ss.vertices.length == graph.getSelectionCount())
  3663. {
  3664. if (mxClient.IS_QUIRKS)
  3665. {
  3666. mxUtils.br(container);
  3667. }
  3668. container.appendChild(perimeterPanel);
  3669. }
  3670. var listener = mxUtils.bind(this, function(sender, evt, force)
  3671. {
  3672. ss = this.format.getSelectionState();
  3673. var color = mxUtils.getValue(ss.style, strokeKey, null);
  3674. if (force || document.activeElement != input)
  3675. {
  3676. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_STROKEWIDTH, 1));
  3677. input.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3678. }
  3679. if (force || document.activeElement != altInput)
  3680. {
  3681. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_STROKEWIDTH, 1));
  3682. altInput.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3683. }
  3684. styleSelect.style.visibility = (ss.style.shape == 'connector' || ss.style.shape == 'filledEdge') ? '' : 'hidden';
  3685. if (mxUtils.getValue(ss.style, mxConstants.STYLE_CURVED, null) == '1')
  3686. {
  3687. styleSelect.value = 'curved';
  3688. }
  3689. else if (mxUtils.getValue(ss.style, mxConstants.STYLE_ROUNDED, null) == '1')
  3690. {
  3691. styleSelect.value = 'rounded';
  3692. }
  3693. if (mxUtils.getValue(ss.style, mxConstants.STYLE_DASHED, null) == '1')
  3694. {
  3695. if (mxUtils.getValue(ss.style, mxConstants.STYLE_DASH_PATTERN, null) == null)
  3696. {
  3697. solid.style.borderBottom = '1px dashed black';
  3698. }
  3699. else
  3700. {
  3701. solid.style.borderBottom = '1px dotted black';
  3702. }
  3703. }
  3704. else
  3705. {
  3706. solid.style.borderBottom = '1px solid black';
  3707. }
  3708. altSolid.style.borderBottom = solid.style.borderBottom;
  3709. // Updates toolbar icon for edge style
  3710. var edgeStyleDiv = edgeStyle.getElementsByTagName('div')[0];
  3711. var es = mxUtils.getValue(ss.style, mxConstants.STYLE_EDGE, null);
  3712. if (mxUtils.getValue(ss.style, mxConstants.STYLE_NOEDGESTYLE, null) == '1')
  3713. {
  3714. es = null;
  3715. }
  3716. if (es == 'orthogonalEdgeStyle' && mxUtils.getValue(ss.style, mxConstants.STYLE_CURVED, null) == '1')
  3717. {
  3718. edgeStyleDiv.className = 'geSprite geSprite-curved';
  3719. }
  3720. else if (es == 'straight' || es == 'none' || es == null)
  3721. {
  3722. edgeStyleDiv.className = 'geSprite geSprite-straight';
  3723. }
  3724. else if (es == 'entityRelationEdgeStyle')
  3725. {
  3726. edgeStyleDiv.className = 'geSprite geSprite-entity';
  3727. }
  3728. else if (es == 'elbowEdgeStyle')
  3729. {
  3730. edgeStyleDiv.className = 'geSprite ' + ((mxUtils.getValue(ss.style,
  3731. mxConstants.STYLE_ELBOW, null) == 'vertical') ?
  3732. 'geSprite-verticalelbow' : 'geSprite-horizontalelbow');
  3733. }
  3734. else if (es == 'isometricEdgeStyle')
  3735. {
  3736. edgeStyleDiv.className = 'geSprite ' + ((mxUtils.getValue(ss.style,
  3737. mxConstants.STYLE_ELBOW, null) == 'vertical') ?
  3738. 'geSprite-verticalisometric' : 'geSprite-horizontalisometric');
  3739. }
  3740. else
  3741. {
  3742. edgeStyleDiv.className = 'geSprite geSprite-orthogonal';
  3743. }
  3744. // Updates icon for edge shape
  3745. var edgeShapeDiv = edgeShape.getElementsByTagName('div')[0];
  3746. if (ss.style.shape == 'link')
  3747. {
  3748. edgeShapeDiv.className = 'geSprite geSprite-linkedge';
  3749. }
  3750. else if (ss.style.shape == 'flexArrow')
  3751. {
  3752. edgeShapeDiv.className = 'geSprite geSprite-arrow';
  3753. }
  3754. else if (ss.style.shape == 'arrow')
  3755. {
  3756. edgeShapeDiv.className = 'geSprite geSprite-simplearrow';
  3757. }
  3758. else
  3759. {
  3760. edgeShapeDiv.className = 'geSprite geSprite-connection';
  3761. }
  3762. if (ss.edges.length == graph.getSelectionCount())
  3763. {
  3764. altStylePanel.style.display = '';
  3765. stylePanel.style.display = 'none';
  3766. }
  3767. else
  3768. {
  3769. altStylePanel.style.display = 'none';
  3770. stylePanel.style.display = '';
  3771. }
  3772. function updateArrow(marker, fill, elt, prefix)
  3773. {
  3774. var markerDiv = elt.getElementsByTagName('div')[0];
  3775. markerDiv.className = ui.getCssClassForMarker(prefix, ss.style.shape, marker, fill);
  3776. if (markerDiv.className == 'geSprite geSprite-noarrow')
  3777. {
  3778. markerDiv.innerHTML = mxUtils.htmlEntities(mxResources.get('none'));
  3779. markerDiv.style.backgroundImage = 'none';
  3780. markerDiv.style.verticalAlign = 'top';
  3781. markerDiv.style.marginTop = '5px';
  3782. markerDiv.style.fontSize = '10px';
  3783. markerDiv.nextSibling.style.marginTop = '0px';
  3784. }
  3785. return markerDiv;
  3786. };
  3787. var sourceDiv = updateArrow(mxUtils.getValue(ss.style, mxConstants.STYLE_STARTARROW, null),
  3788. mxUtils.getValue(ss.style, 'startFill', '1'), lineStart, 'start');
  3789. var targetDiv = updateArrow(mxUtils.getValue(ss.style, mxConstants.STYLE_ENDARROW, null),
  3790. mxUtils.getValue(ss.style, 'endFill', '1'), lineEnd, 'end');
  3791. // Special cases for markers
  3792. if (ss.style.shape == 'arrow')
  3793. {
  3794. sourceDiv.className = 'geSprite geSprite-noarrow';
  3795. targetDiv.className = 'geSprite geSprite-endblocktrans';
  3796. }
  3797. else if (ss.style.shape == 'link')
  3798. {
  3799. sourceDiv.className = 'geSprite geSprite-noarrow';
  3800. targetDiv.className = 'geSprite geSprite-noarrow';
  3801. }
  3802. mxUtils.setOpacity(edgeStyle, (ss.style.shape == 'arrow') ? 30 : 100);
  3803. if (ss.style.shape != 'connector' && ss.style.shape != 'flexArrow' && ss.style.shape != 'filledEdge')
  3804. {
  3805. mxUtils.setOpacity(lineStart, 30);
  3806. mxUtils.setOpacity(lineEnd, 30);
  3807. }
  3808. else
  3809. {
  3810. mxUtils.setOpacity(lineStart, 100);
  3811. mxUtils.setOpacity(lineEnd, 100);
  3812. }
  3813. if (force || document.activeElement != startSize)
  3814. {
  3815. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_MARKERSIZE));
  3816. startSize.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3817. }
  3818. if (force || document.activeElement != startSpacing)
  3819. {
  3820. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_SOURCE_PERIMETER_SPACING, 0));
  3821. startSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3822. }
  3823. if (force || document.activeElement != endSize)
  3824. {
  3825. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_ENDSIZE, mxConstants.DEFAULT_MARKERSIZE));
  3826. endSize.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3827. }
  3828. if (force || document.activeElement != startSpacing)
  3829. {
  3830. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_TARGET_PERIMETER_SPACING, 0));
  3831. endSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3832. }
  3833. if (force || document.activeElement != perimeterSpacing)
  3834. {
  3835. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_PERIMETER_SPACING, 0));
  3836. perimeterSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3837. }
  3838. });
  3839. startSizeUpdate = this.installInputHandler(startSize, mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_MARKERSIZE, 0, 999, ' pt');
  3840. startSpacingUpdate = this.installInputHandler(startSpacing, mxConstants.STYLE_SOURCE_PERIMETER_SPACING, 0, -999, 999, ' pt');
  3841. endSizeUpdate = this.installInputHandler(endSize, mxConstants.STYLE_ENDSIZE, mxConstants.DEFAULT_MARKERSIZE, 0, 999, ' pt');
  3842. endSpacingUpdate = this.installInputHandler(endSpacing, mxConstants.STYLE_TARGET_PERIMETER_SPACING, 0, -999, 999, ' pt');
  3843. perimeterUpdate = this.installInputHandler(perimeterSpacing, mxConstants.STYLE_PERIMETER_SPACING, 0, 0, 999, ' pt');
  3844. this.addKeyHandler(input, listener);
  3845. this.addKeyHandler(startSize, listener);
  3846. this.addKeyHandler(startSpacing, listener);
  3847. this.addKeyHandler(endSize, listener);
  3848. this.addKeyHandler(endSpacing, listener);
  3849. this.addKeyHandler(perimeterSpacing, listener);
  3850. graph.getModel().addListener(mxEvent.CHANGE, listener);
  3851. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  3852. listener();
  3853. return container;
  3854. };
  3855. /**
  3856. * Adds UI for configuring line jumps.
  3857. */
  3858. StyleFormatPanel.prototype.addLineJumps = function(container)
  3859. {
  3860. var ss = this.format.getSelectionState();
  3861. if (Graph.lineJumpsEnabled && ss.edges.length > 0 &&
  3862. ss.vertices.length == 0 && ss.lineJumps)
  3863. {
  3864. container.style.padding = '8px 0px 24px 18px';
  3865. var ui = this.editorUi;
  3866. var editor = ui.editor;
  3867. var graph = editor.graph;
  3868. var span = document.createElement('div');
  3869. span.style.position = 'absolute';
  3870. span.style.fontWeight = 'bold';
  3871. span.style.width = '80px';
  3872. mxUtils.write(span, mxResources.get('lineJumps'));
  3873. container.appendChild(span);
  3874. var styleSelect = document.createElement('select');
  3875. styleSelect.style.position = 'absolute';
  3876. styleSelect.style.marginTop = '-2px';
  3877. styleSelect.style.right = '76px';
  3878. styleSelect.style.width = '62px';
  3879. var styles = ['none', 'arc', 'gap', 'sharp'];
  3880. for (var i = 0; i < styles.length; i++)
  3881. {
  3882. var styleOption = document.createElement('option');
  3883. styleOption.setAttribute('value', styles[i]);
  3884. mxUtils.write(styleOption, mxResources.get(styles[i]));
  3885. styleSelect.appendChild(styleOption);
  3886. }
  3887. mxEvent.addListener(styleSelect, 'change', function(evt)
  3888. {
  3889. graph.getModel().beginUpdate();
  3890. try
  3891. {
  3892. graph.setCellStyles('jumpStyle', styleSelect.value, graph.getSelectionCells());
  3893. ui.fireEvent(new mxEventObject('styleChanged', 'keys', ['jumpStyle'],
  3894. 'values', [styleSelect.value], 'cells', graph.getSelectionCells()));
  3895. }
  3896. finally
  3897. {
  3898. graph.getModel().endUpdate();
  3899. }
  3900. mxEvent.consume(evt);
  3901. });
  3902. // Stops events from bubbling to color option event handler
  3903. mxEvent.addListener(styleSelect, 'click', function(evt)
  3904. {
  3905. mxEvent.consume(evt);
  3906. });
  3907. container.appendChild(styleSelect);
  3908. var jumpSizeUpdate;
  3909. var jumpSize = this.addUnitInput(container, 'pt', 22, 33, function()
  3910. {
  3911. jumpSizeUpdate.apply(this, arguments);
  3912. });
  3913. jumpSizeUpdate = this.installInputHandler(jumpSize, 'jumpSize',
  3914. Graph.defaultJumpSize, 0, 999, ' pt');
  3915. var listener = mxUtils.bind(this, function(sender, evt, force)
  3916. {
  3917. ss = this.format.getSelectionState();
  3918. styleSelect.value = mxUtils.getValue(ss.style, 'jumpStyle', 'none');
  3919. if (force || document.activeElement != jumpSize)
  3920. {
  3921. var tmp = parseInt(mxUtils.getValue(ss.style, 'jumpSize', Graph.defaultJumpSize));
  3922. jumpSize.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3923. }
  3924. });
  3925. this.addKeyHandler(jumpSize, listener);
  3926. graph.getModel().addListener(mxEvent.CHANGE, listener);
  3927. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  3928. listener();
  3929. }
  3930. else
  3931. {
  3932. container.style.display = 'none';
  3933. }
  3934. return container;
  3935. };
  3936. /**
  3937. * Adds the label menu items to the given menu and parent.
  3938. */
  3939. StyleFormatPanel.prototype.addEffects = function(div)
  3940. {
  3941. var ui = this.editorUi;
  3942. var editor = ui.editor;
  3943. var graph = editor.graph;
  3944. var ss = this.format.getSelectionState();
  3945. div.style.paddingTop = '0px';
  3946. div.style.paddingBottom = '2px';
  3947. var table = document.createElement('table');
  3948. if (mxClient.IS_QUIRKS)
  3949. {
  3950. table.style.fontSize = '1em';
  3951. }
  3952. table.style.width = '100%';
  3953. table.style.fontWeight = 'bold';
  3954. table.style.paddingRight = '20px';
  3955. var tbody = document.createElement('tbody');
  3956. var row = document.createElement('tr');
  3957. row.style.padding = '0px';
  3958. var left = document.createElement('td');
  3959. left.style.padding = '0px';
  3960. left.style.width = '50%';
  3961. left.setAttribute('valign', 'top');
  3962. var right = left.cloneNode(true);
  3963. right.style.paddingLeft = '8px';
  3964. row.appendChild(left);
  3965. row.appendChild(right);
  3966. tbody.appendChild(row);
  3967. table.appendChild(tbody);
  3968. div.appendChild(table);
  3969. var current = left;
  3970. var count = 0;
  3971. var addOption = mxUtils.bind(this, function(label, key, defaultValue)
  3972. {
  3973. var opt = this.createCellOption(label, key, defaultValue);
  3974. opt.style.width = '100%';
  3975. current.appendChild(opt);
  3976. current = (current == left) ? right : left;
  3977. count++;
  3978. });
  3979. var listener = mxUtils.bind(this, function(sender, evt, force)
  3980. {
  3981. ss = this.format.getSelectionState();
  3982. left.innerHTML = '';
  3983. right.innerHTML = '';
  3984. current = left;
  3985. if (ss.rounded)
  3986. {
  3987. addOption(mxResources.get('rounded'), mxConstants.STYLE_ROUNDED, 0);
  3988. }
  3989. if (ss.style.shape == 'swimlane')
  3990. {
  3991. addOption(mxResources.get('divider'), 'swimlaneLine', 1);
  3992. }
  3993. if (!ss.containsImage)
  3994. {
  3995. addOption(mxResources.get('shadow'), mxConstants.STYLE_SHADOW, 0);
  3996. }
  3997. if (ss.glass)
  3998. {
  3999. addOption(mxResources.get('glass'), mxConstants.STYLE_GLASS, 0);
  4000. }
  4001. if (ss.comic)
  4002. {
  4003. addOption(mxResources.get('comic'), 'comic', 0);
  4004. }
  4005. if (count == 0)
  4006. {
  4007. div.style.display = 'none';
  4008. }
  4009. });
  4010. graph.getModel().addListener(mxEvent.CHANGE, listener);
  4011. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  4012. listener();
  4013. return div;
  4014. }
  4015. /**
  4016. * Adds the label menu items to the given menu and parent.
  4017. */
  4018. StyleFormatPanel.prototype.addStyleOps = function(div)
  4019. {
  4020. div.style.paddingTop = '10px';
  4021. div.style.paddingBottom = '10px';
  4022. var btn = mxUtils.button(mxResources.get('setAsDefaultStyle'), mxUtils.bind(this, function(evt)
  4023. {
  4024. this.editorUi.actions.get('setAsDefaultStyle').funct();
  4025. }));
  4026. btn.setAttribute('title', mxResources.get('setAsDefaultStyle') + ' (' + this.editorUi.actions.get('setAsDefaultStyle').shortcut + ')');
  4027. btn.style.width = '202px';
  4028. div.appendChild(btn);
  4029. return div;
  4030. };
  4031. /**
  4032. * Adds the label menu items to the given menu and parent.
  4033. */
  4034. DiagramFormatPanel = function(format, editorUi, container)
  4035. {
  4036. BaseFormatPanel.call(this, format, editorUi, container);
  4037. this.init();
  4038. };
  4039. mxUtils.extend(DiagramFormatPanel, BaseFormatPanel);
  4040. /**
  4041. * Switch to disable page view.
  4042. */
  4043. DiagramFormatPanel.showPageView = true;
  4044. /**
  4045. * Specifies if the background image option should be shown. Default is true.
  4046. */
  4047. DiagramFormatPanel.prototype.showBackgroundImageOption = true;
  4048. /**
  4049. * Adds the label menu items to the given menu and parent.
  4050. */
  4051. DiagramFormatPanel.prototype.init = function()
  4052. {
  4053. var ui = this.editorUi;
  4054. var editor = ui.editor;
  4055. var graph = editor.graph;
  4056. this.container.appendChild(this.addView(this.createPanel()));
  4057. if (graph.isEnabled())
  4058. {
  4059. this.container.appendChild(this.addOptions(this.createPanel()));
  4060. this.container.appendChild(this.addPaperSize(this.createPanel()));
  4061. this.container.appendChild(this.addStyleOps(this.createPanel()));
  4062. }
  4063. };
  4064. /**
  4065. * Adds the label menu items to the given menu and parent.
  4066. */
  4067. DiagramFormatPanel.prototype.addView = function(div)
  4068. {
  4069. var ui = this.editorUi;
  4070. var editor = ui.editor;
  4071. var graph = editor.graph;
  4072. div.appendChild(this.createTitle(mxResources.get('view')));
  4073. // Grid
  4074. this.addGridOption(div);
  4075. if (graph.isEnabled())
  4076. {
  4077. // Page View
  4078. if (DiagramFormatPanel.showPageView)
  4079. {
  4080. div.appendChild(this.createOption(mxResources.get('pageView'), function()
  4081. {
  4082. return graph.pageVisible;
  4083. }, function(checked)
  4084. {
  4085. ui.actions.get('pageView').funct();
  4086. },
  4087. {
  4088. install: function(apply)
  4089. {
  4090. this.listener = function()
  4091. {
  4092. apply(graph.pageVisible);
  4093. };
  4094. ui.addListener('pageViewChanged', this.listener);
  4095. },
  4096. destroy: function()
  4097. {
  4098. ui.removeListener(this.listener);
  4099. }
  4100. }));
  4101. }
  4102. // Background
  4103. var bg = this.createColorOption(mxResources.get('background'), function()
  4104. {
  4105. return graph.background;
  4106. }, function(color)
  4107. {
  4108. var change = new ChangePageSetup(ui, color);
  4109. change.ignoreImage = true;
  4110. graph.model.execute(change);
  4111. }, '#ffffff',
  4112. {
  4113. install: function(apply)
  4114. {
  4115. this.listener = function()
  4116. {
  4117. apply(graph.background);
  4118. };
  4119. ui.addListener('backgroundColorChanged', this.listener);
  4120. },
  4121. destroy: function()
  4122. {
  4123. ui.removeListener(this.listener);
  4124. }
  4125. });
  4126. if (this.showBackgroundImageOption)
  4127. {
  4128. var btn = mxUtils.button(mxResources.get('image'), function(evt)
  4129. {
  4130. ui.showBackgroundImageDialog();
  4131. mxEvent.consume(evt);
  4132. })
  4133. btn.style.position = 'absolute';
  4134. btn.className = 'geColorBtn';
  4135. btn.style.marginTop = '-4px';
  4136. btn.style.paddingBottom = (document.documentMode == 11 || mxClient.IS_MT) ? '0px' : '2px';
  4137. btn.style.height = '22px';
  4138. btn.style.right = (mxClient.IS_QUIRKS) ? '52px' : '72px';
  4139. btn.style.width = '56px';
  4140. bg.appendChild(btn);
  4141. }
  4142. div.appendChild(bg);
  4143. }
  4144. return div;
  4145. };
  4146. /**
  4147. * Adds the label menu items to the given menu and parent.
  4148. */
  4149. DiagramFormatPanel.prototype.addOptions = function(div)
  4150. {
  4151. var ui = this.editorUi;
  4152. var editor = ui.editor;
  4153. var graph = editor.graph;
  4154. div.appendChild(this.createTitle(mxResources.get('options')));
  4155. if (graph.isEnabled())
  4156. {
  4157. // Connection arrows
  4158. div.appendChild(this.createOption(mxResources.get('connectionArrows'), function()
  4159. {
  4160. return graph.connectionArrowsEnabled;
  4161. }, function(checked)
  4162. {
  4163. ui.actions.get('connectionArrows').funct();
  4164. },
  4165. {
  4166. install: function(apply)
  4167. {
  4168. this.listener = function()
  4169. {
  4170. apply(graph.connectionArrowsEnabled);
  4171. };
  4172. ui.addListener('connectionArrowsChanged', this.listener);
  4173. },
  4174. destroy: function()
  4175. {
  4176. ui.removeListener(this.listener);
  4177. }
  4178. }));
  4179. // Connection points
  4180. div.appendChild(this.createOption(mxResources.get('connectionPoints'), function()
  4181. {
  4182. return graph.connectionHandler.isEnabled();
  4183. }, function(checked)
  4184. {
  4185. ui.actions.get('connectionPoints').funct();
  4186. },
  4187. {
  4188. install: function(apply)
  4189. {
  4190. this.listener = function()
  4191. {
  4192. apply(graph.connectionHandler.isEnabled());
  4193. };
  4194. ui.addListener('connectionPointsChanged', this.listener);
  4195. },
  4196. destroy: function()
  4197. {
  4198. ui.removeListener(this.listener);
  4199. }
  4200. }));
  4201. // Guides
  4202. div.appendChild(this.createOption(mxResources.get('guides'), function()
  4203. {
  4204. return graph.graphHandler.guidesEnabled;
  4205. }, function(checked)
  4206. {
  4207. ui.actions.get('guides').funct();
  4208. },
  4209. {
  4210. install: function(apply)
  4211. {
  4212. this.listener = function()
  4213. {
  4214. apply(graph.graphHandler.guidesEnabled);
  4215. };
  4216. ui.addListener('guidesEnabledChanged', this.listener);
  4217. },
  4218. destroy: function()
  4219. {
  4220. ui.removeListener(this.listener);
  4221. }
  4222. }));
  4223. }
  4224. return div;
  4225. };
  4226. /**
  4227. *
  4228. */
  4229. DiagramFormatPanel.prototype.addGridOption = function(container)
  4230. {
  4231. var ui = this.editorUi;
  4232. var graph = ui.editor.graph;
  4233. var input = document.createElement('input');
  4234. input.style.position = 'absolute';
  4235. input.style.textAlign = 'right';
  4236. input.style.width = '38px';
  4237. input.value = graph.getGridSize() + ' pt';
  4238. var stepper = this.createStepper(input, update);
  4239. input.style.display = (graph.isGridEnabled()) ? '' : 'none';
  4240. stepper.style.display = input.style.display;
  4241. mxEvent.addListener(input, 'keydown', function(e)
  4242. {
  4243. if (e.keyCode == 13)
  4244. {
  4245. graph.container.focus();
  4246. mxEvent.consume(e);
  4247. }
  4248. else if (e.keyCode == 27)
  4249. {
  4250. input.value = graph.getGridSize();
  4251. graph.container.focus();
  4252. mxEvent.consume(e);
  4253. }
  4254. });
  4255. function update(evt)
  4256. {
  4257. var value = parseInt(input.value);
  4258. value = Math.max(1, (isNaN(value)) ? 10 : value);
  4259. if (value != graph.getGridSize())
  4260. {
  4261. graph.setGridSize(value)
  4262. }
  4263. input.value = value + ' pt';
  4264. mxEvent.consume(evt);
  4265. };
  4266. mxEvent.addListener(input, 'blur', update);
  4267. mxEvent.addListener(input, 'change', update);
  4268. if (mxClient.IS_SVG)
  4269. {
  4270. input.style.marginTop = '-2px';
  4271. input.style.right = '84px';
  4272. stepper.style.marginTop = '-16px';
  4273. stepper.style.right = '72px';
  4274. var panel = this.createColorOption(mxResources.get('grid'), function()
  4275. {
  4276. var color = graph.view.gridColor;
  4277. return (graph.isGridEnabled()) ? color : null;
  4278. }, function(color)
  4279. {
  4280. if (color == mxConstants.NONE)
  4281. {
  4282. graph.setGridEnabled(false);
  4283. ui.fireEvent(new mxEventObject('gridEnabledChanged'));
  4284. }
  4285. else
  4286. {
  4287. graph.setGridEnabled(true);
  4288. ui.setGridColor(color);
  4289. }
  4290. input.style.display = (graph.isGridEnabled()) ? '' : 'none';
  4291. stepper.style.display = input.style.display;
  4292. }, '#e0e0e0',
  4293. {
  4294. install: function(apply)
  4295. {
  4296. this.listener = function()
  4297. {
  4298. apply((graph.isGridEnabled()) ? graph.view.gridColor : null);
  4299. };
  4300. ui.addListener('gridColorChanged', this.listener);
  4301. ui.addListener('gridEnabledChanged', this.listener);
  4302. },
  4303. destroy: function()
  4304. {
  4305. ui.removeListener(this.listener);
  4306. }
  4307. });
  4308. panel.appendChild(input);
  4309. panel.appendChild(stepper);
  4310. container.appendChild(panel);
  4311. }
  4312. else
  4313. {
  4314. input.style.marginTop = '2px';
  4315. input.style.right = '32px';
  4316. stepper.style.marginTop = '2px';
  4317. stepper.style.right = '20px';
  4318. container.appendChild(input);
  4319. container.appendChild(stepper);
  4320. container.appendChild(this.createOption(mxResources.get('grid'), function()
  4321. {
  4322. return graph.isGridEnabled();
  4323. }, function(checked)
  4324. {
  4325. graph.setGridEnabled(checked);
  4326. if (graph.isGridEnabled())
  4327. {
  4328. graph.view.gridColor = '#e0e0e0';
  4329. }
  4330. ui.fireEvent(new mxEventObject('gridEnabledChanged'));
  4331. },
  4332. {
  4333. install: function(apply)
  4334. {
  4335. this.listener = function()
  4336. {
  4337. input.style.display = (graph.isGridEnabled()) ? '' : 'none';
  4338. stepper.style.display = input.style.display;
  4339. apply(graph.isGridEnabled());
  4340. };
  4341. ui.addListener('gridEnabledChanged', this.listener);
  4342. },
  4343. destroy: function()
  4344. {
  4345. ui.removeListener(this.listener);
  4346. }
  4347. }));
  4348. }
  4349. };
  4350. /**
  4351. * Adds the label menu items to the given menu and parent.
  4352. */
  4353. DiagramFormatPanel.prototype.addDocumentProperties = function(div)
  4354. {
  4355. // Hook for subclassers
  4356. var ui = this.editorUi;
  4357. var editor = ui.editor;
  4358. var graph = editor.graph;
  4359. div.appendChild(this.createTitle(mxResources.get('options')));
  4360. return div;
  4361. };
  4362. /**
  4363. * Adds the label menu items to the given menu and parent.
  4364. */
  4365. DiagramFormatPanel.prototype.addPaperSize = function(div)
  4366. {
  4367. var ui = this.editorUi;
  4368. var editor = ui.editor;
  4369. var graph = editor.graph;
  4370. div.appendChild(this.createTitle(mxResources.get('paperSize')));
  4371. var accessor = PageSetupDialog.addPageFormatPanel(div, 'formatpanel', graph.pageFormat, function(pageFormat)
  4372. {
  4373. if (graph.pageFormat == null || graph.pageFormat.width != pageFormat.width ||
  4374. graph.pageFormat.height != pageFormat.height)
  4375. {
  4376. var change = new ChangePageSetup(ui, null, null, pageFormat);
  4377. change.ignoreColor = true;
  4378. change.ignoreImage = true;
  4379. graph.model.execute(change);
  4380. }
  4381. });
  4382. this.addKeyHandler(accessor.widthInput, function()
  4383. {
  4384. accessor.set(graph.pageFormat);
  4385. });
  4386. - this.addKeyHandler(accessor.heightInput, function()
  4387. {
  4388. accessor.set(graph.pageFormat);
  4389. });
  4390. var listener = function()
  4391. {
  4392. accessor.set(graph.pageFormat);
  4393. };
  4394. ui.addListener('pageFormatChanged', listener);
  4395. this.listeners.push({destroy: function() { ui.removeListener(listener); }});
  4396. graph.getModel().addListener(mxEvent.CHANGE, listener);
  4397. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  4398. return div;
  4399. };
  4400. /**
  4401. * Adds the label menu items to the given menu and parent.
  4402. */
  4403. DiagramFormatPanel.prototype.addStyleOps = function(div)
  4404. {
  4405. var btn = mxUtils.button(mxResources.get('editData'), mxUtils.bind(this, function(evt)
  4406. {
  4407. this.editorUi.actions.get('editData').funct();
  4408. }));
  4409. btn.setAttribute('title', mxResources.get('editData') + ' (' + this.editorUi.actions.get('editData').shortcut + ')');
  4410. btn.style.width = '202px';
  4411. btn.style.marginBottom = '2px';
  4412. div.appendChild(btn);
  4413. mxUtils.br(div);
  4414. btn = mxUtils.button(mxResources.get('clearDefaultStyle'), mxUtils.bind(this, function(evt)
  4415. {
  4416. this.editorUi.actions.get('clearDefaultStyle').funct();
  4417. }));
  4418. btn.setAttribute('title', mxResources.get('clearDefaultStyle') + ' (' + this.editorUi.actions.get('clearDefaultStyle').shortcut + ')');
  4419. btn.style.width = '202px';
  4420. div.appendChild(btn);
  4421. return div;
  4422. };
  4423. /**
  4424. * Adds the label menu items to the given menu and parent.
  4425. */
  4426. DiagramFormatPanel.prototype.destroy = function()
  4427. {
  4428. BaseFormatPanel.prototype.destroy.apply(this, arguments);
  4429. if (this.gridEnabledListener)
  4430. {
  4431. this.editorUi.removeListener(this.gridEnabledListener);
  4432. this.gridEnabledListener = null;
  4433. }
  4434. };