Format.js 235 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103
  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. * Background color for inactive tabs.
  11. */
  12. Format.inactiveTabBackgroundColor = '#e4e4e4';
  13. /**
  14. * Icons for markers (24x16).
  15. */
  16. Format.classicFilledMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 L 10 2 L 5 8 L 10 14 Z M 0 8 L 24 8" stroke="#404040" fill="#404040"/>', 32, 20);
  17. Format.classicThinFilledMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 L 8 4 L 3 8 L 8 12 Z M 0 8 L 24 8" stroke="#404040" fill="#404040"/>', 32, 20);
  18. Format.openFilledMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 8 0 L 0 8 L 8 16 M 0 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  19. Format.openThinFilledMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 8 4 L 0 8 L 8 12 M 0 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  20. Format.openAsyncFilledMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 8 4 L 0 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  21. Format.blockFilledMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 L 8 2 L 8 14 Z M 0 8 L 24 8" stroke="#404040" fill="#404040"/>', 32, 20);
  22. Format.blockThinFilledMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 L 8 4 L 8 12 Z M 0 8 L 24 8" stroke="#404040" fill="#404040"/>', 32, 20);
  23. Format.asyncFilledMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 6 8 L 6 4 L 0 8 L 24 8" stroke="#404040" fill="#404040"/>', 32, 20);
  24. Format.ovalFilledMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 A 5 5 0 0 1 5 3 A 5 5 0 0 1 11 8 A 5 5 0 0 1 5 13 A 5 5 0 0 1 0 8 Z M 10 8 L 24 8" stroke="#404040" fill="#404040"/>', 32, 20);
  25. Format.diamondFilledMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 L 6 2 L 12 8 L 6 14 Z M 0 8 L 24 8" stroke="#404040" fill="#404040"/>', 32, 20);
  26. Format.diamondThinFilledMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 L 8 3 L 16 8 L 8 13 Z M 0 8 L 24 8" stroke="#404040" fill="#404040"/>', 32, 20);
  27. Format.classicMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 L 10 2 L 5 8 L 10 14 Z M 5 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  28. Format.classicThinMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 L 8 4 L 5 8 L 8 12 Z M 5 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  29. Format.blockMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 L 8 2 L 8 14 Z M 8 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  30. Format.blockThinMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 L 8 4 L 8 12 Z M 8 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  31. Format.asyncMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 6 8 L 6 4 L 0 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  32. Format.ovalMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 A 5 5 0 0 1 5 3 A 5 5 0 0 1 11 8 A 5 5 0 0 1 5 13 A 5 5 0 0 1 0 8 Z M 10 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  33. Format.diamondMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 L 6 2 L 12 8 L 6 14 Z M 12 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  34. Format.diamondThinMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 L 8 3 L 16 8 L 8 13 Z M 16 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  35. Format.boxMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 3 L 10 3 L 10 13 L 0 13 Z M 10 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  36. Format.halfCircleMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 3 A 5 5 0 0 1 5 8 A 5 5 0 0 1 0 13 M 5 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  37. Format.dashMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 2 L 12 14 M 0 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  38. Format.crossMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 2 L 12 14 M 12 2 L 0 14 M 0 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  39. Format.circlePlusMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 A 6 6 0 0 1 6 2 A 6 6 0 0 1 12 8 A 6 6 0 0 1 6 14 A 6 6 0 0 1 0 8 Z M 6 2 L 6 14 M 0 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  40. Format.circleMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 A 6 6 0 0 1 6 2 A 6 6 0 0 1 12 8 A 6 6 0 0 1 6 14 A 6 6 0 0 1 0 8 Z M 12 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  41. Format.ERmandOneMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 6 2 L 6 14 M 9 2 L 9 14 M 0 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  42. Format.ERmanyMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 2 L 12 8 L 0 14 M 0 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  43. Format.ERoneToManyMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 2 L 12 8 L 0 14 M 15 2 L 15 14 M 0 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  44. Format.ERzeroToOneMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 8 8 A 5 5 0 0 1 13 3 A 5 5 0 0 1 18 8 A 5 5 0 0 1 13 13 A 5 5 0 0 1 8 8 Z M 0 8 L 8 8 M 18 8 L 24 8 M 4 3 L 4 13" stroke="#404040" fill="transparent"/>', 32, 20);
  45. Format.ERzeroToManyMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 8 8 A 5 5 0 0 1 13 3 A 5 5 0 0 1 18 8 A 5 5 0 0 1 13 13 A 5 5 0 0 1 8 8 Z M 0 8 L 8 8 M 18 8 L 24 8 M 0 3 L 8 8 L 0 13" stroke="#404040" fill="transparent"/>', 32, 20);
  46. Format.EROneMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 5 2 L 5 14 M 0 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  47. Format.baseDashMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 2 L 0 14 M 0 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  48. Format.doubleBlockMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 L 8 2 L 8 14 Z M 8 8 L 16 2 L 16 14 Z M 16 8 L 24 8" stroke="#404040" fill="transparent"/>', 32, 20);
  49. Format.doubleBlockFilledMarkerImage = Graph.createSvgImage(20, 22, '<path transform="translate(4,2)" stroke-width="2" d="M 0 8 L 8 2 L 8 14 Z M 8 8 L 16 2 L 16 14 Z M 16 8 L 24 8" stroke="#404040" fill="#404040"/>', 32, 20);
  50. /**
  51. * Adds a style change item to the given menu.
  52. */
  53. Format.processMenuIcon = function(elt, transform)
  54. {
  55. var imgs = elt.getElementsByTagName('img');
  56. if (imgs.length > 0)
  57. {
  58. imgs[0].className = 'geIcon geAdaptiveAsset';
  59. imgs[0].style.padding = '0px';
  60. imgs[0].style.margin = '0 0 0 2px';
  61. if (transform != null)
  62. {
  63. mxUtils.setPrefixedStyle(imgs[0].style, 'transform', transform);
  64. }
  65. }
  66. return elt;
  67. };
  68. /**
  69. * Returns information about the current selection.
  70. */
  71. Format.prototype.labelIndex = 0;
  72. /**
  73. * Returns information about the current selection.
  74. */
  75. Format.prototype.diagramIndex = 0;
  76. /**
  77. * Returns information about the current selection.
  78. */
  79. Format.prototype.currentIndex = 0;
  80. /**
  81. * Returns information about the current selection.
  82. */
  83. Format.prototype.showCloseButton = true;
  84. /**
  85. * Returns information about the current selection.
  86. */
  87. Format.prototype.rounded = false;
  88. /**
  89. * Returns information about the current selection.
  90. */
  91. Format.prototype.curved = false;
  92. /**
  93. * Adds the label menu items to the given menu and parent.
  94. */
  95. Format.prototype.init = function()
  96. {
  97. var ui = this.editorUi;
  98. var editor = ui.editor;
  99. var graph = editor.graph;
  100. this.update = mxUtils.bind(this, function(sender, evt)
  101. {
  102. this.refresh();
  103. });
  104. graph.getSelectionModel().addListener(mxEvent.CHANGE, this.update);
  105. graph.getModel().addListener(mxEvent.CHANGE, this.update);
  106. graph.addListener(mxEvent.EDITING_STARTED, this.update);
  107. graph.addListener(mxEvent.EDITING_STOPPED, this.update);
  108. graph.getView().addListener('unitChanged', this.update);
  109. editor.addListener('autosaveChanged', this.update);
  110. graph.addListener(mxEvent.ROOT, this.update);
  111. ui.addListener('styleChanged', this.update);
  112. ui.addListener('darkModeChanged', this.update);
  113. this.refresh();
  114. };
  115. /**
  116. * Adds the label menu items to the given menu and parent.
  117. */
  118. Format.prototype.clear = function()
  119. {
  120. this.container.innerText = '';
  121. // Destroy existing panels
  122. if (this.panels != null)
  123. {
  124. for (var i = 0; i < this.panels.length; i++)
  125. {
  126. this.panels[i].destroy();
  127. }
  128. }
  129. this.panels = [];
  130. };
  131. /**
  132. * Adds the label menu items to the given menu and parent.
  133. */
  134. Format.prototype.refresh = function()
  135. {
  136. if (this.pendingRefresh != null)
  137. {
  138. window.clearTimeout(this.pendingRefresh);
  139. this.pendingRefresh = null;
  140. }
  141. this.pendingRefresh = window.setTimeout(mxUtils.bind(this, function()
  142. {
  143. this.immediateRefresh();
  144. }));
  145. };
  146. /**
  147. * Adds the label menu items to the given menu and parent.
  148. */
  149. Format.prototype.immediateRefresh = function()
  150. {
  151. // Performance tweak: No refresh needed if not visible
  152. if (this.container.style.width == '0px')
  153. {
  154. return;
  155. }
  156. this.clear();
  157. var ui = this.editorUi;
  158. var graph = ui.editor.graph;
  159. var div = document.createElement('div');
  160. div.style.whiteSpace = 'nowrap';
  161. div.style.color = 'rgb(112, 112, 112)';
  162. div.style.textAlign = 'left';
  163. div.style.cursor = 'default';
  164. var label = document.createElement('div');
  165. label.className = 'geFormatSection';
  166. label.style.textAlign = 'center';
  167. label.style.fontWeight = 'bold';
  168. label.style.paddingTop = '8px';
  169. label.style.fontSize = '13px';
  170. label.style.borderWidth = '0px 0px 1px 1px';
  171. label.style.borderStyle = 'solid';
  172. label.style.display = 'inline-block';
  173. label.style.height = '25px';
  174. label.style.overflow = 'hidden';
  175. label.style.width = '100%';
  176. this.container.appendChild(div);
  177. // Prevents text selection
  178. mxEvent.addListener(label, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  179. mxUtils.bind(this, function(evt)
  180. {
  181. evt.preventDefault();
  182. }));
  183. var ss = ui.getSelectionState();
  184. var containsLabel = ss.containsLabel;
  185. var currentLabel = null;
  186. var currentPanel = null;
  187. var addClickHandler = mxUtils.bind(this, function(elt, panel, index, lastEntry)
  188. {
  189. var clickHandler = mxUtils.bind(this, function(evt)
  190. {
  191. if (currentLabel != elt)
  192. {
  193. if (containsLabel)
  194. {
  195. this.labelIndex = index;
  196. }
  197. else if (graph.isSelectionEmpty())
  198. {
  199. this.diagramIndex = index;
  200. }
  201. else
  202. {
  203. this.currentIndex = index;
  204. }
  205. if (currentLabel != null)
  206. {
  207. currentLabel.style.backgroundColor = Format.inactiveTabBackgroundColor;
  208. currentLabel.style.borderBottomWidth = '1px';
  209. }
  210. currentLabel = elt;
  211. currentLabel.style.backgroundColor = '';
  212. currentLabel.style.borderBottomWidth = '0px';
  213. if (currentPanel != panel)
  214. {
  215. if (currentPanel != null)
  216. {
  217. currentPanel.style.display = 'none';
  218. }
  219. currentPanel = panel;
  220. currentPanel.style.display = '';
  221. }
  222. }
  223. });
  224. mxEvent.addListener(elt, 'click', clickHandler);
  225. // Prevents text selection
  226. mxEvent.addListener(elt, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown',
  227. mxUtils.bind(this, function(evt)
  228. {
  229. evt.preventDefault();
  230. }));
  231. if ((lastEntry && currentLabel == null) ||
  232. (index == ((containsLabel) ? this.labelIndex : ((graph.isSelectionEmpty()) ?
  233. this.diagramIndex : this.currentIndex))))
  234. {
  235. // Invokes handler directly as a workaround for no click on DIV in KHTML.
  236. clickHandler();
  237. }
  238. });
  239. var idx = 0;
  240. if (graph.isSelectionEmpty())
  241. {
  242. mxUtils.write(label, mxResources.get('diagram'));
  243. label.style.borderLeftWidth = '0px';
  244. div.appendChild(label);
  245. var diagramPanel = div.cloneNode(false);
  246. this.panels.push(new DiagramFormatPanel(this, ui, diagramPanel));
  247. this.container.appendChild(diagramPanel);
  248. if (Editor.styles != null)
  249. {
  250. diagramPanel.style.display = 'none';
  251. label.style.width = (this.showCloseButton) ? '106px' : '50%';
  252. label.style.cursor = 'pointer';
  253. label.style.backgroundColor = Format.inactiveTabBackgroundColor;
  254. var label2 = label.cloneNode(false);
  255. label2.style.borderLeftWidth = '1px';
  256. label2.style.borderRightWidth = '1px';
  257. label2.style.backgroundColor = Format.inactiveTabBackgroundColor;
  258. addClickHandler(label, diagramPanel, idx++);
  259. var stylePanel = div.cloneNode(false);
  260. stylePanel.style.display = 'none';
  261. mxUtils.write(label2, mxResources.get('style'));
  262. div.appendChild(label2);
  263. this.panels.push(new DiagramStylePanel(this, ui, stylePanel));
  264. this.container.appendChild(stylePanel);
  265. addClickHandler(label2, stylePanel, idx++);
  266. }
  267. // Adds button to hide the format panel since
  268. // people don't seem to find the toolbar button
  269. // and the menu item in the format menu
  270. if (this.showCloseButton)
  271. {
  272. var label2 = label.cloneNode(false);
  273. label2.style.borderLeftWidth = '1px';
  274. label2.style.borderRightWidth = '1px';
  275. label2.style.borderBottomWidth = '1px';
  276. label2.style.backgroundColor = Format.inactiveTabBackgroundColor;
  277. label2.style.position = 'absolute';
  278. label2.style.right = '0px';
  279. label2.style.top = '0px';
  280. label2.style.width = '25px';
  281. var img = document.createElement('img');
  282. img.setAttribute('border', '0');
  283. img.setAttribute('src', Dialog.prototype.closeImage);
  284. img.setAttribute('title', mxResources.get('hide'));
  285. img.style.position = 'absolute';
  286. img.style.display = 'block';
  287. img.style.right = '0px';
  288. img.style.top = '8px';
  289. img.style.cursor = 'pointer';
  290. img.style.marginTop = '1px';
  291. img.style.marginRight = '6px';
  292. img.style.border = '1px solid transparent';
  293. img.style.padding = '1px';
  294. img.style.opacity = 0.5;
  295. label2.appendChild(img)
  296. mxEvent.addListener(img, 'click', function()
  297. {
  298. ui.actions.get('format').funct();
  299. });
  300. div.appendChild(label2);
  301. }
  302. }
  303. else if (graph.isEditing())
  304. {
  305. mxUtils.write(label, mxResources.get('text'));
  306. div.appendChild(label);
  307. label.style.borderLeftStyle = 'none';
  308. this.panels.push(new TextFormatPanel(this, ui, div));
  309. }
  310. else
  311. {
  312. label.style.backgroundColor = Format.inactiveTabBackgroundColor;
  313. label.style.borderLeftWidth = '1px';
  314. label.style.cursor = 'pointer';
  315. label.style.width = ss.cells.length == 0 ? '100%' :
  316. (containsLabel ? '50%' : '33.3%');
  317. var label2 = label.cloneNode(false);
  318. var label3 = label2.cloneNode(false);
  319. // Workaround for ignored background in IE
  320. label2.style.backgroundColor = Format.inactiveTabBackgroundColor;
  321. label3.style.backgroundColor = Format.inactiveTabBackgroundColor;
  322. // Style
  323. if (containsLabel)
  324. {
  325. label2.style.borderLeftWidth = '0px';
  326. }
  327. else if (ss.cells.length > 0)
  328. {
  329. label.style.borderLeftWidth = '0px';
  330. mxUtils.write(label, mxResources.get('style'));
  331. div.appendChild(label);
  332. var stylePanel = div.cloneNode(false);
  333. stylePanel.style.display = 'none';
  334. this.panels.push(new StyleFormatPanel(this, ui, stylePanel));
  335. this.container.appendChild(stylePanel);
  336. addClickHandler(label, stylePanel, idx++);
  337. }
  338. // Text
  339. mxUtils.write(label2, mxResources.get('text'));
  340. div.appendChild(label2);
  341. var textPanel = div.cloneNode(false);
  342. textPanel.style.display = 'none';
  343. this.panels.push(new TextFormatPanel(this, ui, textPanel));
  344. this.container.appendChild(textPanel);
  345. // Arrange
  346. mxUtils.write(label3, mxResources.get('arrange'));
  347. div.appendChild(label3);
  348. var arrangePanel = div.cloneNode(false);
  349. arrangePanel.style.display = 'none';
  350. this.panels.push(new ArrangePanel(this, ui, arrangePanel));
  351. this.container.appendChild(arrangePanel);
  352. if (ss.cells.length > 0)
  353. {
  354. addClickHandler(label2, textPanel, idx + 1);
  355. }
  356. else
  357. {
  358. label2.style.display = 'none';
  359. }
  360. addClickHandler(label3, arrangePanel, idx++, true);
  361. }
  362. };
  363. /**
  364. * Base class for format panels.
  365. */
  366. BaseFormatPanel = function(format, editorUi, container)
  367. {
  368. this.format = format;
  369. this.editorUi = editorUi;
  370. this.container = container;
  371. this.listeners = [];
  372. };
  373. /**
  374. *
  375. */
  376. BaseFormatPanel.prototype.buttonBackgroundColor = 'transparent';
  377. /**
  378. * Install input handler.
  379. */
  380. BaseFormatPanel.prototype.installInputHandler = function(input, key, defaultValue, min, max, unit, textEditFallback, isFloat)
  381. {
  382. unit = (unit != null) ? unit : '';
  383. isFloat = (isFloat != null) ? isFloat : false;
  384. var ui = this.editorUi;
  385. var graph = ui.editor.graph;
  386. min = (min != null) ? min : 1;
  387. max = (max != null) ? max : 999;
  388. var selState = null;
  389. var updating = false;
  390. var update = mxUtils.bind(this, function(evt)
  391. {
  392. var value = (isFloat) ? parseFloat(input.value) : parseInt(input.value);
  393. // Special case: angle mod 360
  394. if (!isNaN(value) && key == mxConstants.STYLE_ROTATION)
  395. {
  396. // Workaround for decimal rounding errors in floats is to
  397. // use integer and round all numbers to two decimal point
  398. value = mxUtils.mod(Math.round(value * 100), 36000) / 100;
  399. }
  400. value = Math.min(max, Math.max(min, (isNaN(value)) ? defaultValue : value));
  401. if (graph.cellEditor.isContentEditing() && textEditFallback)
  402. {
  403. if (!updating)
  404. {
  405. updating = true;
  406. if (selState != null)
  407. {
  408. graph.cellEditor.restoreSelection(selState);
  409. selState = null;
  410. }
  411. textEditFallback(value);
  412. input.value = value + unit;
  413. // Restore focus and selection in input
  414. updating = false;
  415. }
  416. }
  417. else if (value != mxUtils.getValue(ui.getSelectionState().style, key, defaultValue))
  418. {
  419. if (graph.isEditing())
  420. {
  421. graph.stopEditing(true);
  422. }
  423. graph.getModel().beginUpdate();
  424. try
  425. {
  426. var cells = ui.getSelectionState().cells;
  427. graph.setCellStyles(key, value, cells);
  428. // Handles special case for fontSize where HTML labels are parsed and updated
  429. if (key == mxConstants.STYLE_FONTSIZE)
  430. {
  431. graph.updateLabelElements(cells, function(elt)
  432. {
  433. elt.style.fontSize = value + 'px';
  434. elt.removeAttribute('size');
  435. });
  436. }
  437. for (var i = 0; i < cells.length; i++)
  438. {
  439. if (graph.model.getChildCount(cells[i]) == 0)
  440. {
  441. graph.autoSizeCell(cells[i], false);
  442. }
  443. }
  444. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [key],
  445. 'values', [value], 'cells', cells));
  446. }
  447. finally
  448. {
  449. graph.getModel().endUpdate();
  450. }
  451. }
  452. input.value = value + unit;
  453. mxEvent.consume(evt);
  454. });
  455. if (textEditFallback && graph.cellEditor.isContentEditing())
  456. {
  457. // KNOWN: Arrow up/down clear selection text in quirks/IE 8
  458. // Text size via arrow button limits to 16 in IE11. Why?
  459. mxEvent.addListener(input, 'mousedown', function()
  460. {
  461. if (document.activeElement == graph.cellEditor.textarea)
  462. {
  463. selState = graph.cellEditor.saveSelection();
  464. }
  465. });
  466. mxEvent.addListener(input, 'touchstart', function()
  467. {
  468. if (document.activeElement == graph.cellEditor.textarea)
  469. {
  470. selState = graph.cellEditor.saveSelection();
  471. }
  472. });
  473. }
  474. mxEvent.addListener(input, 'change', update);
  475. mxEvent.addListener(input, 'blur', update);
  476. return update;
  477. };
  478. /**
  479. * Adds the given option.
  480. */
  481. BaseFormatPanel.prototype.createPanel = function()
  482. {
  483. var div = document.createElement('div');
  484. div.className = 'geFormatSection';
  485. div.style.padding = '12px 0px 8px 14px';
  486. return div;
  487. };
  488. /**
  489. * Adds the given option.
  490. */
  491. BaseFormatPanel.prototype.createTitle = function(title)
  492. {
  493. var div = document.createElement('div');
  494. div.style.padding = '0px 0px 6px 0px';
  495. div.style.whiteSpace = 'nowrap';
  496. div.style.overflow = 'hidden';
  497. div.style.width = '200px';
  498. div.style.fontWeight = 'bold';
  499. mxUtils.write(div, title);
  500. return div;
  501. };
  502. /**
  503. *
  504. */
  505. BaseFormatPanel.prototype.addAction = function(div, name)
  506. {
  507. var action = this.editorUi.actions.get(name);
  508. var btn = null;
  509. if (action != null && action.isEnabled())
  510. {
  511. btn = mxUtils.button(action.label, mxUtils.bind(this, function(evt)
  512. {
  513. try
  514. {
  515. action.funct(evt, evt);
  516. }
  517. catch (e)
  518. {
  519. this.editorUi.handleError(e);
  520. }
  521. }));
  522. var short = (action.shortcut != null) ? ' (' + action.shortcut + ')' : '';
  523. btn.setAttribute('title', action.label + short);
  524. btn.style.marginBottom = '2px';
  525. btn.style.width = '210px';
  526. div.appendChild(btn);
  527. result = true;
  528. }
  529. return btn;
  530. };
  531. /**
  532. *
  533. */
  534. BaseFormatPanel.prototype.addActions = function(div, names)
  535. {
  536. var lastBr = null;
  537. var last = null;
  538. var count = 0;
  539. for (var i = 0; i < names.length; i++)
  540. {
  541. var btn = this.addAction(div, names[i]);
  542. if (btn != null)
  543. {
  544. count++;
  545. if (mxUtils.mod(count, 2) == 0)
  546. {
  547. last.style.marginRight = '2px';
  548. last.style.width = '104px';
  549. btn.style.width = '104px';
  550. lastBr.parentNode.removeChild(lastBr);
  551. }
  552. lastBr = mxUtils.br(div);
  553. last = btn;
  554. }
  555. }
  556. return count;
  557. };
  558. /**
  559. *
  560. */
  561. BaseFormatPanel.prototype.createStepper = function(input, update, step, height, disableFocus, defaultValue, isFloat)
  562. {
  563. step = (step != null) ? step : 1;
  564. height = (height != null) ? height : 9;
  565. var bigStep = 10 * step;
  566. var stepper = document.createElement('div');
  567. stepper.className = 'geBtnStepper';
  568. stepper.style.position = 'absolute';
  569. var up = document.createElement('div');
  570. up.style.position = 'relative';
  571. up.style.height = height + 'px';
  572. up.style.width = '10px';
  573. up.className = 'geBtnUp';
  574. stepper.appendChild(up);
  575. var down = up.cloneNode(false);
  576. down.style.border = 'none';
  577. down.style.height = height + 'px';
  578. down.className = 'geBtnDown';
  579. stepper.appendChild(down);
  580. mxEvent.addGestureListeners(down, function(evt)
  581. {
  582. // Stops text selection on shift+click
  583. mxEvent.consume(evt);
  584. }, null, function(evt)
  585. {
  586. if (input.value == '')
  587. {
  588. input.value = defaultValue || '2';
  589. }
  590. var val = isFloat? parseFloat(input.value) : parseInt(input.value);
  591. if (!isNaN(val))
  592. {
  593. input.value = val - (mxEvent.isShiftDown(evt) ? bigStep : step);
  594. if (update != null)
  595. {
  596. update(evt);
  597. }
  598. }
  599. mxEvent.consume(evt);
  600. });
  601. mxEvent.addGestureListeners(up, function(evt)
  602. {
  603. // Stops text selection on shift+click
  604. mxEvent.consume(evt);
  605. }, null, function(evt)
  606. {
  607. if (input.value == '')
  608. {
  609. input.value = defaultValue || '0';
  610. }
  611. var val = isFloat? parseFloat(input.value) : parseInt(input.value);
  612. if (!isNaN(val))
  613. {
  614. input.value = val + (mxEvent.isShiftDown(evt) ? bigStep : step);
  615. if (update != null)
  616. {
  617. update(evt);
  618. }
  619. }
  620. mxEvent.consume(evt);
  621. });
  622. // Disables transfer of focus to DIV but also :active CSS
  623. // so it's only used for fontSize where the focus should
  624. // stay on the selected text, but not for any other input.
  625. if (disableFocus)
  626. {
  627. var currentSelection = null;
  628. mxEvent.addGestureListeners(stepper,
  629. function(evt)
  630. {
  631. mxEvent.consume(evt);
  632. },
  633. null,
  634. function(evt)
  635. {
  636. // Workaround for lost current selection in page because of focus in IE
  637. if (currentSelection != null)
  638. {
  639. try
  640. {
  641. currentSelection.select();
  642. }
  643. catch (e)
  644. {
  645. // ignore
  646. }
  647. currentSelection = null;
  648. mxEvent.consume(evt);
  649. }
  650. }
  651. );
  652. }
  653. else
  654. {
  655. // Stops propagation on checkbox labels
  656. mxEvent.addListener(stepper, 'click', function(evt)
  657. {
  658. mxEvent.consume(evt);
  659. });
  660. }
  661. return stepper;
  662. };
  663. /**
  664. * Adds the given option.
  665. */
  666. BaseFormatPanel.prototype.createOption = function(label, isCheckedFn, setCheckedFn, listener, fn)
  667. {
  668. var div = document.createElement('div');
  669. div.style.display = 'flex';
  670. div.style.alignItems = 'center';
  671. div.style.padding = '3px 0px 3px 0px';
  672. div.style.height = '18px';
  673. var cb = document.createElement('input');
  674. cb.setAttribute('type', 'checkbox');
  675. cb.style.margin = '1px 6px 0px 0px';
  676. cb.style.verticalAlign = 'top';
  677. div.appendChild(cb);
  678. var elt = document.createElement('div');
  679. elt.style.display = 'inline-block';
  680. elt.style.whiteSpace = 'nowrap';
  681. elt.style.textOverflow = 'ellipsis';
  682. elt.style.overflow = 'hidden';
  683. elt.style.maxWidth = '160px';
  684. elt.style.maxWidth = '160px';
  685. elt.style.userSelect = 'none';
  686. mxUtils.write(elt, label);
  687. div.appendChild(elt);
  688. var applying = false;
  689. var value = isCheckedFn();
  690. var apply = function(newValue, evt)
  691. {
  692. if (!applying)
  693. {
  694. applying = true;
  695. if (newValue)
  696. {
  697. cb.setAttribute('checked', 'checked');
  698. cb.defaultChecked = true;
  699. cb.checked = true;
  700. }
  701. else
  702. {
  703. cb.removeAttribute('checked');
  704. cb.defaultChecked = false;
  705. cb.checked = false;
  706. }
  707. if (value != newValue)
  708. {
  709. value = newValue;
  710. // Checks if the color value needs to be updated in the model
  711. if (isCheckedFn() != value)
  712. {
  713. setCheckedFn(value, evt);
  714. }
  715. }
  716. applying = false;
  717. }
  718. };
  719. mxEvent.addListener(div, 'click', function(evt)
  720. {
  721. if (cb.getAttribute('disabled') != 'disabled')
  722. {
  723. // Toggles checkbox state for click on label
  724. var source = mxEvent.getSource(evt);
  725. if (source == div || source == elt)
  726. {
  727. cb.checked = !cb.checked;
  728. }
  729. apply(cb.checked, evt);
  730. }
  731. });
  732. apply(value);
  733. if (listener != null)
  734. {
  735. listener.install(apply);
  736. this.listeners.push(listener);
  737. }
  738. if (fn != null)
  739. {
  740. fn(div);
  741. }
  742. return div;
  743. };
  744. /**
  745. * The string 'null' means use null in values.
  746. */
  747. BaseFormatPanel.prototype.createCellOption = function(label, key, defaultValue, enabledValue, disabledValue, fn, action, stopEditing, cells)
  748. {
  749. var ui = this.editorUi;
  750. var editor = ui.editor;
  751. var graph = editor.graph;
  752. enabledValue = (enabledValue != null) ? ((enabledValue == 'null') ? null : enabledValue) : 1;
  753. disabledValue = (disabledValue != null) ? ((disabledValue == 'null') ? null : disabledValue) : 0;
  754. var style = (cells != null) ? graph.getCommonStyle(cells) : ui.getSelectionState().style;
  755. return this.createOption(label, function()
  756. {
  757. return mxUtils.getValue(style, key, defaultValue) != disabledValue;
  758. }, function(checked)
  759. {
  760. if (stopEditing)
  761. {
  762. graph.stopEditing();
  763. }
  764. if (action != null)
  765. {
  766. action.funct();
  767. }
  768. else
  769. {
  770. graph.getModel().beginUpdate();
  771. try
  772. {
  773. var temp = (cells != null) ? cells : ui.getSelectionState().cells;
  774. var value = (checked) ? enabledValue : disabledValue;
  775. graph.setCellStyles(key, value, temp);
  776. if (fn != null)
  777. {
  778. fn(temp, value);
  779. }
  780. ui.fireEvent(new mxEventObject('styleChanged', 'keys',
  781. [key], 'values', [value], 'cells', temp));
  782. }
  783. finally
  784. {
  785. graph.getModel().endUpdate();
  786. }
  787. }
  788. },
  789. {
  790. install: function(apply)
  791. {
  792. this.listener = function()
  793. {
  794. apply(mxUtils.getValue(style, key, defaultValue) != disabledValue);
  795. };
  796. graph.getModel().addListener(mxEvent.CHANGE, this.listener);
  797. },
  798. destroy: function()
  799. {
  800. graph.getModel().removeListener(this.listener);
  801. }
  802. });
  803. };
  804. /**
  805. * Adds the given color option.
  806. */
  807. BaseFormatPanel.prototype.createColorOption = function(label, getColorFn, setColorFn,
  808. defaultColor, listener, callbackFn, hideCheckbox, defaultColorValue)
  809. {
  810. var graph = this.editorUi.editor.graph;
  811. var div = document.createElement('div');
  812. div.style.padding = '3px 0px 3px 0px';
  813. div.style.whiteSpace = 'nowrap';
  814. div.style.overflow = 'hidden';
  815. div.style.width = '200px';
  816. div.style.height = '18px';
  817. var cb = document.createElement('input');
  818. cb.setAttribute('type', 'checkbox');
  819. cb.style.margin = '1px 6px 0px 0px';
  820. cb.style.verticalAlign = 'top';
  821. if (!hideCheckbox)
  822. {
  823. div.appendChild(cb);
  824. }
  825. var span = document.createElement('span');
  826. span.style.verticalAlign = 'top';
  827. mxUtils.write(span, label);
  828. div.appendChild(span);
  829. var value = getColorFn();
  830. var applying = false;
  831. var dropper = null;
  832. var btn = null;
  833. var clrInput = document.createElement('input');
  834. clrInput.setAttribute('type', 'color');
  835. clrInput.style.position = 'relative';
  836. clrInput.style.visibility = 'hidden';
  837. clrInput.style.top = '10px';
  838. clrInput.style.width = '0px';
  839. clrInput.style.height = '0px';
  840. clrInput.style.border = 'none';
  841. // Adds native color dialog
  842. if (!mxClient.IS_IE && !mxClient.IS_IE11 && !mxClient.IS_TOUCH)
  843. {
  844. dropper = document.createElement('img');
  845. dropper.src = Editor.colorDropperImage;
  846. dropper.className = 'geColorDropper geAdaptiveAsset';
  847. dropper.style.position = 'relative';
  848. dropper.style.right = '-20px';
  849. dropper.style.top = '-1px';
  850. dropper.style.width = 'auto';
  851. dropper.style.height = '14px';
  852. mxEvent.addListener(dropper, 'click', function(evt)
  853. {
  854. var color = value;
  855. if (color == 'default')
  856. {
  857. color = defaultColorValue;
  858. }
  859. clrInput.value = color;
  860. clrInput.click();
  861. mxEvent.consume(evt);
  862. });
  863. }
  864. var apply = function(color, disableUpdate, forceUpdate)
  865. {
  866. if (!applying)
  867. {
  868. var defaultValue = (defaultColor == 'null') ? null : defaultColor;
  869. applying = true;
  870. color = (/(^#?[a-zA-Z0-9]*$)/.test(color)) ? color : defaultValue;
  871. var tempColor = (color != null && color != mxConstants.NONE) ? color : defaultValue;
  872. var div = document.createElement('div');
  873. div.style.width = '21px';
  874. div.style.height = '12px';
  875. div.style.margin = '2px 18px 2px 3px';
  876. div.style.border = '1px solid black';
  877. div.style.backgroundColor = (tempColor == 'default') ? defaultColorValue : tempColor;
  878. btn.innerText = '';
  879. btn.appendChild(div);
  880. if (dropper != null)
  881. {
  882. div.style.width = '21px';
  883. div.style.margin = '2px 18px 2px 3px';
  884. div.appendChild(dropper);
  885. }
  886. else
  887. {
  888. div.style.width = '36px';
  889. div.style.margin = '3px';
  890. }
  891. if (color != null && color != mxConstants.NONE && color.length > 1 && typeof color === 'string')
  892. {
  893. var clr = (color.charAt(0) == '#') ? color.substring(1).toUpperCase() : color;
  894. var name = ColorDialog.prototype.colorNames[clr];
  895. if (name != null)
  896. {
  897. btn.setAttribute('title', name);
  898. }
  899. }
  900. if (color != null && color != mxConstants.NONE &&
  901. !graph.isSpecialColor(color))
  902. {
  903. cb.setAttribute('checked', 'checked');
  904. cb.defaultChecked = true;
  905. cb.checked = true;
  906. }
  907. else
  908. {
  909. cb.removeAttribute('checked');
  910. cb.defaultChecked = false;
  911. cb.checked = false;
  912. }
  913. btn.style.display = (cb.checked || hideCheckbox) ? '' : 'none';
  914. if (callbackFn != null)
  915. {
  916. callbackFn(color == 'null' ? null : color);
  917. }
  918. value = color;
  919. if (!disableUpdate)
  920. {
  921. // Checks if the color value needs to be updated in the model
  922. if (forceUpdate || hideCheckbox || getColorFn() != value)
  923. {
  924. setColorFn(value == 'null' ? null : value, value);
  925. }
  926. }
  927. applying = false;
  928. }
  929. };
  930. div.appendChild(clrInput);
  931. mxEvent.addListener(clrInput, 'change', function()
  932. {
  933. apply(clrInput.value, null, true);
  934. });
  935. btn = mxUtils.button('', mxUtils.bind(this, function(evt)
  936. {
  937. var color = value;
  938. if (color == 'default')
  939. {
  940. color = defaultColorValue;
  941. }
  942. this.editorUi.pickColor(color, function(newColor)
  943. {
  944. apply(newColor, null, true);
  945. }, defaultColorValue);
  946. mxEvent.consume(evt);
  947. }));
  948. btn.style.position = 'absolute';
  949. btn.style.marginTop = '-3px';
  950. btn.style.left = '178px';
  951. btn.style.height = '22px';
  952. btn.className = 'geColorBtn';
  953. btn.style.display = (cb.checked || hideCheckbox) ? '' : 'none';
  954. div.appendChild(btn);
  955. var clr = (value != null && typeof value === 'string' && value.charAt(0) == '#') ? value.substring(1).toUpperCase() : value;
  956. var name = ColorDialog.prototype.colorNames[clr];
  957. if (name != null)
  958. {
  959. btn.setAttribute('title', name);
  960. }
  961. mxEvent.addListener(div, 'click', function(evt)
  962. {
  963. var source = mxEvent.getSource(evt);
  964. if (source == cb || source.nodeName != 'INPUT')
  965. {
  966. // Toggles checkbox state for click on label
  967. if (source != cb)
  968. {
  969. cb.checked = !cb.checked;
  970. }
  971. // Overrides default value with current value to make it easier
  972. // to restore previous value if the checkbox is clicked twice
  973. if (!cb.checked && value != null && value != mxConstants.NONE &&
  974. defaultColor != mxConstants.NONE)
  975. {
  976. defaultColor = value;
  977. }
  978. apply((cb.checked) ? defaultColor : mxConstants.NONE);
  979. }
  980. });
  981. apply(value, true);
  982. if (listener != null)
  983. {
  984. listener.install(apply);
  985. this.listeners.push(listener);
  986. }
  987. return div;
  988. };
  989. /**
  990. *
  991. */
  992. BaseFormatPanel.prototype.createCellColorOption = function(label, colorKey, defaultColor, callbackFn, setStyleFn, defaultColorValue)
  993. {
  994. var ui = this.editorUi;
  995. var editor = ui.editor;
  996. var graph = editor.graph;
  997. return this.createColorOption(label, function()
  998. {
  999. // Seems to be null sometimes, not sure why...
  1000. var state = graph.view.getState(ui.getSelectionState().cells[0]);
  1001. if (state != null)
  1002. {
  1003. return mxUtils.getValue(state.style, colorKey, null);
  1004. }
  1005. return null;
  1006. }, function(color)
  1007. {
  1008. graph.getModel().beginUpdate();
  1009. try
  1010. {
  1011. var cells = ui.getSelectionState().cells;
  1012. graph.setCellStyles(colorKey, color, cells);
  1013. if (setStyleFn != null)
  1014. {
  1015. setStyleFn(color);
  1016. }
  1017. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [colorKey],
  1018. 'values', [color], 'cells', cells));
  1019. }
  1020. finally
  1021. {
  1022. graph.getModel().endUpdate();
  1023. }
  1024. }, defaultColor || mxConstants.NONE,
  1025. {
  1026. install: function(apply)
  1027. {
  1028. this.listener = function()
  1029. {
  1030. // Seems to be null sometimes, not sure why...
  1031. var state = graph.view.getState(ui.getSelectionState().cells[0]);
  1032. if (state != null)
  1033. {
  1034. apply(mxUtils.getValue(state.style, colorKey, null), true);
  1035. }
  1036. };
  1037. graph.getModel().addListener(mxEvent.CHANGE, this.listener);
  1038. },
  1039. destroy: function()
  1040. {
  1041. graph.getModel().removeListener(this.listener);
  1042. }
  1043. }, callbackFn, null, defaultColorValue);
  1044. };
  1045. /**
  1046. *
  1047. */
  1048. BaseFormatPanel.prototype.addArrow = function(elt)
  1049. {
  1050. elt.className = 'geColorBtn';
  1051. elt.style.display = 'inline-flex';
  1052. elt.style.alignItems = 'top';
  1053. elt.style.boxSizing = 'border-box';
  1054. elt.style.width = '64px';
  1055. elt.style.height = '22px';
  1056. elt.style.borderWidth = '1px';
  1057. elt.style.borderStyle = 'solid';
  1058. elt.style.margin = '2px 2px 2px 3px';
  1059. var arrow = document.createElement('div');
  1060. arrow.className = 'geAdaptiveAsset';
  1061. arrow.style.display = 'inline-block';
  1062. arrow.style.backgroundImage = 'url(' + Editor.thinExpandImage + ')';
  1063. arrow.style.backgroundRepeat = 'no-repeat';
  1064. arrow.style.backgroundPosition = '-2px 1px';
  1065. arrow.style.backgroundSize = '18px 18px';
  1066. arrow.style.opacity = '0.5';
  1067. arrow.style.height = '100%';
  1068. arrow.style.width = '14px';
  1069. elt.appendChild(arrow);
  1070. var symbol = elt.getElementsByTagName('div')[0];
  1071. if (symbol != null)
  1072. {
  1073. symbol.style.display = 'inline-block';
  1074. symbol.style.backgroundPositionX = 'center';
  1075. symbol.style.textAlign = 'center';
  1076. symbol.style.height = '100%';
  1077. symbol.style.flexGrow = '1';
  1078. symbol.style.opacity = '0.6';
  1079. }
  1080. return symbol;
  1081. };
  1082. /**
  1083. *
  1084. */
  1085. BaseFormatPanel.prototype.addUnitInput = function(container, unit, right, width, update, step, marginTop, disableFocus, isFloat)
  1086. {
  1087. marginTop = (marginTop != null) ? marginTop : 0;
  1088. var input = document.createElement('input');
  1089. input.style.position = 'absolute';
  1090. input.style.textAlign = 'right';
  1091. input.style.marginTop = '-2px';
  1092. input.style.left = (228 - right - width) + 'px';
  1093. input.style.width = width + 'px';
  1094. input.style.height = '21px';
  1095. input.style.borderWidth = '1px';
  1096. input.style.borderStyle = 'solid';
  1097. input.style.boxSizing = 'border-box';
  1098. container.appendChild(input);
  1099. var stepper = this.createStepper(input, update, step, null, disableFocus, null, isFloat);
  1100. stepper.style.marginTop = (marginTop - 2) + 'px';
  1101. stepper.style.left = (228 - right) + 'px';
  1102. container.appendChild(stepper);
  1103. return input;
  1104. };
  1105. /**
  1106. *
  1107. */
  1108. BaseFormatPanel.prototype.addGenericInput = function(container, unit, left, width, readFn, writeFn)
  1109. {
  1110. var graph = this.editorUi.editor.graph;
  1111. var update = function()
  1112. {
  1113. writeFn(input.value);
  1114. };
  1115. var input = this.addUnitInput(container, unit, left, width, update);
  1116. var listener = mxUtils.bind(this, function(sender, evt, force)
  1117. {
  1118. if (force || input != document.activeElement)
  1119. {
  1120. input.value = readFn() + unit;
  1121. }
  1122. });
  1123. mxEvent.addListener(input, 'keydown', function(e)
  1124. {
  1125. if (e.keyCode == 13)
  1126. {
  1127. graph.container.focus();
  1128. mxEvent.consume(e);
  1129. }
  1130. else if (e.keyCode == 27)
  1131. {
  1132. listener(null, null, true);
  1133. graph.container.focus();
  1134. mxEvent.consume(e);
  1135. }
  1136. });
  1137. graph.getModel().addListener(mxEvent.CHANGE, listener);
  1138. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  1139. listener();
  1140. mxEvent.addListener(input, 'blur', update);
  1141. mxEvent.addListener(input, 'change', update);
  1142. return input;
  1143. };
  1144. /**
  1145. *
  1146. */
  1147. BaseFormatPanel.prototype.createRelativeOption = function(label, key, width, handler, init)
  1148. {
  1149. width = (width != null) ? width : 52;
  1150. var ui = this.editorUi;
  1151. var graph = ui.editor.graph;
  1152. var div = this.createPanel();
  1153. div.style.paddingTop = '10px';
  1154. div.style.paddingBottom = '12px';
  1155. mxUtils.write(div, label);
  1156. div.style.fontWeight = 'bold';
  1157. var update = mxUtils.bind(this, function(evt)
  1158. {
  1159. if (handler != null)
  1160. {
  1161. handler(input);
  1162. }
  1163. else
  1164. {
  1165. var value = parseInt(input.value);
  1166. value = Math.min(100, Math.max(0, (isNaN(value)) ? 100 : value));
  1167. var state = graph.view.getState(ui.getSelectionState().cells[0]);
  1168. if (state != null && value != mxUtils.getValue(state.style, key, 100))
  1169. {
  1170. // Removes entry in style (assumes 100 is default for relative values)
  1171. if (value == 100)
  1172. {
  1173. value = null;
  1174. }
  1175. var cells = ui.getSelectionState().cells;
  1176. graph.setCellStyles(key, value, cells);
  1177. this.editorUi.fireEvent(new mxEventObject('styleChanged', 'keys', [key],
  1178. 'values', [value], 'cells', cells));
  1179. }
  1180. input.value = ((value != null) ? value : '100') + ' %';
  1181. }
  1182. mxEvent.consume(evt);
  1183. });
  1184. var input = this.addUnitInput(div, '%', 16, width, update, 10,
  1185. (mxClient.IS_MAC && mxClient.IS_GC) ? -14 :
  1186. ((mxClient.IS_WIN) ? -16 : -15), handler != null);
  1187. if (key != null)
  1188. {
  1189. var listener = mxUtils.bind(this, function(sender, evt, force)
  1190. {
  1191. if (force || input != document.activeElement)
  1192. {
  1193. var ss = ui.getSelectionState();
  1194. var tmp = parseInt(mxUtils.getValue(ss.style, key, 100));
  1195. input.value = (isNaN(tmp)) ? '' : tmp + ' %';
  1196. }
  1197. });
  1198. mxEvent.addListener(input, 'keydown', function(e)
  1199. {
  1200. if (e.keyCode == 13)
  1201. {
  1202. graph.container.focus();
  1203. mxEvent.consume(e);
  1204. }
  1205. else if (e.keyCode == 27)
  1206. {
  1207. listener(null, null, true);
  1208. graph.container.focus();
  1209. mxEvent.consume(e);
  1210. }
  1211. });
  1212. graph.getModel().addListener(mxEvent.CHANGE, listener);
  1213. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  1214. listener();
  1215. }
  1216. mxEvent.addListener(input, 'blur', update);
  1217. mxEvent.addListener(input, 'change', update);
  1218. if (init != null)
  1219. {
  1220. init(input);
  1221. }
  1222. return div;
  1223. };
  1224. /**
  1225. *
  1226. */
  1227. BaseFormatPanel.prototype.addLabel = function(div, title, right, width)
  1228. {
  1229. width = (width != null) ? width : 61;
  1230. var label = document.createElement('div');
  1231. mxUtils.write(label, title);
  1232. label.style.position = 'absolute';
  1233. label.style.left = (240 - right - width) + 'px';
  1234. label.style.width = width + 'px';
  1235. label.style.marginTop = '6px';
  1236. label.style.display = 'flex';
  1237. label.style.justifyContent = 'center';
  1238. div.appendChild(label);
  1239. return label;
  1240. };
  1241. /**
  1242. *
  1243. */
  1244. BaseFormatPanel.prototype.addKeyHandler = function(input, listener)
  1245. {
  1246. mxEvent.addListener(input, 'keydown', mxUtils.bind(this, function(e)
  1247. {
  1248. if (e.keyCode == 13)
  1249. {
  1250. this.editorUi.editor.graph.container.focus();
  1251. mxEvent.consume(e);
  1252. }
  1253. else if (e.keyCode == 27)
  1254. {
  1255. if (listener != null)
  1256. {
  1257. listener(null, null, true);
  1258. }
  1259. this.editorUi.editor.graph.container.focus();
  1260. mxEvent.consume(e);
  1261. }
  1262. }));
  1263. };
  1264. /**
  1265. *
  1266. */
  1267. BaseFormatPanel.prototype.styleButtons = function(elts)
  1268. {
  1269. for (var i = 0; i < elts.length; i++)
  1270. {
  1271. mxUtils.setPrefixedStyle(elts[i].style, 'borderRadius', '3px');
  1272. mxUtils.setOpacity(elts[i], 100);
  1273. elts[i].style.border = '1px solid #a0a0a0';
  1274. elts[i].style.padding = '4px';
  1275. elts[i].style.paddingTop = '3px';
  1276. elts[i].style.paddingRight = '1px';
  1277. elts[i].style.margin = '1px';
  1278. elts[i].style.marginRight = '2px';
  1279. elts[i].style.width = '24px';
  1280. elts[i].style.height = '20px';
  1281. elts[i].className += ' geColorBtn';
  1282. }
  1283. };
  1284. /**
  1285. * Adds the label menu items to the given menu and parent.
  1286. */
  1287. BaseFormatPanel.prototype.destroy = function()
  1288. {
  1289. if (this.listeners != null)
  1290. {
  1291. for (var i = 0; i < this.listeners.length; i++)
  1292. {
  1293. this.listeners[i].destroy();
  1294. }
  1295. this.listeners = null;
  1296. }
  1297. };
  1298. /**
  1299. * Adds the label menu items to the given menu and parent.
  1300. */
  1301. ArrangePanel = function(format, editorUi, container)
  1302. {
  1303. BaseFormatPanel.call(this, format, editorUi, container);
  1304. this.init();
  1305. };
  1306. mxUtils.extend(ArrangePanel, BaseFormatPanel);
  1307. /**
  1308. * Adds the label menu items to the given menu and parent.
  1309. */
  1310. ArrangePanel.prototype.init = function()
  1311. {
  1312. var ss = this.editorUi.getSelectionState();
  1313. if (ss.cells.length > 0)
  1314. {
  1315. this.container.appendChild(this.addLayerOps(this.createPanel()));
  1316. // Special case that adds two panels
  1317. this.addGeometry(this.container);
  1318. this.addEdgeGeometry(this.container);
  1319. if (!ss.containsLabel || ss.edges.length == 0)
  1320. {
  1321. this.container.appendChild(this.addAngle(this.createPanel()));
  1322. }
  1323. if (!ss.containsLabel)
  1324. {
  1325. this.container.appendChild(this.addFlip(this.createPanel()));
  1326. }
  1327. this.container.appendChild(this.addAlign(this.createPanel()));
  1328. if (ss.vertices.length > 1 && !ss.cell && !ss.row)
  1329. {
  1330. this.container.appendChild(this.addDistribute(this.createPanel()));
  1331. }
  1332. this.container.appendChild(this.addTable(this.createPanel()));
  1333. }
  1334. // Allows to lock/unload button to be added
  1335. this.container.appendChild(this.addGroupOps(this.createPanel()));
  1336. if (ss.containsLabel)
  1337. {
  1338. // Adds functions from hidden style format panel
  1339. var span = document.createElement('div');
  1340. span.style.width = '100%';
  1341. span.style.marginTop = '0px';
  1342. span.style.fontWeight = 'bold';
  1343. span.style.padding = '10px 0 0 14px';
  1344. mxUtils.write(span, mxResources.get('style'));
  1345. this.container.appendChild(span);
  1346. new StyleFormatPanel(this.format, this.editorUi, this.container);
  1347. }
  1348. };
  1349. /**
  1350. *
  1351. */
  1352. ArrangePanel.prototype.addTable = function(div)
  1353. {
  1354. var ui = this.editorUi;
  1355. var editor = ui.editor;
  1356. var graph = editor.graph;
  1357. var ss = ui.getSelectionState();
  1358. div.style.paddingTop = '6px';
  1359. div.style.paddingBottom = '10px';
  1360. var span = document.createElement('div');
  1361. span.style.marginTop = '0px';
  1362. span.style.marginBottom = '6px';
  1363. span.style.fontWeight = 'bold';
  1364. mxUtils.write(span, mxResources.get('table'));
  1365. div.appendChild(span);
  1366. var panel = document.createElement('div');
  1367. panel.style.position = 'relative';
  1368. panel.style.paddingLeft = '0px';
  1369. panel.style.borderWidth = '0px';
  1370. panel.style.width = '220px';
  1371. panel.className = 'geToolbarContainer';
  1372. var cell = ss.vertices[0];
  1373. if (graph.getSelectionCount() > 1)
  1374. {
  1375. if (graph.isTableCell(cell))
  1376. {
  1377. cell = graph.model.getParent(cell);
  1378. }
  1379. if (graph.isTableRow(cell))
  1380. {
  1381. cell = graph.model.getParent(cell);
  1382. }
  1383. }
  1384. var isTable = ss.table || ss.row || ss.cell;
  1385. var isStack = graph.isStack(cell) ||
  1386. graph.isStackChild(cell);
  1387. var showCols = isTable;
  1388. var showRows = isTable;
  1389. if (isStack)
  1390. {
  1391. var style = (graph.isStack(cell)) ? ss.style :
  1392. graph.getCellStyle(graph.model.getParent(cell));
  1393. showRows = style['horizontalStack'] == '0';
  1394. showCols = !showRows;
  1395. }
  1396. var btns = [];
  1397. if (showCols)
  1398. {
  1399. btns = btns.concat([
  1400. ui.toolbar.addButton('geSprite-insertcolumnbefore', mxResources.get('insertColumnBefore'),
  1401. mxUtils.bind(this, function()
  1402. {
  1403. try
  1404. {
  1405. if (isStack)
  1406. {
  1407. graph.insertLane(cell, true);
  1408. }
  1409. else
  1410. {
  1411. graph.insertTableColumn(cell, true);
  1412. }
  1413. }
  1414. catch (e)
  1415. {
  1416. ui.handleError(e);
  1417. }
  1418. }), panel),
  1419. ui.toolbar.addButton('geSprite-insertcolumnafter', mxResources.get('insertColumnAfter'),
  1420. mxUtils.bind(this, function()
  1421. {
  1422. try
  1423. {
  1424. if (isStack)
  1425. {
  1426. graph.insertLane(cell, false);
  1427. }
  1428. else
  1429. {
  1430. graph.insertTableColumn(cell, false);
  1431. }
  1432. }
  1433. catch (e)
  1434. {
  1435. ui.handleError(e);
  1436. }
  1437. }), panel),
  1438. ui.toolbar.addButton('geSprite-deletecolumn', mxResources.get('deleteColumn'),
  1439. mxUtils.bind(this, function()
  1440. {
  1441. try
  1442. {
  1443. if (isStack)
  1444. {
  1445. graph.deleteLane(cell);
  1446. }
  1447. else
  1448. {
  1449. graph.deleteTableColumn(cell);
  1450. }
  1451. }
  1452. catch (e)
  1453. {
  1454. ui.handleError(e);
  1455. }
  1456. }), panel)]);
  1457. }
  1458. if (showRows)
  1459. {
  1460. btns = btns.concat([ui.toolbar.addButton('geSprite-insertrowbefore', mxResources.get('insertRowBefore'),
  1461. mxUtils.bind(this, function()
  1462. {
  1463. try
  1464. {
  1465. if (isStack)
  1466. {
  1467. graph.insertLane(cell, true);
  1468. }
  1469. else
  1470. {
  1471. graph.insertTableRow(cell, true);
  1472. }
  1473. }
  1474. catch (e)
  1475. {
  1476. ui.handleError(e);
  1477. }
  1478. }), panel),
  1479. ui.toolbar.addButton('geSprite-insertrowafter', mxResources.get('insertRowAfter'),
  1480. mxUtils.bind(this, function()
  1481. {
  1482. try
  1483. {
  1484. if (isStack)
  1485. {
  1486. graph.insertLane(cell, false);
  1487. }
  1488. else
  1489. {
  1490. graph.insertTableRow(cell, false);
  1491. }
  1492. }
  1493. catch (e)
  1494. {
  1495. ui.handleError(e);
  1496. }
  1497. }), panel),
  1498. ui.toolbar.addButton('geSprite-deleterow', mxResources.get('deleteRow'),
  1499. mxUtils.bind(this, function()
  1500. {
  1501. try
  1502. {
  1503. if (isStack)
  1504. {
  1505. graph.deleteLane(cell);
  1506. }
  1507. else
  1508. {
  1509. graph.deleteTableRow(cell);
  1510. }
  1511. }
  1512. catch (e)
  1513. {
  1514. ui.handleError(e);
  1515. }
  1516. }), panel)]);
  1517. }
  1518. if (btns.length > 0)
  1519. {
  1520. this.styleButtons(btns);
  1521. div.appendChild(panel);
  1522. if (btns.length > 3)
  1523. {
  1524. btns[2].style.marginRight = '10px';
  1525. }
  1526. var count = 0;
  1527. if (ss.mergeCell != null)
  1528. {
  1529. count += this.addActions(div, ['mergeCells']);
  1530. }
  1531. else if (ss.style['colspan'] > 1 || ss.style['rowspan'] > 1)
  1532. {
  1533. count += this.addActions(div, ['unmergeCells']);
  1534. }
  1535. if (count > 0)
  1536. {
  1537. panel.style.paddingBottom = '2px';
  1538. }
  1539. }
  1540. else
  1541. {
  1542. div.style.display = 'none';
  1543. }
  1544. return div;
  1545. };
  1546. /**
  1547. *
  1548. */
  1549. ArrangePanel.prototype.addLayerOps = function(div)
  1550. {
  1551. this.addActions(div, ['toFront', 'toBack']);
  1552. this.addActions(div, ['bringForward', 'sendBackward']);
  1553. return div;
  1554. };
  1555. /**
  1556. *
  1557. */
  1558. ArrangePanel.prototype.addGroupOps = function(div)
  1559. {
  1560. var ui = this.editorUi;
  1561. var graph = ui.editor.graph;
  1562. var ss = ui.getSelectionState();
  1563. div.style.paddingTop = '8px';
  1564. div.style.paddingBottom = '6px';
  1565. var count = 0;
  1566. if (!ss.cell && !ss.row)
  1567. {
  1568. count += this.addActions(div, ['group', 'ungroup', 'copySize', 'pasteSize']) +
  1569. this.addActions(div, ['removeFromGroup']);
  1570. }
  1571. var clearWaypoints = this.addAction(div, 'clearWaypoints');
  1572. if (clearWaypoints != null)
  1573. {
  1574. mxUtils.br(div);
  1575. clearWaypoints.setAttribute('title', mxResources.get('clearWaypoints') +
  1576. ' (' + this.editorUi.actions.get('clearWaypoints').shortcut + ')' +
  1577. ' Shift+Click to Clear Anchor Points');
  1578. count++;
  1579. }
  1580. count += this.addActions(div, ['lockUnlock']);
  1581. if (count == 0)
  1582. {
  1583. div.style.display = 'none';
  1584. }
  1585. return div;
  1586. };
  1587. /**
  1588. *
  1589. */
  1590. ArrangePanel.prototype.addAlign = function(div)
  1591. {
  1592. var ss = this.editorUi.getSelectionState();
  1593. var graph = this.editorUi.editor.graph;
  1594. div.style.paddingTop = '6px';
  1595. div.style.paddingBottom = '8px';
  1596. div.appendChild(this.createTitle(mxResources.get('align')));
  1597. var stylePanel = document.createElement('div');
  1598. stylePanel.style.position = 'relative';
  1599. stylePanel.style.whiteSpace = 'nowrap';
  1600. stylePanel.style.paddingLeft = '0px';
  1601. stylePanel.style.paddingBottom = '2px';
  1602. stylePanel.style.borderWidth = '0px';
  1603. stylePanel.style.width = '220px';
  1604. stylePanel.className = 'geToolbarContainer';
  1605. if (ss.vertices.length > 1)
  1606. {
  1607. var left = this.editorUi.toolbar.addButton('geSprite-alignleft', mxResources.get('left'),
  1608. function() { graph.alignCells(mxConstants.ALIGN_LEFT); }, stylePanel);
  1609. var center = this.editorUi.toolbar.addButton('geSprite-aligncenter', mxResources.get('center'),
  1610. function() { graph.alignCells(mxConstants.ALIGN_CENTER); }, stylePanel);
  1611. var right = this.editorUi.toolbar.addButton('geSprite-alignright', mxResources.get('right'),
  1612. function() { graph.alignCells(mxConstants.ALIGN_RIGHT); }, stylePanel);
  1613. var top = this.editorUi.toolbar.addButton('geSprite-aligntop', mxResources.get('top'),
  1614. function() { graph.alignCells(mxConstants.ALIGN_TOP); }, stylePanel);
  1615. var middle = this.editorUi.toolbar.addButton('geSprite-alignmiddle', mxResources.get('middle'),
  1616. function() { graph.alignCells(mxConstants.ALIGN_MIDDLE); }, stylePanel);
  1617. var bottom = this.editorUi.toolbar.addButton('geSprite-alignbottom', mxResources.get('bottom'),
  1618. function() { graph.alignCells(mxConstants.ALIGN_BOTTOM); }, stylePanel);
  1619. this.styleButtons([left, center, right, top, middle, bottom]);
  1620. right.style.marginRight = '10px';
  1621. }
  1622. div.appendChild(stylePanel);
  1623. this.addActions(div, ['snapToGrid']);
  1624. return div;
  1625. };
  1626. /**
  1627. *
  1628. */
  1629. ArrangePanel.prototype.addFlip = function(div)
  1630. {
  1631. var ui = this.editorUi;
  1632. var editor = ui.editor;
  1633. var graph = editor.graph;
  1634. div.style.paddingTop = '6px';
  1635. div.style.paddingBottom = '10px';
  1636. var ss = this.editorUi.getSelectionState();
  1637. var span = document.createElement('div');
  1638. span.style.marginTop = '2px';
  1639. span.style.marginBottom = '8px';
  1640. span.style.fontWeight = 'bold';
  1641. mxUtils.write(span, mxResources.get('flip'));
  1642. div.appendChild(span);
  1643. var btn = mxUtils.button(mxResources.get('horizontal'), function(evt)
  1644. {
  1645. graph.flipCells(ss.cells, true);
  1646. })
  1647. btn.setAttribute('title', mxResources.get('horizontal'));
  1648. btn.style.width = '104px';
  1649. btn.style.marginRight = '2px';
  1650. div.appendChild(btn);
  1651. var btn = mxUtils.button(mxResources.get('vertical'), function(evt)
  1652. {
  1653. graph.flipCells(ss.cells, false);
  1654. })
  1655. btn.setAttribute('title', mxResources.get('vertical'));
  1656. btn.style.width = '104px';
  1657. div.appendChild(btn);
  1658. return div;
  1659. };
  1660. /**
  1661. *
  1662. */
  1663. ArrangePanel.prototype.addDistribute = function(div)
  1664. {
  1665. var ui = this.editorUi;
  1666. var editor = ui.editor;
  1667. var graph = editor.graph;
  1668. div.style.paddingTop = '6px';
  1669. div.style.paddingBottom = '8px';
  1670. div.appendChild(this.createTitle(mxResources.get('distribute')));
  1671. var btn = mxUtils.button(mxResources.get('horizontal'), function(evt)
  1672. {
  1673. graph.distributeCells(true, null, cb.checked);
  1674. })
  1675. btn.setAttribute('title', mxResources.get('horizontal'));
  1676. btn.style.width = '104px';
  1677. btn.style.marginRight = '2px';
  1678. div.appendChild(btn);
  1679. var btn = mxUtils.button(mxResources.get('vertical'), function(evt)
  1680. {
  1681. graph.distributeCells(false, null, cb.checked);
  1682. })
  1683. btn.setAttribute('title', mxResources.get('vertical'));
  1684. btn.style.width = '104px';
  1685. div.appendChild(btn);
  1686. mxUtils.br(div);
  1687. var panel = document.createElement('div');
  1688. panel.style.margin = '6px 0 0 0';
  1689. panel.style.display = 'flex';
  1690. panel.style.justifyContent = 'center';
  1691. panel.style.alignItems = 'center';
  1692. var cb = document.createElement('input');
  1693. cb.setAttribute('type', 'checkbox');
  1694. cb.setAttribute('id', 'spacingCheckbox');
  1695. cb.style.margin = '0 6px 0 0';
  1696. panel.appendChild(cb);
  1697. var label = document.createElement('label');
  1698. label.style.verticalAlign = 'top';
  1699. label.setAttribute('for', 'spacingCheckbox');
  1700. label.style.userSelect = 'none';
  1701. mxUtils.write(label, mxResources.get('spacing'));
  1702. panel.appendChild(label);
  1703. div.appendChild(panel);
  1704. return div;
  1705. };
  1706. /**
  1707. *
  1708. */
  1709. ArrangePanel.prototype.addAngle = function(div)
  1710. {
  1711. var ui = this.editorUi;
  1712. var editor = ui.editor;
  1713. var graph = editor.graph;
  1714. var ss = ui.getSelectionState();
  1715. div.style.paddingBottom = '12px';
  1716. var span = document.createElement('div');
  1717. span.style.position = 'absolute';
  1718. span.style.width = '70px';
  1719. span.style.marginTop = '0px';
  1720. span.style.fontWeight = 'bold';
  1721. var input = null;
  1722. var update = null;
  1723. var btn = null;
  1724. if (ss.rotatable && !ss.table && !ss.row && !ss.cell)
  1725. {
  1726. mxUtils.write(span, mxResources.get('angle'));
  1727. div.appendChild(span);
  1728. input = this.addUnitInput(div, '°', 16, 52, function()
  1729. {
  1730. update.apply(this, arguments);
  1731. });
  1732. mxUtils.br(div);
  1733. div.style.paddingTop = '10px';
  1734. }
  1735. else
  1736. {
  1737. div.style.paddingTop = '8px';
  1738. }
  1739. if (!ss.containsLabel)
  1740. {
  1741. var label = mxResources.get('reverse');
  1742. if (ss.vertices.length > 0 && ss.edges.length > 0)
  1743. {
  1744. label = mxResources.get('turn') + ' / ' + label;
  1745. }
  1746. else if (ss.vertices.length > 0)
  1747. {
  1748. label = mxResources.get('turn');
  1749. }
  1750. btn = mxUtils.button(label, function(evt)
  1751. {
  1752. ui.actions.get('turn').funct(evt);
  1753. })
  1754. btn.setAttribute('title', label + ' (' + this.editorUi.actions.get('turn').shortcut + ')');
  1755. btn.style.width = '210px';
  1756. div.appendChild(btn);
  1757. if (input != null)
  1758. {
  1759. btn.style.marginTop = '8px';
  1760. }
  1761. }
  1762. if (input != null)
  1763. {
  1764. var listener = mxUtils.bind(this, function(sender, evt, force)
  1765. {
  1766. if (force || document.activeElement != input)
  1767. {
  1768. ss = ui.getSelectionState();
  1769. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_ROTATION, 0));
  1770. input.value = (isNaN(tmp)) ? '' : tmp + '°';
  1771. }
  1772. });
  1773. update = this.installInputHandler(input, mxConstants.STYLE_ROTATION, 0, 0, 360, '°', null, true);
  1774. this.addKeyHandler(input, listener);
  1775. graph.getModel().addListener(mxEvent.CHANGE, listener);
  1776. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  1777. listener();
  1778. }
  1779. return div;
  1780. };
  1781. BaseFormatPanel.prototype.getUnit = function()
  1782. {
  1783. var unit = this.editorUi.editor.graph.view.unit;
  1784. switch(unit)
  1785. {
  1786. case mxConstants.POINTS:
  1787. return 'pt';
  1788. case mxConstants.INCHES:
  1789. return '"';
  1790. case mxConstants.MILLIMETERS:
  1791. return 'mm';
  1792. case mxConstants.METERS:
  1793. return 'm';
  1794. }
  1795. };
  1796. BaseFormatPanel.prototype.inUnit = function(pixels)
  1797. {
  1798. return this.editorUi.editor.graph.view.formatUnitText(pixels);
  1799. };
  1800. BaseFormatPanel.prototype.fromUnit = function(value)
  1801. {
  1802. var unit = this.editorUi.editor.graph.view.unit;
  1803. switch(unit)
  1804. {
  1805. case mxConstants.POINTS:
  1806. return value;
  1807. case mxConstants.INCHES:
  1808. return value * mxConstants.PIXELS_PER_INCH;
  1809. case mxConstants.MILLIMETERS:
  1810. return value * mxConstants.PIXELS_PER_MM;
  1811. case mxConstants.METERS:
  1812. return value * mxConstants.PIXELS_PER_MM * 1000;
  1813. }
  1814. };
  1815. BaseFormatPanel.prototype.isFloatUnit = function()
  1816. {
  1817. return this.editorUi.editor.graph.view.unit != mxConstants.POINTS;
  1818. };
  1819. BaseFormatPanel.prototype.getUnitStep = function()
  1820. {
  1821. var unit = this.editorUi.editor.graph.view.unit;
  1822. switch(unit)
  1823. {
  1824. case mxConstants.POINTS:
  1825. return 1;
  1826. case mxConstants.INCHES:
  1827. return 0.1;
  1828. case mxConstants.MILLIMETERS:
  1829. return 0.5;
  1830. case mxConstants.METERS:
  1831. return 0.001;
  1832. }
  1833. };
  1834. /**
  1835. *
  1836. */
  1837. ArrangePanel.prototype.addGeometry = function(container)
  1838. {
  1839. var panel = this;
  1840. var ui = this.editorUi;
  1841. var graph = ui.editor.graph;
  1842. var model = graph.getModel();
  1843. var rect = ui.getSelectionState();
  1844. var div = this.createPanel();
  1845. div.style.paddingBottom = '8px';
  1846. var span = document.createElement('div');
  1847. span.style.position = 'absolute';
  1848. span.style.width = '50px';
  1849. span.style.marginTop = '0px';
  1850. span.style.fontWeight = 'bold';
  1851. mxUtils.write(span, mxResources.get('size'));
  1852. div.appendChild(span);
  1853. var widthUpdate, heightUpdate, leftUpdate, topUpdate;
  1854. var width = this.addUnitInput(div, this.getUnit(), 87, 52, function()
  1855. {
  1856. widthUpdate.apply(this, arguments);
  1857. }, this.getUnitStep(), null, null, this.isFloatUnit());
  1858. var height = this.addUnitInput(div, this.getUnit(), 16, 52, function()
  1859. {
  1860. heightUpdate.apply(this, arguments);
  1861. }, this.getUnitStep(), null, null, this.isFloatUnit());
  1862. var autosizeBtn = document.createElement('div');
  1863. autosizeBtn.className = 'geSprite geSprite-fit';
  1864. autosizeBtn.setAttribute('title', mxResources.get('autosize') + ' (' + this.editorUi.actions.get('autosize').shortcut + ')');
  1865. autosizeBtn.style.position = 'relative';
  1866. autosizeBtn.style.cursor = 'pointer';
  1867. autosizeBtn.style.marginTop = '-3px';
  1868. autosizeBtn.style.border = '0px';
  1869. autosizeBtn.style.left = '42px';
  1870. mxUtils.setOpacity(autosizeBtn, 50);
  1871. mxEvent.addListener(autosizeBtn, 'mouseenter', function()
  1872. {
  1873. mxUtils.setOpacity(autosizeBtn, 100);
  1874. });
  1875. mxEvent.addListener(autosizeBtn, 'mouseleave', function()
  1876. {
  1877. mxUtils.setOpacity(autosizeBtn, 50);
  1878. });
  1879. mxEvent.addListener(autosizeBtn, 'click', function()
  1880. {
  1881. ui.actions.get('autosize').funct();
  1882. });
  1883. div.appendChild(autosizeBtn);
  1884. if (rect.row)
  1885. {
  1886. width.style.visibility = 'hidden';
  1887. width.nextSibling.style.visibility = 'hidden';
  1888. }
  1889. else
  1890. {
  1891. this.addLabel(div, mxResources.get('width'), 87, 64);
  1892. }
  1893. this.addLabel(div, mxResources.get('height'), 16, 64);
  1894. mxUtils.br(div);
  1895. var wrapper = document.createElement('div');
  1896. wrapper.style.paddingTop = '8px';
  1897. wrapper.style.paddingRight = '20px';
  1898. wrapper.style.whiteSpace = 'nowrap';
  1899. wrapper.style.textAlign = 'right';
  1900. var opt = this.createCellOption(mxResources.get('constrainProportions'),
  1901. mxConstants.STYLE_ASPECT, null, 'fixed', 'null');
  1902. opt.style.width = '210px';
  1903. wrapper.appendChild(opt);
  1904. if (!rect.cell && !rect.row)
  1905. {
  1906. div.appendChild(wrapper);
  1907. }
  1908. else
  1909. {
  1910. autosizeBtn.style.visibility = 'hidden';
  1911. }
  1912. var constrainCheckbox = opt.getElementsByTagName('input')[0];
  1913. this.addKeyHandler(width, listener);
  1914. this.addKeyHandler(height, listener);
  1915. widthUpdate = this.addGeometryHandler(width, function(geo, value, cell)
  1916. {
  1917. if (graph.isTableCell(cell))
  1918. {
  1919. graph.setTableColumnWidth(cell, value - geo.width, true);
  1920. // Blocks processing in caller
  1921. return true;
  1922. }
  1923. else if (geo.width > 0)
  1924. {
  1925. var value = Math.max(1, panel.fromUnit(value));
  1926. if (constrainCheckbox.checked)
  1927. {
  1928. geo.height = Math.round((geo.height * value * 100) / geo.width) / 100;
  1929. }
  1930. geo.width = value;
  1931. }
  1932. });
  1933. heightUpdate = this.addGeometryHandler(height, function(geo, value, cell)
  1934. {
  1935. if (graph.isTableCell(cell))
  1936. {
  1937. cell = model.getParent(cell);
  1938. }
  1939. if (graph.isTableRow(cell))
  1940. {
  1941. graph.setTableRowHeight(cell, value - geo.height);
  1942. // Blocks processing in caller
  1943. return true;
  1944. }
  1945. else if (geo.height > 0)
  1946. {
  1947. var value = Math.max(1, panel.fromUnit(value));
  1948. if (constrainCheckbox.checked)
  1949. {
  1950. geo.width = Math.round((geo.width * value * 100) / geo.height) / 100;
  1951. }
  1952. geo.height = value;
  1953. }
  1954. });
  1955. if (rect.resizable || rect.row || rect.cell)
  1956. {
  1957. container.appendChild(div);
  1958. }
  1959. var div2 = this.createPanel();
  1960. div2.style.paddingBottom = '30px';
  1961. var span = document.createElement('div');
  1962. span.style.position = 'absolute';
  1963. span.style.width = '70px';
  1964. span.style.marginTop = '0px';
  1965. span.style.fontWeight = 'bold';
  1966. mxUtils.write(span, mxResources.get('position'));
  1967. div2.appendChild(span);
  1968. var left = this.addUnitInput(div2, this.getUnit(), 87, 52, function()
  1969. {
  1970. leftUpdate.apply(this, arguments);
  1971. }, this.getUnitStep(), null, null, this.isFloatUnit());
  1972. var top = this.addUnitInput(div2, this.getUnit(), 16, 52, function()
  1973. {
  1974. topUpdate.apply(this, arguments);
  1975. }, this.getUnitStep(), null, null, this.isFloatUnit());
  1976. mxUtils.br(div2);
  1977. var coordinateLabels = true;
  1978. var dx = null;
  1979. var dy = null;
  1980. if (rect.movable)
  1981. {
  1982. if (rect.edges.length == 0 && rect.vertices.length == 1)
  1983. {
  1984. var geo = graph.getCellGeometry(rect.vertices[0]);
  1985. if (geo != null && geo.relative)
  1986. {
  1987. mxUtils.br(div2);
  1988. var span = document.createElement('div');
  1989. span.style.position = 'absolute';
  1990. span.style.width = '70px';
  1991. span.style.marginTop = '0px';
  1992. mxUtils.write(span, mxResources.get('relative'));
  1993. div2.appendChild(span);
  1994. dx = this.addGenericInput(div2, ' %', 87, 52, function()
  1995. {
  1996. return (Math.round(geo.x * 1000) / 10);
  1997. }, function(value)
  1998. {
  1999. value = parseFloat(value);
  2000. if (!isNaN(value))
  2001. {
  2002. model.beginUpdate();
  2003. try
  2004. {
  2005. geo = geo.clone();
  2006. geo.x = parseFloat(value) / 100;
  2007. model.setGeometry(rect.vertices[0], geo);
  2008. }
  2009. finally
  2010. {
  2011. model.endUpdate();
  2012. }
  2013. }
  2014. });
  2015. if (model.isEdge(model.getParent(rect.vertices[0])))
  2016. {
  2017. coordinateLabels = false;
  2018. var dyUpdate = null;
  2019. dy = this.addUnitInput(div2, this.getUnit(), 16, 52, function()
  2020. {
  2021. dyUpdate.apply(this, arguments);
  2022. });
  2023. dyUpdate = this.addGeometryHandler(dy, function(geo, value)
  2024. {
  2025. console.log('value', value);
  2026. geo.y = panel.fromUnit(value);
  2027. });
  2028. }
  2029. else
  2030. {
  2031. dy = this.addGenericInput(div2, ' %', 16, 52, function()
  2032. {
  2033. return (Math.round(geo.y * 1000) / 10);
  2034. }, function(value)
  2035. {
  2036. value = parseFloat(value);
  2037. if (!isNaN(value))
  2038. {
  2039. model.beginUpdate();
  2040. try
  2041. {
  2042. geo = geo.clone();
  2043. geo.y = parseFloat(value) / 100;
  2044. model.setGeometry(rect.vertices[0], geo);
  2045. }
  2046. finally
  2047. {
  2048. model.endUpdate();
  2049. }
  2050. }
  2051. });
  2052. }
  2053. mxUtils.br(div2);
  2054. }
  2055. }
  2056. container.appendChild(div2);
  2057. }
  2058. this.addLabel(div2, mxResources.get(coordinateLabels ? 'left' : 'line'), 87, 64).style.marginTop = '8px';
  2059. this.addLabel(div2, mxResources.get(coordinateLabels ? 'top' : 'orthogonal'), 16, 64).style.marginTop = '8px';
  2060. var listener = mxUtils.bind(this, function(sender, evt, force)
  2061. {
  2062. rect = ui.getSelectionState();
  2063. if (!rect.containsLabel && rect.vertices.length == graph.getSelectionCount() &&
  2064. rect.width != null && rect.height != null)
  2065. {
  2066. div.style.display = '';
  2067. if (force || document.activeElement != width)
  2068. {
  2069. width.value = this.inUnit(rect.width) + ' ' + this.getUnit();
  2070. }
  2071. if (force || document.activeElement != height)
  2072. {
  2073. height.value = this.inUnit(rect.height) + ' ' + this.getUnit();
  2074. }
  2075. }
  2076. else
  2077. {
  2078. div.style.display = 'none';
  2079. }
  2080. if (rect.vertices.length == graph.getSelectionCount() &&
  2081. rect.vertices.length > 0 && rect.x != null &&
  2082. rect.y != null)
  2083. {
  2084. var geo = graph.getCellGeometry(rect.vertices[0]);
  2085. div2.style.display = '';
  2086. if (force || document.activeElement != left)
  2087. {
  2088. left.value = this.inUnit(rect.x) + ' ' + this.getUnit();
  2089. }
  2090. if (force || document.activeElement != top)
  2091. {
  2092. top.value = this.inUnit(rect.y) + ' ' + this.getUnit();
  2093. }
  2094. if (geo != null && geo.relative)
  2095. {
  2096. if (dx != null && (force || document.activeElement != dx))
  2097. {
  2098. dx.value = (Math.round(geo.x * 1000) / 10) + ' %';
  2099. }
  2100. if (dy != null && (force || document.activeElement != dy))
  2101. {
  2102. if (model.isEdge(model.getParent(rect.vertices[0])))
  2103. {
  2104. dy.value = this.inUnit(geo.y) + ' ' + this.getUnit();
  2105. }
  2106. else
  2107. {
  2108. dy.value = (Math.round(geo.y * 1000) / 10) + ' %';
  2109. }
  2110. }
  2111. }
  2112. }
  2113. else
  2114. {
  2115. div2.style.display = 'none';
  2116. }
  2117. });
  2118. this.listeners.push({destroy: function() { model.removeListener(listener); }});
  2119. model.addListener(mxEvent.CHANGE, listener);
  2120. this.addKeyHandler(left, listener);
  2121. this.addKeyHandler(top, listener);
  2122. listener();
  2123. leftUpdate = this.addGeometryHandler(left, function(geo, value)
  2124. {
  2125. value = panel.fromUnit(value);
  2126. if (geo.relative)
  2127. {
  2128. geo.offset.x = value;
  2129. }
  2130. else
  2131. {
  2132. geo.x = value;
  2133. }
  2134. });
  2135. topUpdate = this.addGeometryHandler(top, function(geo, value)
  2136. {
  2137. value = panel.fromUnit(value);
  2138. if (geo.relative)
  2139. {
  2140. geo.offset.y = value;
  2141. }
  2142. else
  2143. {
  2144. geo.y = value;
  2145. }
  2146. });
  2147. if (rect.movable)
  2148. {
  2149. if (rect.edges.length == 0 && rect.vertices.length == 1 &&
  2150. model.isEdge(model.getParent(rect.vertices[0])))
  2151. {
  2152. var geo = graph.getCellGeometry(rect.vertices[0]);
  2153. if (geo != null && geo.relative)
  2154. {
  2155. var btn = mxUtils.button(mxResources.get('center'), mxUtils.bind(this, function(evt)
  2156. {
  2157. model.beginUpdate();
  2158. try
  2159. {
  2160. geo = geo.clone();
  2161. geo.x = 0;
  2162. geo.y = 0;
  2163. geo.offset = new mxPoint();
  2164. model.setGeometry(rect.vertices[0], geo);
  2165. }
  2166. finally
  2167. {
  2168. model.endUpdate();
  2169. }
  2170. }));
  2171. btn.setAttribute('title', mxResources.get('center'));
  2172. btn.style.width = '134px';
  2173. btn.style.left = '89px';
  2174. btn.style.position = 'absolute';
  2175. mxUtils.br(div2);
  2176. mxUtils.br(div2);
  2177. div2.appendChild(btn);
  2178. }
  2179. }
  2180. container.appendChild(div2);
  2181. }
  2182. };
  2183. /**
  2184. *
  2185. */
  2186. ArrangePanel.prototype.addGeometryHandler = function(input, fn)
  2187. {
  2188. var ui = this.editorUi;
  2189. var graph = ui.editor.graph;
  2190. var initialValue = null;
  2191. var panel = this;
  2192. function update(evt)
  2193. {
  2194. if (input.value != '')
  2195. {
  2196. var value = parseFloat(input.value);
  2197. if (isNaN(value))
  2198. {
  2199. input.value = initialValue + ' ' + panel.getUnit();
  2200. }
  2201. else if (value != initialValue)
  2202. {
  2203. graph.getModel().beginUpdate();
  2204. try
  2205. {
  2206. var cells = ui.getSelectionState().cells;
  2207. for (var i = 0; i < cells.length; i++)
  2208. {
  2209. if (graph.getModel().isVertex(cells[i]))
  2210. {
  2211. var geo = graph.getCellGeometry(cells[i]);
  2212. if (geo != null)
  2213. {
  2214. geo = geo.clone();
  2215. if (!fn(geo, value, cells[i]))
  2216. {
  2217. var state = graph.view.getState(cells[i]);
  2218. if (state != null && graph.isRecursiveVertexResize(state))
  2219. {
  2220. graph.resizeChildCells(cells[i], geo);
  2221. }
  2222. graph.getModel().setGeometry(cells[i], geo);
  2223. graph.constrainChildCells(cells[i]);
  2224. }
  2225. }
  2226. }
  2227. }
  2228. }
  2229. finally
  2230. {
  2231. graph.getModel().endUpdate();
  2232. }
  2233. initialValue = value;
  2234. input.value = value + ' ' + panel.getUnit();
  2235. }
  2236. }
  2237. mxEvent.consume(evt);
  2238. };
  2239. mxEvent.addListener(input, 'blur', update);
  2240. mxEvent.addListener(input, 'change', update);
  2241. mxEvent.addListener(input, 'focus', function()
  2242. {
  2243. initialValue = input.value;
  2244. });
  2245. return update;
  2246. };
  2247. ArrangePanel.prototype.addEdgeGeometryHandler = function(input, fn)
  2248. {
  2249. var ui = this.editorUi;
  2250. var graph = ui.editor.graph;
  2251. var initialValue = null;
  2252. function update(evt)
  2253. {
  2254. if (input.value != '')
  2255. {
  2256. var value = parseFloat(input.value);
  2257. if (isNaN(value))
  2258. {
  2259. input.value = initialValue + ' pt';
  2260. }
  2261. else if (value != initialValue)
  2262. {
  2263. graph.getModel().beginUpdate();
  2264. try
  2265. {
  2266. var cells = ui.getSelectionState().cells;
  2267. for (var i = 0; i < cells.length; i++)
  2268. {
  2269. if (graph.getModel().isEdge(cells[i]))
  2270. {
  2271. var geo = graph.getCellGeometry(cells[i]);
  2272. if (geo != null)
  2273. {
  2274. geo = geo.clone();
  2275. fn(geo, value);
  2276. graph.getModel().setGeometry(cells[i], geo);
  2277. }
  2278. }
  2279. }
  2280. }
  2281. finally
  2282. {
  2283. graph.getModel().endUpdate();
  2284. }
  2285. initialValue = value;
  2286. input.value = value + ' pt';
  2287. }
  2288. }
  2289. mxEvent.consume(evt);
  2290. };
  2291. mxEvent.addListener(input, 'blur', update);
  2292. mxEvent.addListener(input, 'change', update);
  2293. mxEvent.addListener(input, 'focus', function()
  2294. {
  2295. initialValue = input.value;
  2296. });
  2297. return update;
  2298. };
  2299. /**
  2300. *
  2301. */
  2302. ArrangePanel.prototype.addEdgeGeometry = function(container)
  2303. {
  2304. var ui = this.editorUi;
  2305. var graph = ui.editor.graph;
  2306. var rect = ui.getSelectionState();
  2307. var div = this.createPanel();
  2308. var span = document.createElement('div');
  2309. span.style.position = 'absolute';
  2310. span.style.width = '70px';
  2311. span.style.marginTop = '0px';
  2312. span.style.fontWeight = 'bold';
  2313. mxUtils.write(span, mxResources.get('width'));
  2314. div.appendChild(span);
  2315. var widthUpdate, xtUpdate, ytUpdate, xsUpdate, ysUpdate;
  2316. var width = this.addUnitInput(div, 'pt', 12, 44, function()
  2317. {
  2318. widthUpdate.apply(this, arguments);
  2319. });
  2320. mxUtils.br(div);
  2321. this.addKeyHandler(width, listener);
  2322. var widthUpdate = mxUtils.bind(this, function(evt)
  2323. {
  2324. // Maximum stroke width is 999
  2325. var value = parseInt(width.value);
  2326. value = Math.min(999, Math.max(1, (isNaN(value)) ? 1 : value));
  2327. if (value != mxUtils.getValue(rect.style, 'width', mxCellRenderer.defaultShapes['flexArrow'].prototype.defaultWidth))
  2328. {
  2329. var cells = ui.getSelectionState().cells;
  2330. graph.setCellStyles('width', value, cells);
  2331. ui.fireEvent(new mxEventObject('styleChanged', 'keys', ['width'],
  2332. 'values', [value], 'cells', cells));
  2333. }
  2334. width.value = value + ' pt';
  2335. mxEvent.consume(evt);
  2336. });
  2337. mxEvent.addListener(width, 'blur', widthUpdate);
  2338. mxEvent.addListener(width, 'change', widthUpdate);
  2339. container.appendChild(div);
  2340. var divs = this.createPanel();
  2341. divs.style.paddingBottom = '30px';
  2342. var span = document.createElement('div');
  2343. span.style.position = 'absolute';
  2344. span.style.width = '70px';
  2345. span.style.marginTop = '0px';
  2346. mxUtils.write(span, mxResources.get('linestart'));
  2347. divs.appendChild(span);
  2348. var xs = this.addUnitInput(divs, 'pt', 87, 52, function()
  2349. {
  2350. xsUpdate.apply(this, arguments);
  2351. });
  2352. var ys = this.addUnitInput(divs, 'pt', 16, 52, function()
  2353. {
  2354. ysUpdate.apply(this, arguments);
  2355. });
  2356. mxUtils.br(divs);
  2357. this.addLabel(divs, mxResources.get('left'), 87, 64);
  2358. this.addLabel(divs, mxResources.get('top'), 16, 64);
  2359. container.appendChild(divs);
  2360. this.addKeyHandler(xs, listener);
  2361. this.addKeyHandler(ys, listener);
  2362. var divt = this.createPanel();
  2363. divt.style.paddingBottom = '30px';
  2364. var span = document.createElement('div');
  2365. span.style.position = 'absolute';
  2366. span.style.width = '70px';
  2367. span.style.marginTop = '0px';
  2368. mxUtils.write(span, mxResources.get('lineend'));
  2369. divt.appendChild(span);
  2370. var xt = this.addUnitInput(divt, 'pt', 87, 52, function()
  2371. {
  2372. xtUpdate.apply(this, arguments);
  2373. });
  2374. var yt = this.addUnitInput(divt, 'pt', 16, 52, function()
  2375. {
  2376. ytUpdate.apply(this, arguments);
  2377. });
  2378. mxUtils.br(divt);
  2379. this.addLabel(divt, mxResources.get('left'), 87, 64);
  2380. this.addLabel(divt, mxResources.get('top'), 16, 64);
  2381. container.appendChild(divt);
  2382. this.addKeyHandler(xt, listener);
  2383. this.addKeyHandler(yt, listener);
  2384. var listener = mxUtils.bind(this, function(sender, evt, force)
  2385. {
  2386. rect = ui.getSelectionState();
  2387. var cell = rect.cells[0];
  2388. if (rect.style.shape == 'link' || rect.style.shape == 'flexArrow')
  2389. {
  2390. div.style.display = '';
  2391. if (force || document.activeElement != width)
  2392. {
  2393. var value = mxUtils.getValue(rect.style, 'width',
  2394. mxCellRenderer.defaultShapes['flexArrow'].prototype.defaultWidth);
  2395. width.value = value + ' pt';
  2396. }
  2397. }
  2398. else
  2399. {
  2400. div.style.display = 'none';
  2401. }
  2402. if (rect.cells.length == 1 && graph.model.isEdge(cell))
  2403. {
  2404. var geo = graph.model.getGeometry(cell);
  2405. if (geo != null && geo.sourcePoint != null &&
  2406. graph.model.getTerminal(cell, true) == null)
  2407. {
  2408. xs.value = geo.sourcePoint.x;
  2409. ys.value = geo.sourcePoint.y;
  2410. }
  2411. else
  2412. {
  2413. divs.style.display = 'none';
  2414. }
  2415. if (geo != null && geo.targetPoint != null &&
  2416. graph.model.getTerminal(cell, false) == null)
  2417. {
  2418. xt.value = geo.targetPoint.x;
  2419. yt.value = geo.targetPoint.y;
  2420. }
  2421. else
  2422. {
  2423. divt.style.display = 'none';
  2424. }
  2425. }
  2426. else
  2427. {
  2428. divs.style.display = 'none';
  2429. divt.style.display = 'none';
  2430. }
  2431. });
  2432. xsUpdate = this.addEdgeGeometryHandler(xs, function(geo, value)
  2433. {
  2434. geo.sourcePoint.x = value;
  2435. });
  2436. ysUpdate = this.addEdgeGeometryHandler(ys, function(geo, value)
  2437. {
  2438. geo.sourcePoint.y = value;
  2439. });
  2440. xtUpdate = this.addEdgeGeometryHandler(xt, function(geo, value)
  2441. {
  2442. geo.targetPoint.x = value;
  2443. });
  2444. ytUpdate = this.addEdgeGeometryHandler(yt, function(geo, value)
  2445. {
  2446. geo.targetPoint.y = value;
  2447. });
  2448. graph.getModel().addListener(mxEvent.CHANGE, listener);
  2449. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  2450. listener();
  2451. };
  2452. /**
  2453. * Adds the label menu items to the given menu and parent.
  2454. */
  2455. TextFormatPanel = function(format, editorUi, container)
  2456. {
  2457. BaseFormatPanel.call(this, format, editorUi, container);
  2458. this.init();
  2459. };
  2460. mxUtils.extend(TextFormatPanel, BaseFormatPanel);
  2461. /**
  2462. * Adds the label menu items to the given menu and parent.
  2463. */
  2464. TextFormatPanel.prototype.init = function()
  2465. {
  2466. this.container.style.borderBottom = 'none';
  2467. this.addFont(this.container);
  2468. // Allows to lock/unload button to be added
  2469. this.container.appendChild(this.addFontOps(this.createPanel()));
  2470. };
  2471. /**
  2472. *
  2473. */
  2474. TextFormatPanel.prototype.addFontOps = function(div)
  2475. {
  2476. var ui = this.editorUi;
  2477. div.style.paddingTop = '8px';
  2478. div.style.paddingBottom = '6px';
  2479. var count = this.addActions(div, ['removeFormat']);
  2480. if (count == 0)
  2481. {
  2482. div.style.display = 'none';
  2483. }
  2484. return div;
  2485. };
  2486. /**
  2487. * Adds the label menu items to the given menu and parent.
  2488. */
  2489. TextFormatPanel.prototype.addFont = function(container)
  2490. {
  2491. var ui = this.editorUi;
  2492. var editor = ui.editor;
  2493. var graph = editor.graph;
  2494. var ss = ui.getSelectionState();
  2495. var title = this.createTitle(mxResources.get('font'));
  2496. title.style.paddingLeft = '14px';
  2497. title.style.paddingTop = '10px';
  2498. title.style.paddingBottom = '6px';
  2499. container.appendChild(title);
  2500. var stylePanel = this.createPanel();
  2501. stylePanel.style.paddingTop = '2px';
  2502. stylePanel.style.paddingBottom = '2px';
  2503. stylePanel.style.position = 'relative';
  2504. stylePanel.style.marginLeft = '-2px';
  2505. stylePanel.style.borderWidth = '0px';
  2506. stylePanel.className = 'geToolbarContainer';
  2507. if (graph.cellEditor.isContentEditing())
  2508. {
  2509. var cssPanel = stylePanel.cloneNode();
  2510. var cssMenu = this.editorUi.toolbar.addMenu(mxResources.get('style'),
  2511. mxResources.get('style'), true, 'formatBlock', cssPanel, null, true);
  2512. this.addArrow(cssMenu);
  2513. cssMenu.style.width = '211px';
  2514. cssMenu.style.alignItems = 'center';
  2515. cssMenu.style.justifyContent = 'center';
  2516. cssMenu.style.whiteSpace = 'nowrap';
  2517. cssMenu.style.overflow = 'hidden';
  2518. cssMenu.style.margin = '0px';
  2519. cssMenu.style.position = 'relative';
  2520. var arrow = cssMenu.getElementsByTagName('div')[0];
  2521. arrow.style.position = 'absolute';
  2522. arrow.style.right = '2px';
  2523. container.appendChild(cssPanel);
  2524. }
  2525. container.appendChild(stylePanel);
  2526. var colorPanel = this.createPanel();
  2527. colorPanel.style.marginTop = '8px';
  2528. colorPanel.style.borderWidth = '1px';
  2529. colorPanel.style.borderStyle = 'solid';
  2530. colorPanel.style.paddingTop = '6px';
  2531. colorPanel.style.paddingBottom = '2px';
  2532. var fontMenu = this.editorUi.toolbar.addMenu('Helvetica', mxResources.get('fontFamily'),
  2533. true, 'fontFamily', stylePanel, null, true);
  2534. this.addArrow(fontMenu);
  2535. fontMenu.style.width = '211px';
  2536. fontMenu.style.alignItems = 'center';
  2537. fontMenu.style.justifyContent = 'center';
  2538. fontMenu.style.whiteSpace = 'nowrap';
  2539. fontMenu.style.overflow = 'hidden';
  2540. fontMenu.style.margin = '0px';
  2541. fontMenu.style.position = 'relative';
  2542. var arrow = fontMenu.getElementsByTagName('div')[0];
  2543. arrow.style.position = 'absolute';
  2544. arrow.style.right = '2px';
  2545. var stylePanel2 = stylePanel.cloneNode(false);
  2546. stylePanel2.style.marginLeft = '-3px';
  2547. var fontStyleItems = this.editorUi.toolbar.addItems(['bold', 'italic', 'underline'], stylePanel2, true);
  2548. fontStyleItems[0].setAttribute('title', mxResources.get('bold') + ' (' + this.editorUi.actions.get('bold').shortcut + ')');
  2549. fontStyleItems[1].setAttribute('title', mxResources.get('italic') + ' (' + this.editorUi.actions.get('italic').shortcut + ')');
  2550. fontStyleItems[2].setAttribute('title', mxResources.get('underline') + ' (' + this.editorUi.actions.get('underline').shortcut + ')');
  2551. var verticalItem = this.editorUi.toolbar.addItems(['vertical'], stylePanel2, true)[0];
  2552. container.appendChild(stylePanel2);
  2553. this.styleButtons(fontStyleItems);
  2554. this.styleButtons([verticalItem]);
  2555. var stylePanel3 = stylePanel.cloneNode(false);
  2556. stylePanel3.style.marginLeft = '-3px';
  2557. stylePanel3.style.paddingBottom = '0px';
  2558. // Helper function to return a wrapper function does not pass any arguments
  2559. var callFn = function(fn)
  2560. {
  2561. return function()
  2562. {
  2563. return fn();
  2564. };
  2565. };
  2566. var left = this.editorUi.toolbar.addButton('geSprite-left', mxResources.get('left'),
  2567. (graph.cellEditor.isContentEditing()) ?
  2568. function(evt)
  2569. {
  2570. graph.cellEditor.alignText(mxConstants.ALIGN_LEFT, evt);
  2571. ui.fireEvent(new mxEventObject('styleChanged',
  2572. 'keys', [mxConstants.STYLE_ALIGN],
  2573. 'values', [mxConstants.ALIGN_LEFT],
  2574. 'cells', ss.cells));
  2575. } : callFn(this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_ALIGN], [mxConstants.ALIGN_LEFT])), stylePanel3);
  2576. var center = this.editorUi.toolbar.addButton('geSprite-center', mxResources.get('center'),
  2577. (graph.cellEditor.isContentEditing()) ?
  2578. function(evt)
  2579. {
  2580. graph.cellEditor.alignText(mxConstants.ALIGN_CENTER, evt);
  2581. ui.fireEvent(new mxEventObject('styleChanged',
  2582. 'keys', [mxConstants.STYLE_ALIGN],
  2583. 'values', [mxConstants.ALIGN_CENTER],
  2584. 'cells', ss.cells));
  2585. } : callFn(this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_ALIGN], [mxConstants.ALIGN_CENTER])), stylePanel3);
  2586. var right = this.editorUi.toolbar.addButton('geSprite-right', mxResources.get('right'),
  2587. (graph.cellEditor.isContentEditing()) ?
  2588. function(evt)
  2589. {
  2590. graph.cellEditor.alignText(mxConstants.ALIGN_RIGHT, evt);
  2591. ui.fireEvent(new mxEventObject('styleChanged',
  2592. 'keys', [mxConstants.STYLE_ALIGN],
  2593. 'values', [mxConstants.ALIGN_RIGHT],
  2594. 'cells', ss.cells));
  2595. } : callFn(this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_ALIGN], [mxConstants.ALIGN_RIGHT])), stylePanel3);
  2596. this.styleButtons([left, center, right]);
  2597. // Quick hack for strikethrough
  2598. // TODO: Add translations and toggle state
  2599. if (graph.cellEditor.isContentEditing())
  2600. {
  2601. var strike = this.editorUi.toolbar.addButton('geSprite-removeformat', mxResources.get('strikethrough'),
  2602. function()
  2603. {
  2604. document.execCommand('strikeThrough', false, null);
  2605. }, stylePanel2);
  2606. this.styleButtons([strike]);
  2607. strike.firstChild.style.background = 'url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCI+PGRlZnM+PHBhdGggaWQ9ImEiIGQ9Ik0wIDBoMjR2MjRIMFYweiIvPjwvZGVmcz48Y2xpcFBhdGggaWQ9ImIiPjx1c2UgeGxpbms6aHJlZj0iI2EiIG92ZXJmbG93PSJ2aXNpYmxlIi8+PC9jbGlwUGF0aD48cGF0aCBjbGlwLXBhdGg9InVybCgjYikiIGZpbGw9IiMwMTAxMDEiIGQ9Ik03LjI0IDguNzVjLS4yNi0uNDgtLjM5LTEuMDMtLjM5LTEuNjcgMC0uNjEuMTMtMS4xNi40LTEuNjcuMjYtLjUuNjMtLjkzIDEuMTEtMS4yOS40OC0uMzUgMS4wNS0uNjMgMS43LS44My42Ni0uMTkgMS4zOS0uMjkgMi4xOC0uMjkuODEgMCAxLjU0LjExIDIuMjEuMzQuNjYuMjIgMS4yMy41NCAxLjY5Ljk0LjQ3LjQuODMuODggMS4wOCAxLjQzLjI1LjU1LjM4IDEuMTUuMzggMS44MWgtMy4wMWMwLS4zMS0uMDUtLjU5LS4xNS0uODUtLjA5LS4yNy0uMjQtLjQ5LS40NC0uNjgtLjItLjE5LS40NS0uMzMtLjc1LS40NC0uMy0uMS0uNjYtLjE2LTEuMDYtLjE2LS4zOSAwLS43NC4wNC0xLjAzLjEzLS4yOS4wOS0uNTMuMjEtLjcyLjM2LS4xOS4xNi0uMzQuMzQtLjQ0LjU1LS4xLjIxLS4xNS40My0uMTUuNjYgMCAuNDguMjUuODguNzQgMS4yMS4zOC4yNS43Ny40OCAxLjQxLjdINy4zOWMtLjA1LS4wOC0uMTEtLjE3LS4xNS0uMjV6TTIxIDEydi0ySDN2Mmg5LjYyYy4xOC4wNy40LjE0LjU1LjIuMzcuMTcuNjYuMzQuODcuNTEuMjEuMTcuMzUuMzYuNDMuNTcuMDcuMi4xMS40My4xMS42OSAwIC4yMy0uMDUuNDUtLjE0LjY2LS4wOS4yLS4yMy4zOC0uNDIuNTMtLjE5LjE1LS40Mi4yNi0uNzEuMzUtLjI5LjA4LS42My4xMy0xLjAxLjEzLS40MyAwLS44My0uMDQtMS4xOC0uMTNzLS42Ni0uMjMtLjkxLS40MmMtLjI1LS4xOS0uNDUtLjQ0LS41OS0uNzUtLjE0LS4zMS0uMjUtLjc2LS4yNS0xLjIxSDYuNGMwIC41NS4wOCAxLjEzLjI0IDEuNTguMTYuNDUuMzcuODUuNjUgMS4yMS4yOC4zNS42LjY2Ljk4LjkyLjM3LjI2Ljc4LjQ4IDEuMjIuNjUuNDQuMTcuOS4zIDEuMzguMzkuNDguMDguOTYuMTMgMS40NC4xMy44IDAgMS41My0uMDkgMi4xOC0uMjhzMS4yMS0uNDUgMS42Ny0uNzljLjQ2LS4zNC44Mi0uNzcgMS4wNy0xLjI3cy4zOC0xLjA3LjM4LTEuNzFjMC0uNi0uMS0xLjE0LS4zMS0xLjYxLS4wNS0uMTEtLjExLS4yMy0uMTctLjMzSDIxeiIvPjwvc3ZnPg==)';
  2608. strike.firstChild.style.backgroundPosition = '2px 2px';
  2609. strike.firstChild.style.backgroundSize = '18px 18px';
  2610. this.styleButtons([strike]);
  2611. }
  2612. var top = this.editorUi.toolbar.addButton('geSprite-top', mxResources.get('top'),
  2613. callFn(this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_VERTICAL_ALIGN],
  2614. [mxConstants.ALIGN_TOP])), stylePanel3);
  2615. var middle = this.editorUi.toolbar.addButton('geSprite-middle', mxResources.get('middle'),
  2616. callFn(this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_VERTICAL_ALIGN],
  2617. [mxConstants.ALIGN_MIDDLE])), stylePanel3);
  2618. var bottom = this.editorUi.toolbar.addButton('geSprite-bottom', mxResources.get('bottom'),
  2619. callFn(this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_VERTICAL_ALIGN],
  2620. [mxConstants.ALIGN_BOTTOM])), stylePanel3);
  2621. this.styleButtons([top, middle, bottom]);
  2622. container.appendChild(stylePanel3);
  2623. // Hack for updating UI state below based on current text selection
  2624. // currentTable is the current selected DOM table updated below
  2625. var sub, sup, full, tableWrapper, currentTable, tableCell, tableRow;
  2626. if (graph.cellEditor.isContentEditing())
  2627. {
  2628. top.style.display = 'none';
  2629. middle.style.display = 'none';
  2630. bottom.style.display = 'none';
  2631. verticalItem.style.display = 'none';
  2632. full = this.editorUi.toolbar.addButton('geSprite-justifyfull', mxResources.get('block'),
  2633. function()
  2634. {
  2635. if (full.style.opacity == 1)
  2636. {
  2637. document.execCommand('justifyfull', false, null);
  2638. }
  2639. }, stylePanel3);
  2640. full.style.marginRight = '9px';
  2641. full.style.opacity = 1;
  2642. this.styleButtons([full,
  2643. sub = this.editorUi.toolbar.addButton('geSprite-subscript',
  2644. mxResources.get('subscript') + ' (' + Editor.ctrlKey + '+,)',
  2645. function()
  2646. {
  2647. document.execCommand('subscript', false, null);
  2648. }, stylePanel3), sup = this.editorUi.toolbar.addButton('geSprite-superscript',
  2649. mxResources.get('superscript') + ' (' + Editor.ctrlKey + '+.)',
  2650. function()
  2651. {
  2652. document.execCommand('superscript', false, null);
  2653. }, stylePanel3)]);
  2654. sub.style.marginLeft = '10px';
  2655. var tmp = stylePanel3.cloneNode(false);
  2656. tmp.style.paddingTop = '4px';
  2657. var btns = [this.editorUi.toolbar.addButton('geSprite-orderedlist', mxResources.get('numberedList'),
  2658. function()
  2659. {
  2660. document.execCommand('insertorderedlist', false, null);
  2661. }, tmp),
  2662. this.editorUi.toolbar.addButton('geSprite-unorderedlist', mxResources.get('bulletedList'),
  2663. function()
  2664. {
  2665. document.execCommand('insertunorderedlist', false, null);
  2666. }, tmp),
  2667. this.editorUi.toolbar.addButton('geSprite-outdent', mxResources.get('decreaseIndent'),
  2668. function()
  2669. {
  2670. document.execCommand('outdent', false, null);
  2671. }, tmp),
  2672. this.editorUi.toolbar.addButton('geSprite-indent', mxResources.get('increaseIndent'),
  2673. function()
  2674. {
  2675. document.execCommand('indent', false, null);
  2676. }, tmp),
  2677. this.editorUi.toolbar.addButton('geSprite-removeformat', mxResources.get('removeFormat'),
  2678. function()
  2679. {
  2680. document.execCommand('removeformat', false, null);
  2681. }, tmp),
  2682. this.editorUi.toolbar.addButton('geSprite-code', mxResources.get('html'),
  2683. function()
  2684. {
  2685. graph.cellEditor.toggleViewMode();
  2686. }, tmp)];
  2687. this.styleButtons(btns);
  2688. btns[btns.length - 2].style.marginLeft = '10px';
  2689. container.appendChild(tmp);
  2690. }
  2691. else
  2692. {
  2693. fontStyleItems[2].style.marginRight = '12px';
  2694. right.style.marginRight = '12px';
  2695. }
  2696. // Label position
  2697. var stylePanel4 = stylePanel.cloneNode(false);
  2698. stylePanel4.removeAttribute('class');
  2699. stylePanel4.style.marginLeft = '0px';
  2700. stylePanel4.style.paddingTop = '8px';
  2701. stylePanel4.style.paddingBottom = '4px';
  2702. stylePanel4.style.fontWeight = 'normal';
  2703. mxUtils.write(stylePanel4, mxResources.get('position'));
  2704. // Adds label position options
  2705. var positionSelect = document.createElement('select');
  2706. positionSelect.style.position = 'absolute';
  2707. positionSelect.style.left = '126px';
  2708. positionSelect.style.width = '98px';
  2709. positionSelect.style.borderWidth = '1px';
  2710. positionSelect.style.borderStyle = 'solid';
  2711. positionSelect.style.marginTop = '-3px';
  2712. var directions = ['topLeft', 'top', 'topRight', 'left', 'center', 'right', 'bottomLeft', 'bottom', 'bottomRight'];
  2713. var lset = {'topLeft': [mxConstants.ALIGN_LEFT, mxConstants.ALIGN_TOP, mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_BOTTOM],
  2714. 'top': [mxConstants.ALIGN_CENTER, mxConstants.ALIGN_TOP, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_BOTTOM],
  2715. 'topRight': [mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_TOP, mxConstants.ALIGN_LEFT, mxConstants.ALIGN_BOTTOM],
  2716. 'left': [mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_MIDDLE],
  2717. 'center': [mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE],
  2718. 'right': [mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_MIDDLE, mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE],
  2719. 'bottomLeft': [mxConstants.ALIGN_LEFT, mxConstants.ALIGN_BOTTOM, mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_TOP],
  2720. 'bottom': [mxConstants.ALIGN_CENTER, mxConstants.ALIGN_BOTTOM, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_TOP],
  2721. 'bottomRight': [mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_BOTTOM, mxConstants.ALIGN_LEFT, mxConstants.ALIGN_TOP]};
  2722. for (var i = 0; i < directions.length; i++)
  2723. {
  2724. var positionOption = document.createElement('option');
  2725. positionOption.setAttribute('value', directions[i]);
  2726. mxUtils.write(positionOption, mxResources.get(directions[i]));
  2727. positionSelect.appendChild(positionOption);
  2728. }
  2729. stylePanel4.appendChild(positionSelect);
  2730. // Writing direction
  2731. var stylePanel5 = stylePanel.cloneNode(false);
  2732. stylePanel5.removeAttribute('class');
  2733. stylePanel5.style.marginLeft = '0px';
  2734. stylePanel5.style.paddingTop = '4px';
  2735. stylePanel5.style.paddingBottom = '4px';
  2736. stylePanel5.style.fontWeight = 'normal';
  2737. mxUtils.write(stylePanel5, mxResources.get('writingDirection'));
  2738. // Adds writing direction options
  2739. // LATER: Handle reselect of same option in all selects (change event
  2740. // is not fired for same option so have opened state on click) and
  2741. // handle multiple different styles for current selection
  2742. var dirSelect = document.createElement('select');
  2743. dirSelect.style.position = 'absolute';
  2744. dirSelect.style.borderWidth = '1px';
  2745. dirSelect.style.borderStyle = 'solid';
  2746. dirSelect.style.left = '126px';
  2747. dirSelect.style.width = '98px';
  2748. dirSelect.style.marginTop = '-3px';
  2749. // NOTE: For automatic we use the value null since automatic
  2750. // requires the text to be non formatted and non-wrapped
  2751. var dirs = ['automatic', 'leftToRight', 'rightToLeft'];
  2752. var dirSet = {'automatic': null,
  2753. 'leftToRight': mxConstants.TEXT_DIRECTION_LTR,
  2754. 'rightToLeft': mxConstants.TEXT_DIRECTION_RTL};
  2755. for (var i = 0; i < dirs.length; i++)
  2756. {
  2757. var dirOption = document.createElement('option');
  2758. dirOption.setAttribute('value', dirs[i]);
  2759. mxUtils.write(dirOption, mxResources.get(dirs[i]));
  2760. dirSelect.appendChild(dirOption);
  2761. }
  2762. stylePanel5.appendChild(dirSelect);
  2763. if (!graph.isEditing())
  2764. {
  2765. container.appendChild(stylePanel4);
  2766. mxEvent.addListener(positionSelect, 'change', function(evt)
  2767. {
  2768. graph.getModel().beginUpdate();
  2769. try
  2770. {
  2771. var vals = lset[positionSelect.value];
  2772. if (vals != null)
  2773. {
  2774. graph.setCellStyles(mxConstants.STYLE_LABEL_POSITION, vals[0], ss.cells);
  2775. graph.setCellStyles(mxConstants.STYLE_VERTICAL_LABEL_POSITION, vals[1], ss.cells);
  2776. graph.setCellStyles(mxConstants.STYLE_ALIGN, vals[2], ss.cells);
  2777. graph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, vals[3], ss.cells);
  2778. }
  2779. }
  2780. finally
  2781. {
  2782. graph.getModel().endUpdate();
  2783. }
  2784. mxEvent.consume(evt);
  2785. });
  2786. // LATER: Update dir in text editor while editing and update style with label
  2787. // NOTE: The tricky part is handling and passing on the auto value
  2788. container.appendChild(stylePanel5);
  2789. mxEvent.addListener(dirSelect, 'change', function(evt)
  2790. {
  2791. graph.setCellStyles(mxConstants.STYLE_TEXT_DIRECTION, dirSet[dirSelect.value], ss.cells);
  2792. mxEvent.consume(evt);
  2793. });
  2794. }
  2795. // Fontsize
  2796. var input = document.createElement('input');
  2797. input.style.position = 'absolute';
  2798. input.style.borderWidth = '1px';
  2799. input.style.borderStyle = 'solid';
  2800. input.style.textAlign = 'right';
  2801. input.style.marginTop = '4px';
  2802. input.style.left = '161px';
  2803. input.style.width = '53px';
  2804. input.style.height = '23px';
  2805. input.style.boxSizing = 'border-box';
  2806. stylePanel2.appendChild(input);
  2807. // Workaround for font size 4 if no text is selected is update font size below
  2808. // after first character was entered (as the font element is lazy created)
  2809. var pendingFontSize = null;
  2810. var inputUpdate = this.installInputHandler(input, mxConstants.STYLE_FONTSIZE, Menus.prototype.defaultFontSize, 1, 999, ' pt',
  2811. function(fontSize)
  2812. {
  2813. // IE does not support containsNode
  2814. // KNOWN: Fixes font size issues but bypasses undo
  2815. if (window.getSelection && !mxClient.IS_IE && !mxClient.IS_IE11)
  2816. {
  2817. var selection = window.getSelection();
  2818. var container = (selection.rangeCount > 0) ? selection.getRangeAt(0).commonAncestorContainer :
  2819. graph.cellEditor.textarea;
  2820. function updateSize(elt, ignoreContains)
  2821. {
  2822. if (graph.cellEditor.textarea != null && elt != graph.cellEditor.textarea &&
  2823. graph.cellEditor.textarea.contains(elt) &&
  2824. (ignoreContains || selection.containsNode(elt, true)))
  2825. {
  2826. if (elt.nodeName == 'FONT')
  2827. {
  2828. elt.removeAttribute('size');
  2829. elt.style.fontSize = fontSize + 'px';
  2830. }
  2831. else
  2832. {
  2833. var css = mxUtils.getCurrentStyle(elt);
  2834. if (css.fontSize != fontSize + 'px')
  2835. {
  2836. if (mxUtils.getCurrentStyle(elt.parentNode).fontSize != fontSize + 'px')
  2837. {
  2838. elt.style.fontSize = fontSize + 'px';
  2839. }
  2840. else
  2841. {
  2842. elt.style.fontSize = '';
  2843. }
  2844. }
  2845. }
  2846. }
  2847. ui.fireEvent(new mxEventObject('styleChanged',
  2848. 'keys', [mxConstants.STYLE_FONTSIZE],
  2849. 'values', [fontSize], 'cells', ss.cells));
  2850. };
  2851. // Wraps text node or mixed selection with leading text in a font element
  2852. if (container == graph.cellEditor.textarea ||
  2853. container.nodeType != mxConstants.NODETYPE_ELEMENT)
  2854. {
  2855. document.execCommand('fontSize', false, '1');
  2856. }
  2857. if (container != graph.cellEditor.textarea)
  2858. {
  2859. container = container.parentNode;
  2860. }
  2861. if (container != null && container.nodeType == mxConstants.NODETYPE_ELEMENT)
  2862. {
  2863. var elts = container.getElementsByTagName('*');
  2864. updateSize(container);
  2865. for (var i = 0; i < elts.length; i++)
  2866. {
  2867. updateSize(elts[i]);
  2868. }
  2869. }
  2870. input.value = fontSize + ' pt';
  2871. }
  2872. else if (window.getSelection || document.selection)
  2873. {
  2874. // Checks selection
  2875. var par = null;
  2876. if (document.selection)
  2877. {
  2878. par = document.selection.createRange().parentElement();
  2879. }
  2880. else
  2881. {
  2882. var selection = window.getSelection();
  2883. if (selection.rangeCount > 0)
  2884. {
  2885. par = selection.getRangeAt(0).commonAncestorContainer;
  2886. }
  2887. }
  2888. // Node.contains does not work for text nodes in IE11
  2889. function isOrContains(container, node)
  2890. {
  2891. while (node != null)
  2892. {
  2893. if (node === container)
  2894. {
  2895. return true;
  2896. }
  2897. node = node.parentNode;
  2898. }
  2899. return false;
  2900. };
  2901. if (par != null && isOrContains(graph.cellEditor.textarea, par))
  2902. {
  2903. pendingFontSize = fontSize;
  2904. // Workaround for can't set font size in px is to change font size afterwards
  2905. document.execCommand('fontSize', false, '4');
  2906. var elts = graph.cellEditor.textarea.getElementsByTagName('font');
  2907. for (var i = 0; i < elts.length; i++)
  2908. {
  2909. if (elts[i].getAttribute('size') == '4')
  2910. {
  2911. elts[i].removeAttribute('size');
  2912. elts[i].style.fontSize = pendingFontSize + 'px';
  2913. // Overrides fontSize in input with the one just assigned as a workaround
  2914. // for potential fontSize values of parent elements that don't match
  2915. window.setTimeout(function()
  2916. {
  2917. input.value = pendingFontSize + ' pt';
  2918. pendingFontSize = null;
  2919. }, 0);
  2920. break;
  2921. }
  2922. }
  2923. }
  2924. }
  2925. }, true);
  2926. var stepper = this.createStepper(input, inputUpdate, 1, 10, true, Menus.prototype.defaultFontSize);
  2927. stepper.style.display = input.style.display;
  2928. stepper.style.marginTop = '4px';
  2929. stepper.style.left = '214px';
  2930. stylePanel2.appendChild(stepper);
  2931. var arrow = fontMenu.getElementsByTagName('div')[0];
  2932. arrow.style.cssFloat = 'right';
  2933. var bgColorApply = null;
  2934. var currentBgColor = graph.shapeBackgroundColor;
  2935. var fontColorApply = null;
  2936. var currentFontColor = graph.shapeForegroundColor;
  2937. var bgPanel = (graph.cellEditor.isContentEditing()) ? this.createColorOption(mxResources.get('backgroundColor'), function()
  2938. {
  2939. return currentBgColor;
  2940. }, function(color)
  2941. {
  2942. document.execCommand('backcolor', false, (color != mxConstants.NONE) ? color : 'transparent');
  2943. ui.fireEvent(new mxEventObject('styleChanged',
  2944. 'keys', [mxConstants.STYLE_LABEL_BACKGROUNDCOLOR],
  2945. 'values', [color], 'cells', ss.cells));
  2946. }, graph.shapeBackgroundColor,
  2947. {
  2948. install: function(apply) { bgColorApply = apply; },
  2949. destroy: function() { bgColorApply = null; }
  2950. }, null, true) : this.createCellColorOption(mxResources.get('backgroundColor'),
  2951. mxConstants.STYLE_LABEL_BACKGROUNDCOLOR, 'default', null, function(color)
  2952. {
  2953. graph.updateLabelElements(ss.cells, function(elt)
  2954. {
  2955. elt.style.backgroundColor = null;
  2956. });
  2957. }, graph.shapeBackgroundColor);
  2958. bgPanel.style.fontWeight = 'bold';
  2959. var borderPanel = this.createCellColorOption(mxResources.get('borderColor'),
  2960. mxConstants.STYLE_LABEL_BORDERCOLOR, 'default', null, null,
  2961. graph.shapeForegroundColor);
  2962. borderPanel.style.fontWeight = 'bold';
  2963. var defs = (ss.vertices.length >= 1) ?
  2964. graph.stylesheet.getDefaultVertexStyle() :
  2965. graph.stylesheet.getDefaultEdgeStyle();
  2966. var panel = (graph.cellEditor.isContentEditing()) ? this.createColorOption(mxResources.get('fontColor'), function()
  2967. {
  2968. return currentFontColor;
  2969. }, function(color)
  2970. {
  2971. if (mxClient.IS_FF)
  2972. {
  2973. // Workaround for Firefox that adds the font element around
  2974. // anchor elements which ignore inherited colors is to move
  2975. // the font element inside anchor elements
  2976. var tmp = graph.cellEditor.textarea.getElementsByTagName('font');
  2977. var oldFonts = [];
  2978. for (var i = 0; i < tmp.length; i++)
  2979. {
  2980. oldFonts.push(
  2981. {
  2982. node: tmp[i],
  2983. color: tmp[i].getAttribute('color')
  2984. });
  2985. }
  2986. document.execCommand('forecolor', false, (color != mxConstants.NONE) ?
  2987. color : 'transparent');
  2988. ui.fireEvent(new mxEventObject('styleChanged',
  2989. 'keys', [mxConstants.STYLE_FONTCOLOR],
  2990. 'values', [color], 'cells', ss.cells));
  2991. // Finds the new or changed font element
  2992. var newFonts = graph.cellEditor.textarea.getElementsByTagName('font');
  2993. for (var i = 0; i < newFonts.length; i++)
  2994. {
  2995. if (i >= oldFonts.length || newFonts[i] != oldFonts[i].node ||
  2996. (newFonts[i] == oldFonts[i].node &&
  2997. newFonts[i].getAttribute('color') != oldFonts[i].color))
  2998. {
  2999. var child = newFonts[i].firstChild;
  3000. // Moves the font element to inside the anchor element and adopts all children
  3001. if (child != null && child.nodeName == 'A' && child.nextSibling == null &&
  3002. child.firstChild != null)
  3003. {
  3004. var parent = newFonts[i].parentNode;
  3005. parent.insertBefore(child, newFonts[i]);
  3006. var tmp = child.firstChild;
  3007. while (tmp != null)
  3008. {
  3009. var next = tmp.nextSibling;
  3010. newFonts[i].appendChild(tmp);
  3011. tmp = next;
  3012. }
  3013. child.appendChild(newFonts[i]);
  3014. }
  3015. break;
  3016. }
  3017. }
  3018. }
  3019. else
  3020. {
  3021. document.execCommand('forecolor', false, (color != mxConstants.NONE) ?
  3022. color : 'transparent');
  3023. ui.fireEvent(new mxEventObject('styleChanged',
  3024. 'keys', [mxConstants.STYLE_FONTCOLOR],
  3025. 'values', [color], 'cells', ss.cells));
  3026. }
  3027. }, (defs[mxConstants.STYLE_FONTCOLOR] != null) ? defs[mxConstants.STYLE_FONTCOLOR] : graph.shapeForegroundColor,
  3028. {
  3029. install: function(apply) { fontColorApply = apply; },
  3030. destroy: function() { fontColorApply = null; }
  3031. }, null, true) : this.createCellColorOption(mxResources.get('fontColor'),
  3032. mxConstants.STYLE_FONTCOLOR, 'default', function(color)
  3033. {
  3034. if (color == mxConstants.NONE)
  3035. {
  3036. bgPanel.style.display = 'none';
  3037. }
  3038. else
  3039. {
  3040. bgPanel.style.display = '';
  3041. }
  3042. borderPanel.style.display = bgPanel.style.display;
  3043. }, function(color)
  3044. {
  3045. if (color == mxConstants.NONE)
  3046. {
  3047. graph.setCellStyles(mxConstants.STYLE_NOLABEL, '1', ss.cells);
  3048. }
  3049. else
  3050. {
  3051. graph.setCellStyles(mxConstants.STYLE_NOLABEL, null, ss.cells);
  3052. }
  3053. graph.setCellStyles(mxConstants.STYLE_FONTCOLOR, color, ss.cells);
  3054. graph.updateLabelElements(ss.cells, function(elt)
  3055. {
  3056. elt.removeAttribute('color');
  3057. elt.style.color = null;
  3058. });
  3059. }, graph.shapeForegroundColor);
  3060. panel.style.fontWeight = 'bold';
  3061. colorPanel.appendChild(panel);
  3062. colorPanel.appendChild(bgPanel);
  3063. if (!graph.cellEditor.isContentEditing())
  3064. {
  3065. colorPanel.appendChild(borderPanel);
  3066. }
  3067. container.appendChild(colorPanel);
  3068. var extraPanel = this.createPanel();
  3069. extraPanel.style.paddingTop = '2px';
  3070. extraPanel.style.paddingBottom = '4px';
  3071. var wwCells = graph.filterSelectionCells(mxUtils.bind(this, function(cell)
  3072. {
  3073. var state = graph.view.getState(cell);
  3074. return state == null || graph.isAutoSizeState(state) ||
  3075. graph.getModel().isEdge(cell) || (!graph.isTableRow(cell) &&
  3076. !graph.isTableCell(cell) && !graph.isCellResizable(cell));
  3077. }));
  3078. var wwOpt = this.createCellOption(mxResources.get('wordWrap'), mxConstants.STYLE_WHITE_SPACE,
  3079. null, 'wrap', 'null', null, null, true, wwCells);
  3080. wwOpt.style.fontWeight = 'bold';
  3081. // Word wrap in edge labels only supported via labelWidth style
  3082. if (wwCells.length > 0)
  3083. {
  3084. extraPanel.appendChild(wwOpt);
  3085. }
  3086. // Delegates switch of style to formattedText action as it also convertes newlines
  3087. var htmlOpt = this.createCellOption(mxResources.get('formattedText'), 'html', 0,
  3088. null, null, null, ui.actions.get('formattedText'));
  3089. htmlOpt.style.fontWeight = 'bold';
  3090. extraPanel.appendChild(htmlOpt);
  3091. var spacingPanel = this.createPanel();
  3092. spacingPanel.style.paddingTop = '10px';
  3093. spacingPanel.style.paddingBottom = '28px';
  3094. spacingPanel.style.fontWeight = 'normal';
  3095. var span = document.createElement('div');
  3096. span.style.position = 'absolute';
  3097. span.style.width = '70px';
  3098. span.style.marginTop = '0px';
  3099. span.style.fontWeight = 'bold';
  3100. mxUtils.write(span, mxResources.get('spacing'));
  3101. spacingPanel.appendChild(span);
  3102. var topUpdate, globalUpdate, leftUpdate, bottomUpdate, rightUpdate;
  3103. var topSpacing = this.addUnitInput(spacingPanel, 'pt', 87, 52, function()
  3104. {
  3105. topUpdate.apply(this, arguments);
  3106. });
  3107. var globalSpacing = this.addUnitInput(spacingPanel, 'pt', 16, 52, function()
  3108. {
  3109. globalUpdate.apply(this, arguments);
  3110. });
  3111. mxUtils.br(spacingPanel);
  3112. this.addLabel(spacingPanel, mxResources.get('top'), 87, 64);
  3113. this.addLabel(spacingPanel, mxResources.get('global'), 16, 64);
  3114. mxUtils.br(spacingPanel);
  3115. mxUtils.br(spacingPanel);
  3116. var leftSpacing = this.addUnitInput(spacingPanel, 'pt', 158, 52, function()
  3117. {
  3118. leftUpdate.apply(this, arguments);
  3119. });
  3120. var bottomSpacing = this.addUnitInput(spacingPanel, 'pt', 87, 52, function()
  3121. {
  3122. bottomUpdate.apply(this, arguments);
  3123. });
  3124. var rightSpacing = this.addUnitInput(spacingPanel, 'pt', 16, 52, function()
  3125. {
  3126. rightUpdate.apply(this, arguments);
  3127. });
  3128. mxUtils.br(spacingPanel);
  3129. this.addLabel(spacingPanel, mxResources.get('left'), 158, 64);
  3130. this.addLabel(spacingPanel, mxResources.get('bottom'), 87, 64);
  3131. this.addLabel(spacingPanel, mxResources.get('right'), 16, 64);
  3132. if (!graph.cellEditor.isContentEditing())
  3133. {
  3134. container.appendChild(extraPanel);
  3135. container.appendChild(this.createRelativeOption(mxResources.get('opacity'), mxConstants.STYLE_TEXT_OPACITY));
  3136. container.appendChild(spacingPanel);
  3137. }
  3138. else
  3139. {
  3140. var selState = null;
  3141. var lineHeightInput = null;
  3142. container.appendChild(this.createRelativeOption(mxResources.get('lineheight'), null, null, function(input)
  3143. {
  3144. var value = (input.value == '') ? 120 : parseInt(input.value);
  3145. value = Math.max(0, (isNaN(value)) ? 120 : value);
  3146. if (selState != null)
  3147. {
  3148. graph.cellEditor.restoreSelection(selState);
  3149. selState = null;
  3150. }
  3151. var blocks = graph.getSelectedTextBlocks();
  3152. // Adds paragraph tags if no block element is selected
  3153. if (blocks.length == 0 && graph.cellEditor.textarea != null &&
  3154. graph.cellEditor.textarea.firstChild != null)
  3155. {
  3156. if (graph.cellEditor.textarea.firstChild.nodeName != 'P')
  3157. {
  3158. graph.cellEditor.textarea.innerHTML = '<p>' + graph.cellEditor.textarea.innerHTML + '</p>';
  3159. }
  3160. blocks = [graph.cellEditor.textarea.firstChild];
  3161. }
  3162. for (var i = 0; i < blocks.length; i++)
  3163. {
  3164. blocks[i].style.lineHeight = value + '%';
  3165. }
  3166. input.value = value + ' %';
  3167. }, function(input)
  3168. {
  3169. // Used in CSS handler to update current value
  3170. lineHeightInput = input;
  3171. // KNOWN: Arrow up/down clear selection text in quirks/IE 8
  3172. // Text size via arrow button limits to 16 in IE11. Why?
  3173. mxEvent.addListener(input, 'mousedown', function()
  3174. {
  3175. if (document.activeElement == graph.cellEditor.textarea)
  3176. {
  3177. selState = graph.cellEditor.saveSelection();
  3178. }
  3179. });
  3180. mxEvent.addListener(input, 'touchstart', function()
  3181. {
  3182. if (document.activeElement == graph.cellEditor.textarea)
  3183. {
  3184. selState = graph.cellEditor.saveSelection();
  3185. }
  3186. });
  3187. input.value = '120 %';
  3188. }));
  3189. var insertPanel = stylePanel.cloneNode(false);
  3190. insertPanel.style.paddingLeft = '0px';
  3191. var insertBtns = this.editorUi.toolbar.addItems(['link', 'image'], insertPanel, true);
  3192. var btns = [
  3193. this.editorUi.toolbar.addButton('geSprite-horizontalrule', mxResources.get('insertHorizontalRule'),
  3194. function()
  3195. {
  3196. document.execCommand('inserthorizontalrule', false);
  3197. }, insertPanel),
  3198. this.editorUi.toolbar.addMenuFunctionInContainer(insertPanel, 'geSprite-table', mxResources.get('table'), false, mxUtils.bind(this, function(menu)
  3199. {
  3200. this.editorUi.menus.addInsertTableItem(menu, null, null, false);
  3201. }))];
  3202. this.styleButtons(insertBtns);
  3203. this.styleButtons(btns);
  3204. var wrapper2 = this.createPanel();
  3205. wrapper2.style.paddingTop = '10px';
  3206. wrapper2.style.paddingBottom = '10px';
  3207. wrapper2.appendChild(this.createTitle(mxResources.get('insert')));
  3208. wrapper2.appendChild(insertPanel);
  3209. container.appendChild(wrapper2);
  3210. var tablePanel = stylePanel.cloneNode(false);
  3211. tablePanel.style.paddingLeft = '0px';
  3212. var btns = [
  3213. this.editorUi.toolbar.addButton('geSprite-insertcolumnbefore', mxResources.get('insertColumnBefore'),
  3214. mxUtils.bind(this, function()
  3215. {
  3216. try
  3217. {
  3218. if (currentTable != null)
  3219. {
  3220. graph.insertColumn(currentTable, (tableCell != null) ? tableCell.cellIndex : 0);
  3221. }
  3222. }
  3223. catch (e)
  3224. {
  3225. this.editorUi.handleError(e);
  3226. }
  3227. }), tablePanel),
  3228. this.editorUi.toolbar.addButton('geSprite-insertcolumnafter', mxResources.get('insertColumnAfter'),
  3229. mxUtils.bind(this, function()
  3230. {
  3231. try
  3232. {
  3233. if (currentTable != null)
  3234. {
  3235. graph.insertColumn(currentTable, (tableCell != null) ? tableCell.cellIndex + 1 : -1);
  3236. }
  3237. }
  3238. catch (e)
  3239. {
  3240. this.editorUi.handleError(e);
  3241. }
  3242. }), tablePanel),
  3243. this.editorUi.toolbar.addButton('geSprite-deletecolumn', mxResources.get('deleteColumn'),
  3244. mxUtils.bind(this, function()
  3245. {
  3246. try
  3247. {
  3248. if (currentTable != null && tableCell != null)
  3249. {
  3250. graph.deleteColumn(currentTable, tableCell.cellIndex);
  3251. }
  3252. }
  3253. catch (e)
  3254. {
  3255. this.editorUi.handleError(e);
  3256. }
  3257. }), tablePanel),
  3258. this.editorUi.toolbar.addButton('geSprite-insertrowbefore', mxResources.get('insertRowBefore'),
  3259. mxUtils.bind(this, function()
  3260. {
  3261. try
  3262. {
  3263. if (currentTable != null && tableRow != null)
  3264. {
  3265. graph.insertRow(currentTable, tableRow.sectionRowIndex);
  3266. }
  3267. }
  3268. catch (e)
  3269. {
  3270. this.editorUi.handleError(e);
  3271. }
  3272. }), tablePanel),
  3273. this.editorUi.toolbar.addButton('geSprite-insertrowafter', mxResources.get('insertRowAfter'),
  3274. mxUtils.bind(this, function()
  3275. {
  3276. try
  3277. {
  3278. if (currentTable != null && tableRow != null)
  3279. {
  3280. graph.insertRow(currentTable, tableRow.sectionRowIndex + 1);
  3281. }
  3282. }
  3283. catch (e)
  3284. {
  3285. this.editorUi.handleError(e);
  3286. }
  3287. }), tablePanel),
  3288. this.editorUi.toolbar.addButton('geSprite-deleterow', mxResources.get('deleteRow'),
  3289. mxUtils.bind(this, function()
  3290. {
  3291. try
  3292. {
  3293. if (currentTable != null && tableRow != null)
  3294. {
  3295. graph.deleteRow(currentTable, tableRow.sectionRowIndex);
  3296. }
  3297. }
  3298. catch (e)
  3299. {
  3300. this.editorUi.handleError(e);
  3301. }
  3302. }), tablePanel)];
  3303. this.styleButtons(btns);
  3304. btns[2].style.marginRight = '10px';
  3305. var wrapper3 = this.createPanel();
  3306. wrapper3.style.paddingTop = '10px';
  3307. wrapper3.style.paddingBottom = '10px';
  3308. wrapper3.appendChild(this.createTitle(mxResources.get('table')));
  3309. wrapper3.appendChild(tablePanel);
  3310. var tablePanel2 = stylePanel.cloneNode(false);
  3311. tablePanel2.style.paddingLeft = '0px';
  3312. var btns = [
  3313. this.editorUi.toolbar.addButton('geSprite-strokecolor', mxResources.get('borderColor'),
  3314. mxUtils.bind(this, function(evt)
  3315. {
  3316. if (currentTable != null)
  3317. {
  3318. // Converts rgb(r,g,b) values
  3319. var color = currentTable.style.borderColor.replace(
  3320. /\brgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/g,
  3321. function($0, $1, $2, $3) {
  3322. return "#" + ("0"+Number($1).toString(16)).substr(-2) + ("0"+Number($2).toString(16)).substr(-2) + ("0"+Number($3).toString(16)).substr(-2);
  3323. });
  3324. this.editorUi.pickColor(color, function(newColor)
  3325. {
  3326. var targetElt = (tableCell != null && (evt == null || !mxEvent.isShiftDown(evt))) ? tableCell : currentTable;
  3327. graph.processElements(targetElt, function(elt)
  3328. {
  3329. elt.style.border = null;
  3330. });
  3331. if (newColor == null || newColor == mxConstants.NONE)
  3332. {
  3333. targetElt.removeAttribute('border');
  3334. targetElt.style.border = '';
  3335. targetElt.style.borderCollapse = '';
  3336. }
  3337. else
  3338. {
  3339. targetElt.setAttribute('border', '1');
  3340. targetElt.style.border = '1px solid ' + newColor;
  3341. targetElt.style.borderCollapse = 'collapse';
  3342. }
  3343. });
  3344. }
  3345. }), tablePanel2),
  3346. this.editorUi.toolbar.addButton('geSprite-fillcolor', mxResources.get('backgroundColor'),
  3347. mxUtils.bind(this, function(evt)
  3348. {
  3349. // Converts rgb(r,g,b) values
  3350. if (currentTable != null)
  3351. {
  3352. var color = currentTable.style.backgroundColor.replace(
  3353. /\brgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/g,
  3354. function($0, $1, $2, $3) {
  3355. return "#" + ("0"+Number($1).toString(16)).substr(-2) + ("0"+Number($2).toString(16)).substr(-2) + ("0"+Number($3).toString(16)).substr(-2);
  3356. });
  3357. this.editorUi.pickColor(color, function(newColor)
  3358. {
  3359. var targetElt = (tableCell != null && (evt == null || !mxEvent.isShiftDown(evt))) ? tableCell : currentTable;
  3360. graph.processElements(targetElt, function(elt)
  3361. {
  3362. elt.style.backgroundColor = null;
  3363. });
  3364. if (newColor == null || newColor == mxConstants.NONE)
  3365. {
  3366. targetElt.style.backgroundColor = '';
  3367. }
  3368. else
  3369. {
  3370. targetElt.style.backgroundColor = newColor;
  3371. }
  3372. });
  3373. }
  3374. }), tablePanel2),
  3375. this.editorUi.toolbar.addButton('geSprite-fit', mxResources.get('spacing'),
  3376. function()
  3377. {
  3378. if (currentTable != null)
  3379. {
  3380. var value = currentTable.getAttribute('cellPadding') || 0;
  3381. var dlg = new FilenameDialog(ui, value, mxResources.get('apply'), mxUtils.bind(this, function(newValue)
  3382. {
  3383. if (newValue != null && newValue.length > 0)
  3384. {
  3385. currentTable.setAttribute('cellPadding', newValue);
  3386. }
  3387. else
  3388. {
  3389. currentTable.removeAttribute('cellPadding');
  3390. }
  3391. }), mxResources.get('spacing'));
  3392. ui.showDialog(dlg.container, 300, 80, true, true);
  3393. dlg.init();
  3394. }
  3395. }, tablePanel2),
  3396. this.editorUi.toolbar.addButton('geSprite-left', mxResources.get('left'),
  3397. function()
  3398. {
  3399. if (currentTable != null)
  3400. {
  3401. currentTable.setAttribute('align', 'left');
  3402. }
  3403. }, tablePanel2),
  3404. this.editorUi.toolbar.addButton('geSprite-center', mxResources.get('center'),
  3405. function()
  3406. {
  3407. if (currentTable != null)
  3408. {
  3409. currentTable.setAttribute('align', 'center');
  3410. }
  3411. }, tablePanel2),
  3412. this.editorUi.toolbar.addButton('geSprite-right', mxResources.get('right'),
  3413. function()
  3414. {
  3415. if (currentTable != null)
  3416. {
  3417. currentTable.setAttribute('align', 'right');
  3418. }
  3419. }, tablePanel2)];
  3420. this.styleButtons(btns);
  3421. btns[2].style.marginRight = '10px';
  3422. wrapper3.appendChild(tablePanel2);
  3423. container.appendChild(wrapper3);
  3424. tableWrapper = wrapper3;
  3425. }
  3426. function setSelected(elt, selected)
  3427. {
  3428. elt.style.backgroundImage = (selected) ? (Editor.isDarkMode() ?
  3429. 'linear-gradient(rgb(0 161 241) 0px, rgb(0, 97, 146) 100%)':
  3430. 'linear-gradient(#c5ecff 0px,#87d4fb 100%)') : '';
  3431. };
  3432. // Updates font style state before typing
  3433. for (var i = 0; i < 3; i++)
  3434. {
  3435. (function(index)
  3436. {
  3437. mxEvent.addListener(fontStyleItems[index], 'click', function()
  3438. {
  3439. setSelected(fontStyleItems[index], fontStyleItems[index].style.backgroundImage == '');
  3440. });
  3441. })(i);
  3442. }
  3443. var listener = mxUtils.bind(this, function(sender, evt, force)
  3444. {
  3445. ss = ui.getSelectionState();
  3446. var fontStyle = mxUtils.getValue(ss.style, mxConstants.STYLE_FONTSTYLE, 0);
  3447. setSelected(fontStyleItems[0], (fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD);
  3448. setSelected(fontStyleItems[1], (fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC);
  3449. setSelected(fontStyleItems[2], (fontStyle & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE);
  3450. fontMenu.firstChild.nodeValue = mxUtils.getValue(ss.style, mxConstants.STYLE_FONTFAMILY, Menus.prototype.defaultFont);
  3451. setSelected(verticalItem, mxUtils.getValue(ss.style, mxConstants.STYLE_HORIZONTAL, '1') == '0');
  3452. if (force || document.activeElement != input)
  3453. {
  3454. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_FONTSIZE, Menus.prototype.defaultFontSize));
  3455. input.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3456. }
  3457. var align = mxUtils.getValue(ss.style, mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER);
  3458. setSelected(left, align == mxConstants.ALIGN_LEFT);
  3459. setSelected(center, align == mxConstants.ALIGN_CENTER);
  3460. setSelected(right, align == mxConstants.ALIGN_RIGHT);
  3461. var valign = mxUtils.getValue(ss.style, mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE);
  3462. setSelected(top, valign == mxConstants.ALIGN_TOP);
  3463. setSelected(middle, valign == mxConstants.ALIGN_MIDDLE);
  3464. setSelected(bottom, valign == mxConstants.ALIGN_BOTTOM);
  3465. var pos = mxUtils.getValue(ss.style, mxConstants.STYLE_LABEL_POSITION, mxConstants.ALIGN_CENTER);
  3466. var vpos = mxUtils.getValue(ss.style, mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_MIDDLE);
  3467. if (pos == mxConstants.ALIGN_LEFT && vpos == mxConstants.ALIGN_TOP)
  3468. {
  3469. positionSelect.value = 'topLeft';
  3470. }
  3471. else if (pos == mxConstants.ALIGN_CENTER && vpos == mxConstants.ALIGN_TOP)
  3472. {
  3473. positionSelect.value = 'top';
  3474. }
  3475. else if (pos == mxConstants.ALIGN_RIGHT && vpos == mxConstants.ALIGN_TOP)
  3476. {
  3477. positionSelect.value = 'topRight';
  3478. }
  3479. else if (pos == mxConstants.ALIGN_LEFT && vpos == mxConstants.ALIGN_BOTTOM)
  3480. {
  3481. positionSelect.value = 'bottomLeft';
  3482. }
  3483. else if (pos == mxConstants.ALIGN_CENTER && vpos == mxConstants.ALIGN_BOTTOM)
  3484. {
  3485. positionSelect.value = 'bottom';
  3486. }
  3487. else if (pos == mxConstants.ALIGN_RIGHT && vpos == mxConstants.ALIGN_BOTTOM)
  3488. {
  3489. positionSelect.value = 'bottomRight';
  3490. }
  3491. else if (pos == mxConstants.ALIGN_LEFT)
  3492. {
  3493. positionSelect.value = 'left';
  3494. }
  3495. else if (pos == mxConstants.ALIGN_RIGHT)
  3496. {
  3497. positionSelect.value = 'right';
  3498. }
  3499. else
  3500. {
  3501. positionSelect.value = 'center';
  3502. }
  3503. var dir = mxUtils.getValue(ss.style, mxConstants.STYLE_TEXT_DIRECTION, mxConstants.DEFAULT_TEXT_DIRECTION);
  3504. if (dir == mxConstants.TEXT_DIRECTION_RTL)
  3505. {
  3506. dirSelect.value = 'rightToLeft';
  3507. }
  3508. else if (dir == mxConstants.TEXT_DIRECTION_LTR)
  3509. {
  3510. dirSelect.value = 'leftToRight';
  3511. }
  3512. else if (dir == mxConstants.TEXT_DIRECTION_AUTO)
  3513. {
  3514. dirSelect.value = 'automatic';
  3515. }
  3516. if (force || document.activeElement != globalSpacing)
  3517. {
  3518. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_SPACING, 2));
  3519. globalSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3520. }
  3521. if (force || document.activeElement != topSpacing)
  3522. {
  3523. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_SPACING_TOP, 0));
  3524. topSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3525. }
  3526. if (force || document.activeElement != rightSpacing)
  3527. {
  3528. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_SPACING_RIGHT, 0));
  3529. rightSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3530. }
  3531. if (force || document.activeElement != bottomSpacing)
  3532. {
  3533. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_SPACING_BOTTOM, 0));
  3534. bottomSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3535. }
  3536. if (force || document.activeElement != leftSpacing)
  3537. {
  3538. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_SPACING_LEFT, 0));
  3539. leftSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3540. }
  3541. });
  3542. globalUpdate = this.installInputHandler(globalSpacing, mxConstants.STYLE_SPACING, 2, -999, 999, ' pt');
  3543. topUpdate = this.installInputHandler(topSpacing, mxConstants.STYLE_SPACING_TOP, 0, -999, 999, ' pt');
  3544. rightUpdate = this.installInputHandler(rightSpacing, mxConstants.STYLE_SPACING_RIGHT, 0, -999, 999, ' pt');
  3545. bottomUpdate = this.installInputHandler(bottomSpacing, mxConstants.STYLE_SPACING_BOTTOM, 0, -999, 999, ' pt');
  3546. leftUpdate = this.installInputHandler(leftSpacing, mxConstants.STYLE_SPACING_LEFT, 0, -999, 999, ' pt');
  3547. this.addKeyHandler(input, listener);
  3548. this.addKeyHandler(globalSpacing, listener);
  3549. this.addKeyHandler(topSpacing, listener);
  3550. this.addKeyHandler(rightSpacing, listener);
  3551. this.addKeyHandler(bottomSpacing, listener);
  3552. this.addKeyHandler(leftSpacing, listener);
  3553. graph.getModel().addListener(mxEvent.CHANGE, listener);
  3554. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  3555. listener();
  3556. if (graph.cellEditor.isContentEditing())
  3557. {
  3558. var updating = false;
  3559. var updateCssHandler = function()
  3560. {
  3561. if (!updating)
  3562. {
  3563. updating = true;
  3564. window.setTimeout(function()
  3565. {
  3566. var node = graph.getSelectedEditingElement();
  3567. if (node != null)
  3568. {
  3569. function getRelativeLineHeight(fontSize, css, elt)
  3570. {
  3571. if (elt.style != null && css != null)
  3572. {
  3573. var lineHeight = css.lineHeight
  3574. if (elt.style.lineHeight != null && elt.style.lineHeight.substring(elt.style.lineHeight.length - 1) == '%')
  3575. {
  3576. return parseInt(elt.style.lineHeight) / 100;
  3577. }
  3578. else
  3579. {
  3580. return (lineHeight.substring(lineHeight.length - 2) == 'px') ?
  3581. parseFloat(lineHeight) / fontSize : parseInt(lineHeight);
  3582. }
  3583. }
  3584. else
  3585. {
  3586. return '';
  3587. }
  3588. };
  3589. function getAbsoluteFontSize(css)
  3590. {
  3591. var fontSize = (css != null) ? css.fontSize : null;
  3592. if (fontSize != null && fontSize.substring(fontSize.length - 2) == 'px')
  3593. {
  3594. return parseFloat(fontSize);
  3595. }
  3596. else
  3597. {
  3598. return mxConstants.DEFAULT_FONTSIZE;
  3599. }
  3600. };
  3601. var css = mxUtils.getCurrentStyle(node);
  3602. var fontSize = getAbsoluteFontSize(css);
  3603. var lineHeight = getRelativeLineHeight(fontSize, css, node);
  3604. // Finds common font size
  3605. var elts = node.getElementsByTagName('*');
  3606. // IE does not support containsNode
  3607. if (elts.length > 0 && window.getSelection && !mxClient.IS_IE && !mxClient.IS_IE11)
  3608. {
  3609. var selection = window.getSelection();
  3610. for (var i = 0; i < elts.length; i++)
  3611. {
  3612. if (selection.containsNode(elts[i], true))
  3613. {
  3614. temp = mxUtils.getCurrentStyle(elts[i]);
  3615. fontSize = Math.max(getAbsoluteFontSize(temp), fontSize);
  3616. var lh = getRelativeLineHeight(fontSize, temp, elts[i]);
  3617. if (lh != lineHeight || isNaN(lh))
  3618. {
  3619. lineHeight = '';
  3620. }
  3621. }
  3622. }
  3623. }
  3624. function hasParentOrOnlyChild(name)
  3625. {
  3626. if (graph.getParentByName(node, name, graph.cellEditor.textarea) != null)
  3627. {
  3628. return true;
  3629. }
  3630. else
  3631. {
  3632. var child = node;
  3633. while (child != null && child.childNodes.length == 1)
  3634. {
  3635. child = child.childNodes[0];
  3636. if (child.nodeName == name)
  3637. {
  3638. return true;
  3639. }
  3640. }
  3641. }
  3642. return false;
  3643. };
  3644. function isEqualOrPrefixed(str, value)
  3645. {
  3646. if (str != null && value != null)
  3647. {
  3648. if (str == value)
  3649. {
  3650. return true;
  3651. }
  3652. else if (str.length > value.length + 1)
  3653. {
  3654. return str.substring(str.length - value.length - 1, str.length) == '-' + value;
  3655. }
  3656. }
  3657. return false;
  3658. };
  3659. if (css != null)
  3660. {
  3661. setSelected(fontStyleItems[0], css.fontWeight == 'bold' ||
  3662. css.fontWeight > 400 || hasParentOrOnlyChild('B') ||
  3663. hasParentOrOnlyChild('STRONG'));
  3664. setSelected(fontStyleItems[1], css.fontStyle == 'italic' ||
  3665. hasParentOrOnlyChild('I') || hasParentOrOnlyChild('EM'));
  3666. setSelected(fontStyleItems[2], hasParentOrOnlyChild('U'));
  3667. setSelected(sup, hasParentOrOnlyChild('SUP'));
  3668. setSelected(sub, hasParentOrOnlyChild('SUB'));
  3669. if (!graph.cellEditor.isTableSelected())
  3670. {
  3671. var align = graph.cellEditor.align || mxUtils.getValue(ss.style, mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER);
  3672. if (isEqualOrPrefixed(css.textAlign, 'justify'))
  3673. {
  3674. setSelected(full, isEqualOrPrefixed(css.textAlign, 'justify'));
  3675. setSelected(left, false);
  3676. setSelected(center, false);
  3677. setSelected(right, false);
  3678. }
  3679. else
  3680. {
  3681. setSelected(full, false);
  3682. setSelected(left, align == mxConstants.ALIGN_LEFT);
  3683. setSelected(center, align == mxConstants.ALIGN_CENTER);
  3684. setSelected(right, align == mxConstants.ALIGN_RIGHT);
  3685. }
  3686. }
  3687. else
  3688. {
  3689. setSelected(full, isEqualOrPrefixed(css.textAlign, 'justify'));
  3690. setSelected(left, isEqualOrPrefixed(css.textAlign, 'left'));
  3691. setSelected(center, isEqualOrPrefixed(css.textAlign, 'center'));
  3692. setSelected(right, isEqualOrPrefixed(css.textAlign, 'right'));
  3693. }
  3694. currentTable = graph.getParentByName(node, 'TABLE', graph.cellEditor.textarea);
  3695. tableRow = (currentTable == null) ? null : graph.getParentByName(node, 'TR', currentTable);
  3696. tableCell = (currentTable == null) ? null : graph.getParentByNames(node, ['TD', 'TH'], currentTable);
  3697. tableWrapper.style.display = (currentTable != null) ? '' : 'none';
  3698. if (document.activeElement != input)
  3699. {
  3700. if (node.nodeName == 'FONT' && node.getAttribute('size') == '4' &&
  3701. pendingFontSize != null)
  3702. {
  3703. node.removeAttribute('size');
  3704. node.style.fontSize = pendingFontSize + ' pt';
  3705. pendingFontSize = null;
  3706. }
  3707. else
  3708. {
  3709. input.value = (isNaN(fontSize)) ? '' : fontSize + ' pt';
  3710. }
  3711. var lh = parseFloat(lineHeight);
  3712. if (!isNaN(lh))
  3713. {
  3714. lineHeightInput.value = Math.round(lh * 100) + ' %';
  3715. }
  3716. else
  3717. {
  3718. lineHeightInput.value = '100 %';
  3719. }
  3720. }
  3721. // Updates the color picker for the current font
  3722. if (fontColorApply != null)
  3723. {
  3724. if (css.color == 'rgba(0, 0, 0, 0)' ||
  3725. css.color == 'transparent')
  3726. {
  3727. currentFontColor = mxConstants.NONE;
  3728. }
  3729. else
  3730. {
  3731. currentFontColor = mxUtils.rgba2hex(css.color)
  3732. }
  3733. fontColorApply(currentFontColor, true);
  3734. }
  3735. if (bgColorApply != null)
  3736. {
  3737. if (css.backgroundColor == 'rgba(0, 0, 0, 0)' ||
  3738. css.backgroundColor == 'transparent')
  3739. {
  3740. currentBgColor = mxConstants.NONE;
  3741. }
  3742. else
  3743. {
  3744. currentBgColor = mxUtils.rgba2hex(css.backgroundColor);
  3745. }
  3746. bgColorApply(currentBgColor, true);
  3747. }
  3748. // Workaround for firstChild is null or not an object
  3749. // in the log which seems to be IE8- only / 29.01.15
  3750. if (fontMenu.firstChild != null)
  3751. {
  3752. fontMenu.firstChild.nodeValue = Graph.stripQuotes(css.fontFamily);
  3753. }
  3754. }
  3755. }
  3756. updating = false;
  3757. }, 0);
  3758. }
  3759. };
  3760. if (mxClient.IS_FF || mxClient.IS_EDGE || mxClient.IS_IE || mxClient.IS_IE11)
  3761. {
  3762. mxEvent.addListener(graph.cellEditor.textarea, 'DOMSubtreeModified', updateCssHandler);
  3763. }
  3764. mxEvent.addListener(graph.cellEditor.textarea, 'input', updateCssHandler);
  3765. mxEvent.addListener(graph.cellEditor.textarea, 'touchend', updateCssHandler);
  3766. mxEvent.addListener(graph.cellEditor.textarea, 'mouseup', updateCssHandler);
  3767. mxEvent.addListener(graph.cellEditor.textarea, 'keyup', updateCssHandler);
  3768. this.listeners.push({destroy: function()
  3769. {
  3770. // No need to remove listener since textarea is destroyed after edit
  3771. }});
  3772. updateCssHandler();
  3773. }
  3774. return container;
  3775. };
  3776. /**
  3777. * Adds the label menu items to the given menu and parent.
  3778. */
  3779. StyleFormatPanel = function(format, editorUi, container)
  3780. {
  3781. BaseFormatPanel.call(this, format, editorUi, container);
  3782. this.init();
  3783. };
  3784. mxUtils.extend(StyleFormatPanel, BaseFormatPanel);
  3785. /**
  3786. *
  3787. */
  3788. StyleFormatPanel.prototype.defaultStrokeColor = 'black';
  3789. /**
  3790. * Adds the label menu items to the given menu and parent.
  3791. */
  3792. StyleFormatPanel.prototype.init = function()
  3793. {
  3794. var ui = this.editorUi;
  3795. var ss = ui.getSelectionState();
  3796. if (!ss.containsLabel && ss.cells.length > 0)
  3797. {
  3798. if (ss.containsImage && ss.vertices.length == 1 && ss.style.shape == 'image' &&
  3799. ss.style.image != null && ss.style.image.substring(0, 19) == 'data:image/svg+xml;')
  3800. {
  3801. this.container.appendChild(this.addSvgStyles(this.createPanel()));
  3802. }
  3803. if (ss.fill)
  3804. {
  3805. this.container.appendChild(this.addFill(this.createPanel()));
  3806. }
  3807. this.container.appendChild(this.addStroke(this.createPanel()));
  3808. this.container.appendChild(this.addLineJumps(this.createPanel()));
  3809. var opacityPanel = this.createRelativeOption(mxResources.get('opacity'), mxConstants.STYLE_OPACITY);
  3810. opacityPanel.style.paddingTop = '8px';
  3811. opacityPanel.style.paddingBottom = '10px';
  3812. this.container.appendChild(opacityPanel);
  3813. this.container.appendChild(this.addEffects(this.createPanel()));
  3814. }
  3815. var opsPanel = this.createPanel();
  3816. opsPanel.style.paddingTop = '8px';
  3817. if (ss.cells.length == 1)
  3818. {
  3819. this.addEditOps(opsPanel);
  3820. if (opsPanel.firstChild != null)
  3821. {
  3822. mxUtils.br(opsPanel);
  3823. }
  3824. }
  3825. if (ss.cells.length >= 1)
  3826. {
  3827. this.addStyleOps(opsPanel);
  3828. }
  3829. if (opsPanel.firstChild != null)
  3830. {
  3831. this.container.appendChild(opsPanel);
  3832. }
  3833. };
  3834. /**
  3835. * Use browser for parsing CSS.
  3836. */
  3837. StyleFormatPanel.prototype.getCssRules = function(css)
  3838. {
  3839. var doc = document.implementation.createHTMLDocument('');
  3840. var styleElement = document.createElement('style');
  3841. mxUtils.setTextContent(styleElement, css);
  3842. doc.body.appendChild(styleElement);
  3843. return styleElement.sheet.cssRules;
  3844. };
  3845. /**
  3846. * Adds the label menu items to the given menu and parent.
  3847. */
  3848. StyleFormatPanel.prototype.addSvgStyles = function(container)
  3849. {
  3850. var ui = this.editorUi;
  3851. var ss = ui.getSelectionState();
  3852. container.style.paddingTop = '6px';
  3853. container.style.paddingBottom = '6px';
  3854. container.style.fontWeight = 'bold';
  3855. container.style.display = 'none';
  3856. try
  3857. {
  3858. var exp = ss.style.editableCssRules;
  3859. if (exp != null)
  3860. {
  3861. var regex = new RegExp(exp);
  3862. var data = ss.style.image.substring(ss.style.image.indexOf(',') + 1);
  3863. var xml = (window.atob) ? atob(data) : Base64.decode(data, true);
  3864. var svg = mxUtils.parseXml(xml);
  3865. if (svg != null)
  3866. {
  3867. var styles = svg.getElementsByTagName('style');
  3868. for (var i = 0; i < styles.length; i++)
  3869. {
  3870. var rules = this.getCssRules(mxUtils.getTextContent(styles[i]));
  3871. for (var j = 0; j < rules.length; j++)
  3872. {
  3873. this.addSvgRule(container, rules[j], svg, styles[i], rules, j, regex);
  3874. }
  3875. }
  3876. }
  3877. }
  3878. }
  3879. catch (e)
  3880. {
  3881. // ignore
  3882. }
  3883. return container;
  3884. };
  3885. /**
  3886. * Adds the label menu items to the given menu and parent.
  3887. */
  3888. StyleFormatPanel.prototype.addSvgRule = function(container, rule, svg, styleElem, rules, ruleIndex, regex)
  3889. {
  3890. var ui = this.editorUi;
  3891. var graph = ui.editor.graph;
  3892. if (regex.test(rule.selectorText))
  3893. {
  3894. function rgb2hex(rgb)
  3895. {
  3896. rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
  3897. return (rgb && rgb.length === 4) ? "#" +
  3898. ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
  3899. ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
  3900. ("0" + parseInt(rgb[3],10).toString(16)).slice(-2) : '';
  3901. };
  3902. var addStyleRule = mxUtils.bind(this, function(rule, key, label)
  3903. {
  3904. var value = mxUtils.trim(rule.style[key]);
  3905. if (value != '' && value.substring(0, 4) != 'url(')
  3906. {
  3907. var option = this.createColorOption(label + ' ' + rule.selectorText, function()
  3908. {
  3909. return rgb2hex(value);
  3910. }, mxUtils.bind(this, function(color)
  3911. {
  3912. rules[ruleIndex].style[key] = color;
  3913. var cssTxt = '';
  3914. for (var i = 0; i < rules.length; i++)
  3915. {
  3916. cssTxt += rules[i].cssText + ' ';
  3917. }
  3918. styleElem.textContent = cssTxt;
  3919. var xml = mxUtils.getXml(svg.documentElement);
  3920. graph.setCellStyles(mxConstants.STYLE_IMAGE, 'data:image/svg+xml,' +
  3921. ((window.btoa) ? btoa(xml) : Base64.encode(xml, true)),
  3922. ui.getSelectionState().cells);
  3923. }), '#ffffff',
  3924. {
  3925. install: function(apply)
  3926. {
  3927. // ignore
  3928. },
  3929. destroy: function()
  3930. {
  3931. // ignore
  3932. }
  3933. });
  3934. container.appendChild(option);
  3935. // Shows container if rules are added
  3936. container.style.display = '';
  3937. }
  3938. });
  3939. addStyleRule(rule, 'fill', mxResources.get('fill'));
  3940. addStyleRule(rule, 'stroke', mxResources.get('line'));
  3941. addStyleRule(rule, 'stop-color', mxResources.get('gradient'));
  3942. }
  3943. };
  3944. /**
  3945. * Adds the label menu items to the given menu and parent.
  3946. */
  3947. StyleFormatPanel.prototype.addEditOps = function(div)
  3948. {
  3949. var ss = this.editorUi.getSelectionState();
  3950. if (ss.cells.length == 1)
  3951. {
  3952. var editSelect = document.createElement('select');
  3953. editSelect.style.width = '210px';
  3954. editSelect.style.textAlign = 'center';
  3955. editSelect.style.marginBottom = '2px';
  3956. var ops = ['edit', 'editLink', 'editShape', 'editImage', 'editData',
  3957. 'copyData', 'pasteData', 'editConnectionPoints', 'editGeometry',
  3958. 'editTooltip', 'editStyle'];
  3959. for (var i = 0; i < ops.length; i++)
  3960. {
  3961. var action = this.editorUi.actions.get(ops[i]);
  3962. if (action == null || action.enabled)
  3963. {
  3964. var editOption = document.createElement('option');
  3965. editOption.setAttribute('value', ops[i]);
  3966. var title = mxResources.get(ops[i]);
  3967. mxUtils.write(editOption, title + ((ops[i] == 'edit') ? '' : '...'));
  3968. if (action != null && action.shortcut != null)
  3969. {
  3970. title += ' (' + action.shortcut + ')';
  3971. }
  3972. editOption.setAttribute('title', title);
  3973. editSelect.appendChild(editOption);
  3974. }
  3975. }
  3976. if (editSelect.children.length > 1)
  3977. {
  3978. div.appendChild(editSelect);
  3979. mxEvent.addListener(editSelect, 'change', mxUtils.bind(this, function(evt)
  3980. {
  3981. var action = this.editorUi.actions.get(editSelect.value);
  3982. editSelect.value = 'edit';
  3983. if (action != null)
  3984. {
  3985. action.funct();
  3986. }
  3987. }));
  3988. if (ss.image && ss.cells.length > 0)
  3989. {
  3990. var graph = this.editorUi.editor.graph;
  3991. var state = graph.view.getState(graph.getSelectionCell());
  3992. if (state != null && mxUtils.getValue(state.style, mxConstants.STYLE_IMAGE, null) != null)
  3993. {
  3994. var btn = mxUtils.button(mxResources.get('crop') + '...',
  3995. mxUtils.bind(this, function(evt)
  3996. {
  3997. this.editorUi.actions.get('crop').funct();
  3998. }));
  3999. btn.setAttribute('title', mxResources.get('crop'));
  4000. editSelect.style.width = '104px';
  4001. btn.style.width = '104px';
  4002. btn.style.marginLeft = '2px';
  4003. btn.style.marginBottom = '2px';
  4004. div.appendChild(btn);
  4005. }
  4006. }
  4007. }
  4008. }
  4009. return div;
  4010. };
  4011. /**
  4012. * Adds the label menu items to the given menu and parent.
  4013. */
  4014. StyleFormatPanel.prototype.addFill = function(container)
  4015. {
  4016. var ui = this.editorUi;
  4017. var graph = ui.editor.graph;
  4018. var ss = ui.getSelectionState();
  4019. container.style.paddingTop = '6px';
  4020. container.style.paddingBottom = '6px';
  4021. // Adds gradient direction option
  4022. var gradientSelect = document.createElement('select');
  4023. gradientSelect.style.position = 'absolute';
  4024. gradientSelect.style.left = '104px';
  4025. gradientSelect.style.width = '70px';
  4026. gradientSelect.style.height = '22px';
  4027. gradientSelect.style.padding = '0px';
  4028. gradientSelect.style.marginTop = '-3px';
  4029. gradientSelect.style.borderWidth = '1px';
  4030. gradientSelect.style.borderStyle = 'solid';
  4031. gradientSelect.style.boxSizing = 'border-box';
  4032. var fillStyleSelect = gradientSelect.cloneNode(false);
  4033. // Stops events from bubbling to color option event handler
  4034. mxEvent.addListener(gradientSelect, 'click', function(evt)
  4035. {
  4036. mxEvent.consume(evt);
  4037. });
  4038. mxEvent.addListener(fillStyleSelect, 'click', function(evt)
  4039. {
  4040. mxEvent.consume(evt);
  4041. });
  4042. var gradientPanel = this.createCellColorOption(mxResources.get('gradient'),
  4043. mxConstants.STYLE_GRADIENTCOLOR, 'default', function(color)
  4044. {
  4045. if (color == null || color == mxConstants.NONE)
  4046. {
  4047. gradientSelect.style.display = 'none';
  4048. }
  4049. else
  4050. {
  4051. gradientSelect.style.display = '';
  4052. }
  4053. }, function(color)
  4054. {
  4055. graph.updateCellStyles({'gradientColor': color}, graph.getSelectionCells());
  4056. }, graph.getDefaultColor(ss.style, mxConstants.STYLE_GRADIENTCOLOR,
  4057. graph.shapeForegroundColor, graph.shapeBackgroundColor));
  4058. var fillKey = (ss.style.shape == 'image') ? mxConstants.STYLE_IMAGE_BACKGROUND : mxConstants.STYLE_FILLCOLOR;
  4059. var fillPanel = this.createCellColorOption(mxResources.get('fill'),
  4060. fillKey, 'default', null, mxUtils.bind(this, function(color)
  4061. {
  4062. graph.setCellStyles(fillKey, color, ss.cells);
  4063. }), graph.getDefaultColor(ss.style, fillKey, graph.shapeBackgroundColor,
  4064. graph.shapeForegroundColor));
  4065. fillPanel.style.fontWeight = 'bold';
  4066. var tmpColor = mxUtils.getValue(ss.style, fillKey, null);
  4067. gradientPanel.style.display = (tmpColor != null && tmpColor != mxConstants.NONE &&
  4068. ss.fill && ss.style.shape != 'image') ? '' : 'none';
  4069. var directions = [mxConstants.DIRECTION_NORTH, mxConstants.DIRECTION_EAST,
  4070. mxConstants.DIRECTION_SOUTH, mxConstants.DIRECTION_WEST,
  4071. mxConstants.DIRECTION_RADIAL];
  4072. for (var i = 0; i < directions.length; i++)
  4073. {
  4074. var gradientOption = document.createElement('option');
  4075. gradientOption.setAttribute('value', directions[i]);
  4076. mxUtils.write(gradientOption, mxResources.get(directions[i]));
  4077. gradientSelect.appendChild(gradientOption);
  4078. }
  4079. gradientPanel.appendChild(gradientSelect);
  4080. var curFillStyle;
  4081. function populateFillStyle()
  4082. {
  4083. fillStyleSelect.innerHTML = '';
  4084. curFillStyle = 1;
  4085. for (var i = 0; i < Editor.fillStyles.length; i++)
  4086. {
  4087. var fillStyleOption = document.createElement('option');
  4088. fillStyleOption.setAttribute('value', Editor.fillStyles[i].val);
  4089. mxUtils.write(fillStyleOption, Editor.fillStyles[i].dispName);
  4090. fillStyleSelect.appendChild(fillStyleOption);
  4091. }
  4092. };
  4093. function populateRoughFillStyle()
  4094. {
  4095. fillStyleSelect.innerHTML = '';
  4096. curFillStyle = 2;
  4097. for (var i = 0; i < Editor.roughFillStyles.length; i++)
  4098. {
  4099. var fillStyleOption = document.createElement('option');
  4100. fillStyleOption.setAttribute('value', Editor.roughFillStyles[i].val);
  4101. mxUtils.write(fillStyleOption, Editor.roughFillStyles[i].dispName);
  4102. fillStyleSelect.appendChild(fillStyleOption);
  4103. }
  4104. fillStyleSelect.value = 'auto';
  4105. };
  4106. populateFillStyle();
  4107. if (ss.gradient)
  4108. {
  4109. fillPanel.appendChild(fillStyleSelect);
  4110. }
  4111. var listener = mxUtils.bind(this, function()
  4112. {
  4113. ss = ui.getSelectionState();
  4114. var value = mxUtils.getValue(ss.style, mxConstants.STYLE_GRADIENT_DIRECTION,
  4115. mxConstants.DIRECTION_SOUTH);
  4116. var fillStyle = mxUtils.getValue(ss.style, 'fillStyle', 'auto');
  4117. // Handles empty string which is not allowed as a value
  4118. if (value == '')
  4119. {
  4120. value = mxConstants.DIRECTION_SOUTH;
  4121. }
  4122. gradientSelect.value = value;
  4123. container.style.display = (ss.fill) ? '' : 'none';
  4124. var fillColor = mxUtils.getValue(ss.style, fillKey, null);
  4125. if (!ss.fill || fillColor == null || fillColor == mxConstants.NONE ||
  4126. ss.style.shape == 'filledEdge')
  4127. {
  4128. fillStyleSelect.style.display = 'none';
  4129. gradientPanel.style.display = 'none';
  4130. }
  4131. else
  4132. {
  4133. if (ss.style.sketch == '1')
  4134. {
  4135. if (curFillStyle != 2)
  4136. {
  4137. populateRoughFillStyle()
  4138. }
  4139. }
  4140. else if (curFillStyle != 1)
  4141. {
  4142. populateFillStyle();
  4143. }
  4144. fillStyleSelect.value = fillStyle;
  4145. //In case of switching from sketch to regular and fill type is not there
  4146. if (!fillStyleSelect.value)
  4147. {
  4148. fillStyle = 'auto';
  4149. fillStyleSelect.value = fillStyle;
  4150. }
  4151. fillStyleSelect.style.display = ss.style.sketch == '1' ||
  4152. gradientSelect.style.display == 'none'? '' : 'none';
  4153. gradientPanel.style.display = (ss.gradient &&
  4154. !ss.containsImage && (ss.style.sketch != '1' ||
  4155. fillStyle == 'solid' || fillStyle == 'auto')) ?
  4156. '' : 'none';
  4157. }
  4158. });
  4159. graph.getModel().addListener(mxEvent.CHANGE, listener);
  4160. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  4161. listener();
  4162. mxEvent.addListener(gradientSelect, 'change', function(evt)
  4163. {
  4164. graph.setCellStyles(mxConstants.STYLE_GRADIENT_DIRECTION, gradientSelect.value, ss.cells);
  4165. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_GRADIENT_DIRECTION],
  4166. 'values', [gradientSelect.value], 'cells', ss.cells));
  4167. mxEvent.consume(evt);
  4168. });
  4169. mxEvent.addListener(fillStyleSelect, 'change', function(evt)
  4170. {
  4171. graph.setCellStyles('fillStyle', fillStyleSelect.value, ss.cells);
  4172. ui.fireEvent(new mxEventObject('styleChanged', 'keys', ['fillStyle'],
  4173. 'values', [fillStyleSelect.value], 'cells', ss.cells));
  4174. mxEvent.consume(evt);
  4175. });
  4176. container.appendChild(fillPanel);
  4177. container.appendChild(gradientPanel);
  4178. // Adds custom colors
  4179. var custom = this.getCustomColors();
  4180. for (var i = 0; i < custom.length; i++)
  4181. {
  4182. container.appendChild(this.createCellColorOption(custom[i].title,
  4183. custom[i].key, custom[i].defaultValue));
  4184. }
  4185. return container;
  4186. };
  4187. /**
  4188. * Adds the label menu items to the given menu and parent.
  4189. */
  4190. StyleFormatPanel.prototype.getCustomColors = function()
  4191. {
  4192. var ss = this.editorUi.getSelectionState();
  4193. var result = [];
  4194. if (ss.swimlane)
  4195. {
  4196. result.push({title: mxResources.get('laneColor'),
  4197. key: 'swimlaneFillColor', defaultValue: 'default'});
  4198. }
  4199. return result;
  4200. };
  4201. /**
  4202. * Adds the label menu items to the given menu and parent.
  4203. */
  4204. StyleFormatPanel.prototype.addStroke = function(container)
  4205. {
  4206. var ui = this.editorUi;
  4207. var graph = ui.editor.graph;
  4208. var ss = ui.getSelectionState();
  4209. container.style.paddingTop = '6px';
  4210. container.style.paddingBottom = '4px';
  4211. container.style.whiteSpace = 'normal';
  4212. var colorPanel = document.createElement('div');
  4213. colorPanel.style.fontWeight = 'bold';
  4214. if (!ss.stroke)
  4215. {
  4216. colorPanel.style.display = 'none';
  4217. }
  4218. // Adds gradient direction option
  4219. var styleSelect = document.createElement('select');
  4220. styleSelect.style.position = 'absolute';
  4221. styleSelect.style.height = '22px';
  4222. styleSelect.style.padding = '0px';
  4223. styleSelect.style.marginTop = '-3px';
  4224. styleSelect.style.textAlign = 'center';
  4225. styleSelect.style.boxSizing = 'border-box';
  4226. styleSelect.style.left = '90px';
  4227. styleSelect.style.width = '83px';
  4228. styleSelect.style.borderWidth = '1px';
  4229. styleSelect.style.borderStyle = 'solid';
  4230. var styles = ['sharp', 'rounded', 'curved'];
  4231. for (var i = 0; i < styles.length; i++)
  4232. {
  4233. var styleOption = document.createElement('option');
  4234. styleOption.setAttribute('value', styles[i]);
  4235. mxUtils.write(styleOption, mxResources.get(styles[i]));
  4236. styleSelect.appendChild(styleOption);
  4237. }
  4238. mxEvent.addListener(styleSelect, 'change', function(evt)
  4239. {
  4240. graph.getModel().beginUpdate();
  4241. try
  4242. {
  4243. var keys = [mxConstants.STYLE_ROUNDED, mxConstants.STYLE_CURVED];
  4244. // Default for rounded is 1
  4245. var values = ['0', null];
  4246. if (styleSelect.value == 'rounded')
  4247. {
  4248. values = ['1', null];
  4249. }
  4250. else if (styleSelect.value == 'curved')
  4251. {
  4252. values = [null, '1'];
  4253. }
  4254. for (var i = 0; i < keys.length; i++)
  4255. {
  4256. graph.setCellStyles(keys[i], values[i], ss.cells);
  4257. }
  4258. ui.fireEvent(new mxEventObject('styleChanged', 'keys', keys,
  4259. 'values', values, 'cells', ss.cells));
  4260. }
  4261. finally
  4262. {
  4263. graph.getModel().endUpdate();
  4264. }
  4265. mxEvent.consume(evt);
  4266. });
  4267. // Stops events from bubbling to color option event handler
  4268. mxEvent.addListener(styleSelect, 'click', function(evt)
  4269. {
  4270. mxEvent.consume(evt);
  4271. });
  4272. var strokeKey = (ss.style.shape == 'image') ? mxConstants.STYLE_IMAGE_BORDER : mxConstants.STYLE_STROKECOLOR;
  4273. var label = (ss.style.shape == 'image') ? mxResources.get('border') : mxResources.get('line');
  4274. var lineColor = this.createCellColorOption(label, strokeKey, 'default', null, mxUtils.bind(this, function(color)
  4275. {
  4276. graph.setCellStyles(strokeKey, color, ss.cells);
  4277. // Sets strokeColor to inherit for rows and cells in tables
  4278. if (color == null || color == mxConstants.NONE)
  4279. {
  4280. var tableCells = [];
  4281. for (var i = 0; i < ss.cells.length; i++)
  4282. {
  4283. if (graph.isTableCell(ss.cells[i]) ||
  4284. graph.isTableRow(ss.cells[i]))
  4285. {
  4286. tableCells.push(ss.cells[i]);
  4287. }
  4288. }
  4289. if (tableCells.length > 0)
  4290. {
  4291. graph.setCellStyles(strokeKey, 'inherit', tableCells);
  4292. }
  4293. }
  4294. }), graph.shapeForegroundColor);
  4295. lineColor.appendChild(styleSelect);
  4296. colorPanel.appendChild(lineColor);
  4297. // Used if only edges selected
  4298. var stylePanel = colorPanel.cloneNode(false);
  4299. stylePanel.style.display = 'inline-flex';
  4300. stylePanel.style.alignItems = 'top';
  4301. stylePanel.style.fontWeight = 'normal';
  4302. stylePanel.style.whiteSpace = 'nowrap';
  4303. stylePanel.style.position = 'relative';
  4304. stylePanel.style.paddingLeft = '5px';
  4305. stylePanel.style.overflow = 'hidden';
  4306. stylePanel.style.marginTop = '2px';
  4307. stylePanel.style.width = '220px';
  4308. var addItem = mxUtils.bind(this, function(menu, width, cssName, keys, values)
  4309. {
  4310. var item = this.editorUi.menus.styleChange(menu, '', keys, values, 'geIcon', null);
  4311. var pat = document.createElement('div');
  4312. pat.style.width = width + 'px';
  4313. pat.style.height = '1px';
  4314. pat.style.borderBottom = '1px ' + cssName + ' ' + this.defaultStrokeColor;
  4315. pat.style.paddingTop = '6px';
  4316. item.firstChild.firstChild.style.padding = '0px 4px 0px 4px';
  4317. item.firstChild.firstChild.style.width = width + 'px';
  4318. item.firstChild.firstChild.appendChild(pat);
  4319. return item;
  4320. });
  4321. var pattern = this.editorUi.toolbar.addMenuFunctionInContainer(stylePanel, 'geSprite-orthogonal', mxResources.get('pattern'), false, mxUtils.bind(this, function(menu)
  4322. {
  4323. addItem(menu, 75, 'solid', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], [null, null]).setAttribute('title', mxResources.get('solid'));
  4324. addItem(menu, 75, 'dashed', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', null]).setAttribute('title', mxResources.get('dashed') + ' (1)');
  4325. addItem(menu, 75, 'dashed', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '8 8']).setAttribute('title', mxResources.get('dashed') + ' (2)');
  4326. addItem(menu, 75, 'dashed', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '12 12']).setAttribute('title', mxResources.get('dashed') + ' (3)');
  4327. addItem(menu, 75, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 1']).setAttribute('title', mxResources.get('dotted') + ' (1)');
  4328. addItem(menu, 75, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 2']).setAttribute('title', mxResources.get('dotted') + ' (2)');
  4329. addItem(menu, 75, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 4']).setAttribute('title', mxResources.get('dotted') + ' (3)');
  4330. }));
  4331. // Used for mixed selection (vertices and edges)
  4332. var altStylePanel = stylePanel.cloneNode(false);
  4333. var edgeShape = this.editorUi.toolbar.addMenuFunctionInContainer(altStylePanel, 'geSprite-connection', mxResources.get('connection'), false, mxUtils.bind(this, function(menu)
  4334. {
  4335. this.editorUi.menus.styleChange(menu, '', [mxConstants.STYLE_SHAPE, mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE, 'width'],
  4336. [null, null, null, null], 'geIcon geSprite geSprite-connection', null, null, null, true).setAttribute('title', mxResources.get('line'));
  4337. this.editorUi.menus.styleChange(menu, '', [mxConstants.STYLE_SHAPE, mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE, 'width'],
  4338. ['link', null, null, null], 'geIcon geSprite geSprite-linkedge', null, null, null, true).setAttribute('title', mxResources.get('link'));
  4339. this.editorUi.menus.styleChange(menu, '', [mxConstants.STYLE_SHAPE, mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE, 'width'],
  4340. ['flexArrow', null, null, null], 'geIcon geSprite geSprite-arrow', null, null, null, true).setAttribute('title', mxResources.get('arrow'));
  4341. this.editorUi.menus.styleChange(menu, '', [mxConstants.STYLE_SHAPE, mxConstants.STYLE_STARTSIZE, mxConstants.STYLE_ENDSIZE, 'width'],
  4342. ['arrow', null, null, null], 'geIcon geSprite geSprite-simplearrow', null, null, null, true).setAttribute('title', mxResources.get('simpleArrow'));
  4343. }));
  4344. var altPattern = this.editorUi.toolbar.addMenuFunctionInContainer(altStylePanel, 'geSprite-orthogonal', mxResources.get('pattern'), false, mxUtils.bind(this, function(menu)
  4345. {
  4346. addItem(menu, 33, 'solid', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], [null, null]).setAttribute('title', mxResources.get('solid'));
  4347. addItem(menu, 33, 'dashed', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', null]).setAttribute('title', mxResources.get('dashed') + ' (1)');
  4348. addItem(menu, 33, 'dashed', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '8 8']).setAttribute('title', mxResources.get('dashed') + ' (2)');
  4349. addItem(menu, 33, 'dashed', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '12 12']).setAttribute('title', mxResources.get('dashed') + ' (3)');
  4350. addItem(menu, 33, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 1']).setAttribute('title', mxResources.get('dotted') + ' (1)');
  4351. addItem(menu, 33, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 2']).setAttribute('title', mxResources.get('dotted') + ' (2)');
  4352. addItem(menu, 33, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 4']).setAttribute('title', mxResources.get('dotted') + ' (3)');
  4353. }));
  4354. var stylePanel2 = stylePanel.cloneNode(false);
  4355. // Stroke width
  4356. var input = document.createElement('input');
  4357. input.style.position = 'absolute';
  4358. input.style.textAlign = 'right';
  4359. input.style.marginTop = '2px';
  4360. input.style.width = '52px';
  4361. input.style.height = '22px';
  4362. input.style.left = '146px';
  4363. input.style.borderWidth = '1px';
  4364. input.style.borderStyle = 'solid';
  4365. input.style.boxSizing = 'border-box';
  4366. input.setAttribute('title', mxResources.get('linewidth'));
  4367. stylePanel.appendChild(input);
  4368. var altInput = input.cloneNode(true);
  4369. altStylePanel.appendChild(altInput);
  4370. function update(evt)
  4371. {
  4372. // Maximum stroke width is 999
  4373. var value = parseFloat(input.value);
  4374. value = Math.min(999, Math.max(0, (isNaN(value)) ? 1 : value));
  4375. if (value != mxUtils.getValue(ss.style, mxConstants.STYLE_STROKEWIDTH, 1))
  4376. {
  4377. graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, value, ss.cells);
  4378. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_STROKEWIDTH],
  4379. 'values', [value], 'cells', ss.cells));
  4380. }
  4381. input.value = value + ' pt';
  4382. mxEvent.consume(evt);
  4383. };
  4384. function altUpdate(evt)
  4385. {
  4386. // Maximum stroke width is 999
  4387. var value = parseFloat(altInput.value);
  4388. value = Math.min(999, Math.max(0, (isNaN(value)) ? 1 : value));
  4389. if (value != mxUtils.getValue(ss.style, mxConstants.STYLE_STROKEWIDTH, 1))
  4390. {
  4391. graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, value, ss.cells);
  4392. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_STROKEWIDTH],
  4393. 'values', [value], 'cells', ss.cells));
  4394. }
  4395. altInput.value = value + ' pt';
  4396. mxEvent.consume(evt);
  4397. };
  4398. var stepper = this.createStepper(input, update, 1, 9);
  4399. stepper.style.display = input.style.display;
  4400. stepper.style.top = '2px';
  4401. stepper.style.left = '198px';
  4402. stylePanel.appendChild(stepper);
  4403. var altStepper = this.createStepper(altInput, altUpdate, 1, 9);
  4404. altStepper.style.display = altInput.style.display;
  4405. altInput.style.position = 'absolute';
  4406. altStepper.style.top = '2px';
  4407. altStepper.style.left = '198px';
  4408. altStylePanel.appendChild(altStepper);
  4409. mxEvent.addListener(input, 'blur', update);
  4410. mxEvent.addListener(input, 'change', update);
  4411. mxEvent.addListener(altInput, 'blur', altUpdate);
  4412. mxEvent.addListener(altInput, 'change', altUpdate);
  4413. var edgeStyle = this.editorUi.toolbar.addMenuFunctionInContainer(stylePanel2, 'geSprite-orthogonal', mxResources.get('waypoints'), false, mxUtils.bind(this, function(menu)
  4414. {
  4415. if (ss.style.shape != 'arrow')
  4416. {
  4417. 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'));
  4418. 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'));
  4419. 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('vertical'));
  4420. 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('horizontal'));
  4421. 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'));
  4422. 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'));
  4423. if (ss.style.shape == 'connector')
  4424. {
  4425. 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'));
  4426. }
  4427. 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'));
  4428. }
  4429. }));
  4430. var lineStart = this.editorUi.toolbar.addMenuFunctionInContainer(stylePanel2, 'geSprite-startclassic', mxResources.get('linestart'), false, mxUtils.bind(this, function(menu)
  4431. {
  4432. if (ss.style.shape == 'connector' || ss.style.shape == 'flexArrow' || ss.style.shape == 'filledEdge' || ss.style.shape == 'wire')
  4433. {
  4434. var item = this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.NONE, 0], 'geIcon', null, false);
  4435. item.setAttribute('title', mxResources.get('none'));
  4436. var font = document.createElement('span');
  4437. font.style.fontSize = '11px';
  4438. mxUtils.write(font, mxResources.get('none'));
  4439. item.firstChild.firstChild.appendChild(font);
  4440. if (ss.style.shape == 'connector' || ss.style.shape == 'filledEdge' || ss.style.shape == 'wire')
  4441. {
  4442. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_CLASSIC, 1], null, null, false, Format.classicFilledMarkerImage.src));
  4443. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_CLASSIC_THIN, 1], null, null, false, Format.classicThinFilledMarkerImage.src));
  4444. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_OPEN, 0], null, null, false, Format.openFilledMarkerImage.src));
  4445. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_OPEN_THIN, 0], null, null, false, Format.openThinFilledMarkerImage.src));
  4446. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['openAsync', 0], null, null, false, Format.openAsyncFilledMarkerImage.src));
  4447. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_BLOCK, 1], null, null, false, Format.blockFilledMarkerImage.src));
  4448. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_BLOCK_THIN, 1], null, null, false, Format.blockThinFilledMarkerImage.src));
  4449. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['async', 1], null, null, false, Format.asyncFilledMarkerImage.src));
  4450. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_OVAL, 1], null, null, false, Format.ovalFilledMarkerImage.src));
  4451. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_DIAMOND, 1], null, null, false, Format.diamondFilledMarkerImage.src));
  4452. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_DIAMOND_THIN, 1], null, null, false, Format.diamondThinFilledMarkerImage.src));
  4453. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_CLASSIC, 0], null, null, false, Format.classicMarkerImage.src));
  4454. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_CLASSIC_THIN, 0], null, null, false, Format.classicThinMarkerImage.src));
  4455. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_BLOCK, 0], null, null, false, Format.blockMarkerImage.src));
  4456. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_BLOCK_THIN, 0], null, null, false, Format.blockThinMarkerImage.src));
  4457. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['async', 0], null, null, false, Format.asyncMarkerImage.src));
  4458. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_OVAL, 0], null, null, false, Format.ovalMarkerImage.src));
  4459. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_DIAMOND, 0], null, null, false, Format.diamondMarkerImage.src));
  4460. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_DIAMOND_THIN, 0], null, null, false, Format.diamondThinMarkerImage.src));
  4461. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['box', 0], null, null, false, Format.boxMarkerImage.src));
  4462. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['halfCircle', 0], null, null, false, Format.halfCircleMarkerImage.src));
  4463. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['dash', 0], null, null, false, Format.dashMarkerImage.src));
  4464. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['cross', 0], null, null, false, Format.crossMarkerImage.src));
  4465. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['circlePlus', 0], null, null, false, Format.circlePlusMarkerImage.src));
  4466. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['circle', 1], null, null, false, Format.circleMarkerImage.src));
  4467. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['baseDash', 0], null, null, false, Format.baseDashMarkerImage.src));
  4468. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERone', 0], null, null, false, Format.EROneMarkerImage.src));
  4469. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERmandOne', 0], null, null, false, Format.ERmandOneMarkerImage.src));
  4470. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERmany', 0], null, null, false, Format.ERmanyMarkerImage.src));
  4471. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERoneToMany', 0], null, null, false, Format.ERoneToManyMarkerImage.src));
  4472. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERzeroToOne', 0], null, null, false, Format.ERzeroToOneMarkerImage.src));
  4473. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERzeroToMany', 0], null, null, false, Format.ERzeroToManyMarkerImage.src));
  4474. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['doubleBlock', 0], null, null, false, Format.doubleBlockMarkerImage.src));
  4475. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['doubleBlock', 1], null, null, false, Format.doubleBlockFilledMarkerImage.src));
  4476. }
  4477. else
  4478. {
  4479. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW], [mxConstants.ARROW_BLOCK], 'geIcon geSprite geSprite-startblocktrans', null, false).setAttribute('title', mxResources.get('block'));
  4480. }
  4481. menu.div.style.width = '40px';
  4482. window.setTimeout(mxUtils.bind(this, function()
  4483. {
  4484. if (menu.div != null)
  4485. {
  4486. mxUtils.fit(menu.div);
  4487. }
  4488. }), 0);
  4489. }
  4490. }));
  4491. var lineEnd = this.editorUi.toolbar.addMenuFunctionInContainer(stylePanel2, 'geSprite-endclassic', mxResources.get('lineend'), false, mxUtils.bind(this, function(menu)
  4492. {
  4493. if (ss.style.shape == 'connector' || ss.style.shape == 'flexArrow' || ss.style.shape == 'filledEdge' || ss.style.shape == 'wire')
  4494. {
  4495. var item = this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.NONE, 0], 'geIcon', null, false);
  4496. item.setAttribute('title', mxResources.get('none'));
  4497. var font = document.createElement('span');
  4498. font.style.fontSize = '11px';
  4499. mxUtils.write(font, mxResources.get('none'));
  4500. item.firstChild.firstChild.appendChild(font);
  4501. if (ss.style.shape == 'connector' || ss.style.shape == 'filledEdge' || ss.style.shape == 'wire')
  4502. {
  4503. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_CLASSIC, 1], null, null, false, Format.classicFilledMarkerImage.src), 'scaleX(-1)');
  4504. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_CLASSIC_THIN, 1], null, null, false, Format.classicThinFilledMarkerImage.src), 'scaleX(-1)');
  4505. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_OPEN, 0], null, null, false, Format.openFilledMarkerImage.src), 'scaleX(-1)');
  4506. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_OPEN_THIN, 0], null, null, false, Format.openThinFilledMarkerImage.src), 'scaleX(-1)');
  4507. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['openAsync', 0], null, null, false, Format.openAsyncFilledMarkerImage.src), 'scaleX(-1)');
  4508. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_BLOCK, 1], null, null, false, Format.blockFilledMarkerImage.src), 'scaleX(-1)');
  4509. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_BLOCK_THIN, 1], null, null, false, Format.blockThinFilledMarkerImage.src), 'scaleX(-1)');
  4510. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['async', 1], null, null, false, Format.asyncFilledMarkerImage.src), 'scaleX(-1)');
  4511. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_OVAL, 1], null, null, false, Format.ovalFilledMarkerImage.src), 'scaleX(-1)');
  4512. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_DIAMOND, 1], null, null, false, Format.diamondFilledMarkerImage.src), 'scaleX(-1)');
  4513. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_DIAMOND_THIN, 1], null, null, false, Format.diamondThinFilledMarkerImage.src), 'scaleX(-1)');
  4514. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_CLASSIC, 0], null, null, false, Format.classicMarkerImage.src), 'scaleX(-1)');
  4515. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_CLASSIC_THIN, 0], null, null, false, Format.classicThinMarkerImage.src), 'scaleX(-1)');
  4516. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_BLOCK, 0], null, null, false, Format.blockMarkerImage.src), 'scaleX(-1)');
  4517. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_BLOCK_THIN, 0], null, null, false, Format.blockThinMarkerImage.src), 'scaleX(-1)');
  4518. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['async', 0], null, null, false, Format.asyncMarkerImage.src), 'scaleX(-1)');
  4519. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_OVAL, 0], null, null, false, Format.ovalMarkerImage.src), 'scaleX(-1)');
  4520. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_DIAMOND, 0], null, null, false, Format.diamondMarkerImage.src), 'scaleX(-1)');
  4521. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_DIAMOND_THIN, 0], null, null, false, Format.diamondThinMarkerImage.src), 'scaleX(-1)');
  4522. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['box', 0], null, null, false, Format.boxMarkerImage.src), 'scaleX(-1)');
  4523. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['halfCircle', 0], null, null, false, Format.halfCircleMarkerImage.src), 'scaleX(-1)');
  4524. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['dash', 0], null, null, false, Format.dashMarkerImage.src), 'scaleX(-1)');
  4525. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['cross', 0], null, null, false, Format.crossMarkerImage.src), 'scaleX(-1)');
  4526. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['circlePlus', 0], null, null, false, Format.circlePlusMarkerImage.src), 'scaleX(-1)');
  4527. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['circle', 0], null, null, false, Format.circleMarkerImage.src), 'scaleX(-1)');
  4528. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['baseDash', 0], null, null, false, Format.baseDashMarkerImage.src), 'scaleX(-1)');
  4529. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERone', 0], null, null, false, Format.EROneMarkerImage.src), 'scaleX(-1)');
  4530. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERmandOne', 0], null, null, false, Format.ERmandOneMarkerImage.src), 'scaleX(-1)');
  4531. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERmany', 0], null, null, false, Format.ERmanyMarkerImage.src), 'scaleX(-1)');
  4532. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERoneToMany', 0], null, null, false, Format.ERoneToManyMarkerImage.src), 'scaleX(-1)');
  4533. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERzeroToOne', 0], null, null, false, Format.ERzeroToOneMarkerImage.src), 'scaleX(-1)');
  4534. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERzeroToMany', 0], null, null, false, Format.ERzeroToManyMarkerImage.src), 'scaleX(-1)');
  4535. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['doubleBlock', 0], null, null, false, Format.doubleBlockMarkerImage.src), 'scaleX(-1)');
  4536. Format.processMenuIcon(this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['doubleBlock', 1], null, null, false, Format.doubleBlockFilledMarkerImage.src), 'scaleX(-1)');
  4537. }
  4538. else
  4539. {
  4540. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW], [mxConstants.ARROW_BLOCK], 'geIcon geSprite geSprite-endblocktrans', null, false).setAttribute('title', mxResources.get('block'));
  4541. }
  4542. menu.div.style.width = '40px';
  4543. window.setTimeout(mxUtils.bind(this, function()
  4544. {
  4545. if (menu.div != null)
  4546. {
  4547. mxUtils.fit(menu.div);
  4548. }
  4549. }), 0);
  4550. }
  4551. }));
  4552. this.addArrow(edgeShape);
  4553. this.addArrow(edgeStyle).style.marginTop = '-1px';
  4554. this.addArrow(lineStart);
  4555. this.addArrow(lineEnd);
  4556. var symbol = this.addArrow(pattern);
  4557. symbol.className = 'geIcon';
  4558. pattern.style.width = '134px';
  4559. var altSymbol = this.addArrow(altPattern);
  4560. altSymbol.className = 'geIcon';
  4561. altSymbol.style.width = '22px';
  4562. var solid = document.createElement('div');
  4563. solid.style.width = '102px';
  4564. solid.style.height = '10px';
  4565. solid.style.borderBottom = '1px solid ' + this.defaultStrokeColor;
  4566. solid.style.marginLeft = '10px';
  4567. symbol.appendChild(solid);
  4568. var altSolid = document.createElement('div');
  4569. altSolid.style.width = '30px';
  4570. altSolid.style.height = '10px';
  4571. altSolid.style.borderBottom = '1px solid ' + this.defaultStrokeColor;
  4572. altSolid.style.marginLeft = '10px';
  4573. altSymbol.appendChild(altSolid);
  4574. container.appendChild(colorPanel);
  4575. container.appendChild(altStylePanel);
  4576. container.appendChild(stylePanel);
  4577. var arrowPanel = stylePanel.cloneNode(false);
  4578. arrowPanel.style.display = 'block';
  4579. arrowPanel.style.padding = '5px 4px 6px 0px';
  4580. arrowPanel.style.fontWeight = 'normal';
  4581. var span = document.createElement('div');
  4582. span.style.position = 'absolute';
  4583. span.style.maxWidth = '78px';
  4584. span.style.overflow = 'hidden';
  4585. span.style.textOverflow = 'ellipsis';
  4586. span.style.marginLeft = '0px';
  4587. span.style.marginBottom = '12px';
  4588. span.style.marginTop = '2px';
  4589. span.style.fontWeight = 'normal';
  4590. mxUtils.write(span, mxResources.get('lineend'));
  4591. arrowPanel.appendChild(span);
  4592. var endSpacingUpdate, endSizeUpdate;
  4593. var endSpacing = this.addUnitInput(arrowPanel, 'pt', 98, 52, function()
  4594. {
  4595. endSpacingUpdate.apply(this, arguments);
  4596. });
  4597. var endSize = this.addUnitInput(arrowPanel, 'pt', 30, 52, function()
  4598. {
  4599. endSizeUpdate.apply(this, arguments);
  4600. });
  4601. mxUtils.br(arrowPanel);
  4602. var spacer = document.createElement('div');
  4603. spacer.style.height = '8px';
  4604. arrowPanel.appendChild(spacer);
  4605. span = span.cloneNode(false);
  4606. mxUtils.write(span, mxResources.get('linestart'));
  4607. arrowPanel.appendChild(span);
  4608. var startSpacingUpdate, startSizeUpdate;
  4609. var startSpacing = this.addUnitInput(arrowPanel, 'pt', 98, 52, function()
  4610. {
  4611. startSpacingUpdate.apply(this, arguments);
  4612. });
  4613. var startSize = this.addUnitInput(arrowPanel, 'pt', 30, 52, function()
  4614. {
  4615. startSizeUpdate.apply(this, arguments);
  4616. });
  4617. mxUtils.br(arrowPanel);
  4618. this.addLabel(arrowPanel, mxResources.get('spacing'),
  4619. 98, 64).style.fontSize = '11px';
  4620. this.addLabel(arrowPanel, mxResources.get('size'),
  4621. 30, 64).style.fontSize = '11px';
  4622. mxUtils.br(arrowPanel);
  4623. var perimeterPanel = colorPanel.cloneNode(false);
  4624. perimeterPanel.style.fontWeight = 'normal';
  4625. perimeterPanel.style.position = 'relative';
  4626. perimeterPanel.style.paddingLeft = '16px'
  4627. perimeterPanel.style.marginBottom = '2px';
  4628. perimeterPanel.style.marginTop = '6px';
  4629. perimeterPanel.style.borderWidth = '0px';
  4630. perimeterPanel.style.paddingBottom = '18px';
  4631. var span = document.createElement('div');
  4632. span.style.position = 'absolute';
  4633. span.style.marginLeft = '3px';
  4634. span.style.marginBottom = '12px';
  4635. span.style.marginTop = '1px';
  4636. span.style.fontWeight = 'normal';
  4637. span.style.width = '120px';
  4638. mxUtils.write(span, mxResources.get('perimeter'));
  4639. perimeterPanel.appendChild(span);
  4640. var perimeterUpdate;
  4641. var perimeterSpacing = this.addUnitInput(perimeterPanel, 'pt', 30, 52, function()
  4642. {
  4643. perimeterUpdate.apply(this, arguments);
  4644. });
  4645. if (ss.edges.length == ss.cells.length)
  4646. {
  4647. container.appendChild(stylePanel2);
  4648. container.appendChild(arrowPanel);
  4649. }
  4650. else if (ss.vertices.length == ss.cells.length)
  4651. {
  4652. container.appendChild(perimeterPanel);
  4653. }
  4654. var listener = mxUtils.bind(this, function(sender, evt, force)
  4655. {
  4656. ss = ui.getSelectionState();
  4657. if (force || document.activeElement != input)
  4658. {
  4659. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_STROKEWIDTH, 1));
  4660. input.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  4661. }
  4662. if (force || document.activeElement != altInput)
  4663. {
  4664. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_STROKEWIDTH, 1));
  4665. altInput.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  4666. }
  4667. styleSelect.style.visibility = (ss.style.shape == 'connector' ||
  4668. ss.style.shape == 'filledEdge' || ss.style.shape == 'wire') ?
  4669. '' : 'hidden';
  4670. if (mxUtils.getValue(ss.style, mxConstants.STYLE_CURVED, null) == '1')
  4671. {
  4672. styleSelect.value = 'curved';
  4673. }
  4674. else if (mxUtils.getValue(ss.style, mxConstants.STYLE_ROUNDED, null) == '1')
  4675. {
  4676. styleSelect.value = 'rounded';
  4677. }
  4678. if (mxUtils.getValue(ss.style, mxConstants.STYLE_DASHED, null) == '1')
  4679. {
  4680. if (mxUtils.getValue(ss.style, mxConstants.STYLE_DASH_PATTERN, null) == null ||
  4681. String(mxUtils.getValue(ss.style, mxConstants.STYLE_DASH_PATTERN, '')).substring(0, 2) != '1 ')
  4682. {
  4683. solid.style.borderBottom = '1px dashed ' + this.defaultStrokeColor;
  4684. }
  4685. else
  4686. {
  4687. solid.style.borderBottom = '1px dotted ' + this.defaultStrokeColor;
  4688. }
  4689. }
  4690. else
  4691. {
  4692. solid.style.borderBottom = '1px solid ' + this.defaultStrokeColor;
  4693. }
  4694. altSolid.style.borderBottom = solid.style.borderBottom;
  4695. // Updates toolbar icon for edge style
  4696. var edgeStyleDiv = edgeStyle.getElementsByTagName('div')[0];
  4697. if (edgeStyleDiv != null)
  4698. {
  4699. var es = mxUtils.getValue(ss.style, mxConstants.STYLE_EDGE, null);
  4700. if (mxUtils.getValue(ss.style, mxConstants.STYLE_NOEDGESTYLE, null) == '1')
  4701. {
  4702. es = null;
  4703. }
  4704. if (es == 'orthogonalEdgeStyle' && mxUtils.getValue(ss.style, mxConstants.STYLE_CURVED, null) == '1')
  4705. {
  4706. edgeStyleDiv.className = 'geSprite geSprite-curved';
  4707. }
  4708. else if (es == 'straight' || es == 'none' || es == null)
  4709. {
  4710. edgeStyleDiv.className = 'geSprite geSprite-straight';
  4711. }
  4712. else if (es == 'entityRelationEdgeStyle')
  4713. {
  4714. edgeStyleDiv.className = 'geSprite geSprite-entity';
  4715. }
  4716. else if (es == 'elbowEdgeStyle')
  4717. {
  4718. edgeStyleDiv.className = 'geSprite ' + ((mxUtils.getValue(ss.style,
  4719. mxConstants.STYLE_ELBOW, null) == 'vertical') ?
  4720. 'geSprite-verticalelbow' : 'geSprite-horizontalelbow');
  4721. }
  4722. else if (es == 'isometricEdgeStyle')
  4723. {
  4724. edgeStyleDiv.className = 'geSprite ' + ((mxUtils.getValue(ss.style,
  4725. mxConstants.STYLE_ELBOW, null) == 'vertical') ?
  4726. 'geSprite-verticalisometric' : 'geSprite-horizontalisometric');
  4727. }
  4728. else
  4729. {
  4730. edgeStyleDiv.className = 'geSprite geSprite-orthogonal';
  4731. }
  4732. }
  4733. // Updates icon for edge shape
  4734. var edgeShapeDiv = edgeShape.getElementsByTagName('div')[0];
  4735. if (edgeShapeDiv != null)
  4736. {
  4737. if (ss.style.shape == 'link')
  4738. {
  4739. edgeShapeDiv.className = 'geSprite geSprite-linkedge';
  4740. }
  4741. else if (ss.style.shape == 'flexArrow')
  4742. {
  4743. edgeShapeDiv.className = 'geSprite geSprite-arrow';
  4744. }
  4745. else if (ss.style.shape == 'arrow')
  4746. {
  4747. edgeShapeDiv.className = 'geSprite geSprite-simplearrow';
  4748. }
  4749. else
  4750. {
  4751. edgeShapeDiv.className = 'geSprite geSprite-connection';
  4752. }
  4753. }
  4754. if (ss.edges.length == ss.cells.length)
  4755. {
  4756. altStylePanel.style.display = '';
  4757. stylePanel.style.display = 'none';
  4758. }
  4759. else
  4760. {
  4761. altStylePanel.style.display = 'none';
  4762. stylePanel.style.display = '';
  4763. }
  4764. if (Graph.lineJumpsEnabled && ss.edges.length > 0 &&
  4765. ss.vertices.length == 0 && ss.lineJumps)
  4766. {
  4767. container.style.borderBottomStyle = 'none';
  4768. }
  4769. function updateArrow(marker, fill, elt, prefix)
  4770. {
  4771. var markerDiv = elt.getElementsByTagName('div')[0];
  4772. if (markerDiv != null)
  4773. {
  4774. ui.updateCssForMarker(markerDiv, prefix, ss.style.shape, marker, fill);
  4775. }
  4776. return markerDiv;
  4777. };
  4778. var sourceDiv = updateArrow(mxUtils.getValue(ss.style, mxConstants.STYLE_STARTARROW, null),
  4779. mxUtils.getValue(ss.style, 'startFill', '1'), lineStart, 'start');
  4780. var targetDiv = updateArrow(mxUtils.getValue(ss.style, mxConstants.STYLE_ENDARROW, null),
  4781. mxUtils.getValue(ss.style, 'endFill', '1'), lineEnd, 'end');
  4782. // Special cases for markers
  4783. if (sourceDiv != null && targetDiv != null)
  4784. {
  4785. if (ss.style.shape == 'arrow')
  4786. {
  4787. sourceDiv.className = 'geSprite geSprite-noarrow';
  4788. targetDiv.className = 'geSprite geSprite-endblocktrans';
  4789. }
  4790. else if (ss.style.shape == 'link')
  4791. {
  4792. sourceDiv.className = 'geSprite geSprite-noarrow';
  4793. targetDiv.className = 'geSprite geSprite-noarrow';
  4794. }
  4795. }
  4796. mxUtils.setOpacity(edgeStyle, (ss.style.shape == 'arrow') ? 30 : 100);
  4797. if (ss.style.shape != 'connector' && ss.style.shape != 'flexArrow' &&
  4798. ss.style.shape != 'filledEdge' && ss.style.shape != 'wire')
  4799. {
  4800. mxUtils.setOpacity(lineStart, 30);
  4801. mxUtils.setOpacity(lineEnd, 30);
  4802. }
  4803. else
  4804. {
  4805. mxUtils.setOpacity(lineStart, 100);
  4806. mxUtils.setOpacity(lineEnd, 100);
  4807. }
  4808. if (force || document.activeElement != startSize)
  4809. {
  4810. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_MARKERSIZE));
  4811. startSize.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  4812. }
  4813. if (force || document.activeElement != startSpacing)
  4814. {
  4815. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_SOURCE_PERIMETER_SPACING, 0));
  4816. startSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  4817. }
  4818. if (force || document.activeElement != endSize)
  4819. {
  4820. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_ENDSIZE, mxConstants.DEFAULT_MARKERSIZE));
  4821. endSize.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  4822. }
  4823. if (force || document.activeElement != startSpacing)
  4824. {
  4825. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_TARGET_PERIMETER_SPACING, 0));
  4826. endSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  4827. }
  4828. if (force || document.activeElement != perimeterSpacing)
  4829. {
  4830. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_PERIMETER_SPACING, 0));
  4831. perimeterSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  4832. }
  4833. });
  4834. startSizeUpdate = this.installInputHandler(startSize, mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_MARKERSIZE, 0, 999, ' pt');
  4835. startSpacingUpdate = this.installInputHandler(startSpacing, mxConstants.STYLE_SOURCE_PERIMETER_SPACING, 0, -999, 999, ' pt');
  4836. endSizeUpdate = this.installInputHandler(endSize, mxConstants.STYLE_ENDSIZE, mxConstants.DEFAULT_MARKERSIZE, 0, 999, ' pt');
  4837. endSpacingUpdate = this.installInputHandler(endSpacing, mxConstants.STYLE_TARGET_PERIMETER_SPACING, 0, -999, 999, ' pt');
  4838. perimeterUpdate = this.installInputHandler(perimeterSpacing, mxConstants.STYLE_PERIMETER_SPACING, 0, 0, 999, ' pt');
  4839. this.addKeyHandler(input, listener);
  4840. this.addKeyHandler(startSize, listener);
  4841. this.addKeyHandler(startSpacing, listener);
  4842. this.addKeyHandler(endSize, listener);
  4843. this.addKeyHandler(endSpacing, listener);
  4844. this.addKeyHandler(perimeterSpacing, listener);
  4845. graph.getModel().addListener(mxEvent.CHANGE, listener);
  4846. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  4847. listener();
  4848. return container;
  4849. };
  4850. /**
  4851. * Adds UI for configuring line jumps.
  4852. */
  4853. StyleFormatPanel.prototype.addLineJumps = function(container)
  4854. {
  4855. var ui = this.editorUi;
  4856. var editor = ui.editor;
  4857. var graph = editor.graph;
  4858. var ss = ui.getSelectionState();
  4859. if (Graph.lineJumpsEnabled && ss.edges.length > 0 &&
  4860. ss.vertices.length == 0 && ss.lineJumps)
  4861. {
  4862. container.style.padding = '2px 0px 24px 14px';
  4863. var span = document.createElement('div');
  4864. span.style.position = 'absolute';
  4865. span.style.maxWidth = '78px';
  4866. span.style.overflow = 'hidden';
  4867. span.style.textOverflow = 'ellipsis';
  4868. mxUtils.write(span, mxResources.get('lineJumps'));
  4869. container.appendChild(span);
  4870. var styleSelect = document.createElement('select');
  4871. styleSelect.style.position = 'absolute';
  4872. styleSelect.style.height = '21px';
  4873. styleSelect.style.padding = '0px';
  4874. styleSelect.style.marginTop = '-2px';
  4875. styleSelect.style.boxSizing = 'border-box';
  4876. styleSelect.style.textAlign = 'center';
  4877. styleSelect.style.right = '84px';
  4878. styleSelect.style.width = '64px';
  4879. styleSelect.style.borderWidth = '1px';
  4880. styleSelect.style.borderStyle = 'solid';
  4881. var styles = ['none', 'arc', 'gap', 'sharp', 'line'];
  4882. for (var i = 0; i < styles.length; i++)
  4883. {
  4884. var styleOption = document.createElement('option');
  4885. styleOption.setAttribute('value', styles[i]);
  4886. mxUtils.write(styleOption, mxResources.get(styles[i]));
  4887. styleSelect.appendChild(styleOption);
  4888. }
  4889. mxEvent.addListener(styleSelect, 'change', function(evt)
  4890. {
  4891. graph.getModel().beginUpdate();
  4892. try
  4893. {
  4894. graph.setCellStyles('jumpStyle', styleSelect.value, ss.cells);
  4895. ui.fireEvent(new mxEventObject('styleChanged', 'keys', ['jumpStyle'],
  4896. 'values', [styleSelect.value], 'cells', ss.cells));
  4897. }
  4898. finally
  4899. {
  4900. graph.getModel().endUpdate();
  4901. }
  4902. mxEvent.consume(evt);
  4903. });
  4904. // Stops events from bubbling to color option event handler
  4905. mxEvent.addListener(styleSelect, 'click', function(evt)
  4906. {
  4907. mxEvent.consume(evt);
  4908. });
  4909. container.appendChild(styleSelect);
  4910. var jumpSizeUpdate;
  4911. var jumpSize = this.addUnitInput(container, 'pt', 16, 52, function()
  4912. {
  4913. jumpSizeUpdate.apply(this, arguments);
  4914. });
  4915. jumpSizeUpdate = this.installInputHandler(jumpSize, 'jumpSize',
  4916. Graph.defaultJumpSize, 0, 999, ' pt');
  4917. var listener = mxUtils.bind(this, function(sender, evt, force)
  4918. {
  4919. ss = ui.getSelectionState();
  4920. styleSelect.value = mxUtils.getValue(ss.style, 'jumpStyle', 'none');
  4921. if (force || document.activeElement != jumpSize)
  4922. {
  4923. var tmp = parseInt(mxUtils.getValue(ss.style, 'jumpSize', Graph.defaultJumpSize));
  4924. jumpSize.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  4925. }
  4926. });
  4927. this.addKeyHandler(jumpSize, listener);
  4928. graph.getModel().addListener(mxEvent.CHANGE, listener);
  4929. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  4930. listener();
  4931. }
  4932. else
  4933. {
  4934. container.style.display = 'none';
  4935. }
  4936. return container;
  4937. };
  4938. /**
  4939. * Adds the label menu items to the given menu and parent.
  4940. */
  4941. StyleFormatPanel.prototype.addEffects = function(div)
  4942. {
  4943. var ui = this.editorUi;
  4944. var editor = ui.editor;
  4945. var graph = editor.graph;
  4946. var ss = ui.getSelectionState();
  4947. div.style.paddingTop = '4px';
  4948. div.style.paddingBottom = '4px';
  4949. var table = document.createElement('table');
  4950. table.style.width = '210px';
  4951. table.style.fontWeight = 'bold';
  4952. table.style.tableLayout = 'fixed';
  4953. var tbody = document.createElement('tbody');
  4954. var row = document.createElement('tr');
  4955. row.style.padding = '0px';
  4956. var left = document.createElement('td');
  4957. left.style.padding = '0px';
  4958. left.style.width = '50%';
  4959. left.setAttribute('valign', 'top');
  4960. var right = left.cloneNode(true);
  4961. right.style.paddingLeft = '8px';
  4962. row.appendChild(left);
  4963. row.appendChild(right);
  4964. tbody.appendChild(row);
  4965. table.appendChild(tbody);
  4966. div.appendChild(table);
  4967. var current = left;
  4968. var addOption = mxUtils.bind(this, function(label, key, defaultValue, fn)
  4969. {
  4970. var opt = this.createCellOption(label, key, defaultValue, null, null, fn);
  4971. opt.style.width = '100%';
  4972. current.appendChild(opt);
  4973. current = (current == left) ? right : left;
  4974. });
  4975. var listener = mxUtils.bind(this, function(sender, evt, force)
  4976. {
  4977. ss = ui.getSelectionState();
  4978. left.innerText = '';
  4979. right.innerText = '';
  4980. current = left;
  4981. if (ss.rounded)
  4982. {
  4983. addOption(mxResources.get('rounded'), mxConstants.STYLE_ROUNDED, 0);
  4984. }
  4985. if (ss.swimlane)
  4986. {
  4987. addOption(mxResources.get('divider'), 'swimlaneLine', 1);
  4988. }
  4989. addOption(mxResources.get('sketch'), 'sketch', 0, function(cells, enabled)
  4990. {
  4991. graph.updateCellStyles({'sketch': (enabled) ? '1' : null,
  4992. 'curveFitting': (enabled) ? Editor.sketchDefaultCurveFitting : null,
  4993. 'jiggle': (enabled) ? Editor.sketchDefaultJiggle : null}, cells);
  4994. });
  4995. if (ss.glass)
  4996. {
  4997. addOption(mxResources.get('glass'), mxConstants.STYLE_GLASS, 0);
  4998. }
  4999. if (!ss.containsImage)
  5000. {
  5001. addOption(mxResources.get('shadow'), mxConstants.STYLE_SHADOW, 0);
  5002. }
  5003. });
  5004. graph.getModel().addListener(mxEvent.CHANGE, listener);
  5005. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  5006. listener();
  5007. return div;
  5008. }
  5009. /**
  5010. * Adds the label menu items to the given menu and parent.
  5011. */
  5012. StyleFormatPanel.prototype.addStyleOps = function(div)
  5013. {
  5014. var ss = this.editorUi.getSelectionState();
  5015. if (ss.cells.length == 1)
  5016. {
  5017. this.addActions(div, ['setAsDefaultStyle']);
  5018. }
  5019. return div;
  5020. };
  5021. /**
  5022. * Adds the label menu items to the given menu and parent.
  5023. */
  5024. DiagramStylePanel = function(format, editorUi, container)
  5025. {
  5026. BaseFormatPanel.call(this, format, editorUi, container);
  5027. this.init();
  5028. };
  5029. mxUtils.extend(DiagramStylePanel, BaseFormatPanel);
  5030. /**
  5031. * Adds the label menu items to the given menu and parent.
  5032. */
  5033. DiagramStylePanel.prototype.init = function()
  5034. {
  5035. var ui = this.editorUi;
  5036. this.darkModeChangedListener = mxUtils.bind(this, function()
  5037. {
  5038. this.format.cachedStyleEntries = [];
  5039. });
  5040. ui.addListener('darkModeChanged', this.darkModeChangedListener);
  5041. this.container.appendChild(this.addView(this.createPanel()));
  5042. };
  5043. /**
  5044. * Adds the label menu items to the given menu and parent.
  5045. */
  5046. DiagramStylePanel.prototype.getGlobalStyleButtons = function()
  5047. {
  5048. var ui = this.editorUi;
  5049. var editor = ui.editor;
  5050. var graph = editor.graph;
  5051. var buttons = [mxUtils.button(mxResources.get('sketch'), mxUtils.bind(this, function(evt)
  5052. {
  5053. var value = !Editor.sketchMode;
  5054. graph.updateCellStyles({'sketch': (value) ? '1' : null,
  5055. 'curveFitting': (value) ? Editor.sketchDefaultCurveFitting : null,
  5056. 'jiggle': (value) ? Editor.sketchDefaultJiggle : null},
  5057. graph.getVerticesAndEdges());
  5058. ui.setSketchMode(value);
  5059. mxEvent.consume(evt);
  5060. })), mxUtils.button(mxResources.get('rounded'), mxUtils.bind(this, function(evt)
  5061. {
  5062. // Checks if all cells are rounded
  5063. var cells = graph.getVerticesAndEdges();
  5064. var rounded = true;
  5065. if (cells.length > 0)
  5066. {
  5067. for (var i = 0; i < cells.length; i++)
  5068. {
  5069. var style = graph.getCellStyle(cells[i]);
  5070. if (mxUtils.getValue(style, mxConstants.STYLE_ROUNDED, 0) == 0)
  5071. {
  5072. rounded = false;
  5073. break;
  5074. }
  5075. }
  5076. }
  5077. rounded = !rounded;
  5078. graph.updateCellStyles({'rounded': (rounded) ? '1' : '0'}, cells);
  5079. if (rounded)
  5080. {
  5081. graph.currentEdgeStyle['rounded'] = '1';
  5082. graph.currentVertexStyle['rounded'] = '1';
  5083. }
  5084. else
  5085. {
  5086. delete graph.currentEdgeStyle['rounded'];
  5087. delete graph.currentVertexStyle['rounded'];
  5088. }
  5089. mxEvent.consume(evt);
  5090. }))];
  5091. return buttons;
  5092. };
  5093. /**
  5094. * Adds the label menu items to the given menu and parent.
  5095. */
  5096. DiagramStylePanel.prototype.addView = function(div)
  5097. {
  5098. var ui = this.editorUi;
  5099. var editor = ui.editor;
  5100. var graph = editor.graph;
  5101. var model = graph.getModel();
  5102. var gridColor = graph.view.gridColor;
  5103. div.style.paddingTop = '2px';
  5104. div.style.whiteSpace = 'normal';
  5105. var opts = document.createElement('div');
  5106. opts.style.marginRight = '16px';
  5107. opts.style.paddingBottom = '2px';
  5108. var table = document.createElement('table');
  5109. table.style.width = '204px';
  5110. var tbody = document.createElement('tbody');
  5111. var row = document.createElement('tr');
  5112. row.style.padding = '0px';
  5113. var left = document.createElement('td');
  5114. left.style.textAlign = 'center';
  5115. left.style.padding = '2px';
  5116. left.style.width = '50%';
  5117. var right = left.cloneNode(true);
  5118. var buttons = this.getGlobalStyleButtons();
  5119. for (var i = 0; i < buttons.length; i += 2)
  5120. {
  5121. var btn = buttons[i];
  5122. btn.style.height = '22px';
  5123. btn.style.width = '92px';
  5124. left.appendChild(btn);
  5125. row.appendChild(left);
  5126. btn = buttons[i + 1];
  5127. if (btn != null)
  5128. {
  5129. btn.style.height = '22px';
  5130. btn.style.width = '92px';
  5131. right.appendChild(btn);
  5132. }
  5133. row.appendChild(right);
  5134. tbody.appendChild(row);
  5135. left = left.cloneNode(false);
  5136. right = right.cloneNode(false);
  5137. row = row.cloneNode(false);
  5138. }
  5139. table.appendChild(tbody);
  5140. opts.appendChild(table);
  5141. div.appendChild(opts);
  5142. var defaultStyles = ['fillColor', 'strokeColor', 'fontColor', 'gradientColor'];
  5143. div.style.whiteSpace = 'normal';
  5144. div.style.paddingLeft = '18px';
  5145. div.style.paddingTop = '6px';
  5146. var updateCells = mxUtils.bind(this, function(styles, graphStyle)
  5147. {
  5148. var cells = graph.getVerticesAndEdges();
  5149. model.beginUpdate();
  5150. try
  5151. {
  5152. for (var i = 0; i < cells.length; i++)
  5153. {
  5154. var style = graph.getCellStyle(cells[i]);
  5155. // Handles special label background color
  5156. if (!ignoreGraphStyle && style['labelBackgroundColor'] != null)
  5157. {
  5158. graph.updateCellStyles({'labelBackgroundColor': (graphStyle != null) ?
  5159. graphStyle.background : null}, [cells[i]]);
  5160. }
  5161. else if (ignoreGraphStyle)
  5162. {
  5163. graph.updateCellStyles({'labelBackgroundColor': mxConstants.NONE}, [cells[i]]);
  5164. }
  5165. var edge = model.isEdge(cells[i]);
  5166. var newStyle = model.getStyle(cells[i]);
  5167. var current = (edge) ? graph.currentEdgeStyle : graph.currentVertexStyle;
  5168. for (var j = 0; j < styles.length; j++)
  5169. {
  5170. if ((style[styles[j]] != null && style[styles[j]] != mxConstants.NONE) ||
  5171. (styles[j] != mxConstants.STYLE_FILLCOLOR &&
  5172. styles[j] != mxConstants.STYLE_STROKECOLOR))
  5173. {
  5174. if (ignoreGraphStyle && edge && styles[j] == mxConstants.STYLE_FONTCOLOR)
  5175. {
  5176. newStyle = mxUtils.setStyle(newStyle, styles[j], 'default');
  5177. }
  5178. else
  5179. {
  5180. newStyle = mxUtils.setStyle(newStyle, styles[j], current[styles[j]]);
  5181. }
  5182. }
  5183. }
  5184. model.setStyle(cells[i], newStyle);
  5185. }
  5186. }
  5187. finally
  5188. {
  5189. model.endUpdate();
  5190. }
  5191. });
  5192. var removeStyles = mxUtils.bind(this, function(style, styles, defaultStyle)
  5193. {
  5194. if (style != null)
  5195. {
  5196. for (var j = 0; j < styles.length; j++)
  5197. {
  5198. if (((style[styles[j]] != null &&
  5199. style[styles[j]] != mxConstants.NONE) ||
  5200. (styles[j] != mxConstants.STYLE_FILLCOLOR &&
  5201. styles[j] != mxConstants.STYLE_STROKECOLOR)))
  5202. {
  5203. style[styles[j]] = defaultStyle[styles[j]];
  5204. }
  5205. }
  5206. }
  5207. });
  5208. var ignoreGraphStyle = true;
  5209. var applyStyle = mxUtils.bind(this, function(style, result, cell, graphStyle, theGraph)
  5210. {
  5211. if (style != null)
  5212. {
  5213. if (cell != null)
  5214. {
  5215. // Handles special label background color
  5216. if (!ignoreGraphStyle && result['labelBackgroundColor'] != null)
  5217. {
  5218. var bg = (graphStyle != null) ? graphStyle.background : null;
  5219. theGraph = (theGraph != null) ? theGraph : graph;
  5220. if (bg == null)
  5221. {
  5222. bg = theGraph.background;
  5223. }
  5224. if (bg == null)
  5225. {
  5226. bg = theGraph.defaultPageBackgroundColor;
  5227. }
  5228. result['labelBackgroundColor'] = bg;
  5229. }
  5230. else if (ignoreGraphStyle)
  5231. {
  5232. result['labelBackgroundColor'] = mxConstants.NONE;
  5233. }
  5234. }
  5235. for (var key in style)
  5236. {
  5237. if (cell == null || ((result[key] != null &&
  5238. result[key] != mxConstants.NONE) ||
  5239. (key != mxConstants.STYLE_FILLCOLOR &&
  5240. key != mxConstants.STYLE_STROKECOLOR)))
  5241. {
  5242. if (ignoreGraphStyle && model.isEdge(cell) &&
  5243. key == mxConstants.STYLE_FONTCOLOR)
  5244. {
  5245. result[key] = 'default';
  5246. }
  5247. else
  5248. {
  5249. result[key] = style[key];
  5250. }
  5251. }
  5252. }
  5253. }
  5254. });
  5255. var createPreview = mxUtils.bind(this, function(commonStyle, vertexStyle, edgeStyle, graphStyle, container)
  5256. {
  5257. // Wrapper needed to catch events
  5258. var div = document.createElement('div');
  5259. div.style.background = (Editor.isDarkMode() ? '#2a252f' : '#f1f3f4');
  5260. div.style.position = 'absolute';
  5261. div.style.display = 'inline-block';
  5262. div.style.overflow = 'hidden';
  5263. div.style.pointerEvents = 'none';
  5264. div.style.width = '100%';
  5265. div.style.height = '100%';
  5266. container.appendChild(div);
  5267. var graph2 = new Graph(div, null, null, graph.getStylesheet());
  5268. graph2.shapeBackgroundColor = div.style.background;
  5269. graph2.resetViewOnRootChange = false;
  5270. graph2.foldingEnabled = false;
  5271. graph2.gridEnabled = false;
  5272. graph2.autoScroll = false;
  5273. graph2.setTooltips(false);
  5274. graph2.setConnectable(false);
  5275. graph2.setPanning(false);
  5276. graph2.setEnabled(false);
  5277. graph2.getCellStyle = function(cell, resolve)
  5278. {
  5279. resolve = (resolve != null) ? resolve : true;
  5280. var result = mxUtils.clone(graph.getCellStyle.apply(this, arguments));
  5281. var defaultStyle = graph.stylesheet.getDefaultVertexStyle();
  5282. var appliedStyle = vertexStyle;
  5283. if (model.isEdge(cell))
  5284. {
  5285. defaultStyle = graph.stylesheet.getDefaultEdgeStyle();
  5286. appliedStyle = edgeStyle;
  5287. }
  5288. removeStyles(result, defaultStyles, defaultStyle);
  5289. applyStyle(commonStyle, result, cell, graphStyle, graph2);
  5290. applyStyle(appliedStyle, result, cell, graphStyle, graph2);
  5291. if (resolve)
  5292. {
  5293. result = graph.postProcessCellStyle(cell, result);
  5294. }
  5295. return result;
  5296. };
  5297. // Avoid HTML labels to capture events in bubble phase
  5298. graph2.model.beginUpdate();
  5299. try
  5300. {
  5301. var v1 = graph2.insertVertex(graph2.getDefaultParent(), null, 'Shape', 14, 8, 70, 36, 'strokeWidth=2;');
  5302. var e1 = graph2.insertEdge(graph2.getDefaultParent(), null, 'Connector', v1, v1,
  5303. 'edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;endSize=5;strokeWidth=2;')
  5304. e1.geometry.points = [new mxPoint(32, 66)];
  5305. e1.geometry.offset = new mxPoint(0, 8);
  5306. }
  5307. finally
  5308. {
  5309. graph2.model.endUpdate();
  5310. }
  5311. });
  5312. // Entries
  5313. var entries = document.createElement('div');
  5314. entries.style.position = 'relative';
  5315. entries.style.width = '210px';
  5316. div.appendChild(entries);
  5317. // Cached entries
  5318. if (this.format.cachedStyleEntries == null)
  5319. {
  5320. this.format.cachedStyleEntries = [];
  5321. }
  5322. function addKeys(style, result)
  5323. {
  5324. for (var key in style)
  5325. {
  5326. result.push(key);
  5327. }
  5328. return result;
  5329. };
  5330. var addEntry = mxUtils.bind(this, function(commonStyle, vertexStyle, edgeStyle, graphStyle, index)
  5331. {
  5332. var panel = this.format.cachedStyleEntries[index];
  5333. if (panel == null)
  5334. {
  5335. panel = document.createElement('div');
  5336. panel.style.display = 'inline-block';
  5337. panel.style.position = 'relative';
  5338. panel.style.width = '96px';
  5339. panel.style.height = '86px';
  5340. panel.style.cursor = 'pointer';
  5341. panel.style.border = '1px solid gray';
  5342. panel.style.borderRadius = '8px';
  5343. panel.style.margin = '1px 2px';
  5344. panel.style.overflow = 'hidden';
  5345. if (!ignoreGraphStyle && graphStyle != null && graphStyle.background != null)
  5346. {
  5347. panel.style.backgroundColor = graphStyle.background;
  5348. }
  5349. createPreview(commonStyle, vertexStyle, edgeStyle, graphStyle, panel);
  5350. mxEvent.addGestureListeners(panel, mxUtils.bind(this, function(evt)
  5351. {
  5352. panel.style.opacity = 0.5;
  5353. }), null, mxUtils.bind(this, function(evt)
  5354. {
  5355. panel.style.opacity = 1;
  5356. graph.currentVertexStyle = mxUtils.clone(graph.defaultVertexStyle);
  5357. graph.currentEdgeStyle = mxUtils.clone(graph.defaultEdgeStyle);
  5358. applyStyle(commonStyle, graph.currentVertexStyle);
  5359. applyStyle(commonStyle, graph.currentEdgeStyle);
  5360. applyStyle(vertexStyle, graph.currentVertexStyle);
  5361. applyStyle(edgeStyle, graph.currentEdgeStyle);
  5362. model.beginUpdate();
  5363. try
  5364. {
  5365. updateCells(addKeys(commonStyle, defaultStyles.slice()), graphStyle);
  5366. if (!ignoreGraphStyle)
  5367. {
  5368. var change = new ChangePageSetup(ui, (graphStyle != null) ? graphStyle.background : null);
  5369. change.ignoreImage = true;
  5370. model.execute(change);
  5371. model.execute(new ChangeGridColor(ui,
  5372. (graphStyle != null && graphStyle.gridColor != null) ?
  5373. graphStyle.gridColor : gridColor));
  5374. }
  5375. }
  5376. finally
  5377. {
  5378. model.endUpdate();
  5379. }
  5380. }));
  5381. mxEvent.addListener(panel, 'mouseenter', mxUtils.bind(this, function(evt)
  5382. {
  5383. var prev = graph.getCellStyle;
  5384. var prevBg = graph.background;
  5385. var prevGrid = graph.view.gridColor;
  5386. if (!ignoreGraphStyle)
  5387. {
  5388. graph.background = (graphStyle != null) ? graphStyle.background : null;
  5389. graph.view.gridColor = (graphStyle != null && graphStyle.gridColor != null) ?
  5390. graphStyle.gridColor : gridColor;
  5391. }
  5392. graph.getCellStyle = function(cell, resolve)
  5393. {
  5394. resolve = (resolve != null) ? resolve : true;
  5395. var result = mxUtils.clone(prev.apply(this, arguments));
  5396. var defaultStyle = graph.stylesheet.getDefaultVertexStyle();
  5397. var appliedStyle = vertexStyle;
  5398. if (model.isEdge(cell))
  5399. {
  5400. defaultStyle = graph.stylesheet.getDefaultEdgeStyle();
  5401. appliedStyle = edgeStyle;
  5402. }
  5403. removeStyles(result, defaultStyles, defaultStyle);
  5404. applyStyle(commonStyle, result, cell, graphStyle);
  5405. applyStyle(appliedStyle, result, cell, graphStyle);
  5406. if (resolve)
  5407. {
  5408. result = this.postProcessCellStyle(cell, result);
  5409. }
  5410. return result;
  5411. };
  5412. graph.refresh();
  5413. graph.getCellStyle = prev;
  5414. graph.background = prevBg;
  5415. graph.view.gridColor = prevGrid;
  5416. }));
  5417. mxEvent.addListener(panel, 'mouseleave', mxUtils.bind(this, function(evt)
  5418. {
  5419. graph.refresh();
  5420. }));
  5421. // Workaround for broken cache in IE11
  5422. if (!mxClient.IS_IE && !mxClient.IS_IE11)
  5423. {
  5424. this.format.cachedStyleEntries[index] = panel;
  5425. }
  5426. }
  5427. entries.appendChild(panel);
  5428. });
  5429. // Maximum palettes to switch the switcher
  5430. var maxEntries = 10;
  5431. var pageCount = Math.ceil(Editor.styles.length / maxEntries);
  5432. this.format.currentStylePage = (this.format.currentStylePage != null) ? this.format.currentStylePage : 0;
  5433. var dots = [];
  5434. var addEntries = mxUtils.bind(this, function()
  5435. {
  5436. if (dots.length > 0)
  5437. {
  5438. dots[this.format.currentStylePage].style.background = '#84d7ff';
  5439. }
  5440. for (var i = this.format.currentStylePage * maxEntries;
  5441. i < Math.min((this.format.currentStylePage + 1) * maxEntries,
  5442. Editor.styles.length); i++)
  5443. {
  5444. var s = Editor.styles[i];
  5445. addEntry(s.commonStyle, s.vertexStyle, s.edgeStyle, s.graph, i);
  5446. }
  5447. });
  5448. var selectPage = mxUtils.bind(this, function(index)
  5449. {
  5450. if (index >= 0 && index < pageCount)
  5451. {
  5452. dots[this.format.currentStylePage].style.background = 'transparent';
  5453. entries.innerText = '';
  5454. this.format.currentStylePage = index;
  5455. addEntries();
  5456. }
  5457. });
  5458. if (pageCount > 1)
  5459. {
  5460. // Selector
  5461. var switcher = document.createElement('div');
  5462. switcher.style.whiteSpace = 'nowrap';
  5463. switcher.style.position = 'relative';
  5464. switcher.style.textAlign = 'center';
  5465. switcher.style.paddingTop = '4px';
  5466. switcher.style.width = '210px';
  5467. for (var i = 0; i < pageCount; i++)
  5468. {
  5469. var dot = document.createElement('div');
  5470. dot.style.display = 'inline-block';
  5471. dot.style.width = '6px';
  5472. dot.style.height = '6px';
  5473. dot.style.marginLeft = '4px';
  5474. dot.style.marginRight = '3px';
  5475. dot.style.borderRadius = '3px';
  5476. dot.style.cursor = 'pointer';
  5477. dot.style.background = 'transparent';
  5478. dot.style.border = '1px solid #b5b6b7';
  5479. (mxUtils.bind(this, function(index, elt)
  5480. {
  5481. mxEvent.addListener(dot, 'click', mxUtils.bind(this, function()
  5482. {
  5483. selectPage(index);
  5484. }));
  5485. }))(i, dot);
  5486. switcher.appendChild(dot);
  5487. dots.push(dot);
  5488. }
  5489. div.appendChild(switcher);
  5490. addEntries();
  5491. if (pageCount < 15)
  5492. {
  5493. var left = document.createElement('div');
  5494. left.className = 'geAdaptiveAsset';
  5495. left.style.position = 'absolute';
  5496. left.style.left = '0px';
  5497. left.style.top = '0px';
  5498. left.style.bottom = '0px';
  5499. left.style.width = '24px';
  5500. left.style.height = '24px';
  5501. left.style.margin = '0px';
  5502. left.style.cursor = 'pointer';
  5503. left.style.opacity = '0.5';
  5504. left.style.backgroundRepeat = 'no-repeat';
  5505. left.style.backgroundPosition = 'center center';
  5506. left.style.backgroundSize = '24px 24px';
  5507. left.style.backgroundImage = 'url(' + Editor.previousImage + ')';
  5508. var right = left.cloneNode(false);
  5509. right.style.backgroundImage = 'url(' + Editor.nextImage + ')';
  5510. right.style.left = '';
  5511. right.style.right = '2px';
  5512. switcher.appendChild(left);
  5513. switcher.appendChild(right);
  5514. mxEvent.addListener(left, 'click', mxUtils.bind(this, function()
  5515. {
  5516. selectPage(mxUtils.mod(this.format.currentStylePage - 1, pageCount));
  5517. }));
  5518. mxEvent.addListener(right, 'click', mxUtils.bind(this, function()
  5519. {
  5520. selectPage(mxUtils.mod(this.format.currentStylePage + 1, pageCount));
  5521. }));
  5522. // Hover state
  5523. function addHoverState(elt)
  5524. {
  5525. mxEvent.addListener(elt, 'mouseenter', function()
  5526. {
  5527. elt.style.opacity = '1';
  5528. });
  5529. mxEvent.addListener(elt, 'mouseleave', function()
  5530. {
  5531. elt.style.opacity = '0.5';
  5532. });
  5533. };
  5534. addHoverState(left);
  5535. addHoverState(right);
  5536. }
  5537. }
  5538. else
  5539. {
  5540. addEntries();
  5541. }
  5542. return div;
  5543. };
  5544. /**
  5545. * Adds the label menu items to the given menu and parent.
  5546. */
  5547. DiagramStylePanel.prototype.destroy = function()
  5548. {
  5549. BaseFormatPanel.prototype.destroy.apply(this, arguments);
  5550. if (this.darkModeChangedListener)
  5551. {
  5552. this.editorUi.removeListener(this.darkModeChangedListener);
  5553. this.darkModeChangedListener = null;
  5554. }
  5555. };
  5556. /**
  5557. * Adds the label menu items to the given menu and parent.
  5558. */
  5559. DiagramFormatPanel = function(format, editorUi, container)
  5560. {
  5561. BaseFormatPanel.call(this, format, editorUi, container);
  5562. this.init();
  5563. };
  5564. mxUtils.extend(DiagramFormatPanel, BaseFormatPanel);
  5565. /**
  5566. * Switch to disable page view.
  5567. */
  5568. DiagramFormatPanel.showPageView = true;
  5569. /**
  5570. * Specifies if the background image option should be shown. Default is true.
  5571. */
  5572. DiagramFormatPanel.prototype.showBackgroundImageOption = true;
  5573. /**
  5574. * Adds the label menu items to the given menu and parent.
  5575. */
  5576. DiagramFormatPanel.prototype.init = function()
  5577. {
  5578. var ui = this.editorUi;
  5579. var editor = ui.editor;
  5580. var graph = editor.graph;
  5581. this.container.appendChild(this.addView(this.createPanel()));
  5582. if (graph.isEnabled())
  5583. {
  5584. this.container.appendChild(this.addOptions(this.createPanel()));
  5585. this.container.appendChild(this.addPaperSize(this.createPanel()));
  5586. this.container.appendChild(this.addStyleOps(this.createPanel()));
  5587. }
  5588. };
  5589. /**
  5590. * Adds the label menu items to the given menu and parent.
  5591. */
  5592. DiagramFormatPanel.prototype.addView = function(div)
  5593. {
  5594. var ui = this.editorUi;
  5595. var editor = ui.editor;
  5596. var graph = editor.graph;
  5597. div.appendChild(this.createTitle(mxResources.get('view')));
  5598. // Grid
  5599. this.addGridOption(div);
  5600. // Page View
  5601. if (DiagramFormatPanel.showPageView)
  5602. {
  5603. div.appendChild(this.createOption(mxResources.get('pageView'), function()
  5604. {
  5605. return graph.pageVisible;
  5606. }, function(checked)
  5607. {
  5608. ui.actions.get('pageView').funct();
  5609. },
  5610. {
  5611. install: function(apply)
  5612. {
  5613. this.listener = function()
  5614. {
  5615. apply(graph.pageVisible);
  5616. };
  5617. ui.addListener('pageViewChanged', this.listener);
  5618. },
  5619. destroy: function()
  5620. {
  5621. ui.removeListener(this.listener);
  5622. }
  5623. }));
  5624. }
  5625. if (graph.isEnabled())
  5626. {
  5627. if (this.showBackgroundImageOption)
  5628. {
  5629. var bg = this.createOption(mxResources.get('background'), function()
  5630. {
  5631. return graph.backgroundImage != null;
  5632. }, function(checked)
  5633. {
  5634. if (!checked)
  5635. {
  5636. var change = new ChangePageSetup(ui, null, null);
  5637. change.ignoreColor = true;
  5638. graph.model.execute(change);
  5639. }
  5640. },
  5641. {
  5642. install: function(apply)
  5643. {
  5644. this.listener = function()
  5645. {
  5646. apply(graph.backgroundImage != null);
  5647. };
  5648. ui.addListener('backgroundImageChanged', this.listener);
  5649. },
  5650. destroy: function()
  5651. {
  5652. ui.removeListener(this.listener);
  5653. }
  5654. });
  5655. var input = bg.getElementsByTagName('input')[0];
  5656. if (input != null)
  5657. {
  5658. input.style.visibility = graph.backgroundImage != null ? 'visible' : 'hidden';
  5659. }
  5660. var label = bg.getElementsByTagName('div')[0];
  5661. if (label != null)
  5662. {
  5663. label.style.display = 'inline-block';
  5664. label.style.textOverflow = 'ellipsis';
  5665. label.style.overflow = 'hidden';
  5666. label.style.maxWidth = '80px';
  5667. }
  5668. if (mxClient.IS_FF)
  5669. {
  5670. label.style.marginTop = '1px';
  5671. }
  5672. var btn = mxUtils.button(mxResources.get('change') + '...', function(evt)
  5673. {
  5674. ui.showBackgroundImageDialog(null,
  5675. ui.editor.graph.backgroundImage,
  5676. ui.editor.graph.background);
  5677. mxEvent.consume(evt);
  5678. })
  5679. btn.style.position = 'absolute';
  5680. btn.style.height = '22px';
  5681. btn.style.left = '47%';
  5682. btn.style.marginLeft = '1px';
  5683. btn.style.width = '110px';
  5684. btn.style.maxWidth = '110px';
  5685. bg.appendChild(btn);
  5686. div.appendChild(bg);
  5687. }
  5688. var bgColor = this.createColorOption(mxResources.get('backgroundColor'), function()
  5689. {
  5690. return graph.background;
  5691. }, function(color)
  5692. {
  5693. var change = new ChangePageSetup(ui, color);
  5694. change.ignoreImage = true;
  5695. graph.model.execute(change);
  5696. }, '#ffffff');
  5697. bgColor.style.padding = '5px 0 1px 0';
  5698. div.appendChild(bgColor);
  5699. var option = this.createOption(mxResources.get('shadow'), function()
  5700. {
  5701. return graph.shadowVisible;
  5702. }, function(checked)
  5703. {
  5704. var change = new ChangePageSetup(ui);
  5705. change.ignoreColor = true;
  5706. change.ignoreImage = true;
  5707. change.shadowVisible = checked;
  5708. graph.model.execute(change);
  5709. },
  5710. {
  5711. install: function(apply)
  5712. {
  5713. this.listener = function()
  5714. {
  5715. apply(graph.shadowVisible);
  5716. };
  5717. ui.addListener('shadowVisibleChanged', this.listener);
  5718. },
  5719. destroy: function()
  5720. {
  5721. ui.removeListener(this.listener);
  5722. }
  5723. });
  5724. if (!Editor.enableShadowOption)
  5725. {
  5726. option.getElementsByTagName('input')[0].setAttribute('disabled', 'disabled');
  5727. mxUtils.setOpacity(option, 60);
  5728. }
  5729. option.style.display = 'inline-flex';
  5730. option.style.width = '100px';
  5731. option.style.maxWidth = '100px';
  5732. option.style.marginRight = '4px';
  5733. div.appendChild(option);
  5734. var sketchOption = this.createOption(mxResources.get('sketch'), function()
  5735. {
  5736. return Editor.sketchMode;
  5737. }, function(checked)
  5738. {
  5739. ui.setSketchMode(checked);
  5740. },
  5741. {
  5742. install: function(apply)
  5743. {
  5744. this.listener = function()
  5745. {
  5746. apply(Editor.sketchMode);
  5747. };
  5748. ui.addListener('sketchModeChanged', this.listener);
  5749. },
  5750. destroy: function()
  5751. {
  5752. ui.removeListener(this.listener);
  5753. }
  5754. });
  5755. sketchOption.style.display = 'inline-flex';
  5756. sketchOption.style.width = '104px';
  5757. sketchOption.style.maxWidth = '104px';
  5758. div.appendChild(sketchOption);
  5759. }
  5760. return div;
  5761. };
  5762. /**
  5763. * Adds the label menu items to the given menu and parent.
  5764. */
  5765. DiagramFormatPanel.prototype.addOptions = function(div)
  5766. {
  5767. var ui = this.editorUi;
  5768. var editor = ui.editor;
  5769. var graph = editor.graph;
  5770. div.appendChild(this.createTitle(mxResources.get('options')));
  5771. if (graph.isEnabled())
  5772. {
  5773. // Connection arrows
  5774. div.appendChild(this.createOption(mxResources.get('connectionArrows'), function()
  5775. {
  5776. return graph.connectionArrowsEnabled;
  5777. }, function(checked)
  5778. {
  5779. ui.actions.get('connectionArrows').funct();
  5780. },
  5781. {
  5782. install: function(apply)
  5783. {
  5784. this.listener = function()
  5785. {
  5786. apply(graph.connectionArrowsEnabled);
  5787. };
  5788. ui.addListener('connectionArrowsChanged', this.listener);
  5789. },
  5790. destroy: function()
  5791. {
  5792. ui.removeListener(this.listener);
  5793. }
  5794. }));
  5795. // Connection points
  5796. div.appendChild(this.createOption(mxResources.get('connectionPoints'), function()
  5797. {
  5798. return graph.connectionHandler.isEnabled();
  5799. }, function(checked)
  5800. {
  5801. ui.actions.get('connectionPoints').funct();
  5802. },
  5803. {
  5804. install: function(apply)
  5805. {
  5806. this.listener = function()
  5807. {
  5808. apply(graph.connectionHandler.isEnabled());
  5809. };
  5810. ui.addListener('connectionPointsChanged', this.listener);
  5811. },
  5812. destroy: function()
  5813. {
  5814. ui.removeListener(this.listener);
  5815. }
  5816. }));
  5817. // Guides
  5818. div.appendChild(this.createOption(mxResources.get('guides'), function()
  5819. {
  5820. return graph.graphHandler.guidesEnabled;
  5821. }, function(checked)
  5822. {
  5823. ui.actions.get('guides').funct();
  5824. },
  5825. {
  5826. install: function(apply)
  5827. {
  5828. this.listener = function()
  5829. {
  5830. apply(graph.graphHandler.guidesEnabled);
  5831. };
  5832. ui.addListener('guidesEnabledChanged', this.listener);
  5833. },
  5834. destroy: function()
  5835. {
  5836. ui.removeListener(this.listener);
  5837. }
  5838. }));
  5839. }
  5840. return div;
  5841. };
  5842. /**
  5843. *
  5844. */
  5845. DiagramFormatPanel.prototype.addGridOption = function(container)
  5846. {
  5847. var fPanel = this;
  5848. var ui = this.editorUi;
  5849. var graph = ui.editor.graph;
  5850. var input = document.createElement('input');
  5851. input.style.position = 'absolute';
  5852. input.style.textAlign = 'right';
  5853. input.style.width = '48px';
  5854. input.style.marginTop = '-2px';
  5855. input.style.height = '21px';
  5856. input.style.borderWidth = '1px';
  5857. input.style.borderStyle = 'solid';
  5858. input.style.boxSizing = 'border-box';
  5859. input.value = this.inUnit(graph.getGridSize()) + ' ' + this.getUnit();
  5860. var stepper = this.createStepper(input, update, this.getUnitStep(), null, null, null, this.isFloatUnit());
  5861. input.style.display = (graph.isGridEnabled()) ? '' : 'none';
  5862. stepper.style.display = input.style.display;
  5863. mxEvent.addListener(input, 'keydown', function(e)
  5864. {
  5865. if (e.keyCode == 13)
  5866. {
  5867. graph.container.focus();
  5868. mxEvent.consume(e);
  5869. }
  5870. else if (e.keyCode == 27)
  5871. {
  5872. input.value = graph.getGridSize();
  5873. graph.container.focus();
  5874. mxEvent.consume(e);
  5875. }
  5876. });
  5877. function update(evt)
  5878. {
  5879. var value = fPanel.isFloatUnit()? parseFloat(input.value) : parseInt(input.value);
  5880. value = fPanel.fromUnit(Math.max(fPanel.inUnit(1), (isNaN(value)) ? fPanel.inUnit(10) : value));
  5881. if (value != graph.getGridSize())
  5882. {
  5883. mxGraph.prototype.gridSize = value;
  5884. graph.setGridSize(value)
  5885. }
  5886. input.value = fPanel.inUnit(value) + ' ' + fPanel.getUnit();
  5887. mxEvent.consume(evt);
  5888. };
  5889. mxEvent.addListener(input, 'blur', update);
  5890. mxEvent.addListener(input, 'change', update);
  5891. input.style.right = '78px';
  5892. stepper.style.marginTop = (mxClient.IS_MAC && mxClient.IS_GC) ?
  5893. '-16px' : ((mxClient.IS_WIN) ? '-18px' : '-17px');
  5894. stepper.style.right = '66px';
  5895. var panel = this.createColorOption(mxResources.get('grid'), function()
  5896. {
  5897. var color = graph.view.gridColor;
  5898. return (graph.isGridEnabled()) ? color : null;
  5899. }, function(color)
  5900. {
  5901. var enabled = graph.isGridEnabled();
  5902. if (color == mxConstants.NONE)
  5903. {
  5904. graph.setGridEnabled(false);
  5905. }
  5906. else
  5907. {
  5908. graph.setGridEnabled(true);
  5909. ui.setGridColor(color);
  5910. }
  5911. input.style.display = (graph.isGridEnabled()) ? '' : 'none';
  5912. stepper.style.display = input.style.display;
  5913. if (enabled != graph.isGridEnabled())
  5914. {
  5915. graph.defaultGridEnabled = graph.isGridEnabled();
  5916. ui.fireEvent(new mxEventObject('gridEnabledChanged'));
  5917. }
  5918. }, Editor.isDarkMode() ? graph.view.defaultDarkGridColor : graph.view.defaultGridColor,
  5919. {
  5920. install: function(apply)
  5921. {
  5922. this.listener = function()
  5923. {
  5924. apply((graph.isGridEnabled()) ? graph.view.gridColor : null);
  5925. };
  5926. ui.addListener('gridColorChanged', this.listener);
  5927. ui.addListener('gridEnabledChanged', this.listener);
  5928. },
  5929. destroy: function()
  5930. {
  5931. ui.removeListener(this.listener);
  5932. }
  5933. });
  5934. panel.style.padding = '6px 0 0 0';
  5935. panel.appendChild(input);
  5936. panel.appendChild(stepper);
  5937. container.appendChild(panel);
  5938. };
  5939. /**
  5940. * Adds the label menu items to the given menu and parent.
  5941. */
  5942. DiagramFormatPanel.prototype.addDocumentProperties = function(div)
  5943. {
  5944. // Hook for subclassers
  5945. var ui = this.editorUi;
  5946. var editor = ui.editor;
  5947. var graph = editor.graph;
  5948. div.appendChild(this.createTitle(mxResources.get('options')));
  5949. return div;
  5950. };
  5951. /**
  5952. * Adds the label menu items to the given menu and parent.
  5953. */
  5954. DiagramFormatPanel.prototype.addPaperSize = function(div)
  5955. {
  5956. var ui = this.editorUi;
  5957. var editor = ui.editor;
  5958. var graph = editor.graph;
  5959. div.appendChild(this.createTitle(mxResources.get('paperSize')));
  5960. var accessor = PageSetupDialog.addPageFormatPanel(div, 'formatpanel', graph.pageFormat, function(pageFormat)
  5961. {
  5962. if (graph.pageFormat == null || graph.pageFormat.width != pageFormat.width ||
  5963. graph.pageFormat.height != pageFormat.height)
  5964. {
  5965. var change = new ChangePageSetup(ui, null, null, pageFormat);
  5966. change.ignoreColor = true;
  5967. change.ignoreImage = true;
  5968. graph.model.execute(change);
  5969. }
  5970. });
  5971. this.addKeyHandler(accessor.widthInput, function()
  5972. {
  5973. accessor.set(graph.pageFormat);
  5974. });
  5975. this.addKeyHandler(accessor.heightInput, function()
  5976. {
  5977. accessor.set(graph.pageFormat);
  5978. });
  5979. var listener = function()
  5980. {
  5981. accessor.set(graph.pageFormat);
  5982. };
  5983. ui.addListener('pageFormatChanged', listener);
  5984. this.listeners.push({destroy: function() { ui.removeListener(listener); }});
  5985. graph.getModel().addListener(mxEvent.CHANGE, listener);
  5986. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  5987. return div;
  5988. };
  5989. /**
  5990. * Adds the label menu items to the given menu and parent.
  5991. */
  5992. DiagramFormatPanel.prototype.addStyleOps = function(div)
  5993. {
  5994. this.addActions(div, ['editData']);
  5995. this.addActions(div, ['clearDefaultStyle']);
  5996. return div;
  5997. };
  5998. /**
  5999. * Adds the label menu items to the given menu and parent.
  6000. */
  6001. DiagramFormatPanel.prototype.destroy = function()
  6002. {
  6003. BaseFormatPanel.prototype.destroy.apply(this, arguments);
  6004. if (this.gridEnabledListener)
  6005. {
  6006. this.editorUi.removeListener(this.gridEnabledListener);
  6007. this.gridEnabledListener = null;
  6008. }
  6009. };
  6010. /**
  6011. * Configures global color schemes.
  6012. */
  6013. StyleFormatPanel.prototype.defaultColorSchemes = [[{fill: '', stroke: ''}, {fill: '#f5f5f5', stroke: '#666666', font: '#333333'},
  6014. {fill: '#dae8fc', stroke: '#6c8ebf'}, {fill: '#d5e8d4', stroke: '#82b366'},
  6015. {fill: '#ffe6cc', stroke: '#d79b00'}, {fill: '#fff2cc', stroke: '#d6b656'},
  6016. {fill: '#f8cecc', stroke: '#b85450'}, {fill: '#e1d5e7', stroke: '#9673a6'}],
  6017. [{fill: '', stroke: ''}, {fill: '#60a917', stroke: '#2D7600', font: '#ffffff'},
  6018. {fill: '#008a00', stroke: '#005700', font: '#ffffff'}, {fill: '#1ba1e2', stroke: '#006EAF', font: '#ffffff'},
  6019. {fill: '#0050ef', stroke: '#001DBC', font: '#ffffff'}, {fill: '#6a00ff', stroke: '#3700CC', font: '#ffffff'},
  6020. //{fill: '#aa00ff', stroke: '#7700CC', font: '#ffffff'},
  6021. {fill: '#d80073', stroke: '#A50040', font: '#ffffff'}, {fill: '#a20025', stroke: '#6F0000', font: '#ffffff'}],
  6022. [{fill: '#e51400', stroke: '#B20000', font: '#ffffff'}, {fill: '#fa6800', stroke: '#C73500', font: '#000000'},
  6023. {fill: '#f0a30a', stroke: '#BD7000', font: '#000000'}, {fill: '#e3c800', stroke: '#B09500', font: '#000000'},
  6024. {fill: '#6d8764', stroke: '#3A5431', font: '#ffffff'}, {fill: '#647687', stroke: '#314354', font: '#ffffff'},
  6025. {fill: '#76608a', stroke: '#432D57', font: '#ffffff'}, {fill: '#a0522d', stroke: '#6D1F00', font: '#ffffff'}],
  6026. [{fill: '', stroke: ''}, {fill: mxConstants.NONE, stroke: ''},
  6027. {fill: '#fad7ac', stroke: '#b46504'}, {fill: '#fad9d5', stroke: '#ae4132'},
  6028. {fill: '#b0e3e6', stroke: '#0e8088'}, {fill: '#b1ddf0', stroke: '#10739e'},
  6029. {fill: '#d0cee2', stroke: '#56517e'}, {fill: '#bac8d3', stroke: '#23445d'}],
  6030. [{fill: '', stroke: ''},
  6031. {fill: '#f5f5f5', stroke: '#666666', gradient: '#b3b3b3'},
  6032. {fill: '#dae8fc', stroke: '#6c8ebf', gradient: '#7ea6e0'},
  6033. {fill: '#d5e8d4', stroke: '#82b366', gradient: '#97d077'},
  6034. {fill: '#ffcd28', stroke: '#d79b00', gradient: '#ffa500'},
  6035. {fill: '#fff2cc', stroke: '#d6b656', gradient: '#ffd966'},
  6036. {fill: '#f8cecc', stroke: '#b85450', gradient: '#ea6b66'},
  6037. {fill: '#e6d0de', stroke: '#996185', gradient: '#d5739d'}],
  6038. [{fill: '', stroke: ''}, {fill: '#eeeeee', stroke: '#36393d'},
  6039. {fill: '#f9f7ed', stroke: '#36393d'}, {fill: '#ffcc99', stroke: '#36393d'},
  6040. {fill: '#cce5ff', stroke: '#36393d'}, {fill: '#ffff88', stroke: '#36393d'},
  6041. {fill: '#cdeb8b', stroke: '#36393d'}, {fill: '#ffcccc', stroke: '#36393d'}]];
  6042. /**
  6043. * Configures custom color schemes.
  6044. */
  6045. StyleFormatPanel.prototype.customColorSchemes = null;
  6046. StyleFormatPanel.prototype.findCommonProperties = function(cell, properties, addAll)
  6047. {
  6048. if (properties == null) return;
  6049. var handleCustomProp = function(custProperties)
  6050. {
  6051. if (custProperties != null)
  6052. {
  6053. if (addAll)
  6054. {
  6055. for (var i = 0; i < custProperties.length; i++)
  6056. {
  6057. properties[custProperties[i].name] = custProperties[i];
  6058. }
  6059. }
  6060. else
  6061. {
  6062. for (var key in properties)
  6063. {
  6064. var found = false;
  6065. for (var i = 0; i < custProperties.length; i++)
  6066. {
  6067. if (custProperties[i].name == key && custProperties[i].type == properties[key].type)
  6068. {
  6069. found = true;
  6070. break;
  6071. }
  6072. }
  6073. if (!found)
  6074. {
  6075. delete properties[key];
  6076. }
  6077. }
  6078. }
  6079. }
  6080. };
  6081. var view = this.editorUi.editor.graph.view;
  6082. var state = view.getState(cell);
  6083. if (state != null && state.shape != null)
  6084. {
  6085. //Add common properties to all shapes
  6086. if (!state.shape.commonCustomPropAdded)
  6087. {
  6088. state.shape.commonCustomPropAdded = true;
  6089. state.shape.customProperties = state.shape.customProperties || [];
  6090. if (state.cell.vertex)
  6091. {
  6092. Array.prototype.push.apply(state.shape.customProperties, Editor.commonVertexProperties);
  6093. }
  6094. else
  6095. {
  6096. Array.prototype.push.apply(state.shape.customProperties, Editor.commonEdgeProperties);
  6097. }
  6098. }
  6099. handleCustomProp(state.shape.customProperties);
  6100. }
  6101. //This currently is not needed but let's keep it in case we needed in the future
  6102. var userCustomProp = cell.getAttribute('customProperties');
  6103. if (userCustomProp != null)
  6104. {
  6105. try
  6106. {
  6107. handleCustomProp(JSON.parse(userCustomProp));
  6108. }
  6109. catch(e){}
  6110. }
  6111. };
  6112. /**
  6113. * Adds predefiend styles.
  6114. */
  6115. var styleFormatPanelInit = StyleFormatPanel.prototype.init;
  6116. StyleFormatPanel.prototype.init = function()
  6117. {
  6118. var sstate = this.editorUi.getSelectionState();
  6119. if (this.defaultColorSchemes != null && this.defaultColorSchemes.length > 0 &&
  6120. sstate.style.shape != 'image' && !sstate.containsLabel &&
  6121. sstate.cells.length > 0)
  6122. {
  6123. this.container.appendChild(this.addStyles(this.createPanel()));
  6124. }
  6125. styleFormatPanelInit.apply(this, arguments);
  6126. if (Editor.enableCustomProperties)
  6127. {
  6128. var properties = {};
  6129. var vertices = sstate.vertices;
  6130. var edges = sstate.edges;
  6131. for (var i = 0; i < vertices.length; i++)
  6132. {
  6133. this.findCommonProperties(vertices[i], properties, i == 0);
  6134. }
  6135. for (var i = 0; i < edges.length; i++)
  6136. {
  6137. this.findCommonProperties(edges[i], properties, vertices.length == 0 && i == 0);
  6138. }
  6139. if (Object.getOwnPropertyNames != null && Object.getOwnPropertyNames(properties).length > 0)
  6140. {
  6141. this.container.appendChild(this.addProperties(this.createPanel(), properties, sstate));
  6142. }
  6143. }
  6144. };
  6145. /**
  6146. * Overridden to add copy and paste style.
  6147. */
  6148. var styleFormatPanelAddStyleOps = StyleFormatPanel.prototype.addStyleOps;
  6149. StyleFormatPanel.prototype.addStyleOps = function(div)
  6150. {
  6151. var ss = this.editorUi.getSelectionState();
  6152. if (ss.cells.length == 1)
  6153. {
  6154. this.addActions(div, ['copyStyle', 'pasteStyle']);
  6155. }
  6156. else if (ss.cells.length >= 1)
  6157. {
  6158. this.addActions(div, ['pasteStyle', 'pasteData']);
  6159. }
  6160. return styleFormatPanelAddStyleOps.apply(this, arguments);
  6161. };
  6162. /**
  6163. * Initial collapsed state of the properties panel.
  6164. */
  6165. EditorUi.prototype.propertiesCollapsed = true;
  6166. /**
  6167. * Create Properties Panel
  6168. */
  6169. StyleFormatPanel.prototype.addProperties = function(div, properties, state)
  6170. {
  6171. var that = this;
  6172. var graph = this.editorUi.editor.graph;
  6173. var secondLevel = [];
  6174. function insertAfter(newElem, curElem)
  6175. {
  6176. curElem.parentNode.insertBefore(newElem, curElem.nextSibling);
  6177. };
  6178. function applyStyleVal(pName, newVal, prop, delIndex)
  6179. {
  6180. graph.getModel().beginUpdate();
  6181. try
  6182. {
  6183. var changedProps = [];
  6184. var changedVals = [];
  6185. if (prop.index != null)
  6186. {
  6187. var allVals = [];
  6188. var curVal = prop.parentRow.nextSibling;
  6189. while(curVal && curVal.getAttribute('data-pName') == pName)
  6190. {
  6191. allVals.push(curVal.getAttribute('data-pValue'));
  6192. curVal = curVal.nextSibling;
  6193. }
  6194. if (prop.index < allVals.length)
  6195. {
  6196. if (delIndex != null)
  6197. {
  6198. allVals.splice(delIndex, 1);
  6199. }
  6200. else
  6201. {
  6202. allVals[prop.index] = newVal;
  6203. }
  6204. }
  6205. else
  6206. {
  6207. allVals.push(newVal);
  6208. }
  6209. if (prop.size != null && allVals.length > prop.size) //trim the array to the specifies size
  6210. {
  6211. allVals = allVals.slice(0, prop.size);
  6212. }
  6213. newVal = allVals.join(',');
  6214. if (prop.countProperty != null)
  6215. {
  6216. graph.setCellStyles(prop.countProperty, allVals.length, graph.getSelectionCells());
  6217. changedProps.push(prop.countProperty);
  6218. changedVals.push(allVals.length);
  6219. }
  6220. }
  6221. graph.setCellStyles(pName, newVal, graph.getSelectionCells());
  6222. changedProps.push(pName);
  6223. changedVals.push(newVal);
  6224. if (prop.dependentProps != null)
  6225. {
  6226. for (var i = 0; i < prop.dependentProps.length; i++)
  6227. {
  6228. var defVal = prop.dependentPropsDefVal[i];
  6229. var vals = prop.dependentPropsVals[i];
  6230. if (vals.length > newVal)
  6231. {
  6232. vals = vals.slice(0, newVal);
  6233. }
  6234. else
  6235. {
  6236. for (var j = vals.length; j < newVal; j++)
  6237. {
  6238. vals.push(defVal);
  6239. }
  6240. }
  6241. vals = vals.join(',');
  6242. graph.setCellStyles(prop.dependentProps[i], vals, graph.getSelectionCells());
  6243. changedProps.push(prop.dependentProps[i]);
  6244. changedVals.push(vals);
  6245. }
  6246. }
  6247. if (typeof(prop.onChange) == 'function')
  6248. {
  6249. prop.onChange(graph, newVal);
  6250. }
  6251. that.editorUi.fireEvent(new mxEventObject('styleChanged', 'keys', changedProps,
  6252. 'values', changedVals, 'cells', graph.getSelectionCells()));
  6253. }
  6254. finally
  6255. {
  6256. graph.getModel().endUpdate();
  6257. }
  6258. }
  6259. function setElementPos(td, elem, adjustHeight)
  6260. {
  6261. var divPos = mxUtils.getOffset(div, true);
  6262. var pos = mxUtils.getOffset(td, true);
  6263. elem.style.position = 'absolute';
  6264. elem.style.left = (pos.x - divPos.x) + 'px';
  6265. elem.style.top = (pos.y - divPos.y) + 'px';
  6266. elem.style.width = td.offsetWidth + 'px';
  6267. elem.style.height = (td.offsetHeight - (adjustHeight? 4 : 0)) + 'px';
  6268. elem.style.zIndex = 5;
  6269. };
  6270. function createColorBtn(pName, pValue, prop)
  6271. {
  6272. var clrDiv = document.createElement('div');
  6273. clrDiv.style.width = '32px';
  6274. clrDiv.style.height = '4px';
  6275. clrDiv.style.margin = '2px';
  6276. clrDiv.style.border = '1px solid black';
  6277. clrDiv.style.background = !pValue || pValue == 'none'? 'url(\'' + Dialog.prototype.noColorImage + '\')' : pValue;
  6278. btn = mxUtils.button('', mxUtils.bind(that, function(evt)
  6279. {
  6280. this.editorUi.pickColor(pValue, function(color)
  6281. {
  6282. clrDiv.style.background = color == 'none'? 'url(\'' + Dialog.prototype.noColorImage + '\')' : color;
  6283. applyStyleVal(pName, color, prop);
  6284. });
  6285. mxEvent.consume(evt);
  6286. }));
  6287. btn.style.height = '12px';
  6288. btn.style.width = '40px';
  6289. btn.className = 'geColorBtn';
  6290. btn.appendChild(clrDiv);
  6291. return btn;
  6292. };
  6293. function createDynArrList(pName, pValue, subType, defVal, countProperty, myRow, flipBkg)
  6294. {
  6295. if (pValue != null)
  6296. {
  6297. var vals = pValue.split(',');
  6298. secondLevel.push({name: pName, values: vals, type: subType, defVal: defVal, countProperty: countProperty, parentRow: myRow, isDeletable: true, flipBkg: flipBkg});
  6299. }
  6300. btn = mxUtils.button('+', mxUtils.bind(that, function(evt)
  6301. {
  6302. var beforeElem = myRow;
  6303. var index = 0;
  6304. while (beforeElem.nextSibling != null)
  6305. {
  6306. var cur = beforeElem.nextSibling;
  6307. var elemPName = cur.getAttribute('data-pName');
  6308. if (elemPName == pName)
  6309. {
  6310. beforeElem = beforeElem.nextSibling;
  6311. index++;
  6312. }
  6313. else
  6314. {
  6315. break;
  6316. }
  6317. }
  6318. var newProp = {type: subType, parentRow: myRow, index: index, isDeletable: true, defVal: defVal, countProperty: countProperty};
  6319. var arrItem = createPropertyRow(pName, '', newProp, index % 2 == 0, flipBkg);
  6320. applyStyleVal(pName, defVal, newProp);
  6321. insertAfter(arrItem, beforeElem);
  6322. mxEvent.consume(evt);
  6323. }));
  6324. btn.style.height = '16px';
  6325. btn.style.width = '25px';
  6326. btn.className = 'geColorBtn';
  6327. return btn;
  6328. };
  6329. function createStaticArrList(pName, pValue, subType, defVal, size, myRow, flipBkg)
  6330. {
  6331. if (size > 0)
  6332. {
  6333. var vals = new Array(size);
  6334. var curVals = pValue != null? pValue.split(',') : [];
  6335. for (var i = 0; i < size; i++)
  6336. {
  6337. vals[i] = curVals[i] != null? curVals[i] : (defVal != null? defVal : '');
  6338. }
  6339. secondLevel.push({name: pName, values: vals, type: subType, defVal: defVal, parentRow: myRow, flipBkg: flipBkg, size: size});
  6340. }
  6341. return document.createElement('div'); //empty cell
  6342. };
  6343. function createCheckbox(pName, pValue, prop)
  6344. {
  6345. var input = document.createElement('input');
  6346. input.type = 'checkbox';
  6347. input.checked = pValue == '1';
  6348. mxEvent.addListener(input, 'change', function()
  6349. {
  6350. applyStyleVal(pName, input.checked? '1' : '0', prop);
  6351. });
  6352. return input;
  6353. };
  6354. function createPropertyRow(pName, pValue, prop, isOdd, flipBkg)
  6355. {
  6356. var pDiplayName = prop.dispName;
  6357. var pType = prop.type;
  6358. var row = document.createElement('tr');
  6359. row.className = 'gePropRow' + (flipBkg? 'Dark' : '') + (isOdd? 'Alt' : '') + ' gePropNonHeaderRow';
  6360. row.setAttribute('data-pName', pName);
  6361. row.setAttribute('data-pValue', pValue);
  6362. var rightAlig = false;
  6363. if (prop.index != null)
  6364. {
  6365. row.setAttribute('data-index', prop.index);
  6366. pDiplayName = (pDiplayName != null? pDiplayName : '') + '[' + prop.index + ']';
  6367. rightAlig = true;
  6368. }
  6369. var td = document.createElement('td');
  6370. td.className = 'gePropRowCell';
  6371. var label = mxResources.get(pDiplayName, null, pDiplayName);
  6372. mxUtils.write(td, label);
  6373. td.setAttribute('title', label);
  6374. if (rightAlig)
  6375. {
  6376. td.style.textAlign = 'right';
  6377. }
  6378. row.appendChild(td);
  6379. td = document.createElement('td');
  6380. td.className = 'gePropRowCell';
  6381. if (pType == 'color')
  6382. {
  6383. td.appendChild(createColorBtn(pName, pValue, prop));
  6384. }
  6385. else if (pType == 'bool' || pType == 'boolean')
  6386. {
  6387. td.appendChild(createCheckbox(pName, pValue, prop));
  6388. }
  6389. else if (pType == 'enum')
  6390. {
  6391. var pEnumList = prop.enumList;
  6392. for (var i = 0; i < pEnumList.length; i++)
  6393. {
  6394. var op = pEnumList[i];
  6395. if (op.val == pValue)
  6396. {
  6397. mxUtils.write(td, mxResources.get(op.dispName, null, op.dispName));
  6398. break;
  6399. }
  6400. }
  6401. mxEvent.addListener(td, 'click', mxUtils.bind(that, function()
  6402. {
  6403. var select = document.createElement('select');
  6404. setElementPos(td, select);
  6405. for (var i = 0; i < pEnumList.length; i++)
  6406. {
  6407. var op = pEnumList[i];
  6408. var opElem = document.createElement('option');
  6409. opElem.value = mxUtils.htmlEntities(op.val);
  6410. mxUtils.write(opElem, mxResources.get(op.dispName, null, op.dispName));
  6411. select.appendChild(opElem);
  6412. }
  6413. select.value = pValue;
  6414. div.appendChild(select);
  6415. mxEvent.addListener(select, 'change', function()
  6416. {
  6417. var newVal = mxUtils.htmlEntities(select.value);
  6418. applyStyleVal(pName, newVal, prop);
  6419. //set value triggers a redraw of the panel which removes the select and updates the row
  6420. });
  6421. select.focus();
  6422. //FF calls blur on focus! so set the event after focusing (not with selects but to be safe)
  6423. mxEvent.addListener(select, 'blur', function()
  6424. {
  6425. div.removeChild(select);
  6426. });
  6427. }));
  6428. }
  6429. else if (pType == 'dynamicArr')
  6430. {
  6431. td.appendChild(createDynArrList(pName, pValue, prop.subType, prop.subDefVal, prop.countProperty, row, flipBkg));
  6432. }
  6433. else if (pType == 'staticArr')
  6434. {
  6435. td.appendChild(createStaticArrList(pName, pValue, prop.subType, prop.subDefVal, prop.size, row, flipBkg));
  6436. }
  6437. else if (pType == 'readOnly')
  6438. {
  6439. var inp = document.createElement('input');
  6440. inp.setAttribute('readonly', '');
  6441. inp.value = pValue;
  6442. inp.style.width = '96px';
  6443. inp.style.borderWidth = '0px';
  6444. td.appendChild(inp);
  6445. }
  6446. else
  6447. {
  6448. td.innerHTML = mxUtils.htmlEntities(decodeURIComponent(pValue));
  6449. mxEvent.addListener(td, 'click', mxUtils.bind(that, function()
  6450. {
  6451. var input = document.createElement('input');
  6452. setElementPos(td, input, true);
  6453. input.value = decodeURIComponent(pValue);
  6454. input.className = 'gePropEditor';
  6455. if ((pType == 'int' || pType == 'float') && !prop.allowAuto)
  6456. {
  6457. input.type = 'number';
  6458. input.step = pType == 'int'? '1' : 'any';
  6459. if (prop.min != null)
  6460. {
  6461. input.min = parseFloat(prop.min);
  6462. }
  6463. if (prop.max != null)
  6464. {
  6465. input.max = parseFloat(prop.max);
  6466. }
  6467. }
  6468. div.appendChild(input);
  6469. function setInputVal()
  6470. {
  6471. var inputVal = input.value;
  6472. inputVal = inputVal.length == 0 && pType != 'string'? 0 : inputVal;
  6473. if (prop.allowAuto)
  6474. {
  6475. if (inputVal.trim != null && inputVal.trim().toLowerCase() == 'auto')
  6476. {
  6477. inputVal = 'auto';
  6478. pType = 'string';
  6479. }
  6480. else
  6481. {
  6482. inputVal = parseFloat(inputVal);
  6483. inputVal = isNaN(inputVal)? 0 : inputVal;
  6484. }
  6485. }
  6486. if (prop.min != null && inputVal < prop.min)
  6487. {
  6488. inputVal = prop.min;
  6489. }
  6490. else if (prop.max != null && inputVal > prop.max)
  6491. {
  6492. inputVal = prop.max;
  6493. }
  6494. var newVal = encodeURIComponent((pType == 'int'? parseInt(inputVal) : inputVal) + '');
  6495. applyStyleVal(pName, newVal, prop);
  6496. }
  6497. mxEvent.addListener(input, 'keypress', function(e)
  6498. {
  6499. if (e.keyCode == 13)
  6500. {
  6501. setInputVal();
  6502. //set value triggers a redraw of the panel which removes the input
  6503. }
  6504. });
  6505. input.focus();
  6506. //FF calls blur on focus! so set the event after focusing
  6507. mxEvent.addListener(input, 'blur', function()
  6508. {
  6509. setInputVal();
  6510. });
  6511. }));
  6512. }
  6513. if (prop.isDeletable)
  6514. {
  6515. var delBtn = mxUtils.button('-', mxUtils.bind(that, function(evt)
  6516. {
  6517. //delete the node by refreshing the properties
  6518. applyStyleVal(pName, '', prop, prop.index);
  6519. mxEvent.consume(evt);
  6520. }));
  6521. delBtn.style.height = '16px';
  6522. delBtn.style.width = '25px';
  6523. delBtn.style.float = 'right';
  6524. delBtn.className = 'geColorBtn';
  6525. td.appendChild(delBtn);
  6526. }
  6527. row.appendChild(td);
  6528. return row;
  6529. };
  6530. div.style.position = 'relative';
  6531. div.style.padding = '0';
  6532. var grid = document.createElement('table');
  6533. grid.className = 'geProperties';
  6534. grid.style.whiteSpace = 'nowrap';
  6535. grid.style.width = '100%';
  6536. //create header row
  6537. var hrow = document.createElement('tr');
  6538. hrow.className = 'gePropHeader';
  6539. var th = document.createElement('th');
  6540. th.className = 'gePropHeaderCell';
  6541. var collapseImg = document.createElement('img');
  6542. collapseImg.src = Sidebar.prototype.expandedImage;
  6543. collapseImg.style.verticalAlign = 'middle';
  6544. th.appendChild(collapseImg);
  6545. mxUtils.write(th, mxResources.get('property'));
  6546. hrow.style.cursor = 'pointer';
  6547. var onFold = function()
  6548. {
  6549. var rows = grid.querySelectorAll('.gePropNonHeaderRow');
  6550. var display;
  6551. if (!that.editorUi.propertiesCollapsed)
  6552. {
  6553. collapseImg.src = Sidebar.prototype.expandedImage;
  6554. display = '';
  6555. }
  6556. else
  6557. {
  6558. collapseImg.src = Sidebar.prototype.collapsedImage;
  6559. display = 'none';
  6560. for (var e = div.childNodes.length - 1; e >= 0 ; e--)
  6561. {
  6562. //Blur can be executed concurrently with this method and the element is removed before removing it here
  6563. try
  6564. {
  6565. var child = div.childNodes[e];
  6566. var nodeName = child.nodeName.toUpperCase();
  6567. if (nodeName == 'INPUT' || nodeName == 'SELECT')
  6568. {
  6569. div.removeChild(child);
  6570. }
  6571. }
  6572. catch(ex){}
  6573. }
  6574. }
  6575. for (var r = 0; r < rows.length; r++)
  6576. {
  6577. rows[r].style.display = display;
  6578. }
  6579. };
  6580. mxEvent.addListener(hrow, 'click', function()
  6581. {
  6582. that.editorUi.propertiesCollapsed = !that.editorUi.propertiesCollapsed;
  6583. onFold();
  6584. });
  6585. hrow.appendChild(th);
  6586. th = document.createElement('th');
  6587. th.className = 'gePropHeaderCell';
  6588. th.innerHTML = mxResources.get('value');
  6589. hrow.appendChild(th);
  6590. grid.appendChild(hrow);
  6591. var isOdd = false;
  6592. var flipBkg = false;
  6593. var cellId = null;
  6594. if (state.vertices.length == 1 && state.edges.length == 0)
  6595. {
  6596. cellId = state.vertices[0].id;
  6597. }
  6598. else if (state.vertices.length == 0 && state.edges.length == 1)
  6599. {
  6600. cellId = state.edges[0].id;
  6601. }
  6602. //Add it to top (always)
  6603. if (cellId != null)
  6604. {
  6605. grid.appendChild(createPropertyRow('id', mxUtils.htmlEntities(cellId), {dispName: 'ID', type: 'readOnly'}, true, false));
  6606. }
  6607. for (var key in properties)
  6608. {
  6609. var prop = properties[key];
  6610. if (typeof(prop.isVisible) == 'function')
  6611. {
  6612. if (!prop.isVisible(state, this)) continue;
  6613. }
  6614. var pValue = state.style[key] != null? mxUtils.htmlEntities(state.style[key] + '') :
  6615. ((prop.getDefaultValue != null) ? prop.getDefaultValue(state, this) : prop.defVal); //or undefined if defVal is undefined
  6616. if (prop.type == 'separator')
  6617. {
  6618. flipBkg = !flipBkg;
  6619. continue;
  6620. }
  6621. else if (prop.type == 'staticArr') //if dynamic values are needed, a more elegant technique is needed to replace such values
  6622. {
  6623. prop.size = parseInt(state.style[prop.sizeProperty] || properties[prop.sizeProperty].defVal) || 0;
  6624. }
  6625. else if (prop.dependentProps != null)
  6626. {
  6627. var dependentProps = prop.dependentProps;
  6628. var dependentPropsVals = [];
  6629. var dependentPropsDefVal = [];
  6630. for (var i = 0; i < dependentProps.length; i++)
  6631. {
  6632. var propVal = state.style[dependentProps[i]];
  6633. dependentPropsDefVal.push(properties[dependentProps[i]].subDefVal);
  6634. dependentPropsVals.push(propVal != null? propVal.split(',') : []);
  6635. }
  6636. prop.dependentPropsDefVal = dependentPropsDefVal;
  6637. prop.dependentPropsVals = dependentPropsVals;
  6638. }
  6639. grid.appendChild(createPropertyRow(key, pValue, prop, isOdd, flipBkg));
  6640. isOdd = !isOdd;
  6641. }
  6642. for (var i = 0; i < secondLevel.length; i++)
  6643. {
  6644. var prop = secondLevel[i];
  6645. var insertElem = prop.parentRow;
  6646. for (var j = 0; j < prop.values.length; j++)
  6647. {
  6648. //mxUtils.clone failed because of the HTM element, so manual cloning is used
  6649. var iProp = {type: prop.type, parentRow: prop.parentRow, isDeletable: prop.isDeletable, index: j, defVal: prop.defVal, countProperty: prop.countProperty, size: prop.size};
  6650. var arrItem = createPropertyRow(prop.name, prop.values[j], iProp, j % 2 == 0, prop.flipBkg);
  6651. insertAfter(arrItem, insertElem);
  6652. insertElem = arrItem;
  6653. }
  6654. }
  6655. div.appendChild(grid);
  6656. onFold();
  6657. return div;
  6658. };
  6659. /**
  6660. * Creates the buttons for the predefined styles.
  6661. */
  6662. StyleFormatPanel.prototype.addStyles = function(div)
  6663. {
  6664. if (this.defaultColorSchemes != null)
  6665. {
  6666. var ui = this.editorUi;
  6667. var graph = ui.editor.graph;
  6668. var picker = document.createElement('div');
  6669. picker.style.whiteSpace = 'nowrap';
  6670. picker.style.paddingLeft = '24px';
  6671. picker.style.paddingRight = '20px';
  6672. div.style.paddingLeft = '16px';
  6673. div.style.paddingBottom = '6px';
  6674. div.style.position = 'relative';
  6675. div.appendChild(picker);
  6676. var stylenames = ['plain-gray', 'plain-blue', 'plain-green', 'plain-turquoise',
  6677. 'plain-orange', 'plain-yellow', 'plain-red', 'plain-pink', 'plain-purple', 'gray',
  6678. 'blue', 'green', 'turquoise', 'orange', 'yellow', 'red', 'pink', 'purple'];
  6679. // Maximum palettes to switch the switcher
  6680. var maxEntries = 10;
  6681. // Selector
  6682. var switcher = document.createElement('div');
  6683. switcher.style.whiteSpace = 'nowrap';
  6684. switcher.style.position = 'relative';
  6685. switcher.style.textAlign = 'center';
  6686. switcher.style.width = '210px';
  6687. var dots = [];
  6688. for (var i = 0; i < this.defaultColorSchemes.length; i++)
  6689. {
  6690. var dot = document.createElement('div');
  6691. dot.style.display = 'inline-block';
  6692. dot.style.width = '6px';
  6693. dot.style.height = '6px';
  6694. dot.style.marginLeft = '4px';
  6695. dot.style.marginRight = '3px';
  6696. dot.style.borderRadius = '3px';
  6697. dot.style.cursor = 'pointer';
  6698. dot.style.background = 'transparent';
  6699. dot.style.border = '1px solid #b5b6b7';
  6700. (mxUtils.bind(this, function(index)
  6701. {
  6702. mxEvent.addListener(dot, 'click', mxUtils.bind(this, function()
  6703. {
  6704. setScheme(index);
  6705. }));
  6706. }))(i);
  6707. dots.push(dot);
  6708. switcher.appendChild(dot);
  6709. }
  6710. var setScheme = mxUtils.bind(this, function(index)
  6711. {
  6712. if (dots[index] != null)
  6713. {
  6714. if (this.format.currentScheme != null && dots[this.format.currentScheme] != null)
  6715. {
  6716. dots[this.format.currentScheme].style.background = 'transparent';
  6717. }
  6718. this.format.currentScheme = index;
  6719. updateScheme(this.defaultColorSchemes[this.format.currentScheme]);
  6720. dots[this.format.currentScheme].style.background = '#84d7ff';
  6721. }
  6722. });
  6723. var updateScheme = mxUtils.bind(this, function(colorsets)
  6724. {
  6725. var addButton = mxUtils.bind(this, function(colorset)
  6726. {
  6727. var btn = mxUtils.button('', mxUtils.bind(this, function(evt)
  6728. {
  6729. graph.getModel().beginUpdate();
  6730. try
  6731. {
  6732. var cells = ui.getSelectionState().cells;
  6733. for (var i = 0; i < cells.length; i++)
  6734. {
  6735. var style = graph.getModel().getStyle(cells[i]);
  6736. for (var j = 0; j < stylenames.length; j++)
  6737. {
  6738. style = mxUtils.removeStylename(style, stylenames[j]);
  6739. }
  6740. var defaults = (graph.getModel().isVertex(cells[i])) ? graph.defaultVertexStyle : graph.defaultEdgeStyle;
  6741. if (colorset != null)
  6742. {
  6743. if (!mxEvent.isShiftDown(evt))
  6744. {
  6745. if (colorset['fill'] == '')
  6746. {
  6747. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, null);
  6748. }
  6749. else
  6750. {
  6751. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR, colorset['fill'] ||
  6752. mxUtils.getValue(defaults, mxConstants.STYLE_FILLCOLOR, null));
  6753. }
  6754. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR, colorset['gradient'] ||
  6755. mxUtils.getValue(defaults, mxConstants.STYLE_GRADIENTCOLOR, null));
  6756. if (!mxEvent.isControlDown(evt) && (!mxClient.IS_MAC || !mxEvent.isMetaDown(evt)) &&
  6757. graph.getModel().isVertex(cells[i]))
  6758. {
  6759. style = mxUtils.setStyle(style, mxConstants.STYLE_FONTCOLOR, colorset['font'] ||
  6760. mxUtils.getValue(defaults, mxConstants.STYLE_FONTCOLOR, null));
  6761. }
  6762. }
  6763. if (!mxEvent.isAltDown(evt))
  6764. {
  6765. if (colorset['stroke'] == '')
  6766. {
  6767. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, null);
  6768. }
  6769. else
  6770. {
  6771. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR, colorset['stroke'] ||
  6772. mxUtils.getValue(defaults, mxConstants.STYLE_STROKECOLOR, null));
  6773. }
  6774. }
  6775. }
  6776. else
  6777. {
  6778. style = mxUtils.setStyle(style, mxConstants.STYLE_FILLCOLOR,
  6779. mxUtils.getValue(defaults, mxConstants.STYLE_FILLCOLOR, '#ffffff'));
  6780. style = mxUtils.setStyle(style, mxConstants.STYLE_STROKECOLOR,
  6781. mxUtils.getValue(defaults, mxConstants.STYLE_STROKECOLOR, '#000000'));
  6782. style = mxUtils.setStyle(style, mxConstants.STYLE_GRADIENTCOLOR,
  6783. mxUtils.getValue(defaults, mxConstants.STYLE_GRADIENTCOLOR, null));
  6784. if (graph.getModel().isVertex(cells[i]))
  6785. {
  6786. style = mxUtils.setStyle(style, mxConstants.STYLE_FONTCOLOR,
  6787. mxUtils.getValue(defaults, mxConstants.STYLE_FONTCOLOR, null));
  6788. }
  6789. }
  6790. graph.getModel().setStyle(cells[i], style);
  6791. }
  6792. }
  6793. finally
  6794. {
  6795. graph.getModel().endUpdate();
  6796. }
  6797. }));
  6798. btn.className = 'geStyleButton';
  6799. btn.style.width = '36px';
  6800. btn.style.height = (this.defaultColorSchemes.length <= maxEntries) ? '24px' : '30px';
  6801. btn.style.margin = '0px 6px 6px 0px';
  6802. if (colorset != null)
  6803. {
  6804. var b = (Editor.isDarkMode()) ? '2px solid' : '1px solid';
  6805. if (colorset['border'] != null)
  6806. {
  6807. b = colorset['border'];
  6808. }
  6809. if (colorset['gradient'] != null)
  6810. {
  6811. if (mxClient.IS_IE && (document.documentMode < 10))
  6812. {
  6813. btn.style.filter = 'progid:DXImageTransform.Microsoft.Gradient('+
  6814. 'StartColorStr=\'' + colorset['fill'] +
  6815. '\', EndColorStr=\'' + colorset['gradient'] + '\', GradientType=0)';
  6816. }
  6817. else
  6818. {
  6819. btn.style.backgroundImage = 'linear-gradient(' + colorset['fill'] + ' 0px,' +
  6820. colorset['gradient'] + ' 100%)';
  6821. }
  6822. }
  6823. else if (colorset['fill'] == mxConstants.NONE)
  6824. {
  6825. btn.style.background = 'url(\'' + Dialog.prototype.noColorImage + '\')';
  6826. }
  6827. else if (colorset['fill'] == '')
  6828. {
  6829. btn.style.backgroundColor = mxUtils.getValue(graph.defaultVertexStyle,
  6830. mxConstants.STYLE_FILLCOLOR, (Editor.isDarkMode()) ? Editor.darkColor : '#ffffff');
  6831. }
  6832. else
  6833. {
  6834. btn.style.backgroundColor = colorset['fill'] || mxUtils.getValue(graph.defaultVertexStyle,
  6835. mxConstants.STYLE_FILLCOLOR, (Editor.isDarkMode()) ? Editor.darkColor : '#ffffff');
  6836. }
  6837. if (colorset['stroke'] == mxConstants.NONE)
  6838. {
  6839. btn.style.border = b + ' transparent';
  6840. }
  6841. else if (colorset['stroke'] == '')
  6842. {
  6843. btn.style.border = b + ' ' + mxUtils.getValue(graph.defaultVertexStyle,
  6844. mxConstants.STYLE_STROKECOLOR, (!Editor.isDarkMode()) ? Editor.darkColor : '#ffffff');
  6845. }
  6846. else
  6847. {
  6848. btn.style.border = b + ' ' + (colorset['stroke'] || mxUtils.getValue(graph.defaultVertexStyle,
  6849. mxConstants.STYLE_STROKECOLOR, (!Editor.isDarkMode()) ? Editor.darkColor : '#ffffff'));
  6850. }
  6851. if (colorset['title'] != null)
  6852. {
  6853. btn.setAttribute('title', colorset['title']);
  6854. }
  6855. }
  6856. else
  6857. {
  6858. var bg = mxUtils.getValue(graph.defaultVertexStyle, mxConstants.STYLE_FILLCOLOR, '#ffffff');
  6859. var bd = mxUtils.getValue(graph.defaultVertexStyle, mxConstants.STYLE_STROKECOLOR, '#000000');
  6860. btn.style.backgroundColor = bg;
  6861. btn.style.border = '1px solid ' + bd;
  6862. }
  6863. btn.style.borderRadius = '0';
  6864. picker.appendChild(btn);
  6865. });
  6866. picker.innerText = '';
  6867. for (var i = 0; i < colorsets.length; i++)
  6868. {
  6869. if (i > 0 && mxUtils.mod(i, 4) == 0)
  6870. {
  6871. mxUtils.br(picker);
  6872. }
  6873. addButton(colorsets[i]);
  6874. }
  6875. });
  6876. if (this.format.currentScheme == null)
  6877. {
  6878. setScheme(Math.min(dots.length - 1, Editor.isDarkMode()
  6879. ? 1 : (urlParams['sketch'] == '1' ? 5 : 0)));
  6880. }
  6881. else
  6882. {
  6883. setScheme(this.format.currentScheme);
  6884. }
  6885. var bottom = (this.defaultColorSchemes.length <= maxEntries) ? 28 : 8;
  6886. var left = document.createElement('div');
  6887. left.style.cssText = 'position:absolute;left:10px;top:8px;bottom:' + bottom + 'px;width:20px;margin:4px;opacity:0.5;' +
  6888. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ4eHh3d3d1dXVxcXF2dnZ2dnZ2dnZxcXF2dnYmb3w1AAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADRJREFUCNdjwACMAmBKaiGYs2oJmLPKAZ3DabU8AMRTXpUKopislqFyVzCAuUZgikkBZjoAcMYLnp53P/UAAAAASUVORK5CYII=);';
  6889. mxEvent.addListener(left, 'click', mxUtils.bind(this, function()
  6890. {
  6891. setScheme(mxUtils.mod(this.format.currentScheme - 1, this.defaultColorSchemes.length));
  6892. }));
  6893. var right = document.createElement('div');
  6894. right.style.cssText = 'position:absolute;left:202px;top:8px;bottom:' + bottom + 'px;width:20px;margin:4px;opacity:0.5;' +
  6895. 'background-repeat:no-repeat;background-position:center center;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAQBAMAAADQT4M0AAAAIVBMVEUAAAB2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnYBuwCcAAAACnRSTlMAfCTkhhvb7cQSPH2JPgAAADZJREFUCNdjQAOMAmBKaiGY8loF5rKswsZlrVo8AUiFrTICcbIWK8A5DF1gDoMymMPApIAwHwCS0Qx/U7qCBQAAAABJRU5ErkJggg==);';
  6896. if (this.defaultColorSchemes.length > 1)
  6897. {
  6898. div.appendChild(left);
  6899. div.appendChild(right);
  6900. }
  6901. mxEvent.addListener(right, 'click', mxUtils.bind(this, function()
  6902. {
  6903. setScheme(mxUtils.mod(this.format.currentScheme + 1, this.defaultColorSchemes.length));
  6904. }));
  6905. // Hover state
  6906. function addHoverState(elt)
  6907. {
  6908. mxEvent.addListener(elt, 'mouseenter', function()
  6909. {
  6910. elt.style.opacity = '1';
  6911. });
  6912. mxEvent.addListener(elt, 'mouseleave', function()
  6913. {
  6914. elt.style.opacity = '0.5';
  6915. });
  6916. };
  6917. addHoverState(left);
  6918. addHoverState(right);
  6919. updateScheme(this.defaultColorSchemes[this.format.currentScheme]);
  6920. if (this.defaultColorSchemes.length <= maxEntries)
  6921. {
  6922. div.appendChild(switcher);
  6923. }
  6924. }
  6925. return div;
  6926. };