Format.js 189 KB

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