Format.js 141 KB

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