Format.js 144 KB

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