mxVertexHandler.js 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253
  1. /**
  2. * Copyright (c) 2006-2015, JGraph Ltd
  3. * Copyright (c) 2006-2015, Gaudenz Alder
  4. */
  5. /**
  6. * Class: mxVertexHandler
  7. *
  8. * Event handler for resizing cells. This handler is automatically created in
  9. * <mxGraph.createHandler>.
  10. *
  11. * Constructor: mxVertexHandler
  12. *
  13. * Constructs an event handler that allows to resize vertices
  14. * and groups.
  15. *
  16. * Parameters:
  17. *
  18. * state - <mxCellState> of the cell to be resized.
  19. */
  20. function mxVertexHandler(state)
  21. {
  22. if (state != null)
  23. {
  24. this.state = state;
  25. this.init();
  26. // Handles escape keystrokes
  27. this.escapeHandler = mxUtils.bind(this, function(sender, evt)
  28. {
  29. if (this.livePreview && this.index != null)
  30. {
  31. // Redraws the live preview
  32. this.state.view.graph.cellRenderer.redraw(this.state, true);
  33. // Redraws connected edges
  34. this.state.view.invalidate(this.state.cell);
  35. this.state.invalid = false;
  36. this.state.view.validate();
  37. }
  38. this.reset();
  39. });
  40. this.state.view.graph.addListener(mxEvent.ESCAPE, this.escapeHandler);
  41. }
  42. };
  43. /**
  44. * Variable: graph
  45. *
  46. * Reference to the enclosing <mxGraph>.
  47. */
  48. mxVertexHandler.prototype.graph = null;
  49. /**
  50. * Variable: state
  51. *
  52. * Reference to the <mxCellState> being modified.
  53. */
  54. mxVertexHandler.prototype.state = null;
  55. /**
  56. * Variable: singleSizer
  57. *
  58. * Specifies if only one sizer handle at the bottom, right corner should be
  59. * used. Default is false.
  60. */
  61. mxVertexHandler.prototype.singleSizer = false;
  62. /**
  63. * Variable: index
  64. *
  65. * Holds the index of the current handle.
  66. */
  67. mxVertexHandler.prototype.index = null;
  68. /**
  69. * Variable: allowHandleBoundsCheck
  70. *
  71. * Specifies if the bounds of handles should be used for hit-detection in IE or
  72. * if <tolerance> > 0. Default is true.
  73. */
  74. mxVertexHandler.prototype.allowHandleBoundsCheck = true;
  75. /**
  76. * Variable: handleImage
  77. *
  78. * Optional <mxImage> to be used as handles. Default is null.
  79. */
  80. mxVertexHandler.prototype.handleImage = null;
  81. /**
  82. * Variable: handlesVisible
  83. *
  84. * If handles are currently visible.
  85. */
  86. mxVertexHandler.prototype.handlesVisible = true;
  87. /**
  88. * Variable: tolerance
  89. *
  90. * Optional tolerance for hit-detection in <getHandleForEvent>. Default is 0.
  91. */
  92. mxVertexHandler.prototype.tolerance = 0;
  93. /**
  94. * Variable: rotationEnabled
  95. *
  96. * Specifies if a rotation handle should be visible. Default is false.
  97. */
  98. mxVertexHandler.prototype.rotationEnabled = false;
  99. /**
  100. * Variable: parentHighlightEnabled
  101. *
  102. * Specifies if the parent should be highlighted if a child cell is selected.
  103. * Default is false.
  104. */
  105. mxVertexHandler.prototype.parentHighlightEnabled = false;
  106. /**
  107. * Variable: rotationRaster
  108. *
  109. * Specifies if rotation steps should be "rasterized" depening on the distance
  110. * to the handle. Default is true.
  111. */
  112. mxVertexHandler.prototype.rotationRaster = true;
  113. /**
  114. * Variable: rotationCursor
  115. *
  116. * Specifies the cursor for the rotation handle. Default is 'crosshair'.
  117. */
  118. mxVertexHandler.prototype.rotationCursor = 'crosshair';
  119. /**
  120. * Variable: livePreview
  121. *
  122. * Specifies if resize should change the cell in-place. This is an experimental
  123. * feature for non-touch devices. Default is false.
  124. */
  125. mxVertexHandler.prototype.livePreview = false;
  126. /**
  127. * Variable: movePreviewToFront
  128. *
  129. * Specifies if the live preview should be moved to the front.
  130. */
  131. mxVertexHandler.prototype.movePreviewToFront = false;
  132. /**
  133. * Variable: manageSizers
  134. *
  135. * Specifies if sizers should be hidden and spaced if the vertex is small.
  136. * Default is false.
  137. */
  138. mxVertexHandler.prototype.manageSizers = false;
  139. /**
  140. * Variable: constrainGroupByChildren
  141. *
  142. * Specifies if the size of groups should be constrained by the children.
  143. * Default is false.
  144. */
  145. mxVertexHandler.prototype.constrainGroupByChildren = false;
  146. /**
  147. * Variable: rotationHandleVSpacing
  148. *
  149. * Vertical spacing for rotation icon. Default is -16.
  150. */
  151. mxVertexHandler.prototype.rotationHandleVSpacing = -16;
  152. /**
  153. * Variable: horizontalOffset
  154. *
  155. * The horizontal offset for the handles. This is updated in <redrawHandles>
  156. * if <manageSizers> is true and the sizers are offset horizontally.
  157. */
  158. mxVertexHandler.prototype.horizontalOffset = 0;
  159. /**
  160. * Variable: verticalOffset
  161. *
  162. * The horizontal offset for the handles. This is updated in <redrawHandles>
  163. * if <manageSizers> is true and the sizers are offset vertically.
  164. */
  165. mxVertexHandler.prototype.verticalOffset = 0;
  166. /**
  167. * Function: init
  168. *
  169. * Initializes the shapes required for this vertex handler.
  170. */
  171. mxVertexHandler.prototype.init = function()
  172. {
  173. this.graph = this.state.view.graph;
  174. this.selectionBounds = this.getSelectionBounds(this.state);
  175. this.bounds = new mxRectangle(this.selectionBounds.x, this.selectionBounds.y, this.selectionBounds.width, this.selectionBounds.height);
  176. this.selectionBorder = this.createSelectionShape(this.bounds);
  177. // VML dialect required here for event transparency in IE
  178. this.selectionBorder.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ? mxConstants.DIALECT_VML : mxConstants.DIALECT_SVG;
  179. this.selectionBorder.pointerEvents = false;
  180. this.selectionBorder.rotation = Number(this.state.style[mxConstants.STYLE_ROTATION] || '0');
  181. this.selectionBorder.init(this.graph.getView().getOverlayPane());
  182. mxEvent.redirectMouseEvents(this.selectionBorder.node, this.graph, this.state);
  183. if (this.graph.isCellMovable(this.state.cell))
  184. {
  185. this.selectionBorder.setCursor(mxConstants.CURSOR_MOVABLE_VERTEX);
  186. }
  187. // Adds the sizer handles
  188. if (mxGraphHandler.prototype.maxCells <= 0 || this.graph.getSelectionCount() < mxGraphHandler.prototype.maxCells)
  189. {
  190. var resizable = this.graph.isCellResizable(this.state.cell);
  191. this.sizers = [];
  192. if (resizable || (this.graph.isLabelMovable(this.state.cell) &&
  193. this.state.width >= 2 && this.state.height >= 2))
  194. {
  195. var i = 0;
  196. if (resizable)
  197. {
  198. if (!this.singleSizer)
  199. {
  200. this.sizers.push(this.createSizer('nw-resize', i++));
  201. this.sizers.push(this.createSizer('n-resize', i++));
  202. this.sizers.push(this.createSizer('ne-resize', i++));
  203. this.sizers.push(this.createSizer('w-resize', i++));
  204. this.sizers.push(this.createSizer('e-resize', i++));
  205. this.sizers.push(this.createSizer('sw-resize', i++));
  206. this.sizers.push(this.createSizer('s-resize', i++));
  207. }
  208. this.sizers.push(this.createSizer('se-resize', i++));
  209. }
  210. var geo = this.graph.model.getGeometry(this.state.cell);
  211. if (geo != null && !geo.relative && !this.graph.isSwimlane(this.state.cell) &&
  212. this.graph.isLabelMovable(this.state.cell))
  213. {
  214. // Marks this as the label handle for getHandleForEvent
  215. this.labelShape = this.createSizer(mxConstants.CURSOR_LABEL_HANDLE, mxEvent.LABEL_HANDLE,
  216. mxConstants.LABEL_HANDLE_SIZE, mxConstants.LABEL_HANDLE_FILLCOLOR);
  217. this.sizers.push(this.labelShape);
  218. }
  219. }
  220. else if (this.graph.isCellMovable(this.state.cell) && !this.graph.isCellResizable(this.state.cell) &&
  221. this.state.width < 2 && this.state.height < 2)
  222. {
  223. this.labelShape = this.createSizer(mxConstants.CURSOR_MOVABLE_VERTEX,
  224. mxEvent.LABEL_HANDLE, null, mxConstants.LABEL_HANDLE_FILLCOLOR);
  225. this.sizers.push(this.labelShape);
  226. }
  227. }
  228. // Adds the rotation handler
  229. if (this.isRotationHandleVisible())
  230. {
  231. this.rotationShape = this.createSizer(this.rotationCursor, mxEvent.ROTATION_HANDLE,
  232. mxConstants.HANDLE_SIZE + 3, mxConstants.HANDLE_FILLCOLOR);
  233. this.sizers.push(this.rotationShape);
  234. }
  235. this.customHandles = this.createCustomHandles();
  236. this.redraw();
  237. if (this.constrainGroupByChildren)
  238. {
  239. this.updateMinBounds();
  240. }
  241. };
  242. /**
  243. * Function: isRotationHandleVisible
  244. *
  245. * Returns true if the rotation handle should be showing.
  246. */
  247. mxVertexHandler.prototype.isRotationHandleVisible = function()
  248. {
  249. return this.graph.isEnabled() && this.rotationEnabled && this.graph.isCellRotatable(this.state.cell) &&
  250. (mxGraphHandler.prototype.maxCells <= 0 || this.graph.getSelectionCount() < mxGraphHandler.prototype.maxCells);
  251. };
  252. /**
  253. * Function: isConstrainedEvent
  254. *
  255. * Returns true if the aspect ratio if the cell should be maintained.
  256. */
  257. mxVertexHandler.prototype.isConstrainedEvent = function(me)
  258. {
  259. return mxEvent.isShiftDown(me.getEvent()) || this.state.style[mxConstants.STYLE_ASPECT] == 'fixed';
  260. };
  261. /**
  262. * Function: isCenteredEvent
  263. *
  264. * Returns true if the center of the vertex should be maintained during the resize.
  265. */
  266. mxVertexHandler.prototype.isCenteredEvent = function(state, me)
  267. {
  268. return false;
  269. };
  270. /**
  271. * Function: createCustomHandles
  272. *
  273. * Returns an array of custom handles. This implementation returns null.
  274. */
  275. mxVertexHandler.prototype.createCustomHandles = function()
  276. {
  277. return null;
  278. };
  279. /**
  280. * Function: updateMinBounds
  281. *
  282. * Initializes the shapes required for this vertex handler.
  283. */
  284. mxVertexHandler.prototype.updateMinBounds = function()
  285. {
  286. var children = this.graph.getChildCells(this.state.cell);
  287. if (children.length > 0)
  288. {
  289. this.minBounds = this.graph.view.getBounds(children);
  290. if (this.minBounds != null)
  291. {
  292. var s = this.state.view.scale;
  293. var t = this.state.view.translate;
  294. this.minBounds.x -= this.state.x;
  295. this.minBounds.y -= this.state.y;
  296. this.minBounds.x /= s;
  297. this.minBounds.y /= s;
  298. this.minBounds.width /= s;
  299. this.minBounds.height /= s;
  300. this.x0 = this.state.x / s - t.x;
  301. this.y0 = this.state.y / s - t.y;
  302. }
  303. }
  304. };
  305. /**
  306. * Function: getSelectionBounds
  307. *
  308. * Returns the mxRectangle that defines the bounds of the selection
  309. * border.
  310. */
  311. mxVertexHandler.prototype.getSelectionBounds = function(state)
  312. {
  313. return new mxRectangle(Math.round(state.x), Math.round(state.y), Math.round(state.width), Math.round(state.height));
  314. };
  315. /**
  316. * Function: createParentHighlightShape
  317. *
  318. * Creates the shape used to draw the selection border.
  319. */
  320. mxVertexHandler.prototype.createParentHighlightShape = function(bounds)
  321. {
  322. return this.createSelectionShape(bounds);
  323. };
  324. /**
  325. * Function: createSelectionShape
  326. *
  327. * Creates the shape used to draw the selection border.
  328. */
  329. mxVertexHandler.prototype.createSelectionShape = function(bounds)
  330. {
  331. var shape = new mxRectangleShape(
  332. mxRectangle.fromRectangle(bounds),
  333. null, this.getSelectionColor());
  334. shape.strokewidth = this.getSelectionStrokeWidth();
  335. shape.isDashed = this.isSelectionDashed();
  336. return shape;
  337. };
  338. /**
  339. * Function: getSelectionColor
  340. *
  341. * Returns <mxConstants.VERTEX_SELECTION_COLOR>.
  342. */
  343. mxVertexHandler.prototype.getSelectionColor = function()
  344. {
  345. return mxConstants.VERTEX_SELECTION_COLOR;
  346. };
  347. /**
  348. * Function: getSelectionStrokeWidth
  349. *
  350. * Returns <mxConstants.VERTEX_SELECTION_STROKEWIDTH>.
  351. */
  352. mxVertexHandler.prototype.getSelectionStrokeWidth = function()
  353. {
  354. return mxConstants.VERTEX_SELECTION_STROKEWIDTH;
  355. };
  356. /**
  357. * Function: isSelectionDashed
  358. *
  359. * Returns <mxConstants.VERTEX_SELECTION_DASHED>.
  360. */
  361. mxVertexHandler.prototype.isSelectionDashed = function()
  362. {
  363. return mxConstants.VERTEX_SELECTION_DASHED;
  364. };
  365. /**
  366. * Function: createSizer
  367. *
  368. * Creates a sizer handle for the specified cursor and index and returns
  369. * the new <mxRectangleShape> that represents the handle.
  370. */
  371. mxVertexHandler.prototype.createSizer = function(cursor, index, size, fillColor)
  372. {
  373. size = size || mxConstants.HANDLE_SIZE;
  374. var bounds = new mxRectangle(0, 0, size, size);
  375. var sizer = this.createSizerShape(bounds, index, fillColor);
  376. if (sizer.isHtmlAllowed() && this.state.text != null && this.state.text.node.parentNode == this.graph.container)
  377. {
  378. sizer.bounds.height -= 1;
  379. sizer.bounds.width -= 1;
  380. sizer.dialect = mxConstants.DIALECT_STRICTHTML;
  381. sizer.init(this.graph.container);
  382. }
  383. else
  384. {
  385. sizer.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
  386. mxConstants.DIALECT_MIXEDHTML : mxConstants.DIALECT_SVG;
  387. sizer.init(this.graph.getView().getOverlayPane());
  388. }
  389. mxEvent.redirectMouseEvents(sizer.node, this.graph, this.state);
  390. if (this.graph.isEnabled())
  391. {
  392. sizer.setCursor(cursor);
  393. }
  394. if (!this.isSizerVisible(index))
  395. {
  396. sizer.visible = false;
  397. }
  398. return sizer;
  399. };
  400. /**
  401. * Function: isSizerVisible
  402. *
  403. * Returns true if the sizer for the given index is visible.
  404. * This returns true for all given indices.
  405. */
  406. mxVertexHandler.prototype.isSizerVisible = function(index)
  407. {
  408. return true;
  409. };
  410. /**
  411. * Function: createSizerShape
  412. *
  413. * Creates the shape used for the sizer handle for the specified bounds an
  414. * index. Only images and rectangles should be returned if support for HTML
  415. * labels with not foreign objects is required.
  416. */
  417. mxVertexHandler.prototype.createSizerShape = function(bounds, index, fillColor)
  418. {
  419. if (this.handleImage != null)
  420. {
  421. bounds = new mxRectangle(bounds.x, bounds.y, this.handleImage.width, this.handleImage.height);
  422. var shape = new mxImageShape(bounds, this.handleImage.src);
  423. // Allows HTML rendering of the images
  424. shape.preserveImageAspect = false;
  425. return shape;
  426. }
  427. else if (index == mxEvent.ROTATION_HANDLE)
  428. {
  429. return new mxEllipse(bounds, fillColor || mxConstants.HANDLE_FILLCOLOR, mxConstants.HANDLE_STROKECOLOR);
  430. }
  431. else
  432. {
  433. return new mxRectangleShape(bounds, fillColor || mxConstants.HANDLE_FILLCOLOR, mxConstants.HANDLE_STROKECOLOR);
  434. }
  435. };
  436. /**
  437. * Function: createBounds
  438. *
  439. * Helper method to create an <mxRectangle> around the given centerpoint
  440. * with a width and height of 2*s or 6, if no s is given.
  441. */
  442. mxVertexHandler.prototype.moveSizerTo = function(shape, x, y)
  443. {
  444. if (shape != null)
  445. {
  446. shape.bounds.x = Math.floor(x - shape.bounds.width / 2);
  447. shape.bounds.y = Math.floor(y - shape.bounds.height / 2);
  448. // Fixes visible inactive handles in VML
  449. if (shape.node != null && shape.node.style.display != 'none')
  450. {
  451. shape.redraw();
  452. }
  453. }
  454. };
  455. /**
  456. * Function: getHandleForEvent
  457. *
  458. * Returns the index of the handle for the given event. This returns the index
  459. * of the sizer from where the event originated or <mxEvent.LABEL_INDEX>.
  460. */
  461. mxVertexHandler.prototype.getHandleForEvent = function(me)
  462. {
  463. // Connection highlight may consume events before they reach sizer handle
  464. var tol = (!mxEvent.isMouseEvent(me.getEvent())) ? this.tolerance : 1;
  465. var hit = (this.allowHandleBoundsCheck && (mxClient.IS_IE || tol > 0)) ?
  466. new mxRectangle(me.getGraphX() - tol, me.getGraphY() - tol, 2 * tol, 2 * tol) : null;
  467. var checkShape = mxUtils.bind(this, function(shape)
  468. {
  469. var st = (shape != null && shape.constructor != mxImageShape &&
  470. this.allowHandleBoundsCheck) ? shape.strokewidth + shape.svgStrokeTolerance : null;
  471. var real = (st != null) ? new mxRectangle(me.getGraphX() - Math.floor(st / 2),
  472. me.getGraphY() - Math.floor(st / 2), st, st) : hit;
  473. return shape != null && (me.isSource(shape) || (real != null && mxUtils.intersects(shape.bounds, real) &&
  474. shape.node.style.display != 'none' && shape.node.style.visibility != 'hidden'));
  475. });
  476. if (checkShape(this.rotationShape))
  477. {
  478. return mxEvent.ROTATION_HANDLE;
  479. }
  480. else if (checkShape(this.labelShape))
  481. {
  482. return mxEvent.LABEL_HANDLE;
  483. }
  484. if (this.sizers != null)
  485. {
  486. for (var i = 0; i < this.sizers.length; i++)
  487. {
  488. if (checkShape(this.sizers[i]))
  489. {
  490. return i;
  491. }
  492. }
  493. }
  494. if (this.customHandles != null && this.isCustomHandleEvent(me))
  495. {
  496. // Inverse loop order to match display order
  497. for (var i = this.customHandles.length - 1; i >= 0; i--)
  498. {
  499. if (checkShape(this.customHandles[i].shape))
  500. {
  501. // LATER: Return reference to active shape
  502. return mxEvent.CUSTOM_HANDLE - i;
  503. }
  504. }
  505. }
  506. return null;
  507. };
  508. /**
  509. * Function: isCustomHandleEvent
  510. *
  511. * Returns true if the given event allows custom handles to be changed. This
  512. * implementation returns true.
  513. */
  514. mxVertexHandler.prototype.isCustomHandleEvent = function(me)
  515. {
  516. return true;
  517. };
  518. /**
  519. * Function: mouseDown
  520. *
  521. * Handles the event if a handle has been clicked. By consuming the
  522. * event all subsequent events of the gesture are redirected to this
  523. * handler.
  524. */
  525. mxVertexHandler.prototype.mouseDown = function(sender, me)
  526. {
  527. if (!me.isConsumed() && this.graph.isEnabled())
  528. {
  529. var handle = this.getHandleForEvent(me);
  530. if (handle != null)
  531. {
  532. this.start(me.getGraphX(), me.getGraphY(), handle);
  533. me.consume();
  534. }
  535. }
  536. };
  537. /**
  538. * Function: isLivePreviewBorder
  539. *
  540. * Called if <livePreview> is enabled to check if a border should be painted.
  541. * This implementation returns true if the shape is transparent.
  542. */
  543. mxVertexHandler.prototype.isLivePreviewBorder = function()
  544. {
  545. return this.state.shape != null && this.state.shape.fill == null && this.state.shape.stroke == null;
  546. };
  547. /**
  548. * Function: start
  549. *
  550. * Starts the handling of the mouse gesture.
  551. */
  552. mxVertexHandler.prototype.start = function(x, y, index)
  553. {
  554. if (this.selectionBorder != null)
  555. {
  556. this.livePreviewActive = this.livePreview && this.graph.model.getChildCount(this.state.cell) == 0;
  557. this.inTolerance = true;
  558. this.childOffsetX = 0;
  559. this.childOffsetY = 0;
  560. this.index = index;
  561. this.startX = x;
  562. this.startY = y;
  563. if (this.index <= mxEvent.CUSTOM_HANDLE && this.isGhostPreview())
  564. {
  565. this.ghostPreview = this.createGhostPreview();
  566. }
  567. else
  568. {
  569. // Saves reference to parent state
  570. var model = this.state.view.graph.model;
  571. var parent = model.getParent(this.state.cell);
  572. if (this.state.view.currentRoot != parent && (model.isVertex(parent) || model.isEdge(parent)))
  573. {
  574. this.parentState = this.state.view.graph.view.getState(parent);
  575. }
  576. // Creates a preview that can be on top of any HTML label
  577. this.selectionBorder.node.style.display = (index == mxEvent.ROTATION_HANDLE) ? 'inline' : 'none';
  578. // Creates the border that represents the new bounds
  579. if (!this.livePreviewActive || this.isLivePreviewBorder())
  580. {
  581. this.preview = this.createSelectionShape(this.bounds);
  582. if (!(mxClient.IS_SVG && Number(this.state.style[mxConstants.STYLE_ROTATION] || '0') != 0) &&
  583. this.state.text != null && this.state.text.node.parentNode == this.graph.container)
  584. {
  585. this.preview.dialect = mxConstants.DIALECT_STRICTHTML;
  586. this.preview.init(this.graph.container);
  587. }
  588. else
  589. {
  590. this.preview.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ?
  591. mxConstants.DIALECT_VML : mxConstants.DIALECT_SVG;
  592. this.preview.init(this.graph.view.getOverlayPane());
  593. }
  594. }
  595. if (index == mxEvent.ROTATION_HANDLE)
  596. {
  597. // With the rotation handle in a corner, need the angle and distance
  598. var pos = this.getRotationHandlePosition();
  599. var dx = pos.x - this.state.getCenterX();
  600. var dy = pos.y - this.state.getCenterY();
  601. this.startAngle = (dx != 0) ? Math.atan(dy / dx) * 180 / Math.PI + 90 : 0;
  602. this.startDist = Math.sqrt(dx * dx + dy * dy);
  603. }
  604. // Prepares the handles for live preview
  605. if (this.livePreviewActive)
  606. {
  607. this.hideSizers();
  608. if (index == mxEvent.ROTATION_HANDLE)
  609. {
  610. this.rotationShape.node.style.display = '';
  611. }
  612. else if (index == mxEvent.LABEL_HANDLE)
  613. {
  614. this.labelShape.node.style.display = '';
  615. }
  616. else if (this.sizers != null && this.sizers[index] != null)
  617. {
  618. this.sizers[index].node.style.display = '';
  619. }
  620. else if (index <= mxEvent.CUSTOM_HANDLE && this.customHandles != null)
  621. {
  622. this.customHandles[mxEvent.CUSTOM_HANDLE - index].setVisible(true);
  623. }
  624. // Gets the array of connected edge handlers for redrawing
  625. var edges = this.graph.getEdges(this.state.cell);
  626. this.edgeHandlers = [];
  627. for (var i = 0; i < edges.length; i++)
  628. {
  629. var handler = this.graph.selectionCellsHandler.getHandler(edges[i]);
  630. if (handler != null)
  631. {
  632. this.edgeHandlers.push(handler);
  633. }
  634. }
  635. }
  636. }
  637. }
  638. };
  639. /**
  640. * Function: createGhostPreview
  641. *
  642. * Starts the handling of the mouse gesture.
  643. */
  644. mxVertexHandler.prototype.createGhostPreview = function()
  645. {
  646. var shape = this.graph.cellRenderer.createShape(this.state);
  647. shape.init(this.graph.view.getOverlayPane());
  648. shape.scale = this.state.view.scale;
  649. shape.bounds = this.bounds;
  650. shape.outline = true;
  651. return shape;
  652. };
  653. /**
  654. * Function: hideHandles
  655. *
  656. * Shortcut to <hideSizers>.
  657. */
  658. mxVertexHandler.prototype.setHandlesVisible = function(visible)
  659. {
  660. this.handlesVisible = visible;
  661. if (this.sizers != null)
  662. {
  663. for (var i = 0; i < this.sizers.length; i++)
  664. {
  665. this.sizers[i].node.style.display = (visible) ? '' : 'none';
  666. }
  667. }
  668. if (this.customHandles != null)
  669. {
  670. for (var i = 0; i < this.customHandles.length; i++)
  671. {
  672. this.customHandles[i].setVisible(visible);
  673. }
  674. }
  675. };
  676. /**
  677. * Function: hideSizers
  678. *
  679. * Hides all sizers except.
  680. *
  681. * Starts the handling of the mouse gesture.
  682. */
  683. mxVertexHandler.prototype.hideSizers = function()
  684. {
  685. this.setHandlesVisible(false);
  686. };
  687. /**
  688. * Function: checkTolerance
  689. *
  690. * Checks if the coordinates for the given event are within the
  691. * <mxGraph.tolerance>. If the event is a mouse event then the tolerance is
  692. * ignored.
  693. */
  694. mxVertexHandler.prototype.checkTolerance = function(me)
  695. {
  696. if (this.inTolerance && this.startX != null && this.startY != null)
  697. {
  698. if (mxEvent.isMouseEvent(me.getEvent()) ||
  699. Math.abs(me.getGraphX() - this.startX) > this.graph.tolerance ||
  700. Math.abs(me.getGraphY() - this.startY) > this.graph.tolerance)
  701. {
  702. this.inTolerance = false;
  703. }
  704. }
  705. };
  706. /**
  707. * Function: updateHint
  708. *
  709. * Hook for subclassers do show details while the handler is active.
  710. */
  711. mxVertexHandler.prototype.updateHint = function(me) { };
  712. /**
  713. * Function: removeHint
  714. *
  715. * Hooks for subclassers to hide details when the handler gets inactive.
  716. */
  717. mxVertexHandler.prototype.removeHint = function() { };
  718. /**
  719. * Function: roundAngle
  720. *
  721. * Hook for rounding the angle. This uses Math.round.
  722. */
  723. mxVertexHandler.prototype.roundAngle = function(angle)
  724. {
  725. return Math.round(angle * 10) / 10;
  726. };
  727. /**
  728. * Function: roundLength
  729. *
  730. * Hook for rounding the unscaled width or height. This uses Math.round.
  731. */
  732. mxVertexHandler.prototype.roundLength = function(length)
  733. {
  734. return Math.round(length * 100) / 100;
  735. };
  736. /**
  737. * Function: mouseMove
  738. *
  739. * Handles the event by updating the preview.
  740. */
  741. mxVertexHandler.prototype.mouseMove = function(sender, me)
  742. {
  743. if (!me.isConsumed() && this.index != null)
  744. {
  745. // Checks tolerance for ignoring single clicks
  746. this.checkTolerance(me);
  747. if (!this.inTolerance)
  748. {
  749. if (this.index <= mxEvent.CUSTOM_HANDLE)
  750. {
  751. if (this.customHandles != null)
  752. {
  753. this.customHandles[mxEvent.CUSTOM_HANDLE - this.index].processEvent(me);
  754. this.customHandles[mxEvent.CUSTOM_HANDLE - this.index].active = true;
  755. if (this.ghostPreview != null)
  756. {
  757. this.ghostPreview.apply(this.state);
  758. this.ghostPreview.strokewidth = this.getSelectionStrokeWidth() /
  759. this.ghostPreview.scale / this.ghostPreview.scale;
  760. this.ghostPreview.isDashed = this.isSelectionDashed();
  761. this.ghostPreview.stroke = this.getSelectionColor();
  762. this.ghostPreview.redraw();
  763. if (this.selectionBounds != null)
  764. {
  765. this.selectionBorder.node.style.display = 'none';
  766. }
  767. }
  768. else
  769. {
  770. if (this.movePreviewToFront)
  771. {
  772. this.moveToFront();
  773. }
  774. this.customHandles[mxEvent.CUSTOM_HANDLE - this.index].positionChanged();
  775. }
  776. }
  777. }
  778. else if (this.index == mxEvent.LABEL_HANDLE)
  779. {
  780. this.moveLabel(me);
  781. }
  782. else
  783. {
  784. if (this.index == mxEvent.ROTATION_HANDLE)
  785. {
  786. this.rotateVertex(me);
  787. }
  788. else
  789. {
  790. this.resizeVertex(me);
  791. }
  792. this.updateHint(me);
  793. }
  794. }
  795. me.consume();
  796. }
  797. // Workaround for disabling the connect highlight when over handle
  798. else if (!this.graph.isMouseDown && this.getHandleForEvent(me) != null)
  799. {
  800. me.consume(false);
  801. }
  802. };
  803. /**
  804. * Function: isGhostPreview
  805. *
  806. * Returns true if a ghost preview should be used for custom handles.
  807. */
  808. mxVertexHandler.prototype.isGhostPreview = function()
  809. {
  810. return this.state.view.graph.model.getChildCount(this.state.cell) > 0;
  811. };
  812. /**
  813. * Function: moveLabel
  814. *
  815. * Moves the label.
  816. */
  817. mxVertexHandler.prototype.moveLabel = function(me)
  818. {
  819. var point = new mxPoint(me.getGraphX(), me.getGraphY());
  820. var tr = this.graph.view.translate;
  821. var scale = this.graph.view.scale;
  822. if (this.graph.isGridEnabledEvent(me.getEvent()))
  823. {
  824. point.x = (this.graph.snap(point.x / scale - tr.x) + tr.x) * scale;
  825. point.y = (this.graph.snap(point.y / scale - tr.y) + tr.y) * scale;
  826. }
  827. var index = (this.rotationShape != null) ? this.sizers.length - 2 : this.sizers.length - 1;
  828. this.moveSizerTo(this.sizers[index], point.x, point.y);
  829. };
  830. /**
  831. * Function: rotateVertex
  832. *
  833. * Rotates the vertex.
  834. */
  835. mxVertexHandler.prototype.rotateVertex = function(me)
  836. {
  837. var point = new mxPoint(me.getGraphX(), me.getGraphY());
  838. var dx = this.state.x + this.state.width / 2 - point.x;
  839. var dy = this.state.y + this.state.height / 2 - point.y;
  840. this.currentAlpha = (dx != 0) ? Math.atan(dy / dx) * 180 / Math.PI + 90 : ((dy < 0) ? 180 : 0);
  841. if (dx > 0)
  842. {
  843. this.currentAlpha -= 180;
  844. }
  845. this.currentAlpha -= this.startAngle;
  846. // Rotation raster
  847. if (this.rotationRaster && this.graph.isGridEnabledEvent(me.getEvent()))
  848. {
  849. var dx = point.x - this.state.getCenterX();
  850. var dy = point.y - this.state.getCenterY();
  851. var dist = Math.sqrt(dx * dx + dy * dy);
  852. if (dist - this.startDist < 2)
  853. {
  854. raster = 15;
  855. }
  856. else if (dist - this.startDist < 25)
  857. {
  858. raster = 5;
  859. }
  860. else
  861. {
  862. raster = 1;
  863. }
  864. this.currentAlpha = Math.round(this.currentAlpha / raster) * raster;
  865. }
  866. else
  867. {
  868. this.currentAlpha = this.roundAngle(this.currentAlpha);
  869. }
  870. this.selectionBorder.rotation = this.currentAlpha;
  871. this.selectionBorder.redraw();
  872. if (this.livePreviewActive)
  873. {
  874. this.redrawHandles();
  875. }
  876. };
  877. /**
  878. * Function: resizeVertex
  879. *
  880. * Risizes the vertex.
  881. */
  882. mxVertexHandler.prototype.resizeVertex = function(me)
  883. {
  884. var ct = new mxPoint(this.state.getCenterX(), this.state.getCenterY());
  885. var alpha = mxUtils.toRadians(this.state.style[mxConstants.STYLE_ROTATION] || '0');
  886. var point = new mxPoint(me.getGraphX(), me.getGraphY());
  887. var tr = this.graph.view.translate;
  888. var scale = this.graph.view.scale;
  889. var cos = Math.cos(-alpha);
  890. var sin = Math.sin(-alpha);
  891. var dx = point.x - this.startX;
  892. var dy = point.y - this.startY;
  893. // Rotates vector for mouse gesture
  894. var tx = cos * dx - sin * dy;
  895. var ty = sin * dx + cos * dy;
  896. dx = tx;
  897. dy = ty;
  898. var geo = this.graph.getCellGeometry(this.state.cell);
  899. this.unscaledBounds = this.union(geo, dx / scale, dy / scale, this.index,
  900. this.graph.isGridEnabledEvent(me.getEvent()), 1,
  901. new mxPoint(0, 0), this.isConstrainedEvent(me),
  902. this.isCenteredEvent(this.state, me));
  903. // Keeps vertex within maximum graph or parent bounds
  904. if (!geo.relative)
  905. {
  906. var max = this.graph.getMaximumGraphBounds();
  907. // Handles child cells
  908. if (max != null && this.parentState != null)
  909. {
  910. max = mxRectangle.fromRectangle(max);
  911. max.x -= (this.parentState.x - tr.x * scale) / scale;
  912. max.y -= (this.parentState.y - tr.y * scale) / scale;
  913. }
  914. if (this.graph.isConstrainChild(this.state.cell))
  915. {
  916. var tmp = this.graph.getCellContainmentArea(this.state.cell);
  917. if (tmp != null)
  918. {
  919. var overlap = this.graph.getOverlap(this.state.cell);
  920. if (overlap > 0)
  921. {
  922. tmp = mxRectangle.fromRectangle(tmp);
  923. tmp.x -= tmp.width * overlap;
  924. tmp.y -= tmp.height * overlap;
  925. tmp.width += 2 * tmp.width * overlap;
  926. tmp.height += 2 * tmp.height * overlap;
  927. }
  928. if (max == null)
  929. {
  930. max = tmp;
  931. }
  932. else
  933. {
  934. max = mxRectangle.fromRectangle(max);
  935. max.intersect(tmp);
  936. }
  937. }
  938. }
  939. if (max != null)
  940. {
  941. if (this.unscaledBounds.x < max.x)
  942. {
  943. this.unscaledBounds.width -= max.x - this.unscaledBounds.x;
  944. this.unscaledBounds.x = max.x;
  945. }
  946. if (this.unscaledBounds.y < max.y)
  947. {
  948. this.unscaledBounds.height -= max.y - this.unscaledBounds.y;
  949. this.unscaledBounds.y = max.y;
  950. }
  951. if (this.unscaledBounds.x + this.unscaledBounds.width > max.x + max.width)
  952. {
  953. this.unscaledBounds.width -= this.unscaledBounds.x +
  954. this.unscaledBounds.width - max.x - max.width;
  955. }
  956. if (this.unscaledBounds.y + this.unscaledBounds.height > max.y + max.height)
  957. {
  958. this.unscaledBounds.height -= this.unscaledBounds.y +
  959. this.unscaledBounds.height - max.y - max.height;
  960. }
  961. }
  962. }
  963. var old = this.bounds;
  964. this.bounds = new mxRectangle(((this.parentState != null) ? this.parentState.x : tr.x * scale) +
  965. (this.unscaledBounds.x) * scale, ((this.parentState != null) ? this.parentState.y : tr.y * scale) +
  966. (this.unscaledBounds.y) * scale, this.unscaledBounds.width * scale, this.unscaledBounds.height * scale);
  967. if (geo.relative && this.parentState != null)
  968. {
  969. this.bounds.x += this.state.x - this.parentState.x;
  970. this.bounds.y += this.state.y - this.parentState.y;
  971. }
  972. cos = Math.cos(alpha);
  973. sin = Math.sin(alpha);
  974. var c2 = new mxPoint(this.bounds.getCenterX(), this.bounds.getCenterY());
  975. var dx = c2.x - ct.x;
  976. var dy = c2.y - ct.y;
  977. var dx2 = cos * dx - sin * dy;
  978. var dy2 = sin * dx + cos * dy;
  979. var dx3 = dx2 - dx;
  980. var dy3 = dy2 - dy;
  981. var dx4 = this.bounds.x - this.state.x;
  982. var dy4 = this.bounds.y - this.state.y;
  983. var dx5 = cos * dx4 - sin * dy4;
  984. var dy5 = sin * dx4 + cos * dy4;
  985. this.bounds.x += dx3;
  986. this.bounds.y += dy3;
  987. // Rounds unscaled bounds to int
  988. this.unscaledBounds.x = this.roundLength(this.unscaledBounds.x + dx3 / scale);
  989. this.unscaledBounds.y = this.roundLength(this.unscaledBounds.y + dy3 / scale);
  990. this.unscaledBounds.width = this.roundLength(this.unscaledBounds.width);
  991. this.unscaledBounds.height = this.roundLength(this.unscaledBounds.height);
  992. // Shifts the children according to parent offset
  993. if (!this.graph.isCellCollapsed(this.state.cell) && (dx3 != 0 || dy3 != 0))
  994. {
  995. this.childOffsetX = this.state.x - this.bounds.x + dx5;
  996. this.childOffsetY = this.state.y - this.bounds.y + dy5;
  997. }
  998. else
  999. {
  1000. this.childOffsetX = 0;
  1001. this.childOffsetY = 0;
  1002. }
  1003. if (!old.equals(this.bounds))
  1004. {
  1005. if (this.livePreviewActive)
  1006. {
  1007. this.updateLivePreview(me);
  1008. }
  1009. if (this.preview != null)
  1010. {
  1011. this.drawPreview();
  1012. }
  1013. else
  1014. {
  1015. this.updateParentHighlight();
  1016. }
  1017. }
  1018. };
  1019. /**
  1020. * Function: updateLivePreview
  1021. *
  1022. * Repaints the live preview.
  1023. */
  1024. mxVertexHandler.prototype.updateLivePreview = function(me)
  1025. {
  1026. // TODO: Apply child offset to children in live preview
  1027. var scale = this.graph.view.scale;
  1028. var tr = this.graph.view.translate;
  1029. // Saves current state
  1030. var tempState = this.state.clone();
  1031. // Temporarily changes size and origin
  1032. this.state.x = this.bounds.x;
  1033. this.state.y = this.bounds.y;
  1034. this.state.origin = new mxPoint(this.state.x / scale - tr.x, this.state.y / scale - tr.y);
  1035. this.state.width = this.bounds.width;
  1036. this.state.height = this.bounds.height;
  1037. // Redraws cell and handles
  1038. var off = this.state.absoluteOffset;
  1039. off = new mxPoint(off.x, off.y);
  1040. // Required to store and reset absolute offset for updating label position
  1041. this.state.absoluteOffset.x = 0;
  1042. this.state.absoluteOffset.y = 0;
  1043. var geo = this.graph.getCellGeometry(this.state.cell);
  1044. if (geo != null)
  1045. {
  1046. var offset = geo.offset || this.EMPTY_POINT;
  1047. if (offset != null && !geo.relative)
  1048. {
  1049. this.state.absoluteOffset.x = this.state.view.scale * offset.x;
  1050. this.state.absoluteOffset.y = this.state.view.scale * offset.y;
  1051. }
  1052. this.state.view.updateVertexLabelOffset(this.state);
  1053. }
  1054. // Draws the live preview
  1055. this.state.view.graph.cellRenderer.redraw(this.state, true);
  1056. // Redraws connected edges TODO: Include child edges
  1057. this.state.view.invalidate(this.state.cell);
  1058. this.state.invalid = false;
  1059. this.state.view.validate();
  1060. this.redrawHandles();
  1061. // Moves live preview to front
  1062. if (this.movePreviewToFront)
  1063. {
  1064. this.moveToFront();
  1065. }
  1066. // Hides folding icon
  1067. if (this.state.control != null && this.state.control.node != null)
  1068. {
  1069. this.state.control.node.style.visibility = 'hidden';
  1070. }
  1071. // Restores current state
  1072. this.state.setState(tempState);
  1073. };
  1074. /**
  1075. * Function: moveToFront
  1076. *
  1077. * Handles the event by applying the changes to the geometry.
  1078. */
  1079. mxVertexHandler.prototype.moveToFront = function()
  1080. {
  1081. if ((this.state.text != null && this.state.text.node != null &&
  1082. this.state.text.node.nextSibling != null) ||
  1083. (this.state.shape != null && this.state.shape.node != null &&
  1084. this.state.shape.node.nextSibling != null && (this.state.text == null ||
  1085. this.state.shape.node.nextSibling != this.state.text.node)))
  1086. {
  1087. if (this.state.shape != null && this.state.shape.node != null)
  1088. {
  1089. this.state.shape.node.parentNode.appendChild(this.state.shape.node);
  1090. }
  1091. if (this.state.text != null && this.state.text.node != null)
  1092. {
  1093. this.state.text.node.parentNode.appendChild(this.state.text.node);
  1094. }
  1095. }
  1096. };
  1097. /**
  1098. * Function: mouseUp
  1099. *
  1100. * Handles the event by applying the changes to the geometry.
  1101. */
  1102. mxVertexHandler.prototype.mouseUp = function(sender, me)
  1103. {
  1104. if (this.index != null && this.state != null)
  1105. {
  1106. var point = new mxPoint(me.getGraphX(), me.getGraphY());
  1107. var index = this.index;
  1108. this.index = null;
  1109. if (this.ghostPreview == null)
  1110. {
  1111. // Required to restore order in case of no change
  1112. this.state.view.invalidate(this.state.cell, false, false);
  1113. this.state.view.validate();
  1114. }
  1115. this.graph.getModel().beginUpdate();
  1116. try
  1117. {
  1118. if (index <= mxEvent.CUSTOM_HANDLE)
  1119. {
  1120. if (this.customHandles != null)
  1121. {
  1122. // Creates style before changing cell state
  1123. var style = this.state.view.graph.getCellStyle(this.state.cell);
  1124. this.customHandles[mxEvent.CUSTOM_HANDLE - index].active = false;
  1125. this.customHandles[mxEvent.CUSTOM_HANDLE - index].execute(me);
  1126. // Sets style and apply on shape to force repaint and
  1127. // check if execute has removed custom handles
  1128. if (this.customHandles != null &&
  1129. this.customHandles[mxEvent.CUSTOM_HANDLE - index] != null)
  1130. {
  1131. this.state.style = style;
  1132. this.customHandles[mxEvent.CUSTOM_HANDLE - index].positionChanged();
  1133. }
  1134. }
  1135. }
  1136. else if (index == mxEvent.ROTATION_HANDLE)
  1137. {
  1138. if (this.currentAlpha != null)
  1139. {
  1140. var delta = this.currentAlpha - (this.state.style[mxConstants.STYLE_ROTATION] || 0);
  1141. if (delta != 0)
  1142. {
  1143. this.rotateCell(this.state.cell, delta);
  1144. }
  1145. }
  1146. else
  1147. {
  1148. this.rotateClick();
  1149. }
  1150. }
  1151. else
  1152. {
  1153. var gridEnabled = this.graph.isGridEnabledEvent(me.getEvent());
  1154. var alpha = mxUtils.toRadians(this.state.style[mxConstants.STYLE_ROTATION] || '0');
  1155. var cos = Math.cos(-alpha);
  1156. var sin = Math.sin(-alpha);
  1157. var dx = point.x - this.startX;
  1158. var dy = point.y - this.startY;
  1159. // Rotates vector for mouse gesture
  1160. var tx = cos * dx - sin * dy;
  1161. var ty = sin * dx + cos * dy;
  1162. dx = tx;
  1163. dy = ty;
  1164. var s = this.graph.view.scale;
  1165. var recurse = this.isRecursiveResize(this.state, me);
  1166. this.resizeCell(this.state.cell, this.roundLength(dx / s), this.roundLength(dy / s),
  1167. index, gridEnabled, this.isConstrainedEvent(me), recurse);
  1168. }
  1169. }
  1170. finally
  1171. {
  1172. this.graph.getModel().endUpdate();
  1173. }
  1174. me.consume();
  1175. this.reset();
  1176. this.redrawHandles();
  1177. }
  1178. };
  1179. /**
  1180. * Function: isRecursiveResize
  1181. *
  1182. * Returns the recursiveResize of the give state.
  1183. *
  1184. * Parameters:
  1185. *
  1186. * state - the given <mxCellState>. This implementation takes
  1187. * the value of this state.
  1188. * me - the mouse event.
  1189. */
  1190. mxVertexHandler.prototype.isRecursiveResize = function(state, me)
  1191. {
  1192. return this.graph.isRecursiveResize(this.state);
  1193. };
  1194. /**
  1195. * Function: rotateClick
  1196. *
  1197. * Hook for subclassers to implement a single click on the rotation handle.
  1198. * This code is executed as part of the model transaction. This implementation
  1199. * is empty.
  1200. */
  1201. mxVertexHandler.prototype.rotateClick = function() { };
  1202. /**
  1203. * Function: rotateCell
  1204. *
  1205. * Rotates the given cell and its children by the given angle in degrees.
  1206. *
  1207. * Parameters:
  1208. *
  1209. * cell - <mxCell> to be rotated.
  1210. * angle - Angle in degrees.
  1211. */
  1212. mxVertexHandler.prototype.rotateCell = function(cell, angle, parent)
  1213. {
  1214. if (angle != 0)
  1215. {
  1216. var model = this.graph.getModel();
  1217. if (model.isVertex(cell) || model.isEdge(cell))
  1218. {
  1219. if (!model.isEdge(cell))
  1220. {
  1221. var style = this.graph.getCurrentCellStyle(cell);
  1222. var total = (style[mxConstants.STYLE_ROTATION] || 0) + angle;
  1223. this.graph.setCellStyles(mxConstants.STYLE_ROTATION, total, [cell]);
  1224. }
  1225. var geo = this.graph.getCellGeometry(cell);
  1226. if (geo != null)
  1227. {
  1228. var pgeo = this.graph.getCellGeometry(parent);
  1229. if (pgeo != null && !model.isEdge(parent))
  1230. {
  1231. geo = geo.clone();
  1232. geo.rotate(angle, new mxPoint(pgeo.width / 2, pgeo.height / 2));
  1233. model.setGeometry(cell, geo);
  1234. }
  1235. if ((model.isVertex(cell) && !geo.relative) || model.isEdge(cell))
  1236. {
  1237. // Recursive rotation
  1238. var childCount = model.getChildCount(cell);
  1239. for (var i = 0; i < childCount; i++)
  1240. {
  1241. this.rotateCell(model.getChildAt(cell, i), angle, cell);
  1242. }
  1243. }
  1244. }
  1245. }
  1246. }
  1247. };
  1248. /**
  1249. * Function: reset
  1250. *
  1251. * Resets the state of this handler.
  1252. */
  1253. mxVertexHandler.prototype.reset = function()
  1254. {
  1255. if (this.sizers != null && this.index != null && this.sizers[this.index] != null &&
  1256. this.sizers[this.index].node.style.display == 'none')
  1257. {
  1258. this.sizers[this.index].node.style.display = '';
  1259. }
  1260. this.currentAlpha = null;
  1261. this.inTolerance = null;
  1262. this.index = null;
  1263. // TODO: Reset and redraw cell states for live preview
  1264. if (this.preview != null)
  1265. {
  1266. this.preview.destroy();
  1267. this.preview = null;
  1268. }
  1269. if (this.ghostPreview != null)
  1270. {
  1271. this.ghostPreview.destroy();
  1272. this.ghostPreview = null;
  1273. }
  1274. if (this.livePreviewActive && this.sizers != null)
  1275. {
  1276. for (var i = 0; i < this.sizers.length; i++)
  1277. {
  1278. if (this.sizers[i] != null)
  1279. {
  1280. this.sizers[i].node.style.display = '';
  1281. }
  1282. }
  1283. // Shows folding icon
  1284. if (this.state.control != null && this.state.control.node != null)
  1285. {
  1286. this.state.control.node.style.visibility = '';
  1287. }
  1288. }
  1289. if (this.customHandles != null)
  1290. {
  1291. for (var i = 0; i < this.customHandles.length; i++)
  1292. {
  1293. if (this.customHandles[i].active)
  1294. {
  1295. this.customHandles[i].active = false;
  1296. this.customHandles[i].reset();
  1297. }
  1298. else
  1299. {
  1300. this.customHandles[i].setVisible(true);
  1301. }
  1302. }
  1303. }
  1304. // Checks if handler has been destroyed
  1305. if (this.selectionBorder != null)
  1306. {
  1307. this.selectionBorder.node.style.display = 'inline';
  1308. this.selectionBounds = this.getSelectionBounds(this.state);
  1309. this.bounds = new mxRectangle(this.selectionBounds.x, this.selectionBounds.y,
  1310. this.selectionBounds.width, this.selectionBounds.height);
  1311. this.drawPreview();
  1312. }
  1313. this.removeHint();
  1314. this.redrawHandles();
  1315. this.edgeHandlers = null;
  1316. this.handlesVisible = true;
  1317. this.unscaledBounds = null;
  1318. this.livePreviewActive = null;
  1319. };
  1320. /**
  1321. * Function: resizeCell
  1322. *
  1323. * Uses the given vector to change the bounds of the given cell
  1324. * in the graph using <mxGraph.resizeCell>.
  1325. */
  1326. mxVertexHandler.prototype.resizeCell = function(cell, dx, dy, index, gridEnabled, constrained, recurse)
  1327. {
  1328. var geo = this.graph.model.getGeometry(cell);
  1329. if (geo != null)
  1330. {
  1331. if (index == mxEvent.LABEL_HANDLE)
  1332. {
  1333. var alpha = -mxUtils.toRadians(this.state.style[mxConstants.STYLE_ROTATION] || '0');
  1334. var cos = Math.cos(alpha);
  1335. var sin = Math.sin(alpha);
  1336. var scale = this.graph.view.scale;
  1337. var pt = mxUtils.getRotatedPoint(new mxPoint(
  1338. Math.round((this.labelShape.bounds.getCenterX() - this.startX) / scale),
  1339. Math.round((this.labelShape.bounds.getCenterY() - this.startY) / scale)),
  1340. cos, sin);
  1341. geo = geo.clone();
  1342. if (geo.offset == null)
  1343. {
  1344. geo.offset = pt;
  1345. }
  1346. else
  1347. {
  1348. geo.offset.x += pt.x;
  1349. geo.offset.y += pt.y;
  1350. }
  1351. this.graph.model.setGeometry(cell, geo);
  1352. }
  1353. else if (this.unscaledBounds != null)
  1354. {
  1355. var scale = this.graph.view.scale;
  1356. if (this.childOffsetX != 0 || this.childOffsetY != 0)
  1357. {
  1358. this.moveChildren(cell, Math.round(this.childOffsetX / scale), Math.round(this.childOffsetY / scale));
  1359. }
  1360. this.graph.resizeCell(cell, this.unscaledBounds, recurse);
  1361. }
  1362. }
  1363. };
  1364. /**
  1365. * Function: moveChildren
  1366. *
  1367. * Moves the children of the given cell by the given vector.
  1368. */
  1369. mxVertexHandler.prototype.moveChildren = function(cell, dx, dy)
  1370. {
  1371. var model = this.graph.getModel();
  1372. var childCount = model.getChildCount(cell);
  1373. for (var i = 0; i < childCount; i++)
  1374. {
  1375. var child = model.getChildAt(cell, i);
  1376. var geo = this.graph.getCellGeometry(child);
  1377. if (geo != null)
  1378. {
  1379. geo = geo.clone();
  1380. geo.translate(dx, dy);
  1381. model.setGeometry(child, geo);
  1382. }
  1383. }
  1384. };
  1385. /**
  1386. * Function: union
  1387. *
  1388. * Returns the union of the given bounds and location for the specified
  1389. * handle index.
  1390. *
  1391. * To override this to limit the size of vertex via a minWidth/-Height style,
  1392. * the following code can be used.
  1393. *
  1394. * (code)
  1395. * var vertexHandlerUnion = mxVertexHandler.prototype.union;
  1396. * mxVertexHandler.prototype.union = function(bounds, dx, dy, index, gridEnabled, scale, tr, constrained)
  1397. * {
  1398. * var result = vertexHandlerUnion.apply(this, arguments);
  1399. *
  1400. * result.width = Math.max(result.width, mxUtils.getNumber(this.state.style, 'minWidth', 0));
  1401. * result.height = Math.max(result.height, mxUtils.getNumber(this.state.style, 'minHeight', 0));
  1402. *
  1403. * return result;
  1404. * };
  1405. * (end)
  1406. *
  1407. * The minWidth/-Height style can then be used as follows:
  1408. *
  1409. * (code)
  1410. * graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30, 'minWidth=100;minHeight=100;');
  1411. * (end)
  1412. *
  1413. * To override this to update the height for a wrapped text if the width of a vertex is
  1414. * changed, the following can be used.
  1415. *
  1416. * (code)
  1417. * var mxVertexHandlerUnion = mxVertexHandler.prototype.union;
  1418. * mxVertexHandler.prototype.union = function(bounds, dx, dy, index, gridEnabled, scale, tr, constrained)
  1419. * {
  1420. * var result = mxVertexHandlerUnion.apply(this, arguments);
  1421. * var s = this.state;
  1422. *
  1423. * if (this.graph.isHtmlLabel(s.cell) && (index == 3 || index == 4) &&
  1424. * s.text != null && s.style[mxConstants.STYLE_WHITE_SPACE] == 'wrap')
  1425. * {
  1426. * var label = this.graph.getLabel(s.cell);
  1427. * var fontSize = mxUtils.getNumber(s.style, mxConstants.STYLE_FONTSIZE, mxConstants.DEFAULT_FONTSIZE);
  1428. * var ww = result.width / s.view.scale - s.text.spacingRight - s.text.spacingLeft
  1429. *
  1430. * result.height = mxUtils.getSizeForString(label, fontSize, s.style[mxConstants.STYLE_FONTFAMILY], ww).height;
  1431. * }
  1432. *
  1433. * return result;
  1434. * };
  1435. * (end)
  1436. */
  1437. mxVertexHandler.prototype.union = function(bounds, dx, dy, index, gridEnabled, scale, tr, constrained, centered)
  1438. {
  1439. gridEnabled = (gridEnabled != null) ? gridEnabled && this.graph.gridEnabled : this.graph.gridEnabled;
  1440. if (this.singleSizer)
  1441. {
  1442. var x = bounds.x + bounds.width + dx;
  1443. var y = bounds.y + bounds.height + dy;
  1444. if (gridEnabled)
  1445. {
  1446. x = this.graph.snap(x / scale) * scale;
  1447. y = this.graph.snap(y / scale) * scale;
  1448. }
  1449. var rect = new mxRectangle(bounds.x, bounds.y, 0, 0);
  1450. rect.add(new mxRectangle(x, y, 0, 0));
  1451. return rect;
  1452. }
  1453. else
  1454. {
  1455. var w0 = bounds.width;
  1456. var h0 = bounds.height;
  1457. var left = bounds.x - tr.x * scale;
  1458. var right = left + w0;
  1459. var top = bounds.y - tr.y * scale;
  1460. var bottom = top + h0;
  1461. var cx = left + w0 / 2;
  1462. var cy = top + h0 / 2;
  1463. if (index > 4 /* Bottom Row */)
  1464. {
  1465. bottom = bottom + dy;
  1466. if (gridEnabled)
  1467. {
  1468. bottom = this.graph.snap(bottom / scale) * scale;
  1469. }
  1470. else
  1471. {
  1472. bottom = Math.round(bottom / scale) * scale;
  1473. }
  1474. }
  1475. else if (index < 3 /* Top Row */)
  1476. {
  1477. top = top + dy;
  1478. if (gridEnabled)
  1479. {
  1480. top = this.graph.snap(top / scale) * scale;
  1481. }
  1482. else
  1483. {
  1484. top = Math.round(top / scale) * scale;
  1485. }
  1486. }
  1487. if (index == 0 || index == 3 || index == 5 /* Left */)
  1488. {
  1489. left += dx;
  1490. if (gridEnabled)
  1491. {
  1492. left = this.graph.snap(left / scale) * scale;
  1493. }
  1494. else
  1495. {
  1496. left = Math.round(left / scale) * scale;
  1497. }
  1498. }
  1499. else if (index == 2 || index == 4 || index == 7 /* Right */)
  1500. {
  1501. right += dx;
  1502. if (gridEnabled)
  1503. {
  1504. right = this.graph.snap(right / scale) * scale;
  1505. }
  1506. else
  1507. {
  1508. right = Math.round(right / scale) * scale;
  1509. }
  1510. }
  1511. var width = right - left;
  1512. var height = bottom - top;
  1513. if (constrained)
  1514. {
  1515. var geo = this.graph.getCellGeometry(this.state.cell);
  1516. if (geo != null)
  1517. {
  1518. var aspect = geo.width / geo.height;
  1519. if (index== 1 || index== 2 || index == 7 || index == 6)
  1520. {
  1521. width = height * aspect;
  1522. }
  1523. else
  1524. {
  1525. height = width / aspect;
  1526. }
  1527. if (index == 0)
  1528. {
  1529. left = right - width;
  1530. top = bottom - height;
  1531. }
  1532. }
  1533. }
  1534. if (centered)
  1535. {
  1536. width += (width - w0);
  1537. height += (height - h0);
  1538. var cdx = cx - (left + width / 2);
  1539. var cdy = cy - (top + height / 2);
  1540. left += cdx;
  1541. top += cdy;
  1542. right += cdx;
  1543. bottom += cdy;
  1544. }
  1545. // Flips over left side
  1546. if (width < 0)
  1547. {
  1548. left += width;
  1549. width = Math.abs(width);
  1550. }
  1551. // Flips over top side
  1552. if (height < 0)
  1553. {
  1554. top += height;
  1555. height = Math.abs(height);
  1556. }
  1557. var result = new mxRectangle(left + tr.x * scale, top + tr.y * scale, width, height);
  1558. if (this.minBounds != null)
  1559. {
  1560. result.width = Math.max(result.width, this.minBounds.x * scale + this.minBounds.width * scale +
  1561. Math.max(0, this.x0 * scale - result.x));
  1562. result.height = Math.max(result.height, this.minBounds.y * scale + this.minBounds.height * scale +
  1563. Math.max(0, this.y0 * scale - result.y));
  1564. }
  1565. return result;
  1566. }
  1567. };
  1568. /**
  1569. * Function: redraw
  1570. *
  1571. * Redraws the handles and the preview.
  1572. */
  1573. mxVertexHandler.prototype.redraw = function(ignoreHandles)
  1574. {
  1575. this.selectionBounds = this.getSelectionBounds(this.state);
  1576. this.bounds = new mxRectangle(this.selectionBounds.x, this.selectionBounds.y,
  1577. this.selectionBounds.width, this.selectionBounds.height);
  1578. this.drawPreview();
  1579. if (!ignoreHandles)
  1580. {
  1581. this.redrawHandles();
  1582. }
  1583. };
  1584. /**
  1585. * Returns the padding to be used for drawing handles for the current <bounds>.
  1586. */
  1587. mxVertexHandler.prototype.getHandlePadding = function()
  1588. {
  1589. // KNOWN: Tolerance depends on event type (eg. 0 for mouse events)
  1590. var result = new mxPoint(0, 0);
  1591. var tol = this.tolerance;
  1592. if (this.sizers != null && this.sizers.length > 0 && this.sizers[0] != null &&
  1593. (this.bounds.width < 2 * this.sizers[0].bounds.width + 2 * tol ||
  1594. this.bounds.height < 2 * this.sizers[0].bounds.height + 2 * tol))
  1595. {
  1596. tol /= 2;
  1597. result.x = this.sizers[0].bounds.width + tol;
  1598. result.y = this.sizers[0].bounds.height + tol;
  1599. }
  1600. return result;
  1601. };
  1602. /**
  1603. * Function: getSizerBounds
  1604. *
  1605. * Returns the bounds used to paint the resize handles.
  1606. */
  1607. mxVertexHandler.prototype.getSizerBounds = function()
  1608. {
  1609. return this.bounds;
  1610. };
  1611. /**
  1612. * Function: redrawHandles
  1613. *
  1614. * Redraws the handles. To hide certain handles the following code can be used.
  1615. *
  1616. * (code)
  1617. * mxVertexHandler.prototype.redrawHandles = function()
  1618. * {
  1619. * mxVertexHandlerRedrawHandles.apply(this, arguments);
  1620. *
  1621. * if (this.sizers != null && this.sizers.length > 7)
  1622. * {
  1623. * this.sizers[1].node.style.display = 'none';
  1624. * this.sizers[6].node.style.display = 'none';
  1625. * }
  1626. * };
  1627. * (end)
  1628. */
  1629. mxVertexHandler.prototype.redrawHandles = function()
  1630. {
  1631. var s = this.getSizerBounds();
  1632. var tol = this.tolerance;
  1633. this.horizontalOffset = 0;
  1634. this.verticalOffset = 0;
  1635. if (this.customHandles != null)
  1636. {
  1637. for (var i = 0; i < this.customHandles.length; i++)
  1638. {
  1639. var temp = this.customHandles[i].shape.node.style.display;
  1640. this.customHandles[i].redraw();
  1641. this.customHandles[i].shape.node.style.display = temp;
  1642. // Hides custom handles during text editing
  1643. this.customHandles[i].shape.node.style.visibility =
  1644. (this.handlesVisible && this.isCustomHandleVisible(
  1645. this.customHandles[i])) ? '' : 'hidden';
  1646. }
  1647. }
  1648. if (this.sizers != null && this.sizers.length > 0 && this.sizers[0] != null)
  1649. {
  1650. if (this.index == null && this.manageSizers && this.sizers.length >= 8)
  1651. {
  1652. // KNOWN: Tolerance depends on event type (eg. 0 for mouse events)
  1653. var padding = this.getHandlePadding();
  1654. this.horizontalOffset = padding.x;
  1655. this.verticalOffset = padding.y;
  1656. if (this.horizontalOffset != 0 || this.verticalOffset != 0)
  1657. {
  1658. s = new mxRectangle(s.x, s.y, s.width, s.height);
  1659. s.x -= this.horizontalOffset / 2;
  1660. s.width += this.horizontalOffset;
  1661. s.y -= this.verticalOffset / 2;
  1662. s.height += this.verticalOffset;
  1663. }
  1664. if (this.sizers.length >= 8)
  1665. {
  1666. if ((s.width < 2 * this.sizers[0].bounds.width + 2 * tol) ||
  1667. (s.height < 2 * this.sizers[0].bounds.height + 2 * tol))
  1668. {
  1669. this.sizers[0].node.style.display = 'none';
  1670. this.sizers[2].node.style.display = 'none';
  1671. this.sizers[5].node.style.display = 'none';
  1672. this.sizers[7].node.style.display = 'none';
  1673. }
  1674. else if (this.handlesVisible)
  1675. {
  1676. this.sizers[0].node.style.display = '';
  1677. this.sizers[2].node.style.display = '';
  1678. this.sizers[5].node.style.display = '';
  1679. this.sizers[7].node.style.display = '';
  1680. }
  1681. }
  1682. }
  1683. var r = s.x + s.width;
  1684. var b = s.y + s.height;
  1685. if (this.singleSizer)
  1686. {
  1687. this.moveSizerTo(this.sizers[0], r, b);
  1688. }
  1689. else
  1690. {
  1691. var cx = s.x + s.width / 2;
  1692. var cy = s.y + s.height / 2;
  1693. if (this.sizers.length >= 8)
  1694. {
  1695. var crs = ['nw-resize', 'n-resize', 'ne-resize', 'e-resize', 'se-resize', 's-resize', 'sw-resize', 'w-resize'];
  1696. var alpha = mxUtils.toRadians(this.state.style[mxConstants.STYLE_ROTATION] || '0');
  1697. var cos = Math.cos(alpha);
  1698. var sin = Math.sin(alpha);
  1699. var da = Math.round(alpha * 4 / Math.PI);
  1700. var ct = new mxPoint(s.getCenterX(), s.getCenterY());
  1701. var pt = mxUtils.getRotatedPoint(new mxPoint(s.x, s.y), cos, sin, ct);
  1702. this.moveSizerTo(this.sizers[0], pt.x, pt.y);
  1703. this.sizers[0].setCursor(crs[mxUtils.mod(0 + da, crs.length)]);
  1704. pt.x = cx;
  1705. pt.y = s.y;
  1706. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  1707. this.moveSizerTo(this.sizers[1], pt.x, pt.y);
  1708. this.sizers[1].setCursor(crs[mxUtils.mod(1 + da, crs.length)]);
  1709. pt.x = r;
  1710. pt.y = s.y;
  1711. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  1712. this.moveSizerTo(this.sizers[2], pt.x, pt.y);
  1713. this.sizers[2].setCursor(crs[mxUtils.mod(2 + da, crs.length)]);
  1714. pt.x = s.x;
  1715. pt.y = cy;
  1716. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  1717. this.moveSizerTo(this.sizers[3], pt.x, pt.y);
  1718. this.sizers[3].setCursor(crs[mxUtils.mod(7 + da, crs.length)]);
  1719. pt.x = r;
  1720. pt.y = cy;
  1721. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  1722. this.moveSizerTo(this.sizers[4], pt.x, pt.y);
  1723. this.sizers[4].setCursor(crs[mxUtils.mod(3 + da, crs.length)]);
  1724. pt.x = s.x;
  1725. pt.y = b;
  1726. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  1727. this.moveSizerTo(this.sizers[5], pt.x, pt.y);
  1728. this.sizers[5].setCursor(crs[mxUtils.mod(6 + da, crs.length)]);
  1729. pt.x = cx;
  1730. pt.y = b;
  1731. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  1732. this.moveSizerTo(this.sizers[6], pt.x, pt.y);
  1733. this.sizers[6].setCursor(crs[mxUtils.mod(5 + da, crs.length)]);
  1734. pt.x = r;
  1735. pt.y = b;
  1736. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  1737. this.moveSizerTo(this.sizers[7], pt.x, pt.y);
  1738. this.sizers[7].setCursor(crs[mxUtils.mod(4 + da, crs.length)]);
  1739. pt.x = cx + this.state.absoluteOffset.x;
  1740. pt.y = cy + this.state.absoluteOffset.y;
  1741. pt = mxUtils.getRotatedPoint(pt, cos, sin, ct);
  1742. this.moveSizerTo(this.sizers[8], pt.x, pt.y);
  1743. }
  1744. else if (this.state.width >= 2 && this.state.height >= 2)
  1745. {
  1746. this.moveSizerTo(this.sizers[0], cx + this.state.absoluteOffset.x, cy + this.state.absoluteOffset.y);
  1747. }
  1748. else
  1749. {
  1750. this.moveSizerTo(this.sizers[0], this.state.x, this.state.y);
  1751. }
  1752. }
  1753. }
  1754. if (this.rotationShape != null)
  1755. {
  1756. var alpha = mxUtils.toRadians((this.currentAlpha != null) ? this.currentAlpha : this.state.style[mxConstants.STYLE_ROTATION] || '0');
  1757. var cos = Math.cos(alpha);
  1758. var sin = Math.sin(alpha);
  1759. var ct = new mxPoint(this.state.getCenterX(), this.state.getCenterY());
  1760. var pt = mxUtils.getRotatedPoint(this.getRotationHandlePosition(), cos, sin, ct);
  1761. if (this.rotationShape.node != null)
  1762. {
  1763. this.moveSizerTo(this.rotationShape, pt.x, pt.y);
  1764. // Hides rotation handle during text editing
  1765. this.rotationShape.node.style.visibility = (this.state.view.graph.isEditing() ||
  1766. !this.handlesVisible) ? 'hidden' : '';
  1767. }
  1768. }
  1769. if (this.selectionBorder != null)
  1770. {
  1771. this.selectionBorder.rotation = Number(this.state.style[mxConstants.STYLE_ROTATION] || '0');
  1772. }
  1773. if (this.edgeHandlers != null)
  1774. {
  1775. for (var i = 0; i < this.edgeHandlers.length; i++)
  1776. {
  1777. this.edgeHandlers[i].redraw();
  1778. }
  1779. }
  1780. };
  1781. /**
  1782. * Function: isCustomHandleVisible
  1783. *
  1784. * Returns true if the given custom handle is visible.
  1785. */
  1786. mxVertexHandler.prototype.isCustomHandleVisible = function(handle)
  1787. {
  1788. return !this.graph.isEditing() && this.state.view.graph.getSelectionCount() == 1;
  1789. };
  1790. /**
  1791. * Function: getRotationHandlePosition
  1792. *
  1793. * Returns an <mxPoint> that defines the rotation handle position.
  1794. */
  1795. mxVertexHandler.prototype.getRotationHandlePosition = function()
  1796. {
  1797. return new mxPoint(this.bounds.x + this.bounds.width / 2, this.bounds.y + this.rotationHandleVSpacing)
  1798. };
  1799. /**
  1800. * Function: isParentHighlightVisible
  1801. *
  1802. * Returns true if the parent highlight should be visible. This implementation
  1803. * always returns true.
  1804. */
  1805. mxVertexHandler.prototype.isParentHighlightVisible = function()
  1806. {
  1807. return !this.graph.isCellSelected(this.graph.model.getParent(this.state.cell));
  1808. };
  1809. /**
  1810. * Function: updateParentHighlight
  1811. *
  1812. * Updates the highlight of the parent if <parentHighlightEnabled> is true.
  1813. */
  1814. mxVertexHandler.prototype.updateParentHighlight = function()
  1815. {
  1816. if (!this.isDestroyed())
  1817. {
  1818. var visible = this.isParentHighlightVisible();
  1819. var parent = this.graph.model.getParent(this.state.cell);
  1820. var pstate = this.graph.view.getState(parent);
  1821. if (this.parentHighlight != null)
  1822. {
  1823. if (this.graph.model.isVertex(parent) && visible)
  1824. {
  1825. var b = this.parentHighlight.bounds;
  1826. if (pstate != null && (b.x != pstate.x || b.y != pstate.y ||
  1827. b.width != pstate.width || b.height != pstate.height))
  1828. {
  1829. this.parentHighlight.bounds = mxRectangle.fromRectangle(pstate);
  1830. this.parentHighlight.redraw();
  1831. }
  1832. }
  1833. else
  1834. {
  1835. if (pstate != null && pstate.parentHighlight == this.parentHighlight)
  1836. {
  1837. pstate.parentHighlight = null;
  1838. }
  1839. this.parentHighlight.destroy();
  1840. this.parentHighlight = null;
  1841. }
  1842. }
  1843. else if (this.parentHighlightEnabled && visible)
  1844. {
  1845. if (this.graph.model.isVertex(parent) && pstate != null &&
  1846. pstate.parentHighlight == null)
  1847. {
  1848. this.parentHighlight = this.createParentHighlightShape(pstate);
  1849. // VML dialect required here for event transparency in IE
  1850. this.parentHighlight.dialect = (this.graph.dialect != mxConstants.DIALECT_SVG) ? mxConstants.DIALECT_VML : mxConstants.DIALECT_SVG;
  1851. this.parentHighlight.pointerEvents = false;
  1852. this.parentHighlight.rotation = Number(pstate.style[mxConstants.STYLE_ROTATION] || '0');
  1853. this.parentHighlight.init(this.graph.getView().getOverlayPane());
  1854. this.parentHighlight.redraw();
  1855. // Shows highlight once per parent
  1856. pstate.parentHighlight = this.parentHighlight;
  1857. }
  1858. }
  1859. }
  1860. };
  1861. /**
  1862. * Function: drawPreview
  1863. *
  1864. * Redraws the preview.
  1865. */
  1866. mxVertexHandler.prototype.drawPreview = function()
  1867. {
  1868. if (this.preview != null)
  1869. {
  1870. this.preview.bounds = this.bounds;
  1871. if (this.preview.node.parentNode == this.graph.container)
  1872. {
  1873. this.preview.bounds.width = Math.max(0, this.preview.bounds.width - 1);
  1874. this.preview.bounds.height = Math.max(0, this.preview.bounds.height - 1);
  1875. }
  1876. this.preview.rotation = Number(this.state.style[mxConstants.STYLE_ROTATION] || '0');
  1877. this.preview.redraw();
  1878. }
  1879. this.selectionBorder.bounds = this.getSelectionBorderBounds();
  1880. this.selectionBorder.redraw();
  1881. this.updateParentHighlight();
  1882. };
  1883. /**
  1884. * Function: getSelectionBorderBounds
  1885. *
  1886. * Returns the bounds for the selection border.
  1887. */
  1888. mxVertexHandler.prototype.getSelectionBorderBounds = function()
  1889. {
  1890. return this.bounds;
  1891. };
  1892. /**
  1893. * Function: isDestroyed
  1894. *
  1895. * Returns true if this handler was destroyed or not initialized.
  1896. */
  1897. mxVertexHandler.prototype.isDestroyed = function()
  1898. {
  1899. return this.selectionBorder == null;
  1900. };
  1901. /**
  1902. * Function: destroy
  1903. *
  1904. * Destroys the handler and all its resources and DOM nodes.
  1905. */
  1906. mxVertexHandler.prototype.destroy = function()
  1907. {
  1908. if (this.escapeHandler != null)
  1909. {
  1910. this.state.view.graph.removeListener(this.escapeHandler);
  1911. this.escapeHandler = null;
  1912. }
  1913. if (this.preview != null)
  1914. {
  1915. this.preview.destroy();
  1916. this.preview = null;
  1917. }
  1918. if (this.parentHighlight != null)
  1919. {
  1920. var parent = this.graph.model.getParent(this.state.cell);
  1921. var pstate = this.graph.view.getState(parent);
  1922. if (pstate != null && pstate.parentHighlight == this.parentHighlight)
  1923. {
  1924. pstate.parentHighlight = null;
  1925. }
  1926. this.parentHighlight.destroy();
  1927. this.parentHighlight = null;
  1928. }
  1929. if (this.ghostPreview != null)
  1930. {
  1931. this.ghostPreview.destroy();
  1932. this.ghostPreview = null;
  1933. }
  1934. if (this.selectionBorder != null)
  1935. {
  1936. this.selectionBorder.destroy();
  1937. this.selectionBorder = null;
  1938. }
  1939. this.labelShape = null;
  1940. this.removeHint();
  1941. if (this.sizers != null)
  1942. {
  1943. for (var i = 0; i < this.sizers.length; i++)
  1944. {
  1945. this.sizers[i].destroy();
  1946. }
  1947. this.sizers = null;
  1948. }
  1949. if (this.customHandles != null)
  1950. {
  1951. for (var i = 0; i < this.customHandles.length; i++)
  1952. {
  1953. this.customHandles[i].destroy();
  1954. }
  1955. this.customHandles = null;
  1956. }
  1957. };
  1958. __mxOutput.mxVertexHandler = typeof mxVertexHandler !== 'undefined' ? mxVertexHandler : undefined;