Format.js 144 KB

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