mxEditor.js 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120
  1. /**
  2. * Copyright (c) 2006-2019, JGraph Ltd
  3. * Copyright (c) 2006-2019, draw.io AG
  4. */
  5. /**
  6. * Class: mxEditor
  7. *
  8. * Extends <mxEventSource> to implement an application wrapper for a graph that
  9. * adds <actions>, I/O using <mxCodec>, auto-layout using <mxLayoutManager>,
  10. * command history using <undoManager>, and standard dialogs and widgets, eg.
  11. * properties, help, outline, toolbar, and popupmenu. It also adds <templates>
  12. * to be used as cells in toolbars, auto-validation using the <validation>
  13. * flag, attribute cycling using <cycleAttributeValues>, higher-level events
  14. * such as <root>, and backend integration using <urlPost> and <urlImage>.
  15. *
  16. * Actions:
  17. *
  18. * Actions are functions stored in the <actions> array under their names. The
  19. * functions take the <mxEditor> as the first, and an optional <mxCell> as the
  20. * second argument and are invoked using <execute>. Any additional arguments
  21. * passed to execute are passed on to the action as-is.
  22. *
  23. * A list of built-in actions is available in the <addActions> description.
  24. *
  25. * Read/write Diagrams:
  26. *
  27. * To read a diagram from an XML string, for example from a textfield within the
  28. * page, the following code is used:
  29. *
  30. * (code)
  31. * var doc = mxUtils.parseXML(xmlString);
  32. * var node = doc.documentElement;
  33. * editor.readGraphModel(node);
  34. * (end)
  35. *
  36. * For reading a diagram from a remote location, use the <open> method.
  37. *
  38. * To save diagrams in XML on a server, you can set the <urlPost> variable.
  39. * This variable will be used in <getUrlPost> to construct a URL for the post
  40. * request that is issued in the <save> method. The post request contains the
  41. * XML representation of the diagram as returned by <writeGraphModel> in the
  42. * xml parameter.
  43. *
  44. * On the server side, the post request is processed using standard
  45. * technologies such as Java Servlets, CGI, .NET or ASP.
  46. *
  47. * Here are some examples of processing a post request in various languages.
  48. *
  49. * - Java: URLDecoder.decode(request.getParameter("xml"), "UTF-8").replace("\n", "&#xa;")
  50. *
  51. * Note that the linefeeds should only be replaced if the XML is
  52. * processed in Java, for example when creating an image, but not
  53. * if the XML is passed back to the client-side.
  54. *
  55. * - .NET: HttpUtility.UrlDecode(context.Request.Params["xml"])
  56. * - PHP: urldecode($_POST["xml"])
  57. *
  58. * Creating images:
  59. *
  60. * A backend (Java, PHP or C#) is required for creating images. The
  61. * distribution contains an example for each backend (ImageHandler.java,
  62. * ImageHandler.cs and graph.php). More information about using a backend
  63. * to create images can be found in the readme.html files. Note that the
  64. * preview is implemented using VML/SVG in the browser and does not require
  65. * a backend. The backend is only required to creates images (bitmaps).
  66. *
  67. * Special characters:
  68. *
  69. * Note There are five characters that should always appear in XML content as
  70. * escapes, so that they do not interact with the syntax of the markup. These
  71. * are part of the language for all documents based on XML and for HTML.
  72. *
  73. * - &lt; (<)
  74. * - &gt; (>)
  75. * - &amp; (&)
  76. * - &quot; (")
  77. * - &apos; (')
  78. *
  79. * Although it is part of the XML language, &apos; is not defined in HTML.
  80. * For this reason the XHTML specification recommends instead the use of
  81. * &#39; if text may be passed to a HTML user agent.
  82. *
  83. * If you are having problems with special characters on the server-side then
  84. * you may want to try the <escapePostData> flag.
  85. *
  86. * For converting decimal escape sequences inside strings, a user has provided
  87. * us with the following function:
  88. *
  89. * (code)
  90. * function html2js(text)
  91. * {
  92. * var entitySearch = /&#[0-9]+;/;
  93. * var entity;
  94. *
  95. * while (entity = entitySearch.exec(text))
  96. * {
  97. * var charCode = entity[0].substring(2, entity[0].length -1);
  98. * text = text.substring(0, entity.index)
  99. * + String.fromCharCode(charCode)
  100. * + text.substring(entity.index + entity[0].length);
  101. * }
  102. *
  103. * return text;
  104. * }
  105. * (end)
  106. *
  107. * Otherwise try using hex escape sequences and the built-in unescape function
  108. * for converting such strings.
  109. *
  110. * Local Files:
  111. *
  112. * For saving and opening local files, no standardized method exists that
  113. * works across all browsers. The recommended way of dealing with local files
  114. * is to create a backend that streams the XML data back to the browser (echo)
  115. * as an attachment so that a Save-dialog is displayed on the client-side and
  116. * the file can be saved to the local disk.
  117. *
  118. * For example, in PHP the code that does this looks as follows.
  119. *
  120. * (code)
  121. * $xml = stripslashes($_POST["xml"]);
  122. * header("Content-Disposition: attachment; filename=\"diagram.xml\"");
  123. * echo($xml);
  124. * (end)
  125. *
  126. * To open a local file, the file should be uploaded via a form in the browser
  127. * and then opened from the server in the editor.
  128. *
  129. * Cell Properties:
  130. *
  131. * The properties displayed in the properties dialog are the attributes and
  132. * values of the cell's user object, which is an XML node. The XML node is
  133. * defined in the templates section of the config file.
  134. *
  135. * The templates are stored in <mxEditor.templates> and contain cells which
  136. * are cloned at insertion time to create new vertices by use of drag and
  137. * drop from the toolbar. Each entry in the toolbar for adding a new vertex
  138. * must refer to an existing template.
  139. *
  140. * In the following example, the task node is a business object and only the
  141. * mxCell node and its mxGeometry child contain graph information:
  142. *
  143. * (code)
  144. * <Task label="Task" description="">
  145. * <mxCell vertex="true">
  146. * <mxGeometry as="geometry" width="72" height="32"/>
  147. * </mxCell>
  148. * </Task>
  149. * (end)
  150. *
  151. * The idea is that the XML representation is inverse from the in-memory
  152. * representation: The outer XML node is the user object and the inner node is
  153. * the cell. This means the user object of the cell is the Task node with no
  154. * children for the above example:
  155. *
  156. * (code)
  157. * <Task label="Task" description=""/>
  158. * (end)
  159. *
  160. * The Task node can have any tag name, attributes and child nodes. The
  161. * <mxCodec> will use the XML hierarchy as the user object, while removing the
  162. * "known annotations", such as the mxCell node. At save-time the cell data
  163. * will be "merged" back into the user object. The user object is only modified
  164. * via the properties dialog during the lifecycle of the cell.
  165. *
  166. * In the default implementation of <createProperties>, the user object's
  167. * attributes are put into a form for editing. Attributes are changed using
  168. * the <mxCellAttributeChange> action in the model. The dialog can be replaced
  169. * by overriding the <createProperties> hook or by replacing the showProperties
  170. * action in <actions>. Alternatively, the entry in the config file's popupmenu
  171. * section can be modified to invoke a different action.
  172. *
  173. * If you want to displey the properties dialog on a doubleclick, you can set
  174. * <mxEditor.dblClickAction> to showProperties as follows:
  175. *
  176. * (code)
  177. * editor.dblClickAction = 'showProperties';
  178. * (end)
  179. *
  180. * Popupmenu and Toolbar:
  181. *
  182. * The toolbar and popupmenu are typically configured using the respective
  183. * sections in the config file, that is, the popupmenu is defined as follows:
  184. *
  185. * (code)
  186. * <mxEditor>
  187. * <mxDefaultPopupMenu as="popupHandler">
  188. * <add as="cut" action="cut" icon="images/cut.gif"/>
  189. * ...
  190. * (end)
  191. *
  192. * New entries can be added to the toolbar by inserting an add-node into the
  193. * above configuration. Existing entries may be removed and changed by
  194. * modifying or removing the respective entries in the configuration.
  195. * The configuration is read by the <mxDefaultPopupMenuCodec>, the format of the
  196. * configuration is explained in <mxDefaultPopupMenu.decode>.
  197. *
  198. * The toolbar is defined in the mxDefaultToolbar section. Items can be added
  199. * and removed in this section.
  200. *
  201. * (code)
  202. * <mxEditor>
  203. * <mxDefaultToolbar>
  204. * <add as="save" action="save" icon="images/save.gif"/>
  205. * <add as="Swimlane" template="swimlane" icon="images/swimlane.gif"/>
  206. * ...
  207. * (end)
  208. *
  209. * The format of the configuration is described in
  210. * <mxDefaultToolbarCodec.decode>.
  211. *
  212. * Ids:
  213. *
  214. * For the IDs, there is an implicit behaviour in <mxCodec>: It moves the Id
  215. * from the cell to the user object at encoding time and vice versa at decoding
  216. * time. For example, if the Task node from above has an id attribute, then
  217. * the <mxCell.id> of the corresponding cell will have this value. If there
  218. * is no Id collision in the model, then the cell may be retrieved using this
  219. * Id with the <mxGraphModel.getCell> function. If there is a collision, a new
  220. * Id will be created for the cell using <mxGraphModel.createId>. At encoding
  221. * time, this new Id will replace the value previously stored under the id
  222. * attribute in the Task node.
  223. *
  224. * See <mxEditorCodec>, <mxDefaultToolbarCodec> and <mxDefaultPopupMenuCodec>
  225. * for information about configuring the editor and user interface.
  226. *
  227. * Programmatically inserting cells:
  228. *
  229. * For inserting a new cell, say, by clicking a button in the document,
  230. * the following code can be used. This requires an reference to the editor.
  231. *
  232. * (code)
  233. * var userObject = new Object();
  234. * var parent = editor.graph.getDefaultParent();
  235. * var model = editor.graph.model;
  236. * model.beginUpdate();
  237. * try
  238. * {
  239. * editor.graph.insertVertex(parent, null, userObject, 20, 20, 80, 30);
  240. * }
  241. * finally
  242. * {
  243. * model.endUpdate();
  244. * }
  245. * (end)
  246. *
  247. * If a template cell from the config file should be inserted, then a clone
  248. * of the template can be created as follows. The clone is then inserted using
  249. * the add function instead of addVertex.
  250. *
  251. * (code)
  252. * var template = editor.templates['task'];
  253. * var clone = editor.graph.model.cloneCell(template);
  254. * (end)
  255. *
  256. * Resources:
  257. *
  258. * resources/editor - Language resources for mxEditor
  259. *
  260. * Callback: onInit
  261. *
  262. * Called from within the constructor. In the callback,
  263. * "this" refers to the editor instance.
  264. *
  265. * Cookie: mxgraph=seen
  266. *
  267. * Set when the editor is started. Never expires. Use
  268. * <resetFirstTime> to reset this cookie. This cookie
  269. * only exists if <onInit> is implemented.
  270. *
  271. * Event: mxEvent.OPEN
  272. *
  273. * Fires after a file was opened in <open>. The <code>filename</code> property
  274. * contains the filename that was used. The same value is also available in
  275. * <filename>.
  276. *
  277. * Event: mxEvent.SAVE
  278. *
  279. * Fires after the current file was saved in <save>. The <code>url</code>
  280. * property contains the URL that was used for saving.
  281. *
  282. * Event: mxEvent.POST
  283. *
  284. * Fires if a successful response was received in <postDiagram>. The
  285. * <code>request</code> property contains the <mxXmlRequest>, the
  286. * <code>url</code> and <code>data</code> properties contain the URL and the
  287. * data that were used in the post request.
  288. *
  289. * Event: mxEvent.ROOT
  290. *
  291. * Fires when the current root has changed, or when the title of the current
  292. * root has changed. This event has no properties.
  293. *
  294. * Event: mxEvent.BEFORE_ADD_VERTEX
  295. *
  296. * Fires before a vertex is added in <addVertex>. The <code>vertex</code>
  297. * property contains the new vertex and the <code>parent</code> property
  298. * contains its parent.
  299. *
  300. * Event: mxEvent.ADD_VERTEX
  301. *
  302. * Fires between begin- and endUpdate in <addVertex>. The <code>vertex</code>
  303. * property contains the vertex that is being inserted.
  304. *
  305. * Event: mxEvent.AFTER_ADD_VERTEX
  306. *
  307. * Fires after a vertex was inserted and selected in <addVertex>. The
  308. * <code>vertex</code> property contains the new vertex.
  309. *
  310. * Example:
  311. *
  312. * For starting an in-place edit after a new vertex has been added to the
  313. * graph, the following code can be used.
  314. *
  315. * (code)
  316. * editor.addListener(mxEvent.AFTER_ADD_VERTEX, function(sender, evt)
  317. * {
  318. * var vertex = evt.getProperty('vertex');
  319. *
  320. * if (editor.graph.isCellEditable(vertex))
  321. * {
  322. * editor.graph.startEditingAtCell(vertex);
  323. * }
  324. * });
  325. * (end)
  326. *
  327. * Event: mxEvent.ESCAPE
  328. *
  329. * Fires when the escape key is pressed. The <code>event</code> property
  330. * contains the key event.
  331. *
  332. * Constructor: mxEditor
  333. *
  334. * Constructs a new editor. This function invokes the <onInit> callback
  335. * upon completion.
  336. *
  337. * Example:
  338. *
  339. * (code)
  340. * var config = mxUtils.load('config/diagrameditor.xml').getDocumentElement();
  341. * var editor = new mxEditor(config);
  342. * (end)
  343. *
  344. * Parameters:
  345. *
  346. * config - Optional XML node that contains the configuration.
  347. */
  348. function mxEditor(config)
  349. {
  350. this.actions = [];
  351. this.addActions();
  352. // Executes the following only if a document has been instanciated.
  353. // That is, don't execute when the editorcodec is setup.
  354. if (document.body != null)
  355. {
  356. // Defines instance fields
  357. this.cycleAttributeValues = [];
  358. this.popupHandler = new mxDefaultPopupMenu();
  359. this.undoManager = new mxUndoManager();
  360. // Creates the graph and toolbar without the containers
  361. this.graph = this.createGraph();
  362. this.toolbar = this.createToolbar();
  363. // Creates the global keyhandler (requires graph instance)
  364. this.keyHandler = new mxDefaultKeyHandler(this);
  365. // Configures the editor using the URI
  366. // which was passed to the ctor
  367. this.configure(config);
  368. // Assigns the swimlaneIndicatorColorAttribute on the graph
  369. this.graph.swimlaneIndicatorColorAttribute = this.cycleAttributeName;
  370. // Checks if the <onInit> hook has been set
  371. if (this.onInit != null)
  372. {
  373. // Invokes the <onInit> hook
  374. this.onInit();
  375. }
  376. // Automatic deallocation of memory
  377. if (mxClient.IS_IE)
  378. {
  379. mxEvent.addListener(window, 'unload', mxUtils.bind(this, function()
  380. {
  381. this.destroy();
  382. }));
  383. }
  384. }
  385. };
  386. /**
  387. * Installs the required language resources at class
  388. * loading time.
  389. */
  390. if (mxLoadResources)
  391. {
  392. mxResources.add(mxClient.basePath + '/resources/editor');
  393. }
  394. else
  395. {
  396. mxClient.defaultBundles.push(mxClient.basePath + '/resources/editor');
  397. }
  398. /**
  399. * Extends mxEventSource.
  400. */
  401. mxEditor.prototype = new mxEventSource();
  402. mxEditor.prototype.constructor = mxEditor;
  403. /**
  404. * Group: Controls and Handlers
  405. */
  406. /**
  407. * Variable: askZoomResource
  408. *
  409. * Specifies the resource key for the zoom dialog. If the resource for this
  410. * key does not exist then the value is used as the error message. Default
  411. * is 'askZoom'.
  412. */
  413. mxEditor.prototype.askZoomResource = (mxClient.language != 'none') ? 'askZoom' : '';
  414. /**
  415. * Variable: lastSavedResource
  416. *
  417. * Specifies the resource key for the last saved info. If the resource for
  418. * this key does not exist then the value is used as the error message.
  419. * Default is 'lastSaved'.
  420. */
  421. mxEditor.prototype.lastSavedResource = (mxClient.language != 'none') ? 'lastSaved' : '';
  422. /**
  423. * Variable: currentFileResource
  424. *
  425. * Specifies the resource key for the current file info. If the resource for
  426. * this key does not exist then the value is used as the error message.
  427. * Default is 'currentFile'.
  428. */
  429. mxEditor.prototype.currentFileResource = (mxClient.language != 'none') ? 'currentFile' : '';
  430. /**
  431. * Variable: propertiesResource
  432. *
  433. * Specifies the resource key for the properties window title. If the
  434. * resource for this key does not exist then the value is used as the
  435. * error message. Default is 'properties'.
  436. */
  437. mxEditor.prototype.propertiesResource = (mxClient.language != 'none') ? 'properties' : '';
  438. /**
  439. * Variable: tasksResource
  440. *
  441. * Specifies the resource key for the tasks window title. If the
  442. * resource for this key does not exist then the value is used as the
  443. * error message. Default is 'tasks'.
  444. */
  445. mxEditor.prototype.tasksResource = (mxClient.language != 'none') ? 'tasks' : '';
  446. /**
  447. * Variable: helpResource
  448. *
  449. * Specifies the resource key for the help window title. If the
  450. * resource for this key does not exist then the value is used as the
  451. * error message. Default is 'help'.
  452. */
  453. mxEditor.prototype.helpResource = (mxClient.language != 'none') ? 'help' : '';
  454. /**
  455. * Variable: outlineResource
  456. *
  457. * Specifies the resource key for the outline window title. If the
  458. * resource for this key does not exist then the value is used as the
  459. * error message. Default is 'outline'.
  460. */
  461. mxEditor.prototype.outlineResource = (mxClient.language != 'none') ? 'outline' : '';
  462. /**
  463. * Variable: outline
  464. *
  465. * Reference to the <mxWindow> that contains the outline. The <mxOutline>
  466. * is stored in outline.outline.
  467. */
  468. mxEditor.prototype.outline = null;
  469. /**
  470. * Variable: graph
  471. *
  472. * Holds a <mxGraph> for displaying the diagram. The graph
  473. * is created in <setGraphContainer>.
  474. */
  475. mxEditor.prototype.graph = null;
  476. /**
  477. * Variable: graphRenderHint
  478. *
  479. * Holds the render hint used for creating the
  480. * graph in <setGraphContainer>. See <mxGraph>.
  481. * Default is null.
  482. */
  483. mxEditor.prototype.graphRenderHint = null;
  484. /**
  485. * Variable: toolbar
  486. *
  487. * Holds a <mxDefaultToolbar> for displaying the toolbar. The
  488. * toolbar is created in <setToolbarContainer>.
  489. */
  490. mxEditor.prototype.toolbar = null;
  491. /**
  492. * Variable: status
  493. *
  494. * DOM container that holds the statusbar. Default is null.
  495. * Use <setStatusContainer> to set this value.
  496. */
  497. mxEditor.prototype.status = null;
  498. /**
  499. * Variable: popupHandler
  500. *
  501. * Holds a <mxDefaultPopupMenu> for displaying
  502. * popupmenus.
  503. */
  504. mxEditor.prototype.popupHandler = null;
  505. /**
  506. * Variable: undoManager
  507. *
  508. * Holds an <mxUndoManager> for the command history.
  509. */
  510. mxEditor.prototype.undoManager = null;
  511. /**
  512. * Variable: keyHandler
  513. *
  514. * Holds a <mxDefaultKeyHandler> for handling keyboard events.
  515. * The handler is created in <setGraphContainer>.
  516. */
  517. mxEditor.prototype.keyHandler = null;
  518. /**
  519. * Group: Actions and Options
  520. */
  521. /**
  522. * Variable: actions
  523. *
  524. * Maps from actionnames to actions, which are functions taking
  525. * the editor and the cell as arguments. Use <addAction>
  526. * to add or replace an action and <execute> to execute an action
  527. * by name, passing the cell to be operated upon as the second
  528. * argument.
  529. */
  530. mxEditor.prototype.actions = null;
  531. /**
  532. * Variable: dblClickAction
  533. *
  534. * Specifies the name of the action to be executed
  535. * when a cell is double clicked. Default is 'edit'.
  536. *
  537. * To handle a singleclick, use the following code.
  538. *
  539. * (code)
  540. * editor.graph.addListener(mxEvent.CLICK, function(sender, evt)
  541. * {
  542. * var e = evt.getProperty('event');
  543. * var cell = evt.getProperty('cell');
  544. *
  545. * if (cell != null && !e.isConsumed())
  546. * {
  547. * // Do something useful with cell...
  548. * e.consume();
  549. * }
  550. * });
  551. * (end)
  552. */
  553. mxEditor.prototype.dblClickAction = 'edit';
  554. /**
  555. * Variable: swimlaneRequired
  556. *
  557. * Specifies if new cells must be inserted
  558. * into an existing swimlane. Otherwise, cells
  559. * that are not swimlanes can be inserted as
  560. * top-level cells. Default is false.
  561. */
  562. mxEditor.prototype.swimlaneRequired = false;
  563. /**
  564. * Variable: disableContextMenu
  565. *
  566. * Specifies if the context menu should be disabled in the graph container.
  567. * Default is true.
  568. */
  569. mxEditor.prototype.disableContextMenu = true;
  570. /**
  571. * Group: Templates
  572. */
  573. /**
  574. * Variable: insertFunction
  575. *
  576. * Specifies the function to be used for inserting new
  577. * cells into the graph. This is assigned from the
  578. * <mxDefaultToolbar> if a vertex-tool is clicked.
  579. */
  580. mxEditor.prototype.insertFunction = null;
  581. /**
  582. * Variable: forcedInserting
  583. *
  584. * Specifies if a new cell should be inserted on a single
  585. * click even using <insertFunction> if there is a cell
  586. * under the mousepointer, otherwise the cell under the
  587. * mousepointer is selected. Default is false.
  588. */
  589. mxEditor.prototype.forcedInserting = false;
  590. /**
  591. * Variable: templates
  592. *
  593. * Maps from names to protoype cells to be used
  594. * in the toolbar for inserting new cells into
  595. * the diagram.
  596. */
  597. mxEditor.prototype.templates = null;
  598. /**
  599. * Variable: defaultEdge
  600. *
  601. * Prototype edge cell that is used for creating
  602. * new edges.
  603. */
  604. mxEditor.prototype.defaultEdge = null;
  605. /**
  606. * Variable: defaultEdgeStyle
  607. *
  608. * Specifies the edge style to be returned in <getEdgeStyle>.
  609. * Default is null.
  610. */
  611. mxEditor.prototype.defaultEdgeStyle = null;
  612. /**
  613. * Variable: defaultGroup
  614. *
  615. * Prototype group cell that is used for creating
  616. * new groups.
  617. */
  618. mxEditor.prototype.defaultGroup = null;
  619. /**
  620. * Variable: groupBorderSize
  621. *
  622. * Default size for the border of new groups. If null,
  623. * then then <mxGraph.gridSize> is used. Default is
  624. * null.
  625. */
  626. mxEditor.prototype.groupBorderSize = null;
  627. /**
  628. * Group: Backend Integration
  629. */
  630. /**
  631. * Variable: filename
  632. *
  633. * Contains the URL of the last opened file as a string.
  634. * Default is null.
  635. */
  636. mxEditor.prototype.filename = null;
  637. /**
  638. * Variable: lineFeed
  639. *
  640. * Character to be used for encoding linefeeds in <save>. Default is '&#xa;'.
  641. */
  642. mxEditor.prototype.linefeed = '&#xa;';
  643. /**
  644. * Variable: postParameterName
  645. *
  646. * Specifies if the name of the post parameter that contains the diagram
  647. * data in a post request to the server. Default is 'xml'.
  648. */
  649. mxEditor.prototype.postParameterName = 'xml';
  650. /**
  651. * Variable: escapePostData
  652. *
  653. * Specifies if the data in the post request for saving a diagram
  654. * should be converted using encodeURIComponent. Default is true.
  655. */
  656. mxEditor.prototype.escapePostData = true;
  657. /**
  658. * Variable: urlPost
  659. *
  660. * Specifies the URL to be used for posting the diagram
  661. * to a backend in <save>.
  662. */
  663. mxEditor.prototype.urlPost = null;
  664. /**
  665. * Variable: urlImage
  666. *
  667. * Specifies the URL to be used for creating a bitmap of
  668. * the graph in the image action.
  669. */
  670. mxEditor.prototype.urlImage = null;
  671. /**
  672. * Group: Autolayout
  673. */
  674. /**
  675. * Variable: horizontalFlow
  676. *
  677. * Specifies the direction of the flow
  678. * in the diagram. This is used in the
  679. * layout algorithms. Default is false,
  680. * ie. vertical flow.
  681. */
  682. mxEditor.prototype.horizontalFlow = false;
  683. /**
  684. * Variable: layoutDiagram
  685. *
  686. * Specifies if the top-level elements in the
  687. * diagram should be layed out using a vertical
  688. * or horizontal stack depending on the setting
  689. * of <horizontalFlow>. The spacing between the
  690. * swimlanes is specified by <swimlaneSpacing>.
  691. * Default is false.
  692. *
  693. * If the top-level elements are swimlanes, then
  694. * the intra-swimlane layout is activated by
  695. * the <layoutSwimlanes> switch.
  696. */
  697. mxEditor.prototype.layoutDiagram = false;
  698. /**
  699. * Variable: swimlaneSpacing
  700. *
  701. * Specifies the spacing between swimlanes if
  702. * automatic layout is turned on in
  703. * <layoutDiagram>. Default is 0.
  704. */
  705. mxEditor.prototype.swimlaneSpacing = 0;
  706. /**
  707. * Variable: maintainSwimlanes
  708. *
  709. * Specifies if the swimlanes should be kept at the same
  710. * width or height depending on the setting of
  711. * <horizontalFlow>. Default is false.
  712. *
  713. * For horizontal flows, all swimlanes
  714. * have the same height and for vertical flows, all swimlanes
  715. * have the same width. Furthermore, the swimlanes are
  716. * automatically "stacked" if <layoutDiagram> is true.
  717. */
  718. mxEditor.prototype.maintainSwimlanes = false;
  719. /**
  720. * Variable: layoutSwimlanes
  721. *
  722. * Specifies if the children of swimlanes should
  723. * be layed out, either vertically or horizontally
  724. * depending on <horizontalFlow>.
  725. * Default is false.
  726. */
  727. mxEditor.prototype.layoutSwimlanes = false;
  728. /**
  729. * Group: Attribute Cycling
  730. */
  731. /**
  732. * Variable: cycleAttributeValues
  733. *
  734. * Specifies the attribute values to be cycled when
  735. * inserting new swimlanes. Default is an empty
  736. * array.
  737. */
  738. mxEditor.prototype.cycleAttributeValues = null;
  739. /**
  740. * Variable: cycleAttributeIndex
  741. *
  742. * Index of the last consumed attribute index. If a new
  743. * swimlane is inserted, then the <cycleAttributeValues>
  744. * at this index will be used as the value for
  745. * <cycleAttributeName>. Default is 0.
  746. */
  747. mxEditor.prototype.cycleAttributeIndex = 0;
  748. /**
  749. * Variable: cycleAttributeName
  750. *
  751. * Name of the attribute to be assigned a <cycleAttributeValues>
  752. * when inserting new swimlanes. Default is 'fillColor'.
  753. */
  754. mxEditor.prototype.cycleAttributeName = 'fillColor';
  755. /**
  756. * Group: Windows
  757. */
  758. /**
  759. * Variable: tasks
  760. *
  761. * Holds the <mxWindow> created in <showTasks>.
  762. */
  763. mxEditor.prototype.tasks = null;
  764. /**
  765. * Variable: tasksWindowImage
  766. *
  767. * Icon for the tasks window.
  768. */
  769. mxEditor.prototype.tasksWindowImage = null;
  770. /**
  771. * Variable: tasksTop
  772. *
  773. * Specifies the top coordinate of the tasks window in pixels.
  774. * Default is 20.
  775. */
  776. mxEditor.prototype.tasksTop = 20;
  777. /**
  778. * Variable: help
  779. *
  780. * Holds the <mxWindow> created in <showHelp>.
  781. */
  782. mxEditor.prototype.help = null;
  783. /**
  784. * Variable: helpWindowImage
  785. *
  786. * Icon for the help window.
  787. */
  788. mxEditor.prototype.helpWindowImage = null;
  789. /**
  790. * Variable: urlHelp
  791. *
  792. * Specifies the URL to be used for the contents of the
  793. * Online Help window. This is usually specified in the
  794. * resources file under urlHelp for language-specific
  795. * online help support.
  796. */
  797. mxEditor.prototype.urlHelp = null;
  798. /**
  799. * Variable: helpWidth
  800. *
  801. * Specifies the width of the help window in pixels.
  802. * Default is 300.
  803. */
  804. mxEditor.prototype.helpWidth = 300;
  805. /**
  806. * Variable: helpHeight
  807. *
  808. * Specifies the height of the help window in pixels.
  809. * Default is 260.
  810. */
  811. mxEditor.prototype.helpHeight = 260;
  812. /**
  813. * Variable: propertiesWidth
  814. *
  815. * Specifies the width of the properties window in pixels.
  816. * Default is 240.
  817. */
  818. mxEditor.prototype.propertiesWidth = 240;
  819. /**
  820. * Variable: propertiesHeight
  821. *
  822. * Specifies the height of the properties window in pixels.
  823. * If no height is specified then the window will be automatically
  824. * sized to fit its contents. Default is null.
  825. */
  826. mxEditor.prototype.propertiesHeight = null;
  827. /**
  828. * Variable: movePropertiesDialog
  829. *
  830. * Specifies if the properties dialog should be automatically
  831. * moved near the cell it is displayed for, otherwise the
  832. * dialog is not moved. This value is only taken into
  833. * account if the dialog is already visible. Default is false.
  834. */
  835. mxEditor.prototype.movePropertiesDialog = false;
  836. /**
  837. * Variable: validating
  838. *
  839. * Specifies if <mxGraph.validateGraph> should automatically be invoked after
  840. * each change. Default is false.
  841. */
  842. mxEditor.prototype.validating = false;
  843. /**
  844. * Variable: modified
  845. *
  846. * True if the graph has been modified since it was last saved.
  847. */
  848. mxEditor.prototype.modified = false;
  849. /**
  850. * Function: isModified
  851. *
  852. * Returns <modified>.
  853. */
  854. mxEditor.prototype.isModified = function ()
  855. {
  856. return this.modified;
  857. };
  858. /**
  859. * Function: setModified
  860. *
  861. * Sets <modified> to the specified boolean value.
  862. */
  863. mxEditor.prototype.setModified = function (value)
  864. {
  865. this.modified = value;
  866. };
  867. /**
  868. * Function: addActions
  869. *
  870. * Adds the built-in actions to the editor instance.
  871. *
  872. * save - Saves the graph using <urlPost>.
  873. * print - Shows the graph in a new print preview window.
  874. * show - Shows the graph in a new window.
  875. * exportImage - Shows the graph as a bitmap image using <getUrlImage>.
  876. * refresh - Refreshes the graph's display.
  877. * cut - Copies the current selection into the clipboard
  878. * and removes it from the graph.
  879. * copy - Copies the current selection into the clipboard.
  880. * paste - Pastes the clipboard into the graph.
  881. * delete - Removes the current selection from the graph.
  882. * group - Puts the current selection into a new group.
  883. * ungroup - Removes the selected groups and selects the children.
  884. * undo - Undoes the last change on the graph model.
  885. * redo - Redoes the last change on the graph model.
  886. * zoom - Sets the zoom via a dialog.
  887. * zoomIn - Zooms into the graph.
  888. * zoomOut - Zooms out of the graph
  889. * actualSize - Resets the scale and translation on the graph.
  890. * fit - Changes the scale so that the graph fits into the window.
  891. * showProperties - Shows the properties dialog.
  892. * selectAll - Selects all cells.
  893. * selectNone - Clears the selection.
  894. * selectVertices - Selects all vertices.
  895. * selectEdges = Selects all edges.
  896. * edit - Starts editing the current selection cell.
  897. * enterGroup - Drills down into the current selection cell.
  898. * exitGroup - Moves up in the drilling hierachy
  899. * home - Moves to the topmost parent in the drilling hierarchy
  900. * selectPrevious - Selects the previous cell.
  901. * selectNext - Selects the next cell.
  902. * selectParent - Selects the parent of the selection cell.
  903. * selectChild - Selects the first child of the selection cell.
  904. * collapse - Collapses the currently selected cells.
  905. * expand - Expands the currently selected cells.
  906. * bold - Toggle bold text style.
  907. * italic - Toggle italic text style.
  908. * underline - Toggle underline text style.
  909. * alignCellsLeft - Aligns the selection cells at the left.
  910. * alignCellsCenter - Aligns the selection cells in the center.
  911. * alignCellsRight - Aligns the selection cells at the right.
  912. * alignCellsTop - Aligns the selection cells at the top.
  913. * alignCellsMiddle - Aligns the selection cells in the middle.
  914. * alignCellsBottom - Aligns the selection cells at the bottom.
  915. * alignFontLeft - Sets the horizontal text alignment to left.
  916. * alignFontCenter - Sets the horizontal text alignment to center.
  917. * alignFontRight - Sets the horizontal text alignment to right.
  918. * alignFontTop - Sets the vertical text alignment to top.
  919. * alignFontMiddle - Sets the vertical text alignment to middle.
  920. * alignFontBottom - Sets the vertical text alignment to bottom.
  921. * toggleTasks - Shows or hides the tasks window.
  922. * toggleHelp - Shows or hides the help window.
  923. * toggleOutline - Shows or hides the outline window.
  924. * toggleConsole - Shows or hides the console window.
  925. */
  926. mxEditor.prototype.addActions = function ()
  927. {
  928. this.addAction('save', function(editor)
  929. {
  930. editor.save();
  931. });
  932. this.addAction('print', function(editor)
  933. {
  934. var preview = new mxPrintPreview(editor.graph, 1);
  935. preview.open();
  936. });
  937. this.addAction('show', function(editor)
  938. {
  939. mxUtils.show(editor.graph, null, 10, 10);
  940. });
  941. this.addAction('exportImage', function(editor)
  942. {
  943. var url = editor.getUrlImage();
  944. if (url == null || mxClient.IS_LOCAL)
  945. {
  946. editor.execute('show');
  947. }
  948. else
  949. {
  950. var node = mxUtils.getViewXml(editor.graph, 1);
  951. var xml = mxUtils.getXml(node, '\n');
  952. mxUtils.submit(url, editor.postParameterName + '=' +
  953. encodeURIComponent(xml), document, '_blank');
  954. }
  955. });
  956. this.addAction('refresh', function(editor)
  957. {
  958. editor.graph.refresh();
  959. });
  960. this.addAction('cut', function(editor)
  961. {
  962. if (editor.graph.isEnabled())
  963. {
  964. mxClipboard.cut(editor.graph);
  965. }
  966. });
  967. this.addAction('copy', function(editor)
  968. {
  969. if (editor.graph.isEnabled())
  970. {
  971. mxClipboard.copy(editor.graph);
  972. }
  973. });
  974. this.addAction('paste', function(editor)
  975. {
  976. if (editor.graph.isEnabled())
  977. {
  978. mxClipboard.paste(editor.graph);
  979. }
  980. });
  981. this.addAction('delete', function(editor)
  982. {
  983. if (editor.graph.isEnabled())
  984. {
  985. editor.graph.removeCells();
  986. }
  987. });
  988. this.addAction('group', function(editor)
  989. {
  990. if (editor.graph.isEnabled())
  991. {
  992. editor.graph.setSelectionCell(editor.groupCells());
  993. }
  994. });
  995. this.addAction('ungroup', function(editor)
  996. {
  997. if (editor.graph.isEnabled())
  998. {
  999. editor.graph.setSelectionCells(editor.graph.ungroupCells());
  1000. }
  1001. });
  1002. this.addAction('removeFromParent', function(editor)
  1003. {
  1004. if (editor.graph.isEnabled())
  1005. {
  1006. editor.graph.removeCellsFromParent();
  1007. }
  1008. });
  1009. this.addAction('undo', function(editor)
  1010. {
  1011. if (editor.graph.isEnabled())
  1012. {
  1013. editor.undo();
  1014. }
  1015. });
  1016. this.addAction('redo', function(editor)
  1017. {
  1018. if (editor.graph.isEnabled())
  1019. {
  1020. editor.redo();
  1021. }
  1022. });
  1023. this.addAction('zoomIn', function(editor)
  1024. {
  1025. editor.graph.zoomIn();
  1026. });
  1027. this.addAction('zoomOut', function(editor)
  1028. {
  1029. editor.graph.zoomOut();
  1030. });
  1031. this.addAction('actualSize', function(editor)
  1032. {
  1033. editor.graph.zoomActual();
  1034. });
  1035. this.addAction('fit', function(editor)
  1036. {
  1037. editor.graph.fit();
  1038. });
  1039. this.addAction('showProperties', function(editor, cell)
  1040. {
  1041. editor.showProperties(cell);
  1042. });
  1043. this.addAction('selectAll', function(editor)
  1044. {
  1045. if (editor.graph.isEnabled())
  1046. {
  1047. editor.graph.selectAll();
  1048. }
  1049. });
  1050. this.addAction('selectNone', function(editor)
  1051. {
  1052. if (editor.graph.isEnabled())
  1053. {
  1054. editor.graph.clearSelection();
  1055. }
  1056. });
  1057. this.addAction('selectVertices', function(editor)
  1058. {
  1059. if (editor.graph.isEnabled())
  1060. {
  1061. editor.graph.selectVertices();
  1062. }
  1063. });
  1064. this.addAction('selectEdges', function(editor)
  1065. {
  1066. if (editor.graph.isEnabled())
  1067. {
  1068. editor.graph.selectEdges();
  1069. }
  1070. });
  1071. this.addAction('edit', function(editor, cell)
  1072. {
  1073. if (editor.graph.isEnabled() &&
  1074. editor.graph.isCellEditable(cell))
  1075. {
  1076. editor.graph.startEditingAtCell(cell);
  1077. }
  1078. });
  1079. this.addAction('toBack', function(editor, cell)
  1080. {
  1081. if (editor.graph.isEnabled())
  1082. {
  1083. editor.graph.orderCells(true);
  1084. }
  1085. });
  1086. this.addAction('toFront', function(editor, cell)
  1087. {
  1088. if (editor.graph.isEnabled())
  1089. {
  1090. editor.graph.orderCells(false);
  1091. }
  1092. });
  1093. this.addAction('enterGroup', function(editor, cell)
  1094. {
  1095. editor.graph.enterGroup(cell);
  1096. });
  1097. this.addAction('exitGroup', function(editor)
  1098. {
  1099. editor.graph.exitGroup();
  1100. });
  1101. this.addAction('home', function(editor)
  1102. {
  1103. editor.graph.home();
  1104. });
  1105. this.addAction('selectPrevious', function(editor)
  1106. {
  1107. if (editor.graph.isEnabled())
  1108. {
  1109. editor.graph.selectPreviousCell();
  1110. }
  1111. });
  1112. this.addAction('selectNext', function(editor)
  1113. {
  1114. if (editor.graph.isEnabled())
  1115. {
  1116. editor.graph.selectNextCell();
  1117. }
  1118. });
  1119. this.addAction('selectParent', function(editor)
  1120. {
  1121. if (editor.graph.isEnabled())
  1122. {
  1123. editor.graph.selectParentCell();
  1124. }
  1125. });
  1126. this.addAction('selectChild', function(editor)
  1127. {
  1128. if (editor.graph.isEnabled())
  1129. {
  1130. editor.graph.selectChildCell();
  1131. }
  1132. });
  1133. this.addAction('collapse', function(editor)
  1134. {
  1135. if (editor.graph.isEnabled())
  1136. {
  1137. editor.graph.foldCells(true);
  1138. }
  1139. });
  1140. this.addAction('collapseAll', function(editor)
  1141. {
  1142. if (editor.graph.isEnabled())
  1143. {
  1144. var cells = editor.graph.getChildVertices();
  1145. editor.graph.foldCells(true, false, cells);
  1146. }
  1147. });
  1148. this.addAction('expand', function(editor)
  1149. {
  1150. if (editor.graph.isEnabled())
  1151. {
  1152. editor.graph.foldCells(false);
  1153. }
  1154. });
  1155. this.addAction('expandAll', function(editor)
  1156. {
  1157. if (editor.graph.isEnabled())
  1158. {
  1159. var cells = editor.graph.getChildVertices();
  1160. editor.graph.foldCells(false, false, cells);
  1161. }
  1162. });
  1163. this.addAction('bold', function(editor)
  1164. {
  1165. if (editor.graph.isEnabled())
  1166. {
  1167. editor.graph.toggleCellStyleFlags(
  1168. mxConstants.STYLE_FONTSTYLE,
  1169. mxConstants.FONT_BOLD);
  1170. }
  1171. });
  1172. this.addAction('italic', function(editor)
  1173. {
  1174. if (editor.graph.isEnabled())
  1175. {
  1176. editor.graph.toggleCellStyleFlags(
  1177. mxConstants.STYLE_FONTSTYLE,
  1178. mxConstants.FONT_ITALIC);
  1179. }
  1180. });
  1181. this.addAction('underline', function(editor)
  1182. {
  1183. if (editor.graph.isEnabled())
  1184. {
  1185. editor.graph.toggleCellStyleFlags(
  1186. mxConstants.STYLE_FONTSTYLE,
  1187. mxConstants.FONT_UNDERLINE);
  1188. }
  1189. });
  1190. this.addAction('alignCellsLeft', function(editor)
  1191. {
  1192. if (editor.graph.isEnabled())
  1193. {
  1194. editor.graph.alignCells(mxConstants.ALIGN_LEFT);
  1195. }
  1196. });
  1197. this.addAction('alignCellsCenter', function(editor)
  1198. {
  1199. if (editor.graph.isEnabled())
  1200. {
  1201. editor.graph.alignCells(mxConstants.ALIGN_CENTER);
  1202. }
  1203. });
  1204. this.addAction('alignCellsRight', function(editor)
  1205. {
  1206. if (editor.graph.isEnabled())
  1207. {
  1208. editor.graph.alignCells(mxConstants.ALIGN_RIGHT);
  1209. }
  1210. });
  1211. this.addAction('alignCellsTop', function(editor)
  1212. {
  1213. if (editor.graph.isEnabled())
  1214. {
  1215. editor.graph.alignCells(mxConstants.ALIGN_TOP);
  1216. }
  1217. });
  1218. this.addAction('alignCellsMiddle', function(editor)
  1219. {
  1220. if (editor.graph.isEnabled())
  1221. {
  1222. editor.graph.alignCells(mxConstants.ALIGN_MIDDLE);
  1223. }
  1224. });
  1225. this.addAction('alignCellsBottom', function(editor)
  1226. {
  1227. if (editor.graph.isEnabled())
  1228. {
  1229. editor.graph.alignCells(mxConstants.ALIGN_BOTTOM);
  1230. }
  1231. });
  1232. this.addAction('alignFontLeft', function(editor)
  1233. {
  1234. editor.graph.setCellStyles(
  1235. mxConstants.STYLE_ALIGN,
  1236. mxConstants.ALIGN_LEFT);
  1237. });
  1238. this.addAction('alignFontCenter', function(editor)
  1239. {
  1240. if (editor.graph.isEnabled())
  1241. {
  1242. editor.graph.setCellStyles(
  1243. mxConstants.STYLE_ALIGN,
  1244. mxConstants.ALIGN_CENTER);
  1245. }
  1246. });
  1247. this.addAction('alignFontRight', function(editor)
  1248. {
  1249. if (editor.graph.isEnabled())
  1250. {
  1251. editor.graph.setCellStyles(
  1252. mxConstants.STYLE_ALIGN,
  1253. mxConstants.ALIGN_RIGHT);
  1254. }
  1255. });
  1256. this.addAction('alignFontTop', function(editor)
  1257. {
  1258. if (editor.graph.isEnabled())
  1259. {
  1260. editor.graph.setCellStyles(
  1261. mxConstants.STYLE_VERTICAL_ALIGN,
  1262. mxConstants.ALIGN_TOP);
  1263. }
  1264. });
  1265. this.addAction('alignFontMiddle', function(editor)
  1266. {
  1267. if (editor.graph.isEnabled())
  1268. {
  1269. editor.graph.setCellStyles(
  1270. mxConstants.STYLE_VERTICAL_ALIGN,
  1271. mxConstants.ALIGN_MIDDLE);
  1272. }
  1273. });
  1274. this.addAction('alignFontBottom', function(editor)
  1275. {
  1276. if (editor.graph.isEnabled())
  1277. {
  1278. editor.graph.setCellStyles(
  1279. mxConstants.STYLE_VERTICAL_ALIGN,
  1280. mxConstants.ALIGN_BOTTOM);
  1281. }
  1282. });
  1283. this.addAction('zoom', function(editor)
  1284. {
  1285. var current = editor.graph.getView().scale*100;
  1286. var scale = parseFloat(mxUtils.prompt(
  1287. mxResources.get(editor.askZoomResource) ||
  1288. editor.askZoomResource,
  1289. current))/100;
  1290. if (!isNaN(scale))
  1291. {
  1292. editor.graph.getView().setScale(scale);
  1293. }
  1294. });
  1295. this.addAction('toggleTasks', function(editor)
  1296. {
  1297. if (editor.tasks != null)
  1298. {
  1299. editor.tasks.setVisible(!editor.tasks.isVisible());
  1300. }
  1301. else
  1302. {
  1303. editor.showTasks();
  1304. }
  1305. });
  1306. this.addAction('toggleHelp', function(editor)
  1307. {
  1308. if (editor.help != null)
  1309. {
  1310. editor.help.setVisible(!editor.help.isVisible());
  1311. }
  1312. else
  1313. {
  1314. editor.showHelp();
  1315. }
  1316. });
  1317. this.addAction('toggleOutline', function(editor)
  1318. {
  1319. if (editor.outline == null)
  1320. {
  1321. editor.showOutline();
  1322. }
  1323. else
  1324. {
  1325. editor.outline.setVisible(!editor.outline.isVisible());
  1326. }
  1327. });
  1328. this.addAction('toggleConsole', function(editor)
  1329. {
  1330. mxLog.setVisible(!mxLog.isVisible());
  1331. });
  1332. };
  1333. /**
  1334. * Function: configure
  1335. *
  1336. * Configures the editor using the specified node. To load the
  1337. * configuration from a given URL the following code can be used to obtain
  1338. * the XML node.
  1339. *
  1340. * (code)
  1341. * var node = mxUtils.load(url).getDocumentElement();
  1342. * (end)
  1343. *
  1344. * Parameters:
  1345. *
  1346. * node - XML node that contains the configuration.
  1347. */
  1348. mxEditor.prototype.configure = function (node)
  1349. {
  1350. if (node != null)
  1351. {
  1352. // Creates a decoder for the XML data
  1353. // and uses it to configure the editor
  1354. var dec = new mxCodec(node.ownerDocument);
  1355. dec.decode(node, this);
  1356. // Resets the counters, modified state and
  1357. // command history
  1358. this.resetHistory();
  1359. }
  1360. };
  1361. /**
  1362. * Function: resetFirstTime
  1363. *
  1364. * Resets the cookie that is used to remember if the editor has already
  1365. * been used.
  1366. */
  1367. mxEditor.prototype.resetFirstTime = function ()
  1368. {
  1369. document.cookie =
  1370. 'mxgraph=seen; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/';
  1371. };
  1372. /**
  1373. * Function: resetHistory
  1374. *
  1375. * Resets the command history, modified state and counters.
  1376. */
  1377. mxEditor.prototype.resetHistory = function ()
  1378. {
  1379. this.lastSnapshot = new Date().getTime();
  1380. this.undoManager.clear();
  1381. this.ignoredChanges = 0;
  1382. this.setModified(false);
  1383. };
  1384. /**
  1385. * Function: addAction
  1386. *
  1387. * Binds the specified actionname to the specified function.
  1388. *
  1389. * Parameters:
  1390. *
  1391. * actionname - String that specifies the name of the action
  1392. * to be added.
  1393. * funct - Function that implements the new action. The first
  1394. * argument of the function is the editor it is used
  1395. * with, the second argument is the cell it operates
  1396. * upon.
  1397. *
  1398. * Example:
  1399. * (code)
  1400. * editor.addAction('test', function(editor, cell)
  1401. * {
  1402. * mxUtils.alert("test "+cell);
  1403. * });
  1404. * (end)
  1405. */
  1406. mxEditor.prototype.addAction = function (actionname, funct)
  1407. {
  1408. this.actions[actionname] = funct;
  1409. };
  1410. /**
  1411. * Function: execute
  1412. *
  1413. * Executes the function with the given name in <actions> passing the
  1414. * editor instance and given cell as the first and second argument. All
  1415. * additional arguments are passed to the action as well. This method
  1416. * contains a try-catch block and displays an error message if an action
  1417. * causes an exception. The exception is re-thrown after the error
  1418. * message was displayed.
  1419. *
  1420. * Example:
  1421. *
  1422. * (code)
  1423. * editor.execute("showProperties", cell);
  1424. * (end)
  1425. */
  1426. mxEditor.prototype.execute = function (actionname, cell, evt)
  1427. {
  1428. var action = this.actions[actionname];
  1429. if (action != null)
  1430. {
  1431. try
  1432. {
  1433. // Creates the array of arguments by replacing the actionname
  1434. // with the editor instance in the args of this function
  1435. var args = arguments;
  1436. args[0] = this;
  1437. // Invokes the function on the editor using the args
  1438. action.apply(this, args);
  1439. }
  1440. catch (e)
  1441. {
  1442. mxUtils.error('Cannot execute ' + actionname +
  1443. ': ' + e.message, 280, true);
  1444. throw e;
  1445. }
  1446. }
  1447. else
  1448. {
  1449. mxUtils.error('Cannot find action '+actionname, 280, true);
  1450. }
  1451. };
  1452. /**
  1453. * Function: addTemplate
  1454. *
  1455. * Adds the specified template under the given name in <templates>.
  1456. */
  1457. mxEditor.prototype.addTemplate = function (name, template)
  1458. {
  1459. this.templates[name] = template;
  1460. };
  1461. /**
  1462. * Function: getTemplate
  1463. *
  1464. * Returns the template for the given name.
  1465. */
  1466. mxEditor.prototype.getTemplate = function (name)
  1467. {
  1468. return this.templates[name];
  1469. };
  1470. /**
  1471. * Function: createGraph
  1472. *
  1473. * Creates the <graph> for the editor. The graph is created with no
  1474. * container and is initialized from <setGraphContainer>.
  1475. */
  1476. mxEditor.prototype.createGraph = function ()
  1477. {
  1478. var graph = new mxGraph(null, null, this.graphRenderHint);
  1479. // Enables rubberband, tooltips, panning
  1480. graph.setTooltips(true);
  1481. graph.setPanning(true);
  1482. // Overrides the dblclick method on the graph to
  1483. // invoke the dblClickAction for a cell and reset
  1484. // the selection tool in the toolbar
  1485. this.installDblClickHandler(graph);
  1486. // Installs the command history
  1487. this.installUndoHandler(graph);
  1488. // Installs the handlers for the root event
  1489. this.installDrillHandler(graph);
  1490. // Installs the handler for validation
  1491. this.installChangeHandler(graph);
  1492. // Installs the handler for calling the
  1493. // insert function and consume the
  1494. // event if an insert function is defined
  1495. this.installInsertHandler(graph);
  1496. // Redirects the function for creating the
  1497. // popupmenu items
  1498. graph.popupMenuHandler.factoryMethod =
  1499. mxUtils.bind(this, function(menu, cell, evt)
  1500. {
  1501. return this.createPopupMenu(menu, cell, evt);
  1502. });
  1503. // Redirects the function for creating
  1504. // new connections in the diagram
  1505. graph.connectionHandler.factoryMethod =
  1506. mxUtils.bind(this, function(source, target)
  1507. {
  1508. return this.createEdge(source, target);
  1509. });
  1510. // Maintains swimlanes and installs autolayout
  1511. this.createSwimlaneManager(graph);
  1512. this.createLayoutManager(graph);
  1513. return graph;
  1514. };
  1515. /**
  1516. * Function: createSwimlaneManager
  1517. *
  1518. * Sets the graph's container using <mxGraph.init>.
  1519. */
  1520. mxEditor.prototype.createSwimlaneManager = function (graph)
  1521. {
  1522. var swimlaneMgr = new mxSwimlaneManager(graph, false);
  1523. swimlaneMgr.isHorizontal = mxUtils.bind(this, function()
  1524. {
  1525. return this.horizontalFlow;
  1526. });
  1527. swimlaneMgr.isEnabled = mxUtils.bind(this, function()
  1528. {
  1529. return this.maintainSwimlanes;
  1530. });
  1531. return swimlaneMgr;
  1532. };
  1533. /**
  1534. * Function: createLayoutManager
  1535. *
  1536. * Creates a layout manager for the swimlane and diagram layouts, that
  1537. * is, the locally defined inter- and intraswimlane layouts.
  1538. */
  1539. mxEditor.prototype.createLayoutManager = function (graph)
  1540. {
  1541. var layoutMgr = new mxLayoutManager(graph);
  1542. var self = this; // closure
  1543. layoutMgr.getLayout = function(cell)
  1544. {
  1545. var layout = null;
  1546. var model = self.graph.getModel();
  1547. if (model.getParent(cell) != null)
  1548. {
  1549. // Executes the swimlane layout if a child of
  1550. // a swimlane has been changed. The layout is
  1551. // lazy created in createSwimlaneLayout.
  1552. if (self.layoutSwimlanes &&
  1553. graph.isSwimlane(cell))
  1554. {
  1555. if (self.swimlaneLayout == null)
  1556. {
  1557. self.swimlaneLayout = self.createSwimlaneLayout();
  1558. }
  1559. layout = self.swimlaneLayout;
  1560. }
  1561. // Executes the diagram layout if the modified
  1562. // cell is a top-level cell. The layout is
  1563. // lazy created in createDiagramLayout.
  1564. else if (self.layoutDiagram &&
  1565. (graph.isValidRoot(cell) ||
  1566. model.getParent(model.getParent(cell)) == null))
  1567. {
  1568. if (self.diagramLayout == null)
  1569. {
  1570. self.diagramLayout = self.createDiagramLayout();
  1571. }
  1572. layout = self.diagramLayout;
  1573. }
  1574. }
  1575. return layout;
  1576. };
  1577. return layoutMgr;
  1578. };
  1579. /**
  1580. * Function: setGraphContainer
  1581. *
  1582. * Sets the graph's container using <mxGraph.init>.
  1583. */
  1584. mxEditor.prototype.setGraphContainer = function (container)
  1585. {
  1586. if (this.graph.container == null)
  1587. {
  1588. // Creates the graph instance inside the given container and render hint
  1589. //this.graph = new mxGraph(container, null, this.graphRenderHint);
  1590. this.graph.init(container);
  1591. // Install rubberband selection as the last
  1592. // action handler in the chain
  1593. this.rubberband = new mxRubberband(this.graph);
  1594. // Disables the context menu
  1595. if (this.disableContextMenu)
  1596. {
  1597. mxEvent.disableContextMenu(container);
  1598. }
  1599. // Workaround for stylesheet directives in IE
  1600. if (mxClient.IS_QUIRKS)
  1601. {
  1602. new mxDivResizer(container);
  1603. }
  1604. }
  1605. };
  1606. /**
  1607. * Function: installDblClickHandler
  1608. *
  1609. * Overrides <mxGraph.dblClick> to invoke <dblClickAction>
  1610. * on a cell and reset the selection tool in the toolbar.
  1611. */
  1612. mxEditor.prototype.installDblClickHandler = function (graph)
  1613. {
  1614. // Installs a listener for double click events
  1615. graph.addListener(mxEvent.DOUBLE_CLICK,
  1616. mxUtils.bind(this, function(sender, evt)
  1617. {
  1618. var cell = evt.getProperty('cell');
  1619. if (cell != null &&
  1620. graph.isEnabled() &&
  1621. this.dblClickAction != null)
  1622. {
  1623. this.execute(this.dblClickAction, cell);
  1624. evt.consume();
  1625. }
  1626. })
  1627. );
  1628. };
  1629. /**
  1630. * Function: installUndoHandler
  1631. *
  1632. * Adds the <undoManager> to the graph model and the view.
  1633. */
  1634. mxEditor.prototype.installUndoHandler = function (graph)
  1635. {
  1636. var listener = mxUtils.bind(this, function(sender, evt)
  1637. {
  1638. var edit = evt.getProperty('edit');
  1639. this.undoManager.undoableEditHappened(edit);
  1640. });
  1641. graph.getModel().addListener(mxEvent.UNDO, listener);
  1642. graph.getView().addListener(mxEvent.UNDO, listener);
  1643. // Keeps the selection state in sync
  1644. var undoHandler = function(sender, evt)
  1645. {
  1646. var changes = evt.getProperty('edit').changes;
  1647. graph.setSelectionCells(graph.getSelectionCellsForChanges(changes));
  1648. };
  1649. this.undoManager.addListener(mxEvent.UNDO, undoHandler);
  1650. this.undoManager.addListener(mxEvent.REDO, undoHandler);
  1651. };
  1652. /**
  1653. * Function: installDrillHandler
  1654. *
  1655. * Installs listeners for dispatching the <root> event.
  1656. */
  1657. mxEditor.prototype.installDrillHandler = function (graph)
  1658. {
  1659. var listener = mxUtils.bind(this, function(sender)
  1660. {
  1661. this.fireEvent(new mxEventObject(mxEvent.ROOT));
  1662. });
  1663. graph.getView().addListener(mxEvent.DOWN, listener);
  1664. graph.getView().addListener(mxEvent.UP, listener);
  1665. };
  1666. /**
  1667. * Function: installChangeHandler
  1668. *
  1669. * Installs the listeners required to automatically validate
  1670. * the graph. On each change of the root, this implementation
  1671. * fires a <root> event.
  1672. */
  1673. mxEditor.prototype.installChangeHandler = function (graph)
  1674. {
  1675. var listener = mxUtils.bind(this, function(sender, evt)
  1676. {
  1677. // Updates the modified state
  1678. this.setModified(true);
  1679. // Automatically validates the graph
  1680. // after each change
  1681. if (this.validating == true)
  1682. {
  1683. graph.validateGraph();
  1684. }
  1685. // Checks if the root has been changed
  1686. var changes = evt.getProperty('edit').changes;
  1687. for (var i = 0; i < changes.length; i++)
  1688. {
  1689. var change = changes[i];
  1690. if (change instanceof mxRootChange ||
  1691. (change instanceof mxValueChange &&
  1692. change.cell == this.graph.model.root) ||
  1693. (change instanceof mxCellAttributeChange &&
  1694. change.cell == this.graph.model.root))
  1695. {
  1696. this.fireEvent(new mxEventObject(mxEvent.ROOT));
  1697. break;
  1698. }
  1699. }
  1700. });
  1701. graph.getModel().addListener(mxEvent.CHANGE, listener);
  1702. };
  1703. /**
  1704. * Function: installInsertHandler
  1705. *
  1706. * Installs the handler for invoking <insertFunction> if
  1707. * one is defined.
  1708. */
  1709. mxEditor.prototype.installInsertHandler = function (graph)
  1710. {
  1711. var self = this; // closure
  1712. var insertHandler =
  1713. {
  1714. mouseDown: function(sender, me)
  1715. {
  1716. if (self.insertFunction != null &&
  1717. !me.isPopupTrigger() &&
  1718. (self.forcedInserting ||
  1719. me.getState() == null))
  1720. {
  1721. self.graph.clearSelection();
  1722. self.insertFunction(me.getEvent(), me.getCell());
  1723. // Consumes the rest of the events
  1724. // for this gesture (down, move, up)
  1725. this.isActive = true;
  1726. me.consume();
  1727. }
  1728. },
  1729. mouseMove: function(sender, me)
  1730. {
  1731. if (this.isActive)
  1732. {
  1733. me.consume();
  1734. }
  1735. },
  1736. mouseUp: function(sender, me)
  1737. {
  1738. if (this.isActive)
  1739. {
  1740. this.isActive = false;
  1741. me.consume();
  1742. }
  1743. }
  1744. };
  1745. graph.addMouseListener(insertHandler);
  1746. };
  1747. /**
  1748. * Function: createDiagramLayout
  1749. *
  1750. * Creates the layout instance used to layout the
  1751. * swimlanes in the diagram.
  1752. */
  1753. mxEditor.prototype.createDiagramLayout = function ()
  1754. {
  1755. var gs = this.graph.gridSize;
  1756. var layout = new mxStackLayout(this.graph, !this.horizontalFlow,
  1757. this.swimlaneSpacing, 2*gs, 2*gs);
  1758. // Overrides isIgnored to only take into account swimlanes
  1759. layout.isVertexIgnored = function(cell)
  1760. {
  1761. return !layout.graph.isSwimlane(cell);
  1762. };
  1763. return layout;
  1764. };
  1765. /**
  1766. * Function: createSwimlaneLayout
  1767. *
  1768. * Creates the layout instance used to layout the
  1769. * children of each swimlane.
  1770. */
  1771. mxEditor.prototype.createSwimlaneLayout = function ()
  1772. {
  1773. return new mxCompactTreeLayout(this.graph, this.horizontalFlow);
  1774. };
  1775. /**
  1776. * Function: createToolbar
  1777. *
  1778. * Creates the <toolbar> with no container.
  1779. */
  1780. mxEditor.prototype.createToolbar = function ()
  1781. {
  1782. return new mxDefaultToolbar(null, this);
  1783. };
  1784. /**
  1785. * Function: setToolbarContainer
  1786. *
  1787. * Initializes the toolbar for the given container.
  1788. */
  1789. mxEditor.prototype.setToolbarContainer = function (container)
  1790. {
  1791. this.toolbar.init(container);
  1792. // Workaround for stylesheet directives in IE
  1793. if (mxClient.IS_QUIRKS)
  1794. {
  1795. new mxDivResizer(container);
  1796. }
  1797. };
  1798. /**
  1799. * Function: setStatusContainer
  1800. *
  1801. * Creates the <status> using the specified container.
  1802. *
  1803. * This implementation adds listeners in the editor to
  1804. * display the last saved time and the current filename
  1805. * in the status bar.
  1806. *
  1807. * Parameters:
  1808. *
  1809. * container - DOM node that will contain the statusbar.
  1810. */
  1811. mxEditor.prototype.setStatusContainer = function (container)
  1812. {
  1813. if (this.status == null)
  1814. {
  1815. this.status = container;
  1816. // Prints the last saved time in the status bar
  1817. // when files are saved
  1818. this.addListener(mxEvent.SAVE, mxUtils.bind(this, function()
  1819. {
  1820. var tstamp = new Date().toLocaleString();
  1821. this.setStatus((mxResources.get(this.lastSavedResource) ||
  1822. this.lastSavedResource)+': '+tstamp);
  1823. }));
  1824. // Updates the statusbar to display the filename
  1825. // when new files are opened
  1826. this.addListener(mxEvent.OPEN, mxUtils.bind(this, function()
  1827. {
  1828. this.setStatus((mxResources.get(this.currentFileResource) ||
  1829. this.currentFileResource)+': '+this.filename);
  1830. }));
  1831. // Workaround for stylesheet directives in IE
  1832. if (mxClient.IS_QUIRKS)
  1833. {
  1834. new mxDivResizer(container);
  1835. }
  1836. }
  1837. };
  1838. /**
  1839. * Function: setStatus
  1840. *
  1841. * Display the specified message in the status bar.
  1842. *
  1843. * Parameters:
  1844. *
  1845. * message - String the specified the message to
  1846. * be displayed.
  1847. */
  1848. mxEditor.prototype.setStatus = function (message)
  1849. {
  1850. if (this.status != null && message != null)
  1851. {
  1852. this.status.innerHTML = message;
  1853. }
  1854. };
  1855. /**
  1856. * Function: setTitleContainer
  1857. *
  1858. * Creates a listener to update the inner HTML of the
  1859. * specified DOM node with the value of <getTitle>.
  1860. *
  1861. * Parameters:
  1862. *
  1863. * container - DOM node that will contain the title.
  1864. */
  1865. mxEditor.prototype.setTitleContainer = function (container)
  1866. {
  1867. this.addListener(mxEvent.ROOT, mxUtils.bind(this, function(sender)
  1868. {
  1869. container.innerHTML = this.getTitle();
  1870. }));
  1871. // Workaround for stylesheet directives in IE
  1872. if (mxClient.IS_QUIRKS)
  1873. {
  1874. new mxDivResizer(container);
  1875. }
  1876. };
  1877. /**
  1878. * Function: treeLayout
  1879. *
  1880. * Executes a vertical or horizontal compact tree layout
  1881. * using the specified cell as an argument. The cell may
  1882. * either be a group or the root of a tree.
  1883. *
  1884. * Parameters:
  1885. *
  1886. * cell - <mxCell> to use in the compact tree layout.
  1887. * horizontal - Optional boolean to specify the tree's
  1888. * orientation. Default is true.
  1889. */
  1890. mxEditor.prototype.treeLayout = function (cell, horizontal)
  1891. {
  1892. if (cell != null)
  1893. {
  1894. var layout = new mxCompactTreeLayout(this.graph, horizontal);
  1895. layout.execute(cell);
  1896. }
  1897. };
  1898. /**
  1899. * Function: getTitle
  1900. *
  1901. * Returns the string value for the current root of the
  1902. * diagram.
  1903. */
  1904. mxEditor.prototype.getTitle = function ()
  1905. {
  1906. var title = '';
  1907. var graph = this.graph;
  1908. var cell = graph.getCurrentRoot();
  1909. while (cell != null &&
  1910. graph.getModel().getParent(
  1911. graph.getModel().getParent(cell)) != null)
  1912. {
  1913. // Append each label of a valid root
  1914. if (graph.isValidRoot(cell))
  1915. {
  1916. title = ' > ' +
  1917. graph.convertValueToString(cell) + title;
  1918. }
  1919. cell = graph.getModel().getParent(cell);
  1920. }
  1921. var prefix = this.getRootTitle();
  1922. return prefix + title;
  1923. };
  1924. /**
  1925. * Function: getRootTitle
  1926. *
  1927. * Returns the string value of the root cell in
  1928. * <mxGraph.model>.
  1929. */
  1930. mxEditor.prototype.getRootTitle = function ()
  1931. {
  1932. var root = this.graph.getModel().getRoot();
  1933. return this.graph.convertValueToString(root);
  1934. };
  1935. /**
  1936. * Function: undo
  1937. *
  1938. * Undo the last change in <graph>.
  1939. */
  1940. mxEditor.prototype.undo = function ()
  1941. {
  1942. this.undoManager.undo();
  1943. };
  1944. /**
  1945. * Function: redo
  1946. *
  1947. * Redo the last change in <graph>.
  1948. */
  1949. mxEditor.prototype.redo = function ()
  1950. {
  1951. this.undoManager.redo();
  1952. };
  1953. /**
  1954. * Function: groupCells
  1955. *
  1956. * Invokes <createGroup> to create a new group cell and the invokes
  1957. * <mxGraph.groupCells>, using the grid size of the graph as the spacing
  1958. * in the group's content area.
  1959. */
  1960. mxEditor.prototype.groupCells = function ()
  1961. {
  1962. var border = (this.groupBorderSize != null) ?
  1963. this.groupBorderSize :
  1964. this.graph.gridSize;
  1965. return this.graph.groupCells(this.createGroup(), border);
  1966. };
  1967. /**
  1968. * Function: createGroup
  1969. *
  1970. * Creates and returns a clone of <defaultGroup> to be used
  1971. * as a new group cell in <group>.
  1972. */
  1973. mxEditor.prototype.createGroup = function ()
  1974. {
  1975. var model = this.graph.getModel();
  1976. return model.cloneCell(this.defaultGroup);
  1977. };
  1978. /**
  1979. * Function: open
  1980. *
  1981. * Opens the specified file synchronously and parses it using
  1982. * <readGraphModel>. It updates <filename> and fires an <open>-event after
  1983. * the file has been opened. Exceptions should be handled as follows:
  1984. *
  1985. * (code)
  1986. * try
  1987. * {
  1988. * editor.open(filename);
  1989. * }
  1990. * catch (e)
  1991. * {
  1992. * mxUtils.error('Cannot open ' + filename +
  1993. * ': ' + e.message, 280, true);
  1994. * }
  1995. * (end)
  1996. *
  1997. * Parameters:
  1998. *
  1999. * filename - URL of the file to be opened.
  2000. */
  2001. mxEditor.prototype.open = function (filename)
  2002. {
  2003. if (filename != null)
  2004. {
  2005. var xml = mxUtils.load(filename).getXml();
  2006. this.readGraphModel(xml.documentElement);
  2007. this.filename = filename;
  2008. this.fireEvent(new mxEventObject(mxEvent.OPEN, 'filename', filename));
  2009. }
  2010. };
  2011. /**
  2012. * Function: readGraphModel
  2013. *
  2014. * Reads the specified XML node into the existing graph model and resets
  2015. * the command history and modified state.
  2016. */
  2017. mxEditor.prototype.readGraphModel = function (node)
  2018. {
  2019. var dec = new mxCodec(node.ownerDocument);
  2020. dec.decode(node, this.graph.getModel());
  2021. this.resetHistory();
  2022. };
  2023. /**
  2024. * Function: save
  2025. *
  2026. * Posts the string returned by <writeGraphModel> to the given URL or the
  2027. * URL returned by <getUrlPost>. The actual posting is carried out by
  2028. * <postDiagram>. If the URL is null then the resulting XML will be
  2029. * displayed using <mxUtils.popup>. Exceptions should be handled as
  2030. * follows:
  2031. *
  2032. * (code)
  2033. * try
  2034. * {
  2035. * editor.save();
  2036. * }
  2037. * catch (e)
  2038. * {
  2039. * mxUtils.error('Cannot save : ' + e.message, 280, true);
  2040. * }
  2041. * (end)
  2042. */
  2043. mxEditor.prototype.save = function (url, linefeed)
  2044. {
  2045. // Gets the URL to post the data to
  2046. url = url || this.getUrlPost();
  2047. // Posts the data if the URL is not empty
  2048. if (url != null && url.length > 0)
  2049. {
  2050. var data = this.writeGraphModel(linefeed);
  2051. this.postDiagram(url, data);
  2052. // Resets the modified flag
  2053. this.setModified(false);
  2054. }
  2055. // Dispatches a save event
  2056. this.fireEvent(new mxEventObject(mxEvent.SAVE, 'url', url));
  2057. };
  2058. /**
  2059. * Function: postDiagram
  2060. *
  2061. * Hook for subclassers to override the posting of a diagram
  2062. * represented by the given node to the given URL. This fires
  2063. * an asynchronous <post> event if the diagram has been posted.
  2064. *
  2065. * Example:
  2066. *
  2067. * To replace the diagram with the diagram in the response, use the
  2068. * following code.
  2069. *
  2070. * (code)
  2071. * editor.addListener(mxEvent.POST, function(sender, evt)
  2072. * {
  2073. * // Process response (replace diagram)
  2074. * var req = evt.getProperty('request');
  2075. * var root = req.getDocumentElement();
  2076. * editor.graph.readGraphModel(root)
  2077. * });
  2078. * (end)
  2079. */
  2080. mxEditor.prototype.postDiagram = function (url, data)
  2081. {
  2082. if (this.escapePostData)
  2083. {
  2084. data = encodeURIComponent(data);
  2085. }
  2086. mxUtils.post(url, this.postParameterName+'='+data,
  2087. mxUtils.bind(this, function(req)
  2088. {
  2089. this.fireEvent(new mxEventObject(mxEvent.POST,
  2090. 'request', req, 'url', url, 'data', data));
  2091. })
  2092. );
  2093. };
  2094. /**
  2095. * Function: writeGraphModel
  2096. *
  2097. * Hook to create the string representation of the diagram. The default
  2098. * implementation uses an <mxCodec> to encode the graph model as
  2099. * follows:
  2100. *
  2101. * (code)
  2102. * var enc = new mxCodec();
  2103. * var node = enc.encode(this.graph.getModel());
  2104. * return mxUtils.getXml(node, this.linefeed);
  2105. * (end)
  2106. *
  2107. * Parameters:
  2108. *
  2109. * linefeed - Optional character to be used as the linefeed. Default is
  2110. * <linefeed>.
  2111. */
  2112. mxEditor.prototype.writeGraphModel = function (linefeed)
  2113. {
  2114. linefeed = (linefeed != null) ? linefeed : this.linefeed;
  2115. var enc = new mxCodec();
  2116. var node = enc.encode(this.graph.getModel());
  2117. return mxUtils.getXml(node, linefeed);
  2118. };
  2119. /**
  2120. * Function: getUrlPost
  2121. *
  2122. * Returns the URL to post the diagram to. This is used
  2123. * in <save>. The default implementation returns <urlPost>,
  2124. * adding <code>?draft=true</code>.
  2125. */
  2126. mxEditor.prototype.getUrlPost = function ()
  2127. {
  2128. return this.urlPost;
  2129. };
  2130. /**
  2131. * Function: getUrlImage
  2132. *
  2133. * Returns the URL to create the image with. This is typically
  2134. * the URL of a backend which accepts an XML representation
  2135. * of a graph view to create an image. The function is used
  2136. * in the image action to create an image. This implementation
  2137. * returns <urlImage>.
  2138. */
  2139. mxEditor.prototype.getUrlImage = function ()
  2140. {
  2141. return this.urlImage;
  2142. };
  2143. /**
  2144. * Function: swapStyles
  2145. *
  2146. * Swaps the styles for the given names in the graph's
  2147. * stylesheet and refreshes the graph.
  2148. */
  2149. mxEditor.prototype.swapStyles = function (first, second)
  2150. {
  2151. var style = this.graph.getStylesheet().styles[second];
  2152. this.graph.getView().getStylesheet().putCellStyle(
  2153. second, this.graph.getStylesheet().styles[first]);
  2154. this.graph.getStylesheet().putCellStyle(first, style);
  2155. this.graph.refresh();
  2156. };
  2157. /**
  2158. * Function: showProperties
  2159. *
  2160. * Creates and shows the properties dialog for the given
  2161. * cell. The content area of the dialog is created using
  2162. * <createProperties>.
  2163. */
  2164. mxEditor.prototype.showProperties = function (cell)
  2165. {
  2166. cell = cell || this.graph.getSelectionCell();
  2167. // Uses the root node for the properties dialog
  2168. // if not cell was passed in and no cell is
  2169. // selected
  2170. if (cell == null)
  2171. {
  2172. cell = this.graph.getCurrentRoot();
  2173. if (cell == null)
  2174. {
  2175. cell = this.graph.getModel().getRoot();
  2176. }
  2177. }
  2178. if (cell != null)
  2179. {
  2180. // Makes sure there is no in-place editor in the
  2181. // graph and computes the location of the dialog
  2182. this.graph.stopEditing(true);
  2183. var offset = mxUtils.getOffset(this.graph.container);
  2184. var x = offset.x+10;
  2185. var y = offset.y;
  2186. // Avoids moving the dialog if it is alredy open
  2187. if (this.properties != null && !this.movePropertiesDialog)
  2188. {
  2189. x = this.properties.getX();
  2190. y = this.properties.getY();
  2191. }
  2192. // Places the dialog near the cell for which it
  2193. // displays the properties
  2194. else
  2195. {
  2196. var bounds = this.graph.getCellBounds(cell);
  2197. if (bounds != null)
  2198. {
  2199. x += bounds.x+Math.min(200, bounds.width);
  2200. y += bounds.y;
  2201. }
  2202. }
  2203. // Hides the existing properties dialog and creates a new one with the
  2204. // contents created in the hook method
  2205. this.hideProperties();
  2206. var node = this.createProperties(cell);
  2207. if (node != null)
  2208. {
  2209. // Displays the contents in a window and stores a reference to the
  2210. // window for later hiding of the window
  2211. this.properties = new mxWindow(mxResources.get(this.propertiesResource) ||
  2212. this.propertiesResource, node, x, y, this.propertiesWidth, this.propertiesHeight, false);
  2213. this.properties.setVisible(true);
  2214. }
  2215. }
  2216. };
  2217. /**
  2218. * Function: isPropertiesVisible
  2219. *
  2220. * Returns true if the properties dialog is currently visible.
  2221. */
  2222. mxEditor.prototype.isPropertiesVisible = function ()
  2223. {
  2224. return this.properties != null;
  2225. };
  2226. /**
  2227. * Function: createProperties
  2228. *
  2229. * Creates and returns the DOM node that represents the contents
  2230. * of the properties dialog for the given cell. This implementation
  2231. * works for user objects that are XML nodes and display all the
  2232. * node attributes in a form.
  2233. */
  2234. mxEditor.prototype.createProperties = function (cell)
  2235. {
  2236. var model = this.graph.getModel();
  2237. var value = model.getValue(cell);
  2238. if (mxUtils.isNode(value))
  2239. {
  2240. // Creates a form for the user object inside
  2241. // the cell
  2242. var form = new mxForm('properties');
  2243. // Adds a readonly field for the cell id
  2244. var id = form.addText('ID', cell.getId());
  2245. id.setAttribute('readonly', 'true');
  2246. var geo = null;
  2247. var yField = null;
  2248. var xField = null;
  2249. var widthField = null;
  2250. var heightField = null;
  2251. // Adds fields for the location and size
  2252. if (model.isVertex(cell))
  2253. {
  2254. geo = model.getGeometry(cell);
  2255. if (geo != null)
  2256. {
  2257. yField = form.addText('top', geo.y);
  2258. xField = form.addText('left', geo.x);
  2259. widthField = form.addText('width', geo.width);
  2260. heightField = form.addText('height', geo.height);
  2261. }
  2262. }
  2263. // Adds a field for the cell style
  2264. var tmp = model.getStyle(cell);
  2265. var style = form.addText('Style', tmp || '');
  2266. // Creates textareas for each attribute of the
  2267. // user object within the cell
  2268. var attrs = value.attributes;
  2269. var texts = [];
  2270. for (var i = 0; i < attrs.length; i++)
  2271. {
  2272. // Creates a textarea with more lines for
  2273. // the cell label
  2274. var val = attrs[i].value;
  2275. texts[i] = form.addTextarea(attrs[i].nodeName, val,
  2276. (attrs[i].nodeName == 'label') ? 4 : 2);
  2277. }
  2278. // Adds an OK and Cancel button to the dialog
  2279. // contents and implements the respective
  2280. // actions below
  2281. // Defines the function to be executed when the
  2282. // OK button is pressed in the dialog
  2283. var okFunction = mxUtils.bind(this, function()
  2284. {
  2285. // Hides the dialog
  2286. this.hideProperties();
  2287. // Supports undo for the changes on the underlying
  2288. // XML structure / XML node attribute changes.
  2289. model.beginUpdate();
  2290. try
  2291. {
  2292. if (geo != null)
  2293. {
  2294. geo = geo.clone();
  2295. geo.x = parseFloat(xField.value);
  2296. geo.y = parseFloat(yField.value);
  2297. geo.width = parseFloat(widthField.value);
  2298. geo.height = parseFloat(heightField.value);
  2299. model.setGeometry(cell, geo);
  2300. }
  2301. // Applies the style
  2302. if (style.value.length > 0)
  2303. {
  2304. model.setStyle(cell, style.value);
  2305. }
  2306. else
  2307. {
  2308. model.setStyle(cell, null);
  2309. }
  2310. // Creates an undoable change for each
  2311. // attribute and executes it using the
  2312. // model, which will also make the change
  2313. // part of the current transaction
  2314. for (var i=0; i<attrs.length; i++)
  2315. {
  2316. var edit = new mxCellAttributeChange(
  2317. cell, attrs[i].nodeName,
  2318. texts[i].value);
  2319. model.execute(edit);
  2320. }
  2321. // Checks if the graph wants cells to
  2322. // be automatically sized and updates
  2323. // the size as an undoable step if
  2324. // the feature is enabled
  2325. if (this.graph.isAutoSizeCell(cell))
  2326. {
  2327. this.graph.updateCellSize(cell);
  2328. }
  2329. }
  2330. finally
  2331. {
  2332. model.endUpdate();
  2333. }
  2334. });
  2335. // Defines the function to be executed when the
  2336. // Cancel button is pressed in the dialog
  2337. var cancelFunction = mxUtils.bind(this, function()
  2338. {
  2339. // Hides the dialog
  2340. this.hideProperties();
  2341. });
  2342. form.addButtons(okFunction, cancelFunction);
  2343. return form.table;
  2344. }
  2345. return null;
  2346. };
  2347. /**
  2348. * Function: hideProperties
  2349. *
  2350. * Hides the properties dialog.
  2351. */
  2352. mxEditor.prototype.hideProperties = function ()
  2353. {
  2354. if (this.properties != null)
  2355. {
  2356. this.properties.destroy();
  2357. this.properties = null;
  2358. }
  2359. };
  2360. /**
  2361. * Function: showTasks
  2362. *
  2363. * Shows the tasks window. The tasks window is created using <createTasks>. The
  2364. * default width of the window is 200 pixels, the y-coordinate of the location
  2365. * can be specifies in <tasksTop> and the x-coordinate is right aligned with a
  2366. * 20 pixel offset from the right border. To change the location of the tasks
  2367. * window, the following code can be used:
  2368. *
  2369. * (code)
  2370. * var oldShowTasks = mxEditor.prototype.showTasks;
  2371. * mxEditor.prototype.showTasks = function()
  2372. * {
  2373. * oldShowTasks.apply(this, arguments); // "supercall"
  2374. *
  2375. * if (this.tasks != null)
  2376. * {
  2377. * this.tasks.setLocation(10, 10);
  2378. * }
  2379. * };
  2380. * (end)
  2381. */
  2382. mxEditor.prototype.showTasks = function ()
  2383. {
  2384. if (this.tasks == null)
  2385. {
  2386. var div = document.createElement('div');
  2387. div.style.padding = '4px';
  2388. div.style.paddingLeft = '20px';
  2389. var w = document.body.clientWidth;
  2390. var wnd = new mxWindow(
  2391. mxResources.get(this.tasksResource) ||
  2392. this.tasksResource,
  2393. div, w - 220, this.tasksTop, 200);
  2394. wnd.setClosable(true);
  2395. wnd.destroyOnClose = false;
  2396. // Installs a function to update the contents
  2397. // of the tasks window on every change of the
  2398. // model, selection or root.
  2399. var funct = mxUtils.bind(this, function(sender)
  2400. {
  2401. mxEvent.release(div);
  2402. div.innerHTML = '';
  2403. this.createTasks(div);
  2404. });
  2405. this.graph.getModel().addListener(mxEvent.CHANGE, funct);
  2406. this.graph.getSelectionModel().addListener(mxEvent.CHANGE, funct);
  2407. this.graph.addListener(mxEvent.ROOT, funct);
  2408. // Assigns the icon to the tasks window
  2409. if (this.tasksWindowImage != null)
  2410. {
  2411. wnd.setImage(this.tasksWindowImage);
  2412. }
  2413. this.tasks = wnd;
  2414. this.createTasks(div);
  2415. }
  2416. this.tasks.setVisible(true);
  2417. };
  2418. /**
  2419. * Function: refreshTasks
  2420. *
  2421. * Updates the contents of the tasks window using <createTasks>.
  2422. */
  2423. mxEditor.prototype.refreshTasks = function (div)
  2424. {
  2425. if (this.tasks != null)
  2426. {
  2427. var div = this.tasks.content;
  2428. mxEvent.release(div);
  2429. div.innerHTML = '';
  2430. this.createTasks(div);
  2431. }
  2432. };
  2433. /**
  2434. * Function: createTasks
  2435. *
  2436. * Updates the contents of the given DOM node to
  2437. * display the tasks associated with the current
  2438. * editor state. This is invoked whenever there
  2439. * is a possible change of state in the editor.
  2440. * Default implementation is empty.
  2441. */
  2442. mxEditor.prototype.createTasks = function (div)
  2443. {
  2444. // override
  2445. };
  2446. /**
  2447. * Function: showHelp
  2448. *
  2449. * Shows the help window. If the help window does not exist
  2450. * then it is created using an iframe pointing to the resource
  2451. * for the <code>urlHelp</code> key or <urlHelp> if the resource
  2452. * is undefined.
  2453. */
  2454. mxEditor.prototype.showHelp = function (tasks)
  2455. {
  2456. if (this.help == null)
  2457. {
  2458. var frame = document.createElement('iframe');
  2459. frame.setAttribute('src', mxResources.get('urlHelp') || this.urlHelp);
  2460. frame.setAttribute('height', '100%');
  2461. frame.setAttribute('width', '100%');
  2462. frame.setAttribute('frameBorder', '0');
  2463. frame.style.backgroundColor = 'white';
  2464. var w = document.body.clientWidth;
  2465. var h = (document.body.clientHeight || document.documentElement.clientHeight);
  2466. var wnd = new mxWindow(mxResources.get(this.helpResource) || this.helpResource,
  2467. frame, (w-this.helpWidth)/2, (h-this.helpHeight)/3, this.helpWidth, this.helpHeight);
  2468. wnd.setMaximizable(true);
  2469. wnd.setClosable(true);
  2470. wnd.destroyOnClose = false;
  2471. wnd.setResizable(true);
  2472. // Assigns the icon to the help window
  2473. if (this.helpWindowImage != null)
  2474. {
  2475. wnd.setImage(this.helpWindowImage);
  2476. }
  2477. // Workaround for ignored iframe height 100% in FF
  2478. if (mxClient.IS_NS)
  2479. {
  2480. var handler = function(sender)
  2481. {
  2482. var h = wnd.div.offsetHeight;
  2483. frame.setAttribute('height', (h-26)+'px');
  2484. };
  2485. wnd.addListener(mxEvent.RESIZE_END, handler);
  2486. wnd.addListener(mxEvent.MAXIMIZE, handler);
  2487. wnd.addListener(mxEvent.NORMALIZE, handler);
  2488. wnd.addListener(mxEvent.SHOW, handler);
  2489. }
  2490. this.help = wnd;
  2491. }
  2492. this.help.setVisible(true);
  2493. };
  2494. /**
  2495. * Function: showOutline
  2496. *
  2497. * Shows the outline window. If the window does not exist, then it is
  2498. * created using an <mxOutline>.
  2499. */
  2500. mxEditor.prototype.showOutline = function ()
  2501. {
  2502. var create = this.outline == null;
  2503. if (create)
  2504. {
  2505. var div = document.createElement('div');
  2506. div.style.overflow = 'hidden';
  2507. div.style.position = 'relative';
  2508. div.style.width = '100%';
  2509. div.style.height = '100%';
  2510. div.style.background = 'white';
  2511. div.style.cursor = 'move';
  2512. if (document.documentMode == 8)
  2513. {
  2514. div.style.filter = 'progid:DXImageTransform.Microsoft.alpha(opacity=100)';
  2515. }
  2516. var wnd = new mxWindow(
  2517. mxResources.get(this.outlineResource) ||
  2518. this.outlineResource,
  2519. div, 600, 480, 200, 200, false);
  2520. // Creates the outline in the specified div
  2521. // and links it to the existing graph
  2522. var outline = new mxOutline(this.graph, div);
  2523. wnd.setClosable(true);
  2524. wnd.setResizable(true);
  2525. wnd.destroyOnClose = false;
  2526. wnd.addListener(mxEvent.RESIZE_END, function()
  2527. {
  2528. outline.update();
  2529. });
  2530. this.outline = wnd;
  2531. this.outline.outline = outline;
  2532. }
  2533. // Finally shows the outline
  2534. this.outline.setVisible(true);
  2535. this.outline.outline.update(true);
  2536. };
  2537. /**
  2538. * Function: setMode
  2539. *
  2540. * Puts the graph into the specified mode. The following modenames are
  2541. * supported:
  2542. *
  2543. * select - Selects using the left mouse button, new connections
  2544. * are disabled.
  2545. * connect - Selects using the left mouse button or creates new
  2546. * connections if mouse over cell hotspot. See <mxConnectionHandler>.
  2547. * pan - Pans using the left mouse button, new connections are disabled.
  2548. */
  2549. mxEditor.prototype.setMode = function(modename)
  2550. {
  2551. if (modename == 'select')
  2552. {
  2553. this.graph.panningHandler.useLeftButtonForPanning = false;
  2554. this.graph.setConnectable(false);
  2555. }
  2556. else if (modename == 'connect')
  2557. {
  2558. this.graph.panningHandler.useLeftButtonForPanning = false;
  2559. this.graph.setConnectable(true);
  2560. }
  2561. else if (modename == 'pan')
  2562. {
  2563. this.graph.panningHandler.useLeftButtonForPanning = true;
  2564. this.graph.setConnectable(false);
  2565. }
  2566. };
  2567. /**
  2568. * Function: createPopupMenu
  2569. *
  2570. * Uses <popupHandler> to create the menu in the graph's
  2571. * panning handler. The redirection is setup in
  2572. * <setToolbarContainer>.
  2573. */
  2574. mxEditor.prototype.createPopupMenu = function (menu, cell, evt)
  2575. {
  2576. this.popupHandler.createMenu(this, menu, cell, evt);
  2577. };
  2578. /**
  2579. * Function: createEdge
  2580. *
  2581. * Uses <defaultEdge> as the prototype for creating new edges
  2582. * in the connection handler of the graph. The style of the
  2583. * edge will be overridden with the value returned by
  2584. * <getEdgeStyle>.
  2585. */
  2586. mxEditor.prototype.createEdge = function (source, target)
  2587. {
  2588. // Clones the defaultedge prototype
  2589. var e = null;
  2590. if (this.defaultEdge != null)
  2591. {
  2592. var model = this.graph.getModel();
  2593. e = model.cloneCell(this.defaultEdge);
  2594. }
  2595. else
  2596. {
  2597. e = new mxCell('');
  2598. e.setEdge(true);
  2599. var geo = new mxGeometry();
  2600. geo.relative = true;
  2601. e.setGeometry(geo);
  2602. }
  2603. // Overrides the edge style
  2604. var style = this.getEdgeStyle();
  2605. if (style != null)
  2606. {
  2607. e.setStyle(style);
  2608. }
  2609. return e;
  2610. };
  2611. /**
  2612. * Function: getEdgeStyle
  2613. *
  2614. * Returns a string identifying the style of new edges.
  2615. * The function is used in <createEdge> when new edges
  2616. * are created in the graph.
  2617. */
  2618. mxEditor.prototype.getEdgeStyle = function ()
  2619. {
  2620. return this.defaultEdgeStyle;
  2621. };
  2622. /**
  2623. * Function: consumeCycleAttribute
  2624. *
  2625. * Returns the next attribute in <cycleAttributeValues>
  2626. * or null, if not attribute should be used in the
  2627. * specified cell.
  2628. */
  2629. mxEditor.prototype.consumeCycleAttribute = function (cell)
  2630. {
  2631. return (this.cycleAttributeValues != null &&
  2632. this.cycleAttributeValues.length > 0 &&
  2633. this.graph.isSwimlane(cell)) ?
  2634. this.cycleAttributeValues[this.cycleAttributeIndex++ %
  2635. this.cycleAttributeValues.length] : null;
  2636. };
  2637. /**
  2638. * Function: cycleAttribute
  2639. *
  2640. * Uses the returned value from <consumeCycleAttribute>
  2641. * as the value for the <cycleAttributeName> key in
  2642. * the given cell's style.
  2643. */
  2644. mxEditor.prototype.cycleAttribute = function (cell)
  2645. {
  2646. if (this.cycleAttributeName != null)
  2647. {
  2648. var value = this.consumeCycleAttribute(cell);
  2649. if (value != null)
  2650. {
  2651. cell.setStyle(cell.getStyle()+';'+
  2652. this.cycleAttributeName+'='+value);
  2653. }
  2654. }
  2655. };
  2656. /**
  2657. * Function: addVertex
  2658. *
  2659. * Adds the given vertex as a child of parent at the specified
  2660. * x and y coordinate and fires an <addVertex> event.
  2661. */
  2662. mxEditor.prototype.addVertex = function (parent, vertex, x, y)
  2663. {
  2664. var model = this.graph.getModel();
  2665. while (parent != null && !this.graph.isValidDropTarget(parent))
  2666. {
  2667. parent = model.getParent(parent);
  2668. }
  2669. parent = (parent != null) ? parent : this.graph.getSwimlaneAt(x, y);
  2670. var scale = this.graph.getView().scale;
  2671. var geo = model.getGeometry(vertex);
  2672. var pgeo = model.getGeometry(parent);
  2673. if (this.graph.isSwimlane(vertex) &&
  2674. !this.graph.swimlaneNesting)
  2675. {
  2676. parent = null;
  2677. }
  2678. else if (parent == null && this.swimlaneRequired)
  2679. {
  2680. return null;
  2681. }
  2682. else if (parent != null && pgeo != null)
  2683. {
  2684. // Keeps vertex inside parent
  2685. var state = this.graph.getView().getState(parent);
  2686. if (state != null)
  2687. {
  2688. x -= state.origin.x * scale;
  2689. y -= state.origin.y * scale;
  2690. if (this.graph.isConstrainedMoving)
  2691. {
  2692. var width = geo.width;
  2693. var height = geo.height;
  2694. var tmp = state.x+state.width;
  2695. if (x+width > tmp)
  2696. {
  2697. x -= x+width - tmp;
  2698. }
  2699. tmp = state.y+state.height;
  2700. if (y+height > tmp)
  2701. {
  2702. y -= y+height - tmp;
  2703. }
  2704. }
  2705. }
  2706. else if (pgeo != null)
  2707. {
  2708. x -= pgeo.x*scale;
  2709. y -= pgeo.y*scale;
  2710. }
  2711. }
  2712. geo = geo.clone();
  2713. geo.x = this.graph.snap(x / scale -
  2714. this.graph.getView().translate.x -
  2715. this.graph.gridSize/2);
  2716. geo.y = this.graph.snap(y / scale -
  2717. this.graph.getView().translate.y -
  2718. this.graph.gridSize/2);
  2719. vertex.setGeometry(geo);
  2720. if (parent == null)
  2721. {
  2722. parent = this.graph.getDefaultParent();
  2723. }
  2724. this.cycleAttribute(vertex);
  2725. this.fireEvent(new mxEventObject(mxEvent.BEFORE_ADD_VERTEX,
  2726. 'vertex', vertex, 'parent', parent));
  2727. model.beginUpdate();
  2728. try
  2729. {
  2730. vertex = this.graph.addCell(vertex, parent);
  2731. if (vertex != null)
  2732. {
  2733. this.graph.constrainChild(vertex);
  2734. this.fireEvent(new mxEventObject(mxEvent.ADD_VERTEX, 'vertex', vertex));
  2735. }
  2736. }
  2737. finally
  2738. {
  2739. model.endUpdate();
  2740. }
  2741. if (vertex != null)
  2742. {
  2743. this.graph.setSelectionCell(vertex);
  2744. this.graph.scrollCellToVisible(vertex);
  2745. this.fireEvent(new mxEventObject(mxEvent.AFTER_ADD_VERTEX, 'vertex', vertex));
  2746. }
  2747. return vertex;
  2748. };
  2749. /**
  2750. * Function: destroy
  2751. *
  2752. * Removes the editor and all its associated resources. This does not
  2753. * normally need to be called, it is called automatically when the window
  2754. * unloads.
  2755. */
  2756. mxEditor.prototype.destroy = function ()
  2757. {
  2758. if (!this.destroyed)
  2759. {
  2760. this.destroyed = true;
  2761. if (this.tasks != null)
  2762. {
  2763. this.tasks.destroy();
  2764. }
  2765. if (this.outline != null)
  2766. {
  2767. this.outline.destroy();
  2768. }
  2769. if (this.properties != null)
  2770. {
  2771. this.properties.destroy();
  2772. }
  2773. if (this.keyHandler != null)
  2774. {
  2775. this.keyHandler.destroy();
  2776. }
  2777. if (this.rubberband != null)
  2778. {
  2779. this.rubberband.destroy();
  2780. }
  2781. if (this.toolbar != null)
  2782. {
  2783. this.toolbar.destroy();
  2784. }
  2785. if (this.graph != null)
  2786. {
  2787. this.graph.destroy();
  2788. }
  2789. this.status = null;
  2790. this.templates = null;
  2791. }
  2792. };
  2793. __mxOutput.mxEditor = typeof mxEditor !== 'undefined' ? mxEditor : undefined;