Format.js 139 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718
  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'], 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. this.container.appendChild(this.addAngle(this.createPanel()));
  1208. if (!ss.containsLabel && ss.edges.length == 0)
  1209. {
  1210. this.container.appendChild(this.addFlip(this.createPanel()));
  1211. }
  1212. if (ss.vertices.length > 1)
  1213. {
  1214. this.container.appendChild(this.addAlign(this.createPanel()));
  1215. this.container.appendChild(this.addDistribute(this.createPanel()));
  1216. }
  1217. this.container.appendChild(this.addGroupOps(this.createPanel()));
  1218. };
  1219. /**
  1220. *
  1221. */
  1222. ArrangePanel.prototype.addLayerOps = function(div)
  1223. {
  1224. var ui = this.editorUi;
  1225. var btn = mxUtils.button(mxResources.get('toFront'), function(evt)
  1226. {
  1227. ui.actions.get('toFront').funct();
  1228. })
  1229. btn.setAttribute('title', mxResources.get('toFront') + ' (' + this.editorUi.actions.get('toFront').shortcut + ')');
  1230. btn.style.width = '100px';
  1231. btn.style.marginRight = '2px';
  1232. div.appendChild(btn);
  1233. var btn = mxUtils.button(mxResources.get('toBack'), function(evt)
  1234. {
  1235. ui.actions.get('toBack').funct();
  1236. })
  1237. btn.setAttribute('title', mxResources.get('toBack') + ' (' + this.editorUi.actions.get('toBack').shortcut + ')');
  1238. btn.style.width = '100px';
  1239. div.appendChild(btn);
  1240. return div;
  1241. };
  1242. /**
  1243. *
  1244. */
  1245. ArrangePanel.prototype.addGroupOps = function(div)
  1246. {
  1247. var ui = this.editorUi;
  1248. var graph = ui.editor.graph;
  1249. var cell = graph.getSelectionCell();
  1250. var ss = this.format.getSelectionState();
  1251. var count = 0;
  1252. div.style.paddingTop = '8px';
  1253. div.style.paddingBottom = '6px';
  1254. if (graph.getSelectionCount() > 1)
  1255. {
  1256. btn = mxUtils.button(mxResources.get('group'), function(evt)
  1257. {
  1258. ui.actions.get('group').funct();
  1259. })
  1260. btn.setAttribute('title', mxResources.get('group') + ' (' + this.editorUi.actions.get('group').shortcut + ')');
  1261. btn.style.width = '202px';
  1262. btn.style.marginBottom = '2px';
  1263. div.appendChild(btn);
  1264. count++;
  1265. }
  1266. else if (graph.getSelectionCount() == 1 && !graph.getModel().isEdge(cell) && !graph.isSwimlane(cell) &&
  1267. graph.getModel().getChildCount(cell) > 0)
  1268. {
  1269. btn = mxUtils.button(mxResources.get('ungroup'), function(evt)
  1270. {
  1271. ui.actions.get('ungroup').funct();
  1272. })
  1273. btn.setAttribute('title', mxResources.get('ungroup') + ' (' + this.editorUi.actions.get('ungroup').shortcut + ')');
  1274. btn.style.width = '202px';
  1275. btn.style.marginBottom = '2px';
  1276. div.appendChild(btn);
  1277. count++;
  1278. }
  1279. if (graph.getSelectionCount() == 1 && graph.getModel().isVertex(cell) &&
  1280. graph.getModel().isVertex(graph.getModel().getParent(cell)))
  1281. {
  1282. if (count > 0)
  1283. {
  1284. mxUtils.br(div);
  1285. }
  1286. btn = mxUtils.button(mxResources.get('removeFromGroup'), function(evt)
  1287. {
  1288. ui.actions.get('removeFromGroup').funct();
  1289. })
  1290. btn.setAttribute('title', mxResources.get('removeFromGroup'));
  1291. btn.style.width = '202px';
  1292. btn.style.marginBottom = '2px';
  1293. div.appendChild(btn);
  1294. count++;
  1295. }
  1296. else if (ss.edges.length > 0)
  1297. {
  1298. if (count > 0)
  1299. {
  1300. mxUtils.br(div);
  1301. }
  1302. btn = mxUtils.button(mxResources.get('clearWaypoints'), mxUtils.bind(this, function(evt)
  1303. {
  1304. this.editorUi.actions.get('clearWaypoints').funct();
  1305. }));
  1306. btn.setAttribute('title', mxResources.get('clearWaypoints'));
  1307. btn.style.width = '202px';
  1308. btn.style.marginBottom = '2px';
  1309. div.appendChild(btn);
  1310. count++;
  1311. }
  1312. if (graph.getSelectionCount() == 1)
  1313. {
  1314. if (count > 0)
  1315. {
  1316. mxUtils.br(div);
  1317. }
  1318. btn = mxUtils.button(mxResources.get('editData'), mxUtils.bind(this, function(evt)
  1319. {
  1320. this.editorUi.actions.get('editData').funct();
  1321. }));
  1322. btn.setAttribute('title', mxResources.get('editData') + ' (' + this.editorUi.actions.get('editData').shortcut + ')');
  1323. btn.style.width = '100px';
  1324. btn.style.marginBottom = '2px';
  1325. div.appendChild(btn);
  1326. count++;
  1327. btn = mxUtils.button(mxResources.get('editLink'), mxUtils.bind(this, function(evt)
  1328. {
  1329. this.editorUi.actions.get('editLink').funct();
  1330. }));
  1331. btn.setAttribute('title', mxResources.get('editLink'));
  1332. btn.style.width = '100px';
  1333. btn.style.marginLeft = '2px';
  1334. btn.style.marginBottom = '2px';
  1335. div.appendChild(btn);
  1336. count++;
  1337. }
  1338. if (count == 0)
  1339. {
  1340. div.style.display = 'none';
  1341. }
  1342. return div;
  1343. };
  1344. /**
  1345. *
  1346. */
  1347. ArrangePanel.prototype.addAlign = function(div)
  1348. {
  1349. var graph = this.editorUi.editor.graph;
  1350. div.style.paddingTop = '6px';
  1351. div.style.paddingBottom = '12px';
  1352. div.appendChild(this.createTitle(mxResources.get('align')));
  1353. var stylePanel = document.createElement('div');
  1354. stylePanel.style.position = 'relative';
  1355. stylePanel.style.paddingLeft = '0px';
  1356. stylePanel.style.borderWidth = '0px';
  1357. stylePanel.className = 'geToolbarContainer';
  1358. if (mxClient.IS_QUIRKS)
  1359. {
  1360. div.style.height = '60px';
  1361. }
  1362. var left = this.editorUi.toolbar.addButton('geSprite-alignleft', mxResources.get('left'),
  1363. function() { graph.alignCells(mxConstants.ALIGN_LEFT); }, stylePanel);
  1364. var center = this.editorUi.toolbar.addButton('geSprite-aligncenter', mxResources.get('center'),
  1365. function() { graph.alignCells(mxConstants.ALIGN_CENTER); }, stylePanel);
  1366. var right = this.editorUi.toolbar.addButton('geSprite-alignright', mxResources.get('right'),
  1367. function() { graph.alignCells(mxConstants.ALIGN_RIGHT); }, stylePanel);
  1368. var top = this.editorUi.toolbar.addButton('geSprite-aligntop', mxResources.get('top'),
  1369. function() { graph.alignCells(mxConstants.ALIGN_TOP); }, stylePanel);
  1370. var middle = this.editorUi.toolbar.addButton('geSprite-alignmiddle', mxResources.get('middle'),
  1371. function() { graph.alignCells(mxConstants.ALIGN_MIDDLE); }, stylePanel);
  1372. var bottom = this.editorUi.toolbar.addButton('geSprite-alignbottom', mxResources.get('bottom'),
  1373. function() { graph.alignCells(mxConstants.ALIGN_BOTTOM); }, stylePanel);
  1374. this.styleButtons([left, center, right, top, middle, bottom]);
  1375. right.style.marginRight = '6px';
  1376. div.appendChild(stylePanel);
  1377. return div;
  1378. };
  1379. /**
  1380. *
  1381. */
  1382. ArrangePanel.prototype.addFlip = function(div)
  1383. {
  1384. var ui = this.editorUi;
  1385. var editor = ui.editor;
  1386. var graph = editor.graph;
  1387. div.style.paddingTop = '6px';
  1388. div.style.paddingBottom = '10px';
  1389. var span = document.createElement('div');
  1390. span.style.marginTop = '2px';
  1391. span.style.marginBottom = '8px';
  1392. span.style.fontWeight = 'bold';
  1393. mxUtils.write(span, mxResources.get('flip'));
  1394. div.appendChild(span);
  1395. var btn = mxUtils.button(mxResources.get('horizontal'), function(evt)
  1396. {
  1397. graph.toggleCellStyles(mxConstants.STYLE_FLIPH, false);
  1398. })
  1399. btn.setAttribute('title', mxResources.get('horizontal'));
  1400. btn.style.width = '100px';
  1401. btn.style.marginRight = '2px';
  1402. div.appendChild(btn);
  1403. var btn = mxUtils.button(mxResources.get('vertical'), function(evt)
  1404. {
  1405. graph.toggleCellStyles(mxConstants.STYLE_FLIPV, false);
  1406. })
  1407. btn.setAttribute('title', mxResources.get('vertical'));
  1408. btn.style.width = '100px';
  1409. div.appendChild(btn);
  1410. return div;
  1411. };
  1412. /**
  1413. *
  1414. */
  1415. ArrangePanel.prototype.addDistribute = function(div)
  1416. {
  1417. var ui = this.editorUi;
  1418. var editor = ui.editor;
  1419. var graph = editor.graph;
  1420. div.style.paddingTop = '6px';
  1421. div.style.paddingBottom = '12px';
  1422. div.appendChild(this.createTitle(mxResources.get('distribute')));
  1423. var btn = mxUtils.button(mxResources.get('horizontal'), function(evt)
  1424. {
  1425. graph.distributeCells(true);
  1426. })
  1427. btn.setAttribute('title', mxResources.get('horizontal'));
  1428. btn.style.width = '100px';
  1429. btn.style.marginRight = '2px';
  1430. div.appendChild(btn);
  1431. var btn = mxUtils.button(mxResources.get('vertical'), function(evt)
  1432. {
  1433. graph.distributeCells(false);
  1434. })
  1435. btn.setAttribute('title', mxResources.get('vertical'));
  1436. btn.style.width = '100px';
  1437. div.appendChild(btn);
  1438. return div;
  1439. };
  1440. /**
  1441. *
  1442. */
  1443. ArrangePanel.prototype.addAngle = function(div)
  1444. {
  1445. var ui = this.editorUi;
  1446. var editor = ui.editor;
  1447. var graph = editor.graph;
  1448. var ss = this.format.getSelectionState();
  1449. div.style.paddingBottom = '28px';
  1450. var span = document.createElement('div');
  1451. span.style.position = 'absolute';
  1452. span.style.width = '70px';
  1453. span.style.marginTop = '0px';
  1454. span.style.fontWeight = 'bold';
  1455. var input = null;
  1456. var update = null;
  1457. if (ss.edges.length == 0)
  1458. {
  1459. mxUtils.write(span, mxResources.get('angle'));
  1460. div.appendChild(span);
  1461. input = this.addUnitInput(div, '°', 84, 44, function()
  1462. {
  1463. update.apply(this, arguments);
  1464. });
  1465. }
  1466. if (!ss.containsLabel)
  1467. {
  1468. var btn = mxUtils.button(mxResources.get('turn'), function(evt)
  1469. {
  1470. ui.actions.get('turn').funct();
  1471. })
  1472. btn.setAttribute('title', mxResources.get('turn') + ' (' + this.editorUi.actions.get('turn').shortcut + ')');
  1473. btn.style.position = 'absolute';
  1474. btn.style.marginTop = '-2px';
  1475. btn.style.right = '20px';
  1476. btn.style.width = '61px';
  1477. div.appendChild(btn);
  1478. }
  1479. if (input == null)
  1480. {
  1481. btn.style.right = '';
  1482. btn.style.width = '202px';
  1483. }
  1484. else
  1485. {
  1486. var listener = mxUtils.bind(this, function(sender, evt, force)
  1487. {
  1488. if (force || document.activeElement != input)
  1489. {
  1490. ss = this.format.getSelectionState();
  1491. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_ROTATION, 0));
  1492. input.value = (isNaN(tmp)) ? '' : tmp + '°';
  1493. }
  1494. });
  1495. update = this.installInputHandler(input, mxConstants.STYLE_ROTATION, 0, 0, 360, '°', null, true);
  1496. this.addKeyHandler(input, listener);
  1497. graph.getModel().addListener(mxEvent.CHANGE, listener);
  1498. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  1499. listener();
  1500. }
  1501. return div;
  1502. };
  1503. /**
  1504. *
  1505. */
  1506. ArrangePanel.prototype.addGeometry = function(container)
  1507. {
  1508. var ui = this.editorUi;
  1509. var graph = ui.editor.graph;
  1510. var rect = this.format.getSelectionState();
  1511. var div = this.createPanel();
  1512. div.style.paddingBottom = '8px';
  1513. var span = document.createElement('div');
  1514. span.style.position = 'absolute';
  1515. span.style.width = '50px';
  1516. span.style.marginTop = '0px';
  1517. span.style.fontWeight = 'bold';
  1518. mxUtils.write(span, mxResources.get('size'));
  1519. div.appendChild(span);
  1520. var widthUpdate, heightUpdate, leftUpdate, topUpdate;
  1521. var width = this.addUnitInput(div, 'pt', 84, 44, function()
  1522. {
  1523. widthUpdate.apply(this, arguments);
  1524. });
  1525. var height = this.addUnitInput(div, 'pt', 20, 44, function()
  1526. {
  1527. heightUpdate.apply(this, arguments);
  1528. });
  1529. var autosizeBtn = document.createElement('div');
  1530. autosizeBtn.className = 'geSprite geSprite-fit';
  1531. autosizeBtn.setAttribute('title', mxResources.get('autosize') + ' (' + this.editorUi.actions.get('autosize').shortcut + ')');
  1532. autosizeBtn.style.position = 'relative';
  1533. autosizeBtn.style.cursor = 'pointer';
  1534. autosizeBtn.style.marginTop = '-3px';
  1535. autosizeBtn.style.border = '0px';
  1536. autosizeBtn.style.left = '52px';
  1537. mxUtils.setOpacity(autosizeBtn, 50);
  1538. mxEvent.addListener(autosizeBtn, 'mouseenter', function()
  1539. {
  1540. mxUtils.setOpacity(autosizeBtn, 100);
  1541. });
  1542. mxEvent.addListener(autosizeBtn, 'mouseleave', function()
  1543. {
  1544. mxUtils.setOpacity(autosizeBtn, 50);
  1545. });
  1546. mxEvent.addListener(autosizeBtn, 'click', function()
  1547. {
  1548. ui.actions.get('autosize').funct();
  1549. });
  1550. div.appendChild(autosizeBtn);
  1551. this.addLabel(div, mxResources.get('width'), 84);
  1552. this.addLabel(div, mxResources.get('height'), 20);
  1553. mxUtils.br(div);
  1554. var wrapper = document.createElement('div');
  1555. wrapper.style.paddingTop = '8px';
  1556. wrapper.style.paddingRight = '20px';
  1557. wrapper.style.whiteSpace = 'nowrap';
  1558. wrapper.style.textAlign = 'right';
  1559. var opt = this.createCellOption(mxResources.get('constrainProportions'),
  1560. mxConstants.STYLE_ASPECT, null, 'fixed', 'null');
  1561. opt.style.width = '100%';
  1562. wrapper.appendChild(opt);
  1563. div.appendChild(wrapper);
  1564. this.addKeyHandler(width, listener);
  1565. this.addKeyHandler(height, listener);
  1566. widthUpdate = this.addGeometryHandler(width, function(geo, value)
  1567. {
  1568. if (geo.width > 0)
  1569. {
  1570. geo.width = Math.max(1, value);
  1571. }
  1572. });
  1573. heightUpdate = this.addGeometryHandler(height, function(geo, value)
  1574. {
  1575. if (geo.height > 0)
  1576. {
  1577. geo.height = Math.max(1, value);
  1578. }
  1579. });
  1580. container.appendChild(div);
  1581. var div2 = this.createPanel();
  1582. div2.style.paddingBottom = '30px';
  1583. var span = document.createElement('div');
  1584. span.style.position = 'absolute';
  1585. span.style.width = '70px';
  1586. span.style.marginTop = '0px';
  1587. span.style.fontWeight = 'bold';
  1588. mxUtils.write(span, mxResources.get('position'));
  1589. div2.appendChild(span);
  1590. var left = this.addUnitInput(div2, 'pt', 84, 44, function()
  1591. {
  1592. leftUpdate.apply(this, arguments);
  1593. });
  1594. var top = this.addUnitInput(div2, 'pt', 20, 44, function()
  1595. {
  1596. topUpdate.apply(this, arguments);
  1597. });
  1598. mxUtils.br(div2);
  1599. this.addLabel(div2, mxResources.get('left'), 84);
  1600. this.addLabel(div2, mxResources.get('top'), 20);
  1601. var listener = mxUtils.bind(this, function(sender, evt, force)
  1602. {
  1603. rect = this.format.getSelectionState();
  1604. if (!rect.containsLabel && rect.vertices.length == graph.getSelectionCount() &&
  1605. rect.width != null && rect.height != null)
  1606. {
  1607. div.style.display = '';
  1608. if (force || document.activeElement != width)
  1609. {
  1610. width.value = rect.width + ((rect.width == '') ? '' : ' pt');
  1611. }
  1612. if (force || document.activeElement != height)
  1613. {
  1614. height.value = rect.height + ((rect.height == '') ? '' : ' pt');
  1615. }
  1616. }
  1617. else
  1618. {
  1619. div.style.display = 'none';
  1620. }
  1621. if (rect.vertices.length == graph.getSelectionCount() &&
  1622. rect.x != null && rect.y != null)
  1623. {
  1624. div2.style.display = '';
  1625. if (force || document.activeElement != left)
  1626. {
  1627. left.value = rect.x + ((rect.x == '') ? '' : ' pt');
  1628. }
  1629. if (force || document.activeElement != top)
  1630. {
  1631. top.value = rect.y + ((rect.y == '') ? '' : ' pt');
  1632. }
  1633. }
  1634. else
  1635. {
  1636. div2.style.display = 'none';
  1637. }
  1638. });
  1639. this.addKeyHandler(left, listener);
  1640. this.addKeyHandler(top, listener);
  1641. graph.getModel().addListener(mxEvent.CHANGE, listener);
  1642. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  1643. listener();
  1644. leftUpdate = this.addGeometryHandler(left, function(geo, value)
  1645. {
  1646. if (geo.relative)
  1647. {
  1648. geo.offset.x = value;
  1649. }
  1650. else
  1651. {
  1652. geo.x = value;
  1653. }
  1654. });
  1655. topUpdate = this.addGeometryHandler(top, function(geo, value)
  1656. {
  1657. if (geo.relative)
  1658. {
  1659. geo.offset.y = value;
  1660. }
  1661. else
  1662. {
  1663. geo.y = value;
  1664. }
  1665. });
  1666. container.appendChild(div2);
  1667. };
  1668. /**
  1669. *
  1670. */
  1671. ArrangePanel.prototype.addGeometryHandler = function(input, fn)
  1672. {
  1673. var ui = this.editorUi;
  1674. var graph = ui.editor.graph;
  1675. var initialValue = null;
  1676. function update(evt)
  1677. {
  1678. if (input.value != '')
  1679. {
  1680. var value = parseFloat(input.value);
  1681. if (value != initialValue)
  1682. {
  1683. graph.getModel().beginUpdate();
  1684. try
  1685. {
  1686. var cells = graph.getSelectionCells();
  1687. for (var i = 0; i < cells.length; i++)
  1688. {
  1689. if (graph.getModel().isVertex(cells[i]))
  1690. {
  1691. var geo = graph.getCellGeometry(cells[i]);
  1692. if (geo != null)
  1693. {
  1694. geo = geo.clone();
  1695. fn(geo, value);
  1696. graph.getModel().setGeometry(cells[i], geo);
  1697. }
  1698. }
  1699. }
  1700. }
  1701. finally
  1702. {
  1703. graph.getModel().endUpdate();
  1704. }
  1705. initialValue = value;
  1706. input.value = value + ' pt';
  1707. }
  1708. else if (isNaN(value))
  1709. {
  1710. input.value = initialValue + ' pt';
  1711. }
  1712. }
  1713. mxEvent.consume(evt);
  1714. };
  1715. mxEvent.addListener(input, 'blur', update);
  1716. mxEvent.addListener(input, 'change', update);
  1717. mxEvent.addListener(input, 'focus', function()
  1718. {
  1719. initialValue = input.value;
  1720. });
  1721. return update;
  1722. };
  1723. /**
  1724. *
  1725. */
  1726. ArrangePanel.prototype.addEdgeGeometry = function(container)
  1727. {
  1728. var ui = this.editorUi;
  1729. var graph = ui.editor.graph;
  1730. var rect = this.format.getSelectionState();
  1731. var div = this.createPanel();
  1732. var span = document.createElement('div');
  1733. span.style.position = 'absolute';
  1734. span.style.width = '70px';
  1735. span.style.marginTop = '0px';
  1736. span.style.fontWeight = 'bold';
  1737. mxUtils.write(span, mxResources.get('width'));
  1738. div.appendChild(span);
  1739. var widthUpdate, leftUpdate, topUpdate;
  1740. var width = this.addUnitInput(div, 'pt', 20, 44, function()
  1741. {
  1742. widthUpdate.apply(this, arguments);
  1743. });
  1744. mxUtils.br(div);
  1745. this.addKeyHandler(width, listener);
  1746. function widthUpdate(evt)
  1747. {
  1748. // Maximum stroke width is 999
  1749. var value = parseInt(width.value);
  1750. value = Math.min(999, Math.max(1, (isNaN(value)) ? 1 : value));
  1751. if (value != mxUtils.getValue(rect.style, 'width', mxCellRenderer.prototype.defaultShapes['flexArrow'].prototype.defaultWidth))
  1752. {
  1753. graph.setCellStyles('width', value, graph.getSelectionCells());
  1754. ui.fireEvent(new mxEventObject('styleChanged', 'keys', ['width'],
  1755. 'values', [value], 'cells', graph.getSelectionCells()));
  1756. }
  1757. width.value = value + ' pt';
  1758. mxEvent.consume(evt);
  1759. };
  1760. mxEvent.addListener(width, 'blur', widthUpdate);
  1761. mxEvent.addListener(width, 'change', widthUpdate);
  1762. container.appendChild(div);
  1763. var listener = mxUtils.bind(this, function(sender, evt, force)
  1764. {
  1765. rect = this.format.getSelectionState();
  1766. if (rect.style.shape == 'link' || rect.style.shape == 'flexArrow')
  1767. {
  1768. div.style.display = '';
  1769. if (force || document.activeElement != width)
  1770. {
  1771. var value = mxUtils.getValue(rect.style, 'width',
  1772. mxCellRenderer.prototype.defaultShapes['flexArrow'].prototype.defaultWidth);
  1773. width.value = value + ' pt';
  1774. }
  1775. }
  1776. else
  1777. {
  1778. div.style.display = 'none';
  1779. }
  1780. });
  1781. graph.getModel().addListener(mxEvent.CHANGE, listener);
  1782. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  1783. listener();
  1784. };
  1785. /**
  1786. * Adds the label menu items to the given menu and parent.
  1787. */
  1788. TextFormatPanel = function(format, editorUi, container)
  1789. {
  1790. BaseFormatPanel.call(this, format, editorUi, container);
  1791. this.init();
  1792. };
  1793. mxUtils.extend(TextFormatPanel, BaseFormatPanel);
  1794. /**
  1795. * Adds the label menu items to the given menu and parent.
  1796. */
  1797. TextFormatPanel.prototype.init = function()
  1798. {
  1799. this.container.style.borderBottom = 'none';
  1800. this.addFont(this.container);
  1801. };
  1802. /**
  1803. * Adds the label menu items to the given menu and parent.
  1804. */
  1805. TextFormatPanel.prototype.addFont = function(container)
  1806. {
  1807. var ui = this.editorUi;
  1808. var editor = ui.editor;
  1809. var graph = editor.graph;
  1810. var ss = this.format.getSelectionState();
  1811. var title = this.createTitle(mxResources.get('font'));
  1812. title.style.paddingLeft = '18px';
  1813. title.style.paddingTop = '10px';
  1814. title.style.paddingBottom = '6px';
  1815. container.appendChild(title);
  1816. var stylePanel = this.createPanel();
  1817. stylePanel.style.paddingTop = '2px';
  1818. stylePanel.style.paddingBottom = '2px';
  1819. stylePanel.style.position = 'relative';
  1820. stylePanel.style.marginLeft = '-2px';
  1821. stylePanel.style.borderWidth = '0px';
  1822. stylePanel.className = 'geToolbarContainer';
  1823. if (mxClient.IS_QUIRKS)
  1824. {
  1825. stylePanel.style.display = 'block';
  1826. }
  1827. if (graph.cellEditor.isContentEditing())
  1828. {
  1829. var cssPanel = stylePanel.cloneNode();
  1830. var cssMenu = this.editorUi.toolbar.addMenu(mxResources.get('style'),
  1831. mxResources.get('style'), true, 'formatBlock', cssPanel);
  1832. cssMenu.style.color = 'rgb(112, 112, 112)';
  1833. cssMenu.style.whiteSpace = 'nowrap';
  1834. cssMenu.style.overflow = 'hidden';
  1835. cssMenu.style.margin = '0px';
  1836. this.addArrow(cssMenu);
  1837. cssMenu.style.width = '192px';
  1838. cssMenu.style.height = '15px';
  1839. var arrow = cssMenu.getElementsByTagName('div')[0];
  1840. arrow.style.cssFloat = 'right';
  1841. container.appendChild(cssPanel);
  1842. }
  1843. container.appendChild(stylePanel);
  1844. var colorPanel = this.createPanel();
  1845. colorPanel.style.marginTop = '8px';
  1846. colorPanel.style.borderTop = '1px solid #c0c0c0';
  1847. colorPanel.style.paddingTop = '6px';
  1848. colorPanel.style.paddingBottom = '6px';
  1849. var fontMenu = this.editorUi.toolbar.addMenu('Helvetica', mxResources.get('fontFamily'), true, 'fontFamily', stylePanel);
  1850. fontMenu.style.color = 'rgb(112, 112, 112)';
  1851. fontMenu.style.whiteSpace = 'nowrap';
  1852. fontMenu.style.overflow = 'hidden';
  1853. fontMenu.style.margin = '0px';
  1854. this.addArrow(fontMenu);
  1855. fontMenu.style.width = '192px';
  1856. fontMenu.style.height = '15px';
  1857. // Workaround for offset in FF
  1858. if (mxClient.IS_FF)
  1859. {
  1860. fontMenu.getElementsByTagName('div')[0].style.marginTop = '-18px';
  1861. }
  1862. var stylePanel2 = stylePanel.cloneNode(false);
  1863. stylePanel2.style.marginLeft = '-3px';
  1864. var fontStyleItems = this.editorUi.toolbar.addItems(['bold', 'italic', 'underline'], stylePanel2, true);
  1865. fontStyleItems[0].setAttribute('title', mxResources.get('bold') + ' (' + this.editorUi.actions.get('bold').shortcut + ')');
  1866. fontStyleItems[1].setAttribute('title', mxResources.get('italic') + ' (' + this.editorUi.actions.get('italic').shortcut + ')');
  1867. fontStyleItems[2].setAttribute('title', mxResources.get('underline') + ' (' + this.editorUi.actions.get('underline').shortcut + ')');
  1868. var verticalItem = this.editorUi.toolbar.addItems(['vertical'], stylePanel2, true)[0];
  1869. if (mxClient.IS_QUIRKS)
  1870. {
  1871. mxUtils.br(container);
  1872. }
  1873. container.appendChild(stylePanel2);
  1874. this.styleButtons(fontStyleItems);
  1875. this.styleButtons([verticalItem]);
  1876. var stylePanel3 = stylePanel.cloneNode(false);
  1877. stylePanel3.style.marginLeft = '-3px';
  1878. stylePanel3.style.paddingBottom = '0px';
  1879. var left = this.editorUi.toolbar.addButton('geSprite-left', mxResources.get('left'),
  1880. (graph.cellEditor.isContentEditing()) ?
  1881. function()
  1882. {
  1883. document.execCommand('justifyleft', false, null);
  1884. } : this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_ALIGN], [mxConstants.ALIGN_LEFT]), stylePanel3);
  1885. var center = this.editorUi.toolbar.addButton('geSprite-center', mxResources.get('center'),
  1886. (graph.cellEditor.isContentEditing()) ?
  1887. function()
  1888. {
  1889. document.execCommand('justifycenter', false, null);
  1890. } : this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_ALIGN], [mxConstants.ALIGN_CENTER]), stylePanel3);
  1891. var right = this.editorUi.toolbar.addButton('geSprite-right', mxResources.get('right'),
  1892. (graph.cellEditor.isContentEditing()) ?
  1893. function()
  1894. {
  1895. document.execCommand('justifyright', false, null);
  1896. } : this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_ALIGN], [mxConstants.ALIGN_RIGHT]), stylePanel3);
  1897. this.styleButtons([left, center, right]);
  1898. if (graph.cellEditor.isContentEditing())
  1899. {
  1900. var clear = this.editorUi.toolbar.addButton('geSprite-removeformat', mxResources.get('removeFormat'),
  1901. function()
  1902. {
  1903. document.execCommand('removeformat', false, null);
  1904. }, stylePanel2);
  1905. this.styleButtons([clear]);
  1906. }
  1907. var top = this.editorUi.toolbar.addButton('geSprite-top', mxResources.get('top'),
  1908. this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_VERTICAL_ALIGN], [mxConstants.ALIGN_TOP]), stylePanel3);
  1909. var middle = this.editorUi.toolbar.addButton('geSprite-middle', mxResources.get('middle'),
  1910. this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_VERTICAL_ALIGN], [mxConstants.ALIGN_MIDDLE]), stylePanel3);
  1911. var bottom = this.editorUi.toolbar.addButton('geSprite-bottom', mxResources.get('bottom'),
  1912. this.editorUi.menus.createStyleChangeFunction([mxConstants.STYLE_VERTICAL_ALIGN], [mxConstants.ALIGN_BOTTOM]), stylePanel3);
  1913. this.styleButtons([top, middle, bottom]);
  1914. if (mxClient.IS_QUIRKS)
  1915. {
  1916. mxUtils.br(container);
  1917. }
  1918. container.appendChild(stylePanel3);
  1919. // Hack for updating UI state below based on current text selection
  1920. // currentTable is the current selected DOM table updated below
  1921. var sub, sup, full, tableWrapper, currentTable, tableCell, tableRow;
  1922. if (graph.cellEditor.isContentEditing())
  1923. {
  1924. top.style.display = 'none';
  1925. middle.style.display = 'none';
  1926. bottom.style.display = 'none';
  1927. verticalItem.style.display = 'none';
  1928. full = this.editorUi.toolbar.addButton('geSprite-justifyfull', null,
  1929. function()
  1930. {
  1931. document.execCommand('justifyfull', false, null);
  1932. }, stylePanel3);
  1933. this.styleButtons([full,
  1934. sub = this.editorUi.toolbar.addButton('geSprite-subscript', mxResources.get('subscript') + ' (Ctrl+,)',
  1935. function()
  1936. {
  1937. document.execCommand('subscript', false, null);
  1938. }, stylePanel3), sup = this.editorUi.toolbar.addButton('geSprite-superscript', mxResources.get('superscript') + ' (Ctrl+.)',
  1939. function()
  1940. {
  1941. document.execCommand('superscript', false, null);
  1942. }, stylePanel3)]);
  1943. full.style.marginRight = '9px';
  1944. var tmp = stylePanel3.cloneNode(false);
  1945. tmp.style.paddingTop = '4px';
  1946. var btns = [this.editorUi.toolbar.addButton('geSprite-orderedlist', mxResources.get('numberedList'),
  1947. function()
  1948. {
  1949. document.execCommand('insertorderedlist', false, null);
  1950. }, tmp),
  1951. this.editorUi.toolbar.addButton('geSprite-unorderedlist', mxResources.get('bulletedList'),
  1952. function()
  1953. {
  1954. document.execCommand('insertunorderedlist', false, null);
  1955. }, tmp),
  1956. this.editorUi.toolbar.addButton('geSprite-outdent', mxResources.get('decreaseIndent'),
  1957. function()
  1958. {
  1959. document.execCommand('outdent', false, null);
  1960. }, tmp),
  1961. this.editorUi.toolbar.addButton('geSprite-indent', mxResources.get('increaseIndent'),
  1962. function()
  1963. {
  1964. document.execCommand('indent', false, null);
  1965. }, tmp),
  1966. this.editorUi.toolbar.addButton('geSprite-code', mxResources.get('html'),
  1967. function()
  1968. {
  1969. graph.cellEditor.toggleViewMode();
  1970. }, tmp)];
  1971. this.styleButtons(btns);
  1972. btns[btns.length - 1].style.marginLeft = '9px';
  1973. if (mxClient.IS_QUIRKS)
  1974. {
  1975. mxUtils.br(container);
  1976. tmp.style.height = '40';
  1977. }
  1978. container.appendChild(tmp);
  1979. }
  1980. else
  1981. {
  1982. fontStyleItems[2].style.marginRight = '9px';
  1983. right.style.marginRight = '9px';
  1984. }
  1985. // Label position
  1986. var stylePanel4 = stylePanel.cloneNode(false);
  1987. stylePanel4.style.marginLeft = '0px';
  1988. stylePanel4.style.paddingTop = '8px';
  1989. stylePanel4.style.paddingBottom = '4px';
  1990. stylePanel4.style.fontWeight = 'normal';
  1991. mxUtils.write(stylePanel4, mxResources.get('position'));
  1992. // Adds label position options
  1993. var positionSelect = document.createElement('select');
  1994. positionSelect.style.position = 'absolute';
  1995. positionSelect.style.right = '20px';
  1996. positionSelect.style.width = '97px';
  1997. positionSelect.style.marginTop = '-2px';
  1998. var directions = ['topLeft', 'top', 'topRight', 'left', 'center', 'right', 'bottomLeft', 'bottom', 'bottomRight'];
  1999. var lset = {'topLeft': [mxConstants.ALIGN_LEFT, mxConstants.ALIGN_TOP, mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_BOTTOM],
  2000. 'top': [mxConstants.ALIGN_CENTER, mxConstants.ALIGN_TOP, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_BOTTOM],
  2001. 'topRight': [mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_TOP, mxConstants.ALIGN_LEFT, mxConstants.ALIGN_BOTTOM],
  2002. 'left': [mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_MIDDLE],
  2003. 'center': [mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE],
  2004. 'right': [mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_MIDDLE, mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE],
  2005. 'bottomLeft': [mxConstants.ALIGN_LEFT, mxConstants.ALIGN_BOTTOM, mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_TOP],
  2006. 'bottom': [mxConstants.ALIGN_CENTER, mxConstants.ALIGN_BOTTOM, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_TOP],
  2007. 'bottomRight': [mxConstants.ALIGN_RIGHT, mxConstants.ALIGN_BOTTOM, mxConstants.ALIGN_LEFT, mxConstants.ALIGN_TOP]};
  2008. for (var i = 0; i < directions.length; i++)
  2009. {
  2010. var positionOption = document.createElement('option');
  2011. positionOption.setAttribute('value', directions[i]);
  2012. mxUtils.write(positionOption, mxResources.get(directions[i]));
  2013. positionSelect.appendChild(positionOption);
  2014. }
  2015. stylePanel4.appendChild(positionSelect);
  2016. // Writing direction
  2017. var stylePanel5 = stylePanel.cloneNode(false);
  2018. stylePanel5.style.marginLeft = '0px';
  2019. stylePanel5.style.paddingTop = '4px';
  2020. stylePanel5.style.paddingBottom = '4px';
  2021. stylePanel5.style.fontWeight = 'normal';
  2022. mxUtils.write(stylePanel5, mxResources.get('writingDirection'));
  2023. // Adds writing direction options
  2024. // LATER: Handle reselect of same option in all selects (change event
  2025. // is not fired for same option so have opened state on click) and
  2026. // handle multiple different styles for current selection
  2027. var dirSelect = document.createElement('select');
  2028. dirSelect.style.position = 'absolute';
  2029. dirSelect.style.right = '20px';
  2030. dirSelect.style.width = '97px';
  2031. dirSelect.style.marginTop = '-2px';
  2032. // NOTE: For automatic we use the value null since automatic
  2033. // requires the text to be non formatted and non-wrapped
  2034. var dirs = ['automatic', 'leftToRight', 'rightToLeft'];
  2035. var dirSet = {'automatic': null,
  2036. 'leftToRight': mxConstants.TEXT_DIRECTION_LTR,
  2037. 'rightToLeft': mxConstants.TEXT_DIRECTION_RTL};
  2038. for (var i = 0; i < dirs.length; i++)
  2039. {
  2040. var dirOption = document.createElement('option');
  2041. dirOption.setAttribute('value', dirs[i]);
  2042. mxUtils.write(dirOption, mxResources.get(dirs[i]));
  2043. dirSelect.appendChild(dirOption);
  2044. }
  2045. stylePanel5.appendChild(dirSelect);
  2046. if (!graph.isEditing())
  2047. {
  2048. container.appendChild(stylePanel4);
  2049. mxEvent.addListener(positionSelect, 'change', function(evt)
  2050. {
  2051. graph.getModel().beginUpdate();
  2052. try
  2053. {
  2054. var vals = lset[positionSelect.value];
  2055. if (vals != null)
  2056. {
  2057. graph.setCellStyles(mxConstants.STYLE_LABEL_POSITION, vals[0], graph.getSelectionCells());
  2058. graph.setCellStyles(mxConstants.STYLE_VERTICAL_LABEL_POSITION, vals[1], graph.getSelectionCells());
  2059. graph.setCellStyles(mxConstants.STYLE_ALIGN, vals[2], graph.getSelectionCells());
  2060. graph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, vals[3], graph.getSelectionCells());
  2061. }
  2062. }
  2063. finally
  2064. {
  2065. graph.getModel().endUpdate();
  2066. }
  2067. mxEvent.consume(evt);
  2068. });
  2069. // LATER: Update dir in text editor while editing and update style with label
  2070. // NOTE: The tricky part is handling and passing on the auto value
  2071. container.appendChild(stylePanel5);
  2072. mxEvent.addListener(dirSelect, 'change', function(evt)
  2073. {
  2074. graph.setCellStyles(mxConstants.STYLE_TEXT_DIRECTION, dirSet[dirSelect.value], graph.getSelectionCells());
  2075. mxEvent.consume(evt);
  2076. });
  2077. }
  2078. // Font size
  2079. var input = document.createElement('input');
  2080. input.style.textAlign = 'right';
  2081. input.style.marginTop = '4px';
  2082. if (!mxClient.IS_QUIRKS)
  2083. {
  2084. input.style.position = 'absolute';
  2085. input.style.right = '32px';
  2086. }
  2087. input.style.width = '46px';
  2088. input.style.height = (mxClient.IS_QUIRKS) ? '21px' : '17px';
  2089. stylePanel2.appendChild(input);
  2090. // Workaround for font size 4 if no text is selected is update font size below
  2091. // after first character was entered (as the font element is lazy created)
  2092. var pendingFontSize = null;
  2093. var inputUpdate = this.installInputHandler(input, mxConstants.STYLE_FONTSIZE, Menus.prototype.defaultFontSize, 1, 999, ' pt',
  2094. function(fontsize)
  2095. {
  2096. pendingFontSize = fontsize;
  2097. // Workaround for can't set font size in px is to change font size afterwards
  2098. document.execCommand('fontSize', false, '4');
  2099. var elts = graph.cellEditor.textarea.getElementsByTagName('font');
  2100. for (var i = 0; i < elts.length; i++)
  2101. {
  2102. if (elts[i].getAttribute('size') == '4')
  2103. {
  2104. elts[i].removeAttribute('size');
  2105. elts[i].style.fontSize = pendingFontSize + 'px';
  2106. // Overrides fontSize in input with the one just assigned as a workaround
  2107. // for potential fontSize values of parent elements that don't match
  2108. window.setTimeout(function()
  2109. {
  2110. input.value = pendingFontSize + ' pt';
  2111. pendingFontSize = null;
  2112. }, 0);
  2113. break;
  2114. }
  2115. }
  2116. }, true);
  2117. var stepper = this.createStepper(input, inputUpdate, 1, 10, true, Menus.prototype.defaultFontSize);
  2118. stepper.style.display = input.style.display;
  2119. stepper.style.marginTop = '4px';
  2120. if (!mxClient.IS_QUIRKS)
  2121. {
  2122. stepper.style.right = '20px';
  2123. }
  2124. stylePanel2.appendChild(stepper);
  2125. var arrow = fontMenu.getElementsByTagName('div')[0];
  2126. arrow.style.cssFloat = 'right';
  2127. var bgColorApply = null;
  2128. var currentBgColor = '#ffffff';
  2129. var fontColorApply = null;
  2130. var currentFontColor = '#000000';
  2131. var bgPanel = (graph.cellEditor.isContentEditing()) ? this.createColorOption(mxResources.get('backgroundColor'), function()
  2132. {
  2133. return currentBgColor;
  2134. }, function(color)
  2135. {
  2136. document.execCommand('backcolor', false, (color != mxConstants.NONE) ? color : 'transparent');
  2137. }, '#ffffff',
  2138. {
  2139. install: function(apply) { bgColorApply = apply; },
  2140. destroy: function() { bgColorApply = null; }
  2141. }, null, true) : this.createCellColorOption(mxResources.get('backgroundColor'), mxConstants.STYLE_LABEL_BACKGROUNDCOLOR, '#ffffff');
  2142. bgPanel.style.fontWeight = 'bold';
  2143. var borderPanel = this.createCellColorOption(mxResources.get('borderColor'), mxConstants.STYLE_LABEL_BORDERCOLOR, '#000000');
  2144. borderPanel.style.fontWeight = 'bold';
  2145. var panel = (graph.cellEditor.isContentEditing()) ? this.createColorOption(mxResources.get('fontColor'), function()
  2146. {
  2147. return currentFontColor;
  2148. }, function(color)
  2149. {
  2150. document.execCommand('forecolor', false, (color != mxConstants.NONE) ? color : 'transparent');
  2151. }, '#000000',
  2152. {
  2153. install: function(apply) { fontColorApply = apply; },
  2154. destroy: function() { fontColorApply = null; }
  2155. }, null, true) : this.createCellColorOption(mxResources.get('fontColor'), mxConstants.STYLE_FONTCOLOR, '#000000', function(color)
  2156. {
  2157. if (color == null || color == mxConstants.NONE)
  2158. {
  2159. bgPanel.style.display = 'none';
  2160. }
  2161. else
  2162. {
  2163. bgPanel.style.display = '';
  2164. }
  2165. borderPanel.style.display = bgPanel.style.display;
  2166. }, function(color)
  2167. {
  2168. if (color == null || color == mxConstants.NONE)
  2169. {
  2170. graph.setCellStyles(mxConstants.STYLE_NOLABEL, '1', graph.getSelectionCells());
  2171. }
  2172. else
  2173. {
  2174. graph.setCellStyles(mxConstants.STYLE_NOLABEL, null, graph.getSelectionCells());
  2175. }
  2176. });
  2177. panel.style.fontWeight = 'bold';
  2178. colorPanel.appendChild(panel);
  2179. colorPanel.appendChild(bgPanel);
  2180. if (!graph.cellEditor.isContentEditing())
  2181. {
  2182. colorPanel.appendChild(borderPanel);
  2183. }
  2184. container.appendChild(colorPanel);
  2185. var extraPanel = this.createPanel();
  2186. extraPanel.style.paddingTop = '2px';
  2187. extraPanel.style.paddingBottom = '4px';
  2188. // LATER: Fix toggle using '' instead of 'null'
  2189. var wwOpt = this.createCellOption(mxResources.get('wordWrap'), mxConstants.STYLE_WHITE_SPACE, null, 'wrap', 'null', null, null, true);
  2190. wwOpt.style.fontWeight = 'bold';
  2191. // Word wrap in edge labels only supported via labelWidth style
  2192. if (!ss.containsLabel && !ss.autoSize && ss.edges.length == 0)
  2193. {
  2194. extraPanel.appendChild(wwOpt);
  2195. }
  2196. // Delegates switch of style to formattedText action as it also convertes newlines
  2197. var htmlOpt = this.createCellOption(mxResources.get('formattedText'), 'html', '0',
  2198. null, null, null, ui.actions.get('formattedText'));
  2199. htmlOpt.style.fontWeight = 'bold';
  2200. extraPanel.appendChild(htmlOpt);
  2201. var spacingPanel = this.createPanel();
  2202. spacingPanel.style.paddingTop = '10px';
  2203. spacingPanel.style.paddingBottom = '28px';
  2204. spacingPanel.style.fontWeight = 'normal';
  2205. var span = document.createElement('div');
  2206. span.style.position = 'absolute';
  2207. span.style.width = '70px';
  2208. span.style.marginTop = '0px';
  2209. span.style.fontWeight = 'bold';
  2210. mxUtils.write(span, mxResources.get('spacing'));
  2211. spacingPanel.appendChild(span);
  2212. var topUpdate, globalUpdate, leftUpdate, bottomUpdate, rightUpdate;
  2213. var topSpacing = this.addUnitInput(spacingPanel, 'pt', 91, 44, function()
  2214. {
  2215. topUpdate.apply(this, arguments);
  2216. });
  2217. var globalSpacing = this.addUnitInput(spacingPanel, 'pt', 20, 44, function()
  2218. {
  2219. globalUpdate.apply(this, arguments);
  2220. });
  2221. mxUtils.br(spacingPanel);
  2222. this.addLabel(spacingPanel, mxResources.get('top'), 91);
  2223. this.addLabel(spacingPanel, mxResources.get('global'), 20);
  2224. mxUtils.br(spacingPanel);
  2225. mxUtils.br(spacingPanel);
  2226. var leftSpacing = this.addUnitInput(spacingPanel, 'pt', 162, 44, function()
  2227. {
  2228. leftUpdate.apply(this, arguments);
  2229. });
  2230. var bottomSpacing = this.addUnitInput(spacingPanel, 'pt', 91, 44, function()
  2231. {
  2232. bottomUpdate.apply(this, arguments);
  2233. });
  2234. var rightSpacing = this.addUnitInput(spacingPanel, 'pt', 20, 44, function()
  2235. {
  2236. rightUpdate.apply(this, arguments);
  2237. });
  2238. mxUtils.br(spacingPanel);
  2239. this.addLabel(spacingPanel, mxResources.get('left'), 162);
  2240. this.addLabel(spacingPanel, mxResources.get('bottom'), 91);
  2241. this.addLabel(spacingPanel, mxResources.get('right'), 20);
  2242. if (!graph.cellEditor.isContentEditing())
  2243. {
  2244. container.appendChild(extraPanel);
  2245. container.appendChild(this.createRelativeOption(mxResources.get('opacity'), mxConstants.STYLE_TEXT_OPACITY));
  2246. container.appendChild(spacingPanel);
  2247. }
  2248. else
  2249. {
  2250. var selState = null;
  2251. var lineHeightInput = null;
  2252. container.appendChild(this.createRelativeOption(mxResources.get('lineheight'), null, null, function(input)
  2253. {
  2254. var value = (input.value == '') ? 120 : parseInt(input.value);
  2255. value = Math.max(120, (isNaN(value)) ? 120 : value);
  2256. if (selState != null)
  2257. {
  2258. graph.cellEditor.restoreSelection(selState);
  2259. selState = null;
  2260. }
  2261. var selectedElement = graph.getSelectedElement();
  2262. var node = selectedElement;
  2263. while (node != null && node.nodeType != mxConstants.NODETYPE_ELEMENT)
  2264. {
  2265. node = node.parentNode;
  2266. }
  2267. if (node != null && node == graph.cellEditor.textarea && graph.cellEditor.textarea.firstChild != null)
  2268. {
  2269. if (graph.cellEditor.textarea.firstChild.nodeName != 'FONT')
  2270. {
  2271. graph.cellEditor.textarea.innerHTML = '<font>' + graph.cellEditor.textarea.innerHTML + '</font>';
  2272. }
  2273. node = graph.cellEditor.textarea.firstChild;
  2274. }
  2275. if (node != null && node != graph.cellEditor.textarea)
  2276. {
  2277. node.style.lineHeight = value + '%';
  2278. }
  2279. input.value = value + ' %';
  2280. }, function(input)
  2281. {
  2282. // Used in CSS handler to update current value
  2283. lineHeightInput = input;
  2284. // KNOWN: Arrow up/down clear selection text in quirks/IE 8
  2285. // Text size via arrow button limits to 16 in IE11. Why?
  2286. mxEvent.addListener(input, 'mousedown', function()
  2287. {
  2288. selState = graph.cellEditor.saveSelection();
  2289. });
  2290. mxEvent.addListener(input, 'touchstart', function()
  2291. {
  2292. selState = graph.cellEditor.saveSelection();
  2293. });
  2294. input.value = '120 %';
  2295. }));
  2296. var insertPanel = stylePanel.cloneNode(false);
  2297. insertPanel.style.paddingLeft = '0px';
  2298. var insertBtns = this.editorUi.toolbar.addItems(['link', 'image'], insertPanel, true);
  2299. var btns = [
  2300. this.editorUi.toolbar.addButton('geSprite-horizontalrule', mxResources.get('insertHorizontalRule'),
  2301. function()
  2302. {
  2303. document.execCommand('inserthorizontalrule', false, null);
  2304. }, insertPanel),
  2305. this.editorUi.toolbar.addMenuFunctionInContainer(insertPanel, 'geSprite-table', mxResources.get('table'), false, mxUtils.bind(this, function(menu)
  2306. {
  2307. this.editorUi.menus.addInsertTableItem(menu);
  2308. }))];
  2309. this.styleButtons(insertBtns);
  2310. this.styleButtons(btns);
  2311. var wrapper2 = this.createPanel();
  2312. wrapper2.style.paddingTop = '10px';
  2313. wrapper2.style.paddingBottom = '10px';
  2314. wrapper2.appendChild(this.createTitle(mxResources.get('insert')));
  2315. wrapper2.appendChild(insertPanel);
  2316. container.appendChild(wrapper2);
  2317. if (mxClient.IS_QUIRKS)
  2318. {
  2319. wrapper2.style.height = '70';
  2320. }
  2321. var tablePanel = stylePanel.cloneNode(false);
  2322. tablePanel.style.paddingLeft = '0px';
  2323. var btns = [
  2324. this.editorUi.toolbar.addButton('geSprite-insertcolumnbefore', mxResources.get('insertColumnBefore'),
  2325. function()
  2326. {
  2327. try
  2328. {
  2329. if (currentTable != null)
  2330. {
  2331. graph.selectNode(graph.insertColumn(currentTable, (tableCell != null) ? tableCell.cellIndex : 0));
  2332. }
  2333. }
  2334. catch (e)
  2335. {
  2336. alert(e);
  2337. }
  2338. }, tablePanel),
  2339. this.editorUi.toolbar.addButton('geSprite-insertcolumnafter', mxResources.get('insertColumnAfter'),
  2340. function()
  2341. {
  2342. try
  2343. {
  2344. if (currentTable != null)
  2345. {
  2346. graph.selectNode(graph.insertColumn(currentTable, (tableCell != null) ? tableCell.cellIndex + 1 : -1));
  2347. }
  2348. }
  2349. catch (e)
  2350. {
  2351. alert(e);
  2352. }
  2353. }, tablePanel),
  2354. this.editorUi.toolbar.addButton('geSprite-deletecolumn', mxResources.get('deleteColumn'),
  2355. function()
  2356. {
  2357. try
  2358. {
  2359. if (currentTable != null && tableCell != null)
  2360. {
  2361. graph.deleteColumn(currentTable, tableCell.cellIndex);
  2362. }
  2363. }
  2364. catch (e)
  2365. {
  2366. alert(e);
  2367. }
  2368. }, tablePanel),
  2369. this.editorUi.toolbar.addButton('geSprite-insertrowbefore', mxResources.get('insertRowBefore'),
  2370. function()
  2371. {
  2372. try
  2373. {
  2374. if (currentTable != null && tableRow != null)
  2375. {
  2376. graph.selectNode(graph.insertRow(currentTable, tableRow.sectionRowIndex));
  2377. }
  2378. }
  2379. catch (e)
  2380. {
  2381. alert(e);
  2382. }
  2383. }, tablePanel),
  2384. this.editorUi.toolbar.addButton('geSprite-insertrowafter', mxResources.get('insertRowAfter'),
  2385. function()
  2386. {
  2387. try
  2388. {
  2389. if (currentTable != null && tableRow != null)
  2390. {
  2391. graph.selectNode(graph.insertRow(currentTable, tableRow.sectionRowIndex + 1));
  2392. }
  2393. }
  2394. catch (e)
  2395. {
  2396. alert(e);
  2397. }
  2398. }, tablePanel),
  2399. this.editorUi.toolbar.addButton('geSprite-deleterow', mxResources.get('deleteRow'),
  2400. function()
  2401. {
  2402. try
  2403. {
  2404. if (currentTable != null && tableRow != null)
  2405. {
  2406. graph.deleteRow(currentTable, tableRow.sectionRowIndex);
  2407. }
  2408. }
  2409. catch (e)
  2410. {
  2411. alert(e);
  2412. }
  2413. }, tablePanel)];
  2414. this.styleButtons(btns);
  2415. btns[2].style.marginRight = '9px';
  2416. var wrapper3 = this.createPanel();
  2417. wrapper3.style.paddingTop = '10px';
  2418. wrapper3.style.paddingBottom = '10px';
  2419. wrapper3.appendChild(this.createTitle(mxResources.get('table')));
  2420. wrapper3.appendChild(tablePanel);
  2421. if (mxClient.IS_QUIRKS)
  2422. {
  2423. mxUtils.br(container);
  2424. wrapper3.style.height = '70';
  2425. }
  2426. var tablePanel2 = stylePanel.cloneNode(false);
  2427. tablePanel2.style.paddingLeft = '0px';
  2428. var btns = [
  2429. this.editorUi.toolbar.addButton('geSprite-strokecolor', mxResources.get('borderColor'),
  2430. mxUtils.bind(this, function()
  2431. {
  2432. if (currentTable != null)
  2433. {
  2434. // Converts rgb(r,g,b) values
  2435. var color = currentTable.style.borderColor.replace(
  2436. /\brgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/g,
  2437. function($0, $1, $2, $3) {
  2438. return "#" + ("0"+Number($1).toString(16)).substr(-2) + ("0"+Number($2).toString(16)).substr(-2) + ("0"+Number($3).toString(16)).substr(-2);
  2439. });
  2440. this.editorUi.pickColor(color, function(newColor)
  2441. {
  2442. if (newColor == null || newColor == mxConstants.NONE)
  2443. {
  2444. currentTable.removeAttribute('border');
  2445. currentTable.style.border = '';
  2446. currentTable.style.borderCollapse = '';
  2447. }
  2448. else
  2449. {
  2450. currentTable.setAttribute('border', '1');
  2451. currentTable.style.border = '1px solid ' + newColor;
  2452. currentTable.style.borderCollapse = 'collapse';
  2453. }
  2454. });
  2455. }
  2456. }), tablePanel2),
  2457. this.editorUi.toolbar.addButton('geSprite-fillcolor', mxResources.get('backgroundColor'),
  2458. mxUtils.bind(this, function()
  2459. {
  2460. // Converts rgb(r,g,b) values
  2461. if (currentTable != null)
  2462. {
  2463. var color = currentTable.style.backgroundColor.replace(
  2464. /\brgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/g,
  2465. function($0, $1, $2, $3) {
  2466. return "#" + ("0"+Number($1).toString(16)).substr(-2) + ("0"+Number($2).toString(16)).substr(-2) + ("0"+Number($3).toString(16)).substr(-2);
  2467. });
  2468. this.editorUi.pickColor(color, function(newColor)
  2469. {
  2470. if (newColor == null || newColor == mxConstants.NONE)
  2471. {
  2472. currentTable.style.backgroundColor = '';
  2473. }
  2474. else
  2475. {
  2476. currentTable.style.backgroundColor = newColor;
  2477. }
  2478. });
  2479. }
  2480. }), tablePanel2),
  2481. this.editorUi.toolbar.addButton('geSprite-fit', mxResources.get('spacing'),
  2482. function()
  2483. {
  2484. if (currentTable != null)
  2485. {
  2486. var value = currentTable.getAttribute('cellPadding') || 0;
  2487. var dlg = new FilenameDialog(ui, value, mxResources.get('apply'), mxUtils.bind(this, function(newValue)
  2488. {
  2489. if (newValue != null && newValue.length > 0)
  2490. {
  2491. currentTable.setAttribute('cellPadding', newValue);
  2492. }
  2493. else
  2494. {
  2495. currentTable.removeAttribute('cellPadding');
  2496. }
  2497. }), mxResources.get('spacing'));
  2498. ui.showDialog(dlg.container, 300, 80, true, true);
  2499. dlg.init();
  2500. }
  2501. }, tablePanel2),
  2502. this.editorUi.toolbar.addButton('geSprite-left', mxResources.get('left'),
  2503. function()
  2504. {
  2505. if (currentTable != null)
  2506. {
  2507. currentTable.setAttribute('align', 'left');
  2508. }
  2509. }, tablePanel2),
  2510. this.editorUi.toolbar.addButton('geSprite-center', mxResources.get('center'),
  2511. function()
  2512. {
  2513. if (currentTable != null)
  2514. {
  2515. currentTable.setAttribute('align', 'center');
  2516. }
  2517. }, tablePanel2),
  2518. this.editorUi.toolbar.addButton('geSprite-right', mxResources.get('right'),
  2519. function()
  2520. {
  2521. if (currentTable != null)
  2522. {
  2523. currentTable.setAttribute('align', 'right');
  2524. }
  2525. }, tablePanel2)];
  2526. this.styleButtons(btns);
  2527. btns[2].style.marginRight = '9px';
  2528. if (mxClient.IS_QUIRKS)
  2529. {
  2530. mxUtils.br(wrapper3);
  2531. mxUtils.br(wrapper3);
  2532. }
  2533. wrapper3.appendChild(tablePanel2);
  2534. container.appendChild(wrapper3);
  2535. tableWrapper = wrapper3;
  2536. }
  2537. function setSelected(elt, selected)
  2538. {
  2539. if (mxClient.IS_IE && (mxClient.IS_QUIRKS || document.documentMode < 10))
  2540. {
  2541. elt.style.filter = (selected) ? 'progid:DXImageTransform.Microsoft.Gradient('+
  2542. 'StartColorStr=\'#c5ecff\', EndColorStr=\'#87d4fb\', GradientType=0)' : '';
  2543. }
  2544. else
  2545. {
  2546. elt.style.backgroundImage = (selected) ? 'linear-gradient(#c5ecff 0px,#87d4fb 100%)' : '';
  2547. }
  2548. };
  2549. var listener = mxUtils.bind(this, function(sender, evt, force)
  2550. {
  2551. ss = this.format.getSelectionState();
  2552. var fontStyle = mxUtils.getValue(ss.style, mxConstants.STYLE_FONTSTYLE, 0);
  2553. setSelected(fontStyleItems[0], (fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD);
  2554. setSelected(fontStyleItems[1], (fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC);
  2555. setSelected(fontStyleItems[2], (fontStyle & mxConstants.FONT_UNDERLINE) == mxConstants.FONT_UNDERLINE);
  2556. fontMenu.firstChild.nodeValue = mxUtils.htmlEntities(mxUtils.getValue(ss.style, mxConstants.STYLE_FONTFAMILY, Menus.prototype.defaultFont));
  2557. setSelected(verticalItem, mxUtils.getValue(ss.style, mxConstants.STYLE_HORIZONTAL, '1') == '0');
  2558. if (force || document.activeElement != input)
  2559. {
  2560. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_FONTSIZE, Menus.prototype.defaultFontSize));
  2561. input.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  2562. }
  2563. var align = mxUtils.getValue(ss.style, mxConstants.STYLE_ALIGN, mxConstants.ALIGN_CENTER);
  2564. setSelected(left, align == mxConstants.ALIGN_LEFT);
  2565. setSelected(center, align == mxConstants.ALIGN_CENTER);
  2566. setSelected(right, align == mxConstants.ALIGN_RIGHT);
  2567. var valign = mxUtils.getValue(ss.style, mxConstants.STYLE_VERTICAL_ALIGN, mxConstants.ALIGN_MIDDLE);
  2568. setSelected(top, valign == mxConstants.ALIGN_TOP);
  2569. setSelected(middle, valign == mxConstants.ALIGN_MIDDLE);
  2570. setSelected(bottom, valign == mxConstants.ALIGN_BOTTOM);
  2571. var pos = mxUtils.getValue(ss.style, mxConstants.STYLE_LABEL_POSITION, mxConstants.ALIGN_CENTER);
  2572. var vpos = mxUtils.getValue(ss.style, mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_MIDDLE);
  2573. if (pos == mxConstants.ALIGN_LEFT && vpos == mxConstants.ALIGN_TOP)
  2574. {
  2575. positionSelect.value = 'topLeft';
  2576. }
  2577. else if (pos == mxConstants.ALIGN_CENTER && vpos == mxConstants.ALIGN_TOP)
  2578. {
  2579. positionSelect.value = 'top';
  2580. }
  2581. else if (pos == mxConstants.ALIGN_RIGHT && vpos == mxConstants.ALIGN_TOP)
  2582. {
  2583. positionSelect.value = 'topRight';
  2584. }
  2585. else if (pos == mxConstants.ALIGN_LEFT && vpos == mxConstants.ALIGN_BOTTOM)
  2586. {
  2587. positionSelect.value = 'bottomLeft';
  2588. }
  2589. else if (pos == mxConstants.ALIGN_CENTER && vpos == mxConstants.ALIGN_BOTTOM)
  2590. {
  2591. positionSelect.value = 'bottom';
  2592. }
  2593. else if (pos == mxConstants.ALIGN_RIGHT && vpos == mxConstants.ALIGN_BOTTOM)
  2594. {
  2595. positionSelect.value = 'bottomRight';
  2596. }
  2597. else if (pos == mxConstants.ALIGN_LEFT)
  2598. {
  2599. positionSelect.value = 'left';
  2600. }
  2601. else if (pos == mxConstants.ALIGN_RIGHT)
  2602. {
  2603. positionSelect.value = 'right';
  2604. }
  2605. else
  2606. {
  2607. positionSelect.value = 'center';
  2608. }
  2609. var dir = mxUtils.getValue(ss.style, mxConstants.STYLE_TEXT_DIRECTION, mxConstants.DEFAULT_TEXT_DIRECTION);
  2610. if (dir == mxConstants.TEXT_DIRECTION_RTL)
  2611. {
  2612. dirSelect.value = 'rightToLeft';
  2613. }
  2614. else if (dir == mxConstants.TEXT_DIRECTION_LTR)
  2615. {
  2616. dirSelect.value = 'leftToRight';
  2617. }
  2618. else if (dir == mxConstants.TEXT_DIRECTION_AUTO)
  2619. {
  2620. dirSelect.value = 'automatic';
  2621. }
  2622. if (force || document.activeElement != globalSpacing)
  2623. {
  2624. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_SPACING, 2));
  2625. globalSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  2626. }
  2627. if (force || document.activeElement != topSpacing)
  2628. {
  2629. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_SPACING_TOP, 0));
  2630. topSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  2631. }
  2632. if (force || document.activeElement != rightSpacing)
  2633. {
  2634. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_SPACING_RIGHT, 0));
  2635. rightSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  2636. }
  2637. if (force || document.activeElement != bottomSpacing)
  2638. {
  2639. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_SPACING_BOTTOM, 0));
  2640. bottomSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  2641. }
  2642. if (force || document.activeElement != leftSpacing)
  2643. {
  2644. var tmp = parseFloat(mxUtils.getValue(ss.style, mxConstants.STYLE_SPACING_LEFT, 0));
  2645. leftSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  2646. }
  2647. });
  2648. globalUpdate = this.installInputHandler(globalSpacing, mxConstants.STYLE_SPACING, 2, -999, 999, ' pt');
  2649. topUpdate = this.installInputHandler(topSpacing, mxConstants.STYLE_SPACING_TOP, 0, -999, 999, ' pt');
  2650. rightUpdate = this.installInputHandler(rightSpacing, mxConstants.STYLE_SPACING_RIGHT, 0, -999, 999, ' pt');
  2651. bottomUpdate = this.installInputHandler(bottomSpacing, mxConstants.STYLE_SPACING_BOTTOM, 0, -999, 999, ' pt');
  2652. leftUpdate = this.installInputHandler(leftSpacing, mxConstants.STYLE_SPACING_LEFT, 0, -999, 999, ' pt');
  2653. this.addKeyHandler(input, listener);
  2654. this.addKeyHandler(globalSpacing, listener);
  2655. this.addKeyHandler(topSpacing, listener);
  2656. this.addKeyHandler(rightSpacing, listener);
  2657. this.addKeyHandler(bottomSpacing, listener);
  2658. this.addKeyHandler(leftSpacing, listener);
  2659. graph.getModel().addListener(mxEvent.CHANGE, listener);
  2660. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  2661. listener();
  2662. if (graph.cellEditor.isContentEditing())
  2663. {
  2664. var updating = false;
  2665. var updateCssHandler = function()
  2666. {
  2667. if (!updating)
  2668. {
  2669. updating = true;
  2670. window.setTimeout(function()
  2671. {
  2672. var selectedElement = graph.getSelectedElement();
  2673. var node = selectedElement;
  2674. while (node != null && node.nodeType != mxConstants.NODETYPE_ELEMENT)
  2675. {
  2676. node = node.parentNode;
  2677. }
  2678. if (node != null)
  2679. {
  2680. var css = mxUtils.getCurrentStyle(node);
  2681. if (css != null)
  2682. {
  2683. setSelected(fontStyleItems[0], css.fontWeight == 'bold' || graph.getParentByName(node, 'B', graph.cellEditor.textarea) != null);
  2684. setSelected(fontStyleItems[1], css.fontStyle == 'italic' || graph.getParentByName(node, 'I', graph.cellEditor.textarea) != null);
  2685. setSelected(fontStyleItems[2], graph.getParentByName(node, 'U', graph.cellEditor.textarea) != null);
  2686. setSelected(left, css.textAlign == 'left');
  2687. setSelected(center, css.textAlign == 'center');
  2688. setSelected(right, css.textAlign == 'right');
  2689. setSelected(full, css.textAlign == 'justify');
  2690. setSelected(sup, graph.getParentByName(node, 'SUP', graph.cellEditor.textarea) != null);
  2691. setSelected(sub, graph.getParentByName(node, 'SUB', graph.cellEditor.textarea) != null);
  2692. currentTable = graph.getParentByName(node, 'TABLE', graph.cellEditor.textarea);
  2693. tableRow = (currentTable == null) ? null : graph.getParentByName(node, 'TR', currentTable);
  2694. tableCell = (currentTable == null) ? null : graph.getParentByName(node, 'TD', currentTable);
  2695. tableWrapper.style.display = (currentTable != null) ? '' : 'none';
  2696. if (document.activeElement != input)
  2697. {
  2698. if (node.nodeName == 'FONT' && node.getAttribute('size') == '4' &&
  2699. pendingFontSize != null)
  2700. {
  2701. node.removeAttribute('size');
  2702. node.style.fontSize = pendingFontSize + 'px';
  2703. pendingFontSize = null;
  2704. }
  2705. else
  2706. {
  2707. input.value = parseFloat(css.fontSize) + ' pt';
  2708. }
  2709. var tmp = node.style.lineHeight || css.lineHeight;
  2710. var lh = parseFloat(tmp);
  2711. if (tmp.substring(tmp.length - 2) == 'px')
  2712. {
  2713. lh = lh / parseFloat(css.fontSize);
  2714. }
  2715. if (tmp.substring(tmp.length - 1) != '%')
  2716. {
  2717. lh *= 100;
  2718. }
  2719. lineHeightInput.value = lh + ' %';
  2720. }
  2721. // Converts rgb(r,g,b) values
  2722. var color = css.color.replace(
  2723. /\brgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/g,
  2724. function($0, $1, $2, $3) {
  2725. return "#" + ("0"+Number($1).toString(16)).substr(-2) + ("0"+Number($2).toString(16)).substr(-2) + ("0"+Number($3).toString(16)).substr(-2);
  2726. });
  2727. var color2 = css.backgroundColor.replace(
  2728. /\brgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/g,
  2729. function($0, $1, $2, $3) {
  2730. return "#" + ("0"+Number($1).toString(16)).substr(-2) + ("0"+Number($2).toString(16)).substr(-2) + ("0"+Number($3).toString(16)).substr(-2);
  2731. });
  2732. // Updates the color picker for the current font
  2733. if (fontColorApply != null)
  2734. {
  2735. if (color.charAt(0) == '#')
  2736. {
  2737. currentFontColor = color;
  2738. }
  2739. else
  2740. {
  2741. currentFontColor = '#000000';
  2742. }
  2743. fontColorApply(currentFontColor, true);
  2744. }
  2745. if (bgColorApply != null)
  2746. {
  2747. if (color2.charAt(0) == '#')
  2748. {
  2749. currentBgColor = color2;
  2750. }
  2751. else
  2752. {
  2753. currentBgColor = null;
  2754. }
  2755. bgColorApply(currentBgColor, true);
  2756. }
  2757. // Workaround for firstChild is null or not an object
  2758. // in the log which seems to be IE8- only / 29.01.15
  2759. if (fontMenu.firstChild != null)
  2760. {
  2761. // Strips leading and trailing quotes
  2762. var ff = css.fontFamily;
  2763. if (ff.charAt(0) == '\'')
  2764. {
  2765. ff = ff.substring(1);
  2766. }
  2767. if (ff.charAt(ff.length - 1) == '\'')
  2768. {
  2769. ff = ff.substring(0, ff.length - 1);
  2770. }
  2771. fontMenu.firstChild.nodeValue = ff;
  2772. }
  2773. }
  2774. }
  2775. updating = false;
  2776. }, 0);
  2777. }
  2778. };
  2779. mxEvent.addListener(graph.cellEditor.textarea, 'input', updateCssHandler)
  2780. mxEvent.addListener(graph.cellEditor.textarea, 'touchend', updateCssHandler);
  2781. mxEvent.addListener(graph.cellEditor.textarea, 'mouseup', updateCssHandler);
  2782. mxEvent.addListener(graph.cellEditor.textarea, 'keyup', updateCssHandler);
  2783. this.listeners.push({destroy: function()
  2784. {
  2785. // No need to remove listener since textarea is destroyed after edit
  2786. }});
  2787. updateCssHandler();
  2788. }
  2789. return container;
  2790. };
  2791. /**
  2792. * Adds the label menu items to the given menu and parent.
  2793. */
  2794. StyleFormatPanel = function(format, editorUi, container)
  2795. {
  2796. BaseFormatPanel.call(this, format, editorUi, container);
  2797. this.init();
  2798. };
  2799. mxUtils.extend(StyleFormatPanel, BaseFormatPanel);
  2800. /**
  2801. * Adds the label menu items to the given menu and parent.
  2802. */
  2803. StyleFormatPanel.prototype.init = function()
  2804. {
  2805. var ui = this.editorUi;
  2806. var editor = ui.editor;
  2807. var graph = editor.graph;
  2808. var ss = this.format.getSelectionState();
  2809. if (!ss.containsImage || ss.style.shape == 'image')
  2810. {
  2811. this.container.appendChild(this.addFill(this.createPanel()));
  2812. }
  2813. this.container.appendChild(this.addStroke(this.createPanel()));
  2814. var opacityPanel = this.createRelativeOption(mxResources.get('opacity'), mxConstants.STYLE_OPACITY, 41);
  2815. opacityPanel.style.paddingTop = '8px';
  2816. opacityPanel.style.paddingBottom = '8px';
  2817. this.container.appendChild(opacityPanel);
  2818. this.container.appendChild(this.addEffects(this.createPanel()));
  2819. var opsPanel = this.addEditOps(this.createPanel());
  2820. if (opsPanel.firstChild != null)
  2821. {
  2822. mxUtils.br(opsPanel);
  2823. }
  2824. this.container.appendChild(this.addStyleOps(opsPanel));
  2825. };
  2826. /**
  2827. * Adds the label menu items to the given menu and parent.
  2828. */
  2829. StyleFormatPanel.prototype.addEditOps = function(div)
  2830. {
  2831. var ss = this.format.getSelectionState();
  2832. var btn = null;
  2833. if (this.editorUi.editor.graph.getSelectionCount() == 1)
  2834. {
  2835. btn = mxUtils.button(mxResources.get('editStyle'), mxUtils.bind(this, function(evt)
  2836. {
  2837. this.editorUi.actions.get('editStyle').funct();
  2838. }));
  2839. btn.setAttribute('title', mxResources.get('editStyle') + ' (' + this.editorUi.actions.get('editStyle').shortcut + ')');
  2840. btn.style.width = '202px';
  2841. btn.style.marginBottom = '2px';
  2842. div.appendChild(btn);
  2843. }
  2844. if (ss.image)
  2845. {
  2846. var btn2 = mxUtils.button(mxResources.get('editImage'), mxUtils.bind(this, function(evt)
  2847. {
  2848. this.editorUi.actions.get('image').funct();
  2849. }));
  2850. btn2.setAttribute('title', mxResources.get('editImage'));
  2851. btn2.style.marginBottom = '2px';
  2852. if (btn == null)
  2853. {
  2854. btn2.style.width = '202px';
  2855. }
  2856. else
  2857. {
  2858. btn.style.width = '100px';
  2859. btn2.style.width = '100px';
  2860. btn2.style.marginLeft = '2px';
  2861. }
  2862. div.appendChild(btn2);
  2863. }
  2864. return div;
  2865. };
  2866. /**
  2867. * Adds the label menu items to the given menu and parent.
  2868. */
  2869. StyleFormatPanel.prototype.addFill = function(container)
  2870. {
  2871. var ui = this.editorUi;
  2872. var graph = ui.editor.graph;
  2873. var ss = this.format.getSelectionState();
  2874. container.style.paddingTop = '6px';
  2875. container.style.paddingBottom = '6px';
  2876. // Adds gradient direction option
  2877. var gradientSelect = document.createElement('select');
  2878. gradientSelect.style.position = 'absolute';
  2879. gradientSelect.style.marginTop = '-2px';
  2880. gradientSelect.style.right = (mxClient.IS_QUIRKS) ? '52px' : '72px';
  2881. gradientSelect.style.width = '70px';
  2882. // Stops events from bubbling to color option event handler
  2883. mxEvent.addListener(gradientSelect, 'click', function(evt)
  2884. {
  2885. mxEvent.consume(evt);
  2886. });
  2887. var gradientPanel = this.createCellColorOption(mxResources.get('gradient'), mxConstants.STYLE_GRADIENTCOLOR, '#ffffff', function(color)
  2888. {
  2889. if (color == null || color == mxConstants.NONE)
  2890. {
  2891. gradientSelect.style.display = 'none';
  2892. }
  2893. else
  2894. {
  2895. gradientSelect.style.display = '';
  2896. }
  2897. });
  2898. var fillKey = (ss.style.shape == 'image') ? mxConstants.STYLE_IMAGE_BACKGROUND : mxConstants.STYLE_FILLCOLOR;
  2899. var fillPanel = this.createCellColorOption(mxResources.get('fill'), fillKey, '#ffffff');
  2900. fillPanel.style.fontWeight = 'bold';
  2901. var tmpColor = mxUtils.getValue(ss.style, fillKey, null);
  2902. gradientPanel.style.display = (tmpColor != null && tmpColor != mxConstants.NONE &&
  2903. ss.fill && ss.style.shape != 'image') ? '' : 'none';
  2904. var directions = [mxConstants.DIRECTION_NORTH, mxConstants.DIRECTION_EAST,
  2905. mxConstants.DIRECTION_SOUTH, mxConstants.DIRECTION_WEST];
  2906. for (var i = 0; i < directions.length; i++)
  2907. {
  2908. var gradientOption = document.createElement('option');
  2909. gradientOption.setAttribute('value', directions[i]);
  2910. mxUtils.write(gradientOption, mxResources.get(directions[i]));
  2911. gradientSelect.appendChild(gradientOption);
  2912. }
  2913. gradientPanel.appendChild(gradientSelect);
  2914. var listener = mxUtils.bind(this, function()
  2915. {
  2916. ss = this.format.getSelectionState();
  2917. var value = mxUtils.getValue(ss.style, mxConstants.STYLE_GRADIENT_DIRECTION, mxConstants.DIRECTION_SOUTH);
  2918. // Handles empty string which is not allowed as a value
  2919. if (value == '')
  2920. {
  2921. value = mxConstants.DIRECTION_SOUTH;
  2922. }
  2923. gradientSelect.value = value;
  2924. container.style.display = (ss.fill) ? '' : 'none';
  2925. var fillColor = mxUtils.getValue(ss.style, mxConstants.STYLE_FILLCOLOR, null);
  2926. if (!ss.fill || ss.containsImage || fillColor == null || fillColor == mxConstants.NONE)
  2927. {
  2928. gradientPanel.style.display = 'none';
  2929. }
  2930. else
  2931. {
  2932. gradientPanel.style.display = '';
  2933. }
  2934. });
  2935. graph.getModel().addListener(mxEvent.CHANGE, listener);
  2936. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  2937. listener();
  2938. mxEvent.addListener(gradientSelect, 'change', function(evt)
  2939. {
  2940. graph.setCellStyles(mxConstants.STYLE_GRADIENT_DIRECTION, gradientSelect.value, graph.getSelectionCells());
  2941. mxEvent.consume(evt);
  2942. });
  2943. container.appendChild(fillPanel);
  2944. container.appendChild(gradientPanel);
  2945. if (ss.style.shape == 'swimlane')
  2946. {
  2947. container.appendChild(this.createCellColorOption(mxResources.get('laneColor'), 'swimlaneFillColor', '#ffffff'));
  2948. }
  2949. return container;
  2950. };
  2951. /**
  2952. * Adds the label menu items to the given menu and parent.
  2953. */
  2954. StyleFormatPanel.prototype.addStroke = function(container)
  2955. {
  2956. var ui = this.editorUi;
  2957. var graph = ui.editor.graph;
  2958. var ss = this.format.getSelectionState();
  2959. container.style.paddingTop = '4px';
  2960. container.style.paddingBottom = '4px';
  2961. container.style.whiteSpace = 'normal';
  2962. var colorPanel = document.createElement('div');
  2963. colorPanel.style.fontWeight = 'bold';
  2964. // Adds gradient direction option
  2965. var styleSelect = document.createElement('select');
  2966. styleSelect.style.position = 'absolute';
  2967. styleSelect.style.marginTop = '-2px';
  2968. styleSelect.style.right = '72px';
  2969. styleSelect.style.width = '80px';
  2970. var styles = ['sharp', 'rounded', 'curved'];
  2971. for (var i = 0; i < styles.length; i++)
  2972. {
  2973. var styleOption = document.createElement('option');
  2974. styleOption.setAttribute('value', styles[i]);
  2975. mxUtils.write(styleOption, mxResources.get(styles[i]));
  2976. styleSelect.appendChild(styleOption);
  2977. }
  2978. mxEvent.addListener(styleSelect, 'change', function(evt)
  2979. {
  2980. graph.getModel().beginUpdate();
  2981. try
  2982. {
  2983. var keys = [mxConstants.STYLE_ROUNDED, mxConstants.STYLE_CURVED];
  2984. // Default for rounded is 1
  2985. var values = ['0', null];
  2986. if (styleSelect.value == 'rounded')
  2987. {
  2988. values = ['1', null];
  2989. }
  2990. else if (styleSelect.value == 'curved')
  2991. {
  2992. values = [null, '1'];
  2993. }
  2994. for (var i = 0; i < keys.length; i++)
  2995. {
  2996. graph.setCellStyles(keys[i], values[i], graph.getSelectionCells());
  2997. }
  2998. ui.fireEvent(new mxEventObject('styleChanged', 'keys', keys,
  2999. 'values', values, 'cells', graph.getSelectionCells()));
  3000. }
  3001. finally
  3002. {
  3003. graph.getModel().endUpdate();
  3004. }
  3005. mxEvent.consume(evt);
  3006. });
  3007. // Stops events from bubbling to color option event handler
  3008. mxEvent.addListener(styleSelect, 'click', function(evt)
  3009. {
  3010. mxEvent.consume(evt);
  3011. });
  3012. var strokeKey = (ss.style.shape == 'image') ? mxConstants.STYLE_IMAGE_BORDER : mxConstants.STYLE_STROKECOLOR;
  3013. var lineColor = this.createCellColorOption(mxResources.get('line'), strokeKey, '#000000');
  3014. lineColor.appendChild(styleSelect);
  3015. colorPanel.appendChild(lineColor);
  3016. // Used if only edges selected
  3017. var stylePanel = colorPanel.cloneNode(false);
  3018. stylePanel.style.fontWeight = 'normal';
  3019. stylePanel.style.whiteSpace = 'nowrap';
  3020. stylePanel.style.position = 'relative';
  3021. stylePanel.style.paddingLeft = '16px'
  3022. stylePanel.style.marginBottom = '2px';
  3023. stylePanel.style.marginTop = '2px';
  3024. stylePanel.className = 'geToolbarContainer';
  3025. var addItem = mxUtils.bind(this, function(menu, width, cssName, keys, values)
  3026. {
  3027. var item = this.editorUi.menus.styleChange(menu, '', keys, values, 'geIcon', null);
  3028. var pat = document.createElement('div');
  3029. pat.style.width = width + 'px';
  3030. pat.style.height = '1px';
  3031. pat.style.borderBottom = '1px ' + cssName + ' black';
  3032. pat.style.paddingTop = '6px';
  3033. item.firstChild.firstChild.style.padding = '0px 4px 0px 4px';
  3034. item.firstChild.firstChild.style.width = width + 'px';
  3035. item.firstChild.firstChild.appendChild(pat);
  3036. return item;
  3037. });
  3038. var pattern = this.editorUi.toolbar.addMenuFunctionInContainer(stylePanel, 'geSprite-orthogonal', mxResources.get('pattern'), false, mxUtils.bind(this, function(menu)
  3039. {
  3040. addItem(menu, 75, 'solid', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], [null, null]).setAttribute('title', mxResources.get('solid'));
  3041. addItem(menu, 75, 'dashed', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', null]).setAttribute('title', mxResources.get('dashed'));
  3042. addItem(menu, 75, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 1']).setAttribute('title', mxResources.get('dotted') + ' (1)');
  3043. addItem(menu, 75, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 2']).setAttribute('title', mxResources.get('dotted') + ' (2)');
  3044. addItem(menu, 75, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 4']).setAttribute('title', mxResources.get('dotted') + ' (3)');
  3045. }));
  3046. // Used for mixed selection (vertices and edges)
  3047. var altStylePanel = stylePanel.cloneNode(false);
  3048. var edgeShape = this.editorUi.toolbar.addMenuFunctionInContainer(altStylePanel, 'geSprite-connection', mxResources.get('connection'), false, mxUtils.bind(this, function(menu)
  3049. {
  3050. 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'));
  3051. 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'));
  3052. 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'));
  3053. 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'));
  3054. }));
  3055. var altPattern = this.editorUi.toolbar.addMenuFunctionInContainer(altStylePanel, 'geSprite-orthogonal', mxResources.get('pattern'), false, mxUtils.bind(this, function(menu)
  3056. {
  3057. addItem(menu, 33, 'solid', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], [null, null]).setAttribute('title', mxResources.get('solid'));
  3058. addItem(menu, 33, 'dashed', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', null]).setAttribute('title', mxResources.get('dashed'));
  3059. addItem(menu, 33, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 1']).setAttribute('title', mxResources.get('dotted') + ' (1)');
  3060. addItem(menu, 33, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 2']).setAttribute('title', mxResources.get('dotted') + ' (2)');
  3061. addItem(menu, 33, 'dotted', [mxConstants.STYLE_DASHED, mxConstants.STYLE_DASH_PATTERN], ['1', '1 4']).setAttribute('title', mxResources.get('dotted') + ' (3)');
  3062. }));
  3063. var stylePanel2 = stylePanel.cloneNode(false);
  3064. // Stroke width
  3065. var input = document.createElement('input');
  3066. input.style.textAlign = 'right';
  3067. input.style.marginTop = '2px';
  3068. input.style.width = '41px';
  3069. input.setAttribute('title', mxResources.get('linewidth'));
  3070. stylePanel.appendChild(input);
  3071. var altInput = input.cloneNode(true);
  3072. altStylePanel.appendChild(altInput);
  3073. function update(evt)
  3074. {
  3075. // Maximum stroke width is 999
  3076. var value = parseInt(input.value);
  3077. value = Math.min(999, Math.max(1, (isNaN(value)) ? 1 : value));
  3078. if (value != mxUtils.getValue(ss.style, mxConstants.STYLE_STROKEWIDTH, 1))
  3079. {
  3080. graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, value, graph.getSelectionCells());
  3081. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_STROKEWIDTH],
  3082. 'values', [value], 'cells', graph.getSelectionCells()));
  3083. }
  3084. input.value = value + ' pt';
  3085. mxEvent.consume(evt);
  3086. };
  3087. function altUpdate(evt)
  3088. {
  3089. // Maximum stroke width is 999
  3090. var value = parseInt(altInput.value);
  3091. value = Math.min(999, Math.max(1, (isNaN(value)) ? 1 : value));
  3092. if (value != mxUtils.getValue(ss.style, mxConstants.STYLE_STROKEWIDTH, 1))
  3093. {
  3094. graph.setCellStyles(mxConstants.STYLE_STROKEWIDTH, value, graph.getSelectionCells());
  3095. ui.fireEvent(new mxEventObject('styleChanged', 'keys', [mxConstants.STYLE_STROKEWIDTH],
  3096. 'values', [value], 'cells', graph.getSelectionCells()));
  3097. }
  3098. altInput.value = value + ' pt';
  3099. mxEvent.consume(evt);
  3100. };
  3101. var stepper = this.createStepper(input, update, 1, 9);
  3102. stepper.style.display = input.style.display;
  3103. stepper.style.marginTop = '2px';
  3104. stylePanel.appendChild(stepper);
  3105. var altStepper = this.createStepper(altInput, altUpdate, 1, 9);
  3106. altStepper.style.display = altInput.style.display;
  3107. altStepper.style.marginTop = '2px';
  3108. altStylePanel.appendChild(altStepper);
  3109. if (!mxClient.IS_QUIRKS)
  3110. {
  3111. input.style.position = 'absolute';
  3112. input.style.right = '32px';
  3113. input.style.height = '15px';
  3114. stepper.style.right = '20px';
  3115. altInput.style.position = 'absolute';
  3116. altInput.style.right = '32px';
  3117. altInput.style.height = '15px';
  3118. altStepper.style.right = '20px';
  3119. }
  3120. else
  3121. {
  3122. input.style.height = '17px';
  3123. altInput.style.height = '17px';
  3124. }
  3125. mxEvent.addListener(input, 'blur', update);
  3126. mxEvent.addListener(input, 'change', update);
  3127. mxEvent.addListener(altInput, 'blur', altUpdate);
  3128. mxEvent.addListener(altInput, 'change', altUpdate);
  3129. if (mxClient.IS_QUIRKS)
  3130. {
  3131. mxUtils.br(stylePanel2);
  3132. mxUtils.br(stylePanel2);
  3133. }
  3134. var edgeStyle = this.editorUi.toolbar.addMenuFunctionInContainer(stylePanel2, 'geSprite-orthogonal', mxResources.get('waypoints'), false, mxUtils.bind(this, function(menu)
  3135. {
  3136. if (ss.style.shape != 'arrow')
  3137. {
  3138. 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'));
  3139. 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'));
  3140. 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'));
  3141. 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'));
  3142. 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'));
  3143. 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'));
  3144. if (ss.style.shape == 'connector')
  3145. {
  3146. 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'));
  3147. }
  3148. 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'));
  3149. }
  3150. }));
  3151. var lineStart = this.editorUi.toolbar.addMenuFunctionInContainer(stylePanel2, 'geSprite-startclassic', mxResources.get('linestart'), false, mxUtils.bind(this, function(menu)
  3152. {
  3153. if (ss.style.shape == 'connector' || ss.style.shape == 'flexArrow')
  3154. {
  3155. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.NONE, 0], 'geIcon geSprite geSprite-noarrow', null, false).setAttribute('title', mxResources.get('none'));
  3156. if (ss.style.shape == 'connector')
  3157. {
  3158. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_CLASSIC, 1], 'geIcon geSprite geSprite-startclassic', null, false).setAttribute('title', mxResources.get('classic'));
  3159. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_CLASSIC_THIN, 1], 'geIcon geSprite geSprite-startclassicthin', null, false);
  3160. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_OPEN, 0], 'geIcon geSprite geSprite-startopen', null, false).setAttribute('title', mxResources.get('openArrow'));
  3161. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_OPEN_THIN, 0], 'geIcon geSprite geSprite-startopenthin', null, false);
  3162. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['openAsync', 0], 'geIcon geSprite geSprite-startopenasync', null, false);
  3163. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_BLOCK, 1], 'geIcon geSprite geSprite-startblock', null, false).setAttribute('title', mxResources.get('block'));
  3164. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_BLOCK_THIN, 1], 'geIcon geSprite geSprite-startblockthin', null, false);
  3165. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['async', 1], 'geIcon geSprite geSprite-startasync', null, false);
  3166. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_OVAL, 1], 'geIcon geSprite geSprite-startoval', null, false).setAttribute('title', mxResources.get('oval'));
  3167. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_DIAMOND, 1], 'geIcon geSprite geSprite-startdiamond', null, false).setAttribute('title', mxResources.get('diamond'));
  3168. 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'));
  3169. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_CLASSIC, 0], 'geIcon geSprite geSprite-startclassictrans', null, false).setAttribute('title', mxResources.get('classic'));
  3170. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_CLASSIC_THIN, 0], 'geIcon geSprite geSprite-startclassicthintrans', null, false);
  3171. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_BLOCK, 0], 'geIcon geSprite geSprite-startblocktrans', null, false).setAttribute('title', mxResources.get('block'));
  3172. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_BLOCK_THIN, 0], 'geIcon geSprite geSprite-startblockthintrans', null, false);
  3173. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['async', 0], 'geIcon geSprite geSprite-startasynctrans', null, false);
  3174. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_OVAL, 0], 'geIcon geSprite geSprite-startovaltrans', null, false).setAttribute('title', mxResources.get('oval'));
  3175. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], [mxConstants.ARROW_DIAMOND, 0], 'geIcon geSprite geSprite-startdiamondtrans', null, false).setAttribute('title', mxResources.get('diamond'));
  3176. 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'));
  3177. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['dash', 0], 'geIcon geSprite geSprite-startdash', null, false);
  3178. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['cross', 0], 'geIcon geSprite geSprite-startcross', null, false);
  3179. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['circlePlus', 0], 'geIcon geSprite geSprite-startcircleplus', null, false);
  3180. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['circle', 1], 'geIcon geSprite geSprite-startcircle', null, false);
  3181. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERone', 0], 'geIcon geSprite geSprite-starterone', null, false);
  3182. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERmandOne', 0], 'geIcon geSprite geSprite-starteronetoone', null, false);
  3183. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERmany', 0], 'geIcon geSprite geSprite-startermany', null, false);
  3184. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERoneToMany', 0], 'geIcon geSprite geSprite-starteronetomany', null, false);
  3185. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERzeroToOne', 1], 'geIcon geSprite geSprite-starteroneopt', null, false);
  3186. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW, 'startFill'], ['ERzeroToMany', 1], 'geIcon geSprite geSprite-startermanyopt', null, false);
  3187. }
  3188. else
  3189. {
  3190. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_STARTARROW], [mxConstants.ARROW_BLOCK], 'geIcon geSprite geSprite-startblocktrans', null, false).setAttribute('title', mxResources.get('block'));
  3191. }
  3192. }
  3193. }));
  3194. var lineEnd = this.editorUi.toolbar.addMenuFunctionInContainer(stylePanel2, 'geSprite-endclassic', mxResources.get('lineend'), false, mxUtils.bind(this, function(menu)
  3195. {
  3196. if (ss.style.shape == 'connector' || ss.style.shape == 'flexArrow')
  3197. {
  3198. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.NONE, 0], 'geIcon geSprite geSprite-noarrow', null, false).setAttribute('title', mxResources.get('none'));
  3199. if (ss.style.shape == 'connector')
  3200. {
  3201. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_CLASSIC, 1], 'geIcon geSprite geSprite-endclassic', null, false).setAttribute('title', mxResources.get('classic'));
  3202. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_CLASSIC_THIN, 1], 'geIcon geSprite geSprite-endclassicthin', null, false);
  3203. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_OPEN, 0], 'geIcon geSprite geSprite-endopen', null, false).setAttribute('title', mxResources.get('openArrow'));
  3204. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_OPEN_THIN, 0], 'geIcon geSprite geSprite-endopenthin', null, false);
  3205. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['openAsync', 0], 'geIcon geSprite geSprite-endopenasync', null, false);
  3206. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_BLOCK, 1], 'geIcon geSprite geSprite-endblock', null, false).setAttribute('title', mxResources.get('block'));
  3207. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_BLOCK_THIN, 1], 'geIcon geSprite geSprite-endblockthin', null, false);
  3208. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['async', 1], 'geIcon geSprite geSprite-endasync', null, false);
  3209. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_OVAL, 1], 'geIcon geSprite geSprite-endoval', null, false).setAttribute('title', mxResources.get('oval'));
  3210. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_DIAMOND, 1], 'geIcon geSprite geSprite-enddiamond', null, false).setAttribute('title', mxResources.get('diamond'));
  3211. 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'));
  3212. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_CLASSIC, 0], 'geIcon geSprite geSprite-endclassictrans', null, false).setAttribute('title', mxResources.get('classic'));
  3213. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_CLASSIC_THIN, 0], 'geIcon geSprite geSprite-endclassicthintrans', null, false);
  3214. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_BLOCK, 0], 'geIcon geSprite geSprite-endblocktrans', null, false).setAttribute('title', mxResources.get('block'));
  3215. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_BLOCK_THIN, 0], 'geIcon geSprite geSprite-endblockthintrans', null, false);
  3216. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['async', 0], 'geIcon geSprite geSprite-endasynctrans', null, false);
  3217. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_OVAL, 0], 'geIcon geSprite geSprite-endovaltrans', null, false).setAttribute('title', mxResources.get('oval'));
  3218. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], [mxConstants.ARROW_DIAMOND, 0], 'geIcon geSprite geSprite-enddiamondtrans', null, false).setAttribute('title', mxResources.get('diamond'));
  3219. 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'));
  3220. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['dash', 0], 'geIcon geSprite geSprite-enddash', null, false);
  3221. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['cross', 0], 'geIcon geSprite geSprite-endcross', null, false);
  3222. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['circlePlus', 0], 'geIcon geSprite geSprite-endcircleplus', null, false);
  3223. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['circle', 1], 'geIcon geSprite geSprite-endcircle', null, false);
  3224. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERone', 0], 'geIcon geSprite geSprite-enderone', null, false);
  3225. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERmandOne', 0], 'geIcon geSprite geSprite-enderonetoone', null, false);
  3226. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERmany', 0], 'geIcon geSprite geSprite-endermany', null, false);
  3227. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERoneToMany', 0], 'geIcon geSprite geSprite-enderonetomany', null, false);
  3228. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERzeroToOne', 1], 'geIcon geSprite geSprite-enderoneopt', null, false);
  3229. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW, 'endFill'], ['ERzeroToMany', 1], 'geIcon geSprite geSprite-endermanyopt', null, false);
  3230. }
  3231. else
  3232. {
  3233. this.editorUi.menus.edgeStyleChange(menu, '', [mxConstants.STYLE_ENDARROW], [mxConstants.ARROW_BLOCK], 'geIcon geSprite geSprite-endblocktrans', null, false).setAttribute('title', mxResources.get('block'));
  3234. }
  3235. }
  3236. }));
  3237. this.addArrow(edgeShape, 8);
  3238. this.addArrow(edgeStyle);
  3239. this.addArrow(lineStart);
  3240. this.addArrow(lineEnd);
  3241. var symbol = this.addArrow(pattern, 9);
  3242. symbol.className = 'geIcon';
  3243. symbol.style.width = '84px';
  3244. var altSymbol = this.addArrow(altPattern, 9);
  3245. altSymbol.className = 'geIcon';
  3246. altSymbol.style.width = '22px';
  3247. var solid = document.createElement('div');
  3248. solid.style.width = '85px';
  3249. solid.style.height = '1px';
  3250. solid.style.borderBottom = '1px solid black';
  3251. solid.style.marginBottom = '9px';
  3252. symbol.appendChild(solid);
  3253. var altSolid = document.createElement('div');
  3254. altSolid.style.width = '23px';
  3255. altSolid.style.height = '1px';
  3256. altSolid.style.borderBottom = '1px solid black';
  3257. altSolid.style.marginBottom = '9px';
  3258. altSymbol.appendChild(altSolid);
  3259. pattern.style.height = '15px';
  3260. altPattern.style.height = '15px';
  3261. edgeShape.style.height = '15px';
  3262. edgeStyle.style.height = '17px';
  3263. lineStart.style.marginLeft = '3px';
  3264. lineStart.style.height = '17px';
  3265. lineEnd.style.marginLeft = '3px';
  3266. lineEnd.style.height = '17px';
  3267. container.appendChild(colorPanel);
  3268. container.appendChild(altStylePanel);
  3269. container.appendChild(stylePanel);
  3270. var arrowPanel = stylePanel.cloneNode(false);
  3271. arrowPanel.style.paddingBottom = '6px';
  3272. arrowPanel.style.paddingTop = '4px';
  3273. arrowPanel.style.fontWeight = 'normal';
  3274. var span = document.createElement('div');
  3275. span.style.position = 'absolute';
  3276. span.style.marginLeft = '3px';
  3277. span.style.marginBottom = '12px';
  3278. span.style.marginTop = '2px';
  3279. span.style.fontWeight = 'normal';
  3280. span.style.width = '76px';
  3281. mxUtils.write(span, mxResources.get('lineend'));
  3282. arrowPanel.appendChild(span);
  3283. var endSpacingUpdate, endSizeUpdate;
  3284. var endSpacing = this.addUnitInput(arrowPanel, 'pt', 74, 33, function()
  3285. {
  3286. endSpacingUpdate.apply(this, arguments);
  3287. });
  3288. var endSize = this.addUnitInput(arrowPanel, 'pt', 20, 33, function()
  3289. {
  3290. endSizeUpdate.apply(this, arguments);
  3291. });
  3292. mxUtils.br(arrowPanel);
  3293. var spacer = document.createElement('div');
  3294. spacer.style.height = '8px';
  3295. arrowPanel.appendChild(spacer);
  3296. span = span.cloneNode(false);
  3297. mxUtils.write(span, mxResources.get('linestart'));
  3298. arrowPanel.appendChild(span);
  3299. var startSpacingUpdate, startSizeUpdate;
  3300. var startSpacing = this.addUnitInput(arrowPanel, 'pt', 74, 33, function()
  3301. {
  3302. startSpacingUpdate.apply(this, arguments);
  3303. });
  3304. var startSize = this.addUnitInput(arrowPanel, 'pt', 20, 33, function()
  3305. {
  3306. startSizeUpdate.apply(this, arguments);
  3307. });
  3308. mxUtils.br(arrowPanel);
  3309. this.addLabel(arrowPanel, mxResources.get('spacing'), 74, 50);
  3310. this.addLabel(arrowPanel, mxResources.get('size'), 20, 50);
  3311. mxUtils.br(arrowPanel);
  3312. var perimeterPanel = colorPanel.cloneNode(false);
  3313. perimeterPanel.style.fontWeight = 'normal';
  3314. perimeterPanel.style.position = 'relative';
  3315. perimeterPanel.style.paddingLeft = '16px'
  3316. perimeterPanel.style.marginBottom = '2px';
  3317. perimeterPanel.style.marginTop = '6px';
  3318. perimeterPanel.style.borderWidth = '0px';
  3319. perimeterPanel.style.paddingBottom = '18px';
  3320. var span = document.createElement('div');
  3321. span.style.position = 'absolute';
  3322. span.style.marginLeft = '3px';
  3323. span.style.marginBottom = '12px';
  3324. span.style.marginTop = '1px';
  3325. span.style.fontWeight = 'normal';
  3326. span.style.width = '120px';
  3327. mxUtils.write(span, mxResources.get('perimeter'));
  3328. perimeterPanel.appendChild(span);
  3329. var perimeterUpdate;
  3330. var perimeterSpacing = this.addUnitInput(perimeterPanel, 'pt', 20, 41, function()
  3331. {
  3332. perimeterUpdate.apply(this, arguments);
  3333. });
  3334. if (ss.edges.length == graph.getSelectionCount())
  3335. {
  3336. container.appendChild(stylePanel2);
  3337. if (mxClient.IS_QUIRKS)
  3338. {
  3339. mxUtils.br(container);
  3340. mxUtils.br(container);
  3341. }
  3342. container.appendChild(arrowPanel);
  3343. }
  3344. else if (ss.vertices.length == graph.getSelectionCount())
  3345. {
  3346. if (mxClient.IS_QUIRKS)
  3347. {
  3348. mxUtils.br(container);
  3349. }
  3350. container.appendChild(perimeterPanel);
  3351. }
  3352. var listener = mxUtils.bind(this, function(sender, evt, force)
  3353. {
  3354. ss = this.format.getSelectionState();
  3355. var color = mxUtils.getValue(ss.style, strokeKey, null);
  3356. if (force || document.activeElement != input)
  3357. {
  3358. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_STROKEWIDTH, 1));
  3359. input.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3360. }
  3361. if (force || document.activeElement != altInput)
  3362. {
  3363. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_STROKEWIDTH, 1));
  3364. altInput.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3365. }
  3366. styleSelect.style.visibility = (ss.style.shape == 'connector') ? '' : 'hidden';
  3367. if (mxUtils.getValue(ss.style, mxConstants.STYLE_CURVED, null) == '1')
  3368. {
  3369. styleSelect.value = 'curved';
  3370. }
  3371. else if (mxUtils.getValue(ss.style, mxConstants.STYLE_ROUNDED, null) == '1')
  3372. {
  3373. styleSelect.value = 'rounded';
  3374. }
  3375. if (mxUtils.getValue(ss.style, mxConstants.STYLE_DASHED, null) == '1')
  3376. {
  3377. if (mxUtils.getValue(ss.style, mxConstants.STYLE_DASH_PATTERN, null) == null)
  3378. {
  3379. solid.style.borderBottom = '1px dashed black';
  3380. }
  3381. else
  3382. {
  3383. solid.style.borderBottom = '1px dotted black';
  3384. }
  3385. }
  3386. else
  3387. {
  3388. solid.style.borderBottom = '1px solid black';
  3389. }
  3390. altSolid.style.borderBottom = solid.style.borderBottom;
  3391. // Updates toolbar icon for edge style
  3392. var edgeStyleDiv = edgeStyle.getElementsByTagName('div')[0];
  3393. var es = mxUtils.getValue(ss.style, mxConstants.STYLE_EDGE, null);
  3394. if (mxUtils.getValue(ss.style, mxConstants.STYLE_NOEDGESTYLE, null) == '1')
  3395. {
  3396. es = null;
  3397. }
  3398. if (es == 'orthogonalEdgeStyle' && mxUtils.getValue(ss.style, mxConstants.STYLE_CURVED, null) == '1')
  3399. {
  3400. edgeStyleDiv.className = 'geSprite geSprite-curved';
  3401. }
  3402. else if (es == 'straight' || es == 'none' || es == null)
  3403. {
  3404. edgeStyleDiv.className = 'geSprite geSprite-straight';
  3405. }
  3406. else if (es == 'entityRelationEdgeStyle')
  3407. {
  3408. edgeStyleDiv.className = 'geSprite geSprite-entity';
  3409. }
  3410. else if (es == 'elbowEdgeStyle')
  3411. {
  3412. edgeStyleDiv.className = 'geSprite ' + ((mxUtils.getValue(ss.style,
  3413. mxConstants.STYLE_ELBOW, null) == 'vertical') ?
  3414. 'geSprite-verticalelbow' : 'geSprite-horizontalelbow');
  3415. }
  3416. else if (es == 'isometricEdgeStyle')
  3417. {
  3418. edgeStyleDiv.className = 'geSprite ' + ((mxUtils.getValue(ss.style,
  3419. mxConstants.STYLE_ELBOW, null) == 'vertical') ?
  3420. 'geSprite-verticalisometric' : 'geSprite-horizontalisometric');
  3421. }
  3422. else
  3423. {
  3424. edgeStyleDiv.className = 'geSprite geSprite-orthogonal';
  3425. }
  3426. // Updates icon for edge shape
  3427. var edgeShapeDiv = edgeShape.getElementsByTagName('div')[0];
  3428. if (ss.style.shape == 'link')
  3429. {
  3430. edgeShapeDiv.className = 'geSprite geSprite-linkedge';
  3431. }
  3432. else if (ss.style.shape == 'flexArrow')
  3433. {
  3434. edgeShapeDiv.className = 'geSprite geSprite-arrow';
  3435. }
  3436. else if (ss.style.shape == 'arrow')
  3437. {
  3438. edgeShapeDiv.className = 'geSprite geSprite-simplearrow';
  3439. }
  3440. else
  3441. {
  3442. edgeShapeDiv.className = 'geSprite geSprite-connection';
  3443. }
  3444. if (ss.edges.length == graph.getSelectionCount())
  3445. {
  3446. altStylePanel.style.display = '';
  3447. stylePanel.style.display = 'none';
  3448. }
  3449. else
  3450. {
  3451. altStylePanel.style.display = 'none';
  3452. stylePanel.style.display = '';
  3453. }
  3454. function updateArrow(marker, fill, elt, prefix)
  3455. {
  3456. var markerDiv = elt.getElementsByTagName('div')[0];
  3457. markerDiv.className = ui.getCssClassForMarker(prefix, ss.style.shape, marker, fill);
  3458. return markerDiv;
  3459. };
  3460. var sourceDiv = updateArrow(mxUtils.getValue(ss.style, mxConstants.STYLE_STARTARROW, null),
  3461. mxUtils.getValue(ss.style, 'startFill', '1'), lineStart, 'start');
  3462. var targetDiv = updateArrow(mxUtils.getValue(ss.style, mxConstants.STYLE_ENDARROW, null),
  3463. mxUtils.getValue(ss.style, 'endFill', '1'), lineEnd, 'end');
  3464. // Special cases for markers
  3465. if (ss.style.shape == 'arrow')
  3466. {
  3467. sourceDiv.className = 'geSprite geSprite-noarrow';
  3468. targetDiv.className = 'geSprite geSprite-endblocktrans';
  3469. }
  3470. else if (ss.style.shape == 'link')
  3471. {
  3472. sourceDiv.className = 'geSprite geSprite-noarrow';
  3473. targetDiv.className = 'geSprite geSprite-noarrow';
  3474. }
  3475. mxUtils.setOpacity(edgeStyle, (ss.style.shape == 'arrow') ? 30 : 100);
  3476. if (ss.style.shape != 'connector' && ss.style.shape != 'flexArrow')
  3477. {
  3478. mxUtils.setOpacity(lineStart, 30);
  3479. mxUtils.setOpacity(lineEnd, 30);
  3480. }
  3481. else
  3482. {
  3483. mxUtils.setOpacity(lineStart, 100);
  3484. mxUtils.setOpacity(lineEnd, 100);
  3485. }
  3486. if (force || document.activeElement != startSize)
  3487. {
  3488. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_MARKERSIZE));
  3489. startSize.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3490. }
  3491. if (force || document.activeElement != startSpacing)
  3492. {
  3493. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_SOURCE_PERIMETER_SPACING, 0));
  3494. startSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3495. }
  3496. if (force || document.activeElement != endSize)
  3497. {
  3498. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_ENDSIZE, mxConstants.DEFAULT_MARKERSIZE));
  3499. endSize.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3500. }
  3501. if (force || document.activeElement != startSpacing)
  3502. {
  3503. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_TARGET_PERIMETER_SPACING, 0));
  3504. endSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3505. }
  3506. if (force || document.activeElement != perimeterSpacing)
  3507. {
  3508. var tmp = parseInt(mxUtils.getValue(ss.style, mxConstants.STYLE_PERIMETER_SPACING, 0));
  3509. perimeterSpacing.value = (isNaN(tmp)) ? '' : tmp + ' pt';
  3510. }
  3511. });
  3512. startSizeUpdate = this.installInputHandler(startSize, mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_MARKERSIZE, 0, 999, ' pt');
  3513. startSpacingUpdate = this.installInputHandler(startSpacing, mxConstants.STYLE_SOURCE_PERIMETER_SPACING, 0, -999, 999, ' pt');
  3514. endSizeUpdate = this.installInputHandler(endSize, mxConstants.STYLE_ENDSIZE, mxConstants.DEFAULT_MARKERSIZE, 0, 999, ' pt');
  3515. endSpacingUpdate = this.installInputHandler(endSpacing, mxConstants.STYLE_TARGET_PERIMETER_SPACING, 0, -999, 999, ' pt');
  3516. perimeterUpdate = this.installInputHandler(perimeterSpacing, mxConstants.STYLE_PERIMETER_SPACING, 0, 0, 999, ' pt');
  3517. this.addKeyHandler(input, listener);
  3518. this.addKeyHandler(startSize, listener);
  3519. this.addKeyHandler(startSpacing, listener);
  3520. this.addKeyHandler(endSize, listener);
  3521. this.addKeyHandler(endSpacing, listener);
  3522. this.addKeyHandler(perimeterSpacing, listener);
  3523. graph.getModel().addListener(mxEvent.CHANGE, listener);
  3524. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  3525. listener();
  3526. return container;
  3527. };
  3528. /**
  3529. * Adds the label menu items to the given menu and parent.
  3530. */
  3531. StyleFormatPanel.prototype.addEffects = function(div)
  3532. {
  3533. var ui = this.editorUi;
  3534. var editor = ui.editor;
  3535. var graph = editor.graph;
  3536. var ss = this.format.getSelectionState();
  3537. div.style.paddingTop = '0px';
  3538. div.style.paddingBottom = '2px';
  3539. var table = document.createElement('table');
  3540. if (mxClient.IS_QUIRKS)
  3541. {
  3542. table.style.fontSize = '1em';
  3543. }
  3544. table.style.width = '100%';
  3545. table.style.fontWeight = 'bold';
  3546. table.style.paddingRight = '20px';
  3547. var tbody = document.createElement('tbody');
  3548. var row = document.createElement('tr');
  3549. row.style.padding = '0px';
  3550. var left = document.createElement('td');
  3551. left.style.padding = '0px';
  3552. left.style.width = '50%';
  3553. left.setAttribute('valign', 'top');
  3554. var right = left.cloneNode(true);
  3555. right.style.paddingLeft = '8px';
  3556. row.appendChild(left);
  3557. row.appendChild(right);
  3558. tbody.appendChild(row);
  3559. table.appendChild(tbody);
  3560. div.appendChild(table);
  3561. var current = left;
  3562. var count = 0;
  3563. var addOption = mxUtils.bind(this, function(label, key, defaultValue)
  3564. {
  3565. var opt = this.createCellOption(label, key, defaultValue);
  3566. opt.style.width = '100%';
  3567. current.appendChild(opt);
  3568. current = (current == left) ? right : left;
  3569. count++;
  3570. });
  3571. var listener = mxUtils.bind(this, function(sender, evt, force)
  3572. {
  3573. ss = this.format.getSelectionState();
  3574. left.innerHTML = '';
  3575. right.innerHTML = '';
  3576. current = left;
  3577. if (ss.rounded)
  3578. {
  3579. addOption(mxResources.get('rounded'), mxConstants.STYLE_ROUNDED, 0);
  3580. }
  3581. if (ss.style.shape == 'swimlane')
  3582. {
  3583. addOption(mxResources.get('divider'), 'swimlaneLine', 1);
  3584. }
  3585. if (!ss.containsImage)
  3586. {
  3587. addOption(mxResources.get('shadow'), mxConstants.STYLE_SHADOW, 0);
  3588. }
  3589. if (ss.glass)
  3590. {
  3591. addOption(mxResources.get('glass'), mxConstants.STYLE_GLASS, 0);
  3592. }
  3593. if (ss.comic)
  3594. {
  3595. addOption(mxResources.get('comic'), 'comic', 0);
  3596. }
  3597. if (count == 0)
  3598. {
  3599. div.style.display = 'none';
  3600. }
  3601. });
  3602. graph.getModel().addListener(mxEvent.CHANGE, listener);
  3603. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  3604. listener();
  3605. return div;
  3606. }
  3607. /**
  3608. * Adds the label menu items to the given menu and parent.
  3609. */
  3610. StyleFormatPanel.prototype.addStyleOps = function(div)
  3611. {
  3612. div.style.paddingTop = '10px';
  3613. div.style.paddingBottom = '10px';
  3614. var btn = mxUtils.button(mxResources.get('setAsDefaultStyle'), mxUtils.bind(this, function(evt)
  3615. {
  3616. this.editorUi.actions.get('setAsDefaultStyle').funct();
  3617. }));
  3618. btn.setAttribute('title', mxResources.get('setAsDefaultStyle') + ' (' + this.editorUi.actions.get('setAsDefaultStyle').shortcut + ')');
  3619. btn.style.width = '202px';
  3620. div.appendChild(btn);
  3621. return div;
  3622. };
  3623. /**
  3624. * Adds the label menu items to the given menu and parent.
  3625. */
  3626. DiagramFormatPanel = function(format, editorUi, container)
  3627. {
  3628. BaseFormatPanel.call(this, format, editorUi, container);
  3629. this.init();
  3630. };
  3631. mxUtils.extend(DiagramFormatPanel, BaseFormatPanel);
  3632. /**
  3633. * Specifies if the background image option should be shown. Default is true.
  3634. */
  3635. DiagramFormatPanel.prototype.showBackgroundImageOption = true;
  3636. /**
  3637. * Adds the label menu items to the given menu and parent.
  3638. */
  3639. DiagramFormatPanel.prototype.init = function()
  3640. {
  3641. var ui = this.editorUi;
  3642. var editor = ui.editor;
  3643. var graph = editor.graph;
  3644. this.container.appendChild(this.addView(this.createPanel()));
  3645. if (graph.isEnabled())
  3646. {
  3647. this.container.appendChild(this.addOptions(this.createPanel()));
  3648. this.container.appendChild(this.addPaperSize(this.createPanel()));
  3649. this.container.appendChild(this.addStyleOps(this.createPanel()));
  3650. }
  3651. };
  3652. /**
  3653. * Adds the label menu items to the given menu and parent.
  3654. */
  3655. DiagramFormatPanel.prototype.addView = function(div)
  3656. {
  3657. var ui = this.editorUi;
  3658. var editor = ui.editor;
  3659. var graph = editor.graph;
  3660. div.appendChild(this.createTitle(mxResources.get('view')));
  3661. // Grid
  3662. this.addGridOption(div);
  3663. if (graph.isEnabled())
  3664. {
  3665. // Guides
  3666. div.appendChild(this.createOption(mxResources.get('guides'), function()
  3667. {
  3668. return graph.graphHandler.guidesEnabled;
  3669. }, function(checked)
  3670. {
  3671. ui.actions.get('guides').funct();
  3672. },
  3673. {
  3674. install: function(apply)
  3675. {
  3676. this.listener = function()
  3677. {
  3678. apply(graph.graphHandler.guidesEnabled);
  3679. };
  3680. ui.addListener('guidesEnabledChanged', this.listener);
  3681. },
  3682. destroy: function()
  3683. {
  3684. ui.removeListener(this.listener);
  3685. }
  3686. }));
  3687. // Page View
  3688. div.appendChild(this.createOption(mxResources.get('pageView'), function()
  3689. {
  3690. return graph.pageVisible;
  3691. }, function(checked)
  3692. {
  3693. ui.actions.get('pageView').funct();
  3694. },
  3695. {
  3696. install: function(apply)
  3697. {
  3698. this.listener = function()
  3699. {
  3700. apply(graph.pageVisible);
  3701. };
  3702. ui.addListener('pageViewChanged', this.listener);
  3703. },
  3704. destroy: function()
  3705. {
  3706. ui.removeListener(this.listener);
  3707. }
  3708. }));
  3709. // Background
  3710. var bg = this.createColorOption(mxResources.get('background'), function()
  3711. {
  3712. return graph.background;
  3713. }, function(color)
  3714. {
  3715. ui.setBackgroundColor(color);
  3716. }, '#ffffff',
  3717. {
  3718. install: function(apply)
  3719. {
  3720. this.listener = function()
  3721. {
  3722. apply(graph.background);
  3723. };
  3724. ui.addListener('backgroundColorChanged', this.listener);
  3725. },
  3726. destroy: function()
  3727. {
  3728. ui.removeListener(this.listener);
  3729. }
  3730. });
  3731. if (this.showBackgroundImageOption)
  3732. {
  3733. var btn = mxUtils.button(mxResources.get('image'), function(evt)
  3734. {
  3735. ui.showBackgroundImageDialog();
  3736. mxEvent.consume(evt);
  3737. })
  3738. btn.style.position = 'absolute';
  3739. btn.className = 'geColorBtn';
  3740. btn.style.marginTop = '-4px';
  3741. btn.style.paddingBottom = (document.documentMode == 11 || mxClient.IS_MT) ? '0px' : '2px';
  3742. btn.style.height = '22px';
  3743. btn.style.right = (mxClient.IS_QUIRKS) ? '52px' : '72px';
  3744. btn.style.width = '56px';
  3745. bg.appendChild(btn);
  3746. }
  3747. div.appendChild(bg);
  3748. }
  3749. return div;
  3750. };
  3751. /**
  3752. * Adds the label menu items to the given menu and parent.
  3753. */
  3754. DiagramFormatPanel.prototype.addOptions = function(div)
  3755. {
  3756. var ui = this.editorUi;
  3757. var editor = ui.editor;
  3758. var graph = editor.graph;
  3759. div.appendChild(this.createTitle(mxResources.get('options')));
  3760. if (graph.isEnabled())
  3761. {
  3762. // Connection arrows
  3763. div.appendChild(this.createOption(mxResources.get('connectionArrows'), function()
  3764. {
  3765. return graph.connectionArrowsEnabled;
  3766. }, function(checked)
  3767. {
  3768. ui.actions.get('connectionArrows').funct();
  3769. },
  3770. {
  3771. install: function(apply)
  3772. {
  3773. this.listener = function()
  3774. {
  3775. apply(graph.connectionArrowsEnabled);
  3776. };
  3777. ui.addListener('connectionArrowsChanged', this.listener);
  3778. },
  3779. destroy: function()
  3780. {
  3781. ui.removeListener(this.listener);
  3782. }
  3783. }));
  3784. // Connection points
  3785. div.appendChild(this.createOption(mxResources.get('connectionPoints'), function()
  3786. {
  3787. return graph.connectionHandler.isEnabled();
  3788. }, function(checked)
  3789. {
  3790. ui.actions.get('connectionPoints').funct();
  3791. },
  3792. {
  3793. install: function(apply)
  3794. {
  3795. this.listener = function()
  3796. {
  3797. apply(graph.connectionHandler.isEnabled());
  3798. };
  3799. ui.addListener('connectionPointsChanged', this.listener);
  3800. },
  3801. destroy: function()
  3802. {
  3803. ui.removeListener(this.listener);
  3804. }
  3805. }));
  3806. }
  3807. return div;
  3808. };
  3809. /**
  3810. *
  3811. */
  3812. DiagramFormatPanel.prototype.addGridOption = function(container)
  3813. {
  3814. var ui = this.editorUi;
  3815. var graph = ui.editor.graph;
  3816. var input = document.createElement('input');
  3817. input.style.position = 'absolute';
  3818. input.style.textAlign = 'right';
  3819. input.style.width = '38px';
  3820. input.value = graph.getGridSize() + ' pt';
  3821. var stepper = this.createStepper(input, update);
  3822. input.style.display = (graph.isGridEnabled()) ? '' : 'none';
  3823. stepper.style.display = input.style.display;
  3824. mxEvent.addListener(input, 'keydown', function(e)
  3825. {
  3826. if (e.keyCode == 13)
  3827. {
  3828. graph.container.focus();
  3829. mxEvent.consume(e);
  3830. }
  3831. else if (e.keyCode == 27)
  3832. {
  3833. input.value = graph.getGridSize();
  3834. graph.container.focus();
  3835. mxEvent.consume(e);
  3836. }
  3837. });
  3838. function update(evt)
  3839. {
  3840. var value = parseInt(input.value);
  3841. value = Math.max(1, (isNaN(value)) ? 10 : value);
  3842. if (value != graph.getGridSize())
  3843. {
  3844. graph.setGridSize(value)
  3845. }
  3846. input.value = value + ' pt';
  3847. mxEvent.consume(evt);
  3848. };
  3849. mxEvent.addListener(input, 'blur', update);
  3850. mxEvent.addListener(input, 'change', update);
  3851. if (mxClient.IS_SVG)
  3852. {
  3853. input.style.marginTop = '-2px';
  3854. input.style.right = '84px';
  3855. stepper.style.marginTop = '-16px';
  3856. stepper.style.right = '72px';
  3857. var panel = this.createColorOption(mxResources.get('grid'), function()
  3858. {
  3859. var color = graph.view.gridColor;
  3860. return (graph.isGridEnabled()) ? color : null;
  3861. }, function(color)
  3862. {
  3863. if (color == mxConstants.NONE)
  3864. {
  3865. graph.setGridEnabled(false);
  3866. ui.fireEvent(new mxEventObject('gridEnabledChanged'));
  3867. }
  3868. else
  3869. {
  3870. graph.setGridEnabled(true);
  3871. ui.setGridColor(color);
  3872. }
  3873. input.style.display = (graph.isGridEnabled()) ? '' : 'none';
  3874. stepper.style.display = input.style.display;
  3875. }, '#e0e0e0',
  3876. {
  3877. install: function(apply)
  3878. {
  3879. this.listener = function()
  3880. {
  3881. apply((graph.isGridEnabled()) ? graph.view.gridColor : null);
  3882. };
  3883. ui.addListener('gridColorChanged', this.listener);
  3884. ui.addListener('gridEnabledChanged', this.listener);
  3885. },
  3886. destroy: function()
  3887. {
  3888. ui.removeListener(this.listener);
  3889. }
  3890. });
  3891. panel.appendChild(input);
  3892. panel.appendChild(stepper);
  3893. container.appendChild(panel);
  3894. }
  3895. else
  3896. {
  3897. input.style.marginTop = '2px';
  3898. input.style.right = '32px';
  3899. stepper.style.marginTop = '2px';
  3900. stepper.style.right = '20px';
  3901. container.appendChild(input);
  3902. container.appendChild(stepper);
  3903. container.appendChild(this.createOption(mxResources.get('grid'), function()
  3904. {
  3905. return graph.isGridEnabled();
  3906. }, function(checked)
  3907. {
  3908. graph.setGridEnabled(checked);
  3909. if (graph.isGridEnabled())
  3910. {
  3911. graph.view.gridColor = '#e0e0e0';
  3912. }
  3913. ui.fireEvent(new mxEventObject('gridEnabledChanged'));
  3914. },
  3915. {
  3916. install: function(apply)
  3917. {
  3918. this.listener = function()
  3919. {
  3920. input.style.display = (graph.isGridEnabled()) ? '' : 'none';
  3921. stepper.style.display = input.style.display;
  3922. apply(graph.isGridEnabled());
  3923. };
  3924. ui.addListener('gridEnabledChanged', this.listener);
  3925. },
  3926. destroy: function()
  3927. {
  3928. ui.removeListener(this.listener);
  3929. }
  3930. }));
  3931. }
  3932. };
  3933. /**
  3934. * Adds the label menu items to the given menu and parent.
  3935. */
  3936. DiagramFormatPanel.prototype.addDocumentProperties = function(div)
  3937. {
  3938. // Hook for subclassers
  3939. var ui = this.editorUi;
  3940. var editor = ui.editor;
  3941. var graph = editor.graph;
  3942. div.appendChild(this.createTitle(mxResources.get('options')));
  3943. return div;
  3944. };
  3945. /**
  3946. * Adds the label menu items to the given menu and parent.
  3947. */
  3948. DiagramFormatPanel.prototype.addPaperSize = function(div)
  3949. {
  3950. var ui = this.editorUi;
  3951. var editor = ui.editor;
  3952. var graph = editor.graph;
  3953. div.appendChild(this.createTitle(mxResources.get('paperSize')));
  3954. var accessor = PageSetupDialog.addPageFormatPanel(div, 'formatpanel', graph.pageFormat, function(pageFormat)
  3955. {
  3956. if (graph.pageFormat == null || graph.pageFormat.width != pageFormat.width || graph.pageFormat.height != pageFormat.height)
  3957. {
  3958. ui.setPageFormat(pageFormat);
  3959. }
  3960. });
  3961. this.addKeyHandler(accessor.widthInput, function()
  3962. {
  3963. console.log('here', graph.pageFormat);
  3964. accessor.set(graph.pageFormat);
  3965. });
  3966. - this.addKeyHandler(accessor.heightInput, function()
  3967. {
  3968. accessor.set(graph.pageFormat);
  3969. });
  3970. var listener = function()
  3971. {
  3972. accessor.set(graph.pageFormat);
  3973. };
  3974. ui.addListener('pageFormatChanged', listener);
  3975. this.listeners.push({destroy: function() { ui.removeListener(listener); }});
  3976. graph.getModel().addListener(mxEvent.CHANGE, listener);
  3977. this.listeners.push({destroy: function() { graph.getModel().removeListener(listener); }});
  3978. return div;
  3979. };
  3980. /**
  3981. * Adds the label menu items to the given menu and parent.
  3982. */
  3983. DiagramFormatPanel.prototype.addStyleOps = function(div)
  3984. {
  3985. var btn = mxUtils.button(mxResources.get('editData'), mxUtils.bind(this, function(evt)
  3986. {
  3987. this.editorUi.actions.get('editData').funct();
  3988. }));
  3989. btn.setAttribute('title', mxResources.get('editData') + ' (' + this.editorUi.actions.get('editData').shortcut + ')');
  3990. btn.style.width = '202px';
  3991. btn.style.marginBottom = '2px';
  3992. div.appendChild(btn);
  3993. mxUtils.br(div);
  3994. btn = mxUtils.button(mxResources.get('clearDefaultStyle'), mxUtils.bind(this, function(evt)
  3995. {
  3996. this.editorUi.actions.get('clearDefaultStyle').funct();
  3997. }));
  3998. btn.setAttribute('title', mxResources.get('clearDefaultStyle') + ' (' + this.editorUi.actions.get('clearDefaultStyle').shortcut + ')');
  3999. btn.style.width = '202px';
  4000. div.appendChild(btn);
  4001. return div;
  4002. };
  4003. /**
  4004. * Adds the label menu items to the given menu and parent.
  4005. */
  4006. DiagramFormatPanel.prototype.destroy = function()
  4007. {
  4008. BaseFormatPanel.prototype.destroy.apply(this, arguments);
  4009. if (this.gridEnabledListener)
  4010. {
  4011. this.editorUi.removeListener(this.gridEnabledListener);
  4012. this.gridEnabledListener = null;
  4013. }
  4014. };