Format.js 140 KB

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