Format.js 192 KB

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