Format.js 140 KB

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