Format.js 163 KB

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