Format.js 152 KB

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