Format.js 144 KB

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