Format.js 172 KB

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