Format.js 139 KB

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