Format.js 204 KB

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