mxMockupText.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. /**
  2. * $Id: mxMockupText.js,v 1.4 2013/05/24 07:12:36 mate Exp $
  3. * Copyright (c) 2006-2010, JGraph Ltd
  4. */
  5. //**********************************************************************************************************************************************************
  6. //Link
  7. //**********************************************************************************************************************************************************
  8. /**
  9. * Extends mxShape.
  10. */
  11. function mxShapeMockupLink(bounds, fill, stroke, strokewidth)
  12. {
  13. mxShape.call(this);
  14. this.bounds = bounds;
  15. this.fill = fill;
  16. this.stroke = stroke;
  17. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  18. };
  19. /**
  20. * Extends mxShape.
  21. */
  22. mxUtils.extend(mxShapeMockupLink, mxShape);
  23. mxShapeMockupLink.prototype.cst = {
  24. LINK_TEXT : 'linkText',
  25. TEXT_SIZE : 'textSize',
  26. TEXT_COLOR : 'textColor',
  27. SHAPE_LINK : 'mxgraph.mockup.text.link'
  28. };
  29. /**
  30. * Function: paintVertexShape
  31. *
  32. * Paints the vertex shape.
  33. */
  34. mxShapeMockupLink.prototype.paintVertexShape = function(c, x, y, w, h)
  35. {
  36. var linkText = mxUtils.getValue(this.style, mxShapeMockupLink.prototype.cst.LINK_TEXT, 'Link');
  37. var textSize = mxUtils.getValue(this.style, mxShapeMockupLink.prototype.cst.TEXT_SIZE, '17');
  38. var textColor = mxUtils.getValue(this.style, mxShapeMockupLink.prototype.cst.TEXT_COLOR, '#0000ff');
  39. c.translate(x, y);
  40. var width = mxUtils.getSizeForString(linkText, textSize, mxConstants.DEFAULT_FONTFAMILY).width;
  41. c.setStrokeColor(textColor);
  42. c.setFontSize(textSize);
  43. c.setFontColor(textColor);
  44. c.text(w * 0.5, h * 0.5, 0, 0, linkText, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  45. c.begin();
  46. c.moveTo(w * 0.5 - width * 0.5, (h + parseInt(textSize, 10)) * 0.5);
  47. c.lineTo(w * 0.5 + width * 0.5, (h + parseInt(textSize, 10)) * 0.5);
  48. c.stroke();
  49. };
  50. mxCellRenderer.registerShape(mxShapeMockupLink.prototype.cst.SHAPE_LINK, mxShapeMockupLink);
  51. //**********************************************************************************************************************************************************
  52. //Link Bar
  53. //**********************************************************************************************************************************************************
  54. /**
  55. * Extends mxShape.
  56. */
  57. function mxShapeMockupLinkBar(bounds, fill, stroke, strokewidth)
  58. {
  59. mxShape.call(this);
  60. this.bounds = bounds;
  61. this.fill = fill;
  62. this.stroke = stroke;
  63. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  64. };
  65. /**
  66. * Extends mxShape.
  67. */
  68. mxUtils.extend(mxShapeMockupLinkBar, mxShape);
  69. mxShapeMockupLinkBar.prototype.cst = {
  70. MAIN_TEXT : 'mainText',
  71. SHAPE_LINK_BAR : 'mxgraph.mockup.text.linkBar',
  72. TEXT_COLOR : 'textColor',
  73. TEXT_COLOR2 : 'textColor2',
  74. STROKE_COLOR2 : 'strokeColor2',
  75. FILL_COLOR2 : 'fillColor2',
  76. SELECTED : '+', //must be 1 char
  77. TEXT_SIZE : 'textSize'
  78. };
  79. /**
  80. * Function: paintVertexShape
  81. *
  82. * Paints the vertex shape.
  83. */
  84. mxShapeMockupLinkBar.prototype.paintVertexShape = function(c, x, y, w, h)
  85. {
  86. var textStrings = mxUtils.getValue(this.style, mxShapeMockupLinkBar.prototype.cst.MAIN_TEXT, '+Button 1, Button 2, Button 3').toString().split(',');
  87. var fontColor = mxUtils.getValue(this.style, mxShapeMockupLinkBar.prototype.cst.TEXT_COLOR, '#666666');
  88. var selectedFontColor = mxUtils.getValue(this.style, mxShapeMockupLinkBar.prototype.cst.TEXT_COLOR2, '#ffffff');
  89. var fontSize = mxUtils.getValue(this.style, mxShapeMockupLinkBar.prototype.cst.TEXT_SIZE, '17').toString();
  90. var frameColor = mxUtils.getValue(this.style, mxConstants.STYLE_STROKECOLOR, '#666666');
  91. var separatorColor = mxUtils.getValue(this.style, mxShapeMockupLinkBar.prototype.cst.STROKE_COLOR2, '#c4c4c4');
  92. var bgColor = mxUtils.getValue(this.style, mxConstants.STYLE_FILLCOLOR, '#ffffff');
  93. var selectedFillColor = mxUtils.getValue(this.style, mxShapeMockupLinkBar.prototype.cst.FILL_COLOR2, '#008cff');
  94. var buttonNum = textStrings.length;
  95. var buttonWidths = new Array(buttonNum);
  96. var buttonTotalWidth = 0;
  97. var selectedButton = -1;
  98. var rSize = 10; //rounding size
  99. var labelOffset = 5;
  100. for (var i = 0; i < buttonNum; i++)
  101. {
  102. var buttonText = textStrings[i];
  103. if(buttonText.charAt(0) === mxShapeMockupLinkBar.prototype.cst.SELECTED)
  104. {
  105. buttonText = textStrings[i].substring(1);
  106. selectedButton = i;
  107. }
  108. var currW = mxUtils.getSizeForString(buttonText, fontSize, mxConstants.DEFAULT_FONTFAMILY).width;
  109. if (currW === 0)
  110. {
  111. buttonWidths[i] = 42;
  112. }
  113. else
  114. {
  115. buttonWidths[i] = currW;
  116. }
  117. buttonTotalWidth += buttonWidths[i];
  118. }
  119. var trueH = Math.max(h, fontSize * 1.5, 20);
  120. var minW = 2 * labelOffset * buttonNum + buttonTotalWidth;
  121. var trueW = Math.max(w, minW);
  122. c.translate(x, y);
  123. this.background(c, trueW, trueH, rSize, buttonNum, buttonWidths, labelOffset, minW, frameColor, separatorColor, bgColor, selectedFillColor, selectedButton);
  124. c.setShadow(false);
  125. var currWidth = 0;
  126. for (var i = 0; i < buttonNum; i++)
  127. {
  128. if (i === selectedButton)
  129. {
  130. c.setFontColor(selectedFontColor);
  131. c.setStrokeColor(selectedFontColor);
  132. }
  133. else
  134. {
  135. c.setFontColor(fontColor);
  136. c.setStrokeColor(fontColor);
  137. }
  138. currWidth = currWidth + labelOffset;
  139. this.buttonText(c, currWidth, trueH, textStrings[i], buttonWidths[i], fontSize, minW, trueW);
  140. currWidth = currWidth + buttonWidths[i] + labelOffset;
  141. }
  142. };
  143. mxShapeMockupLinkBar.prototype.background = function(c, w, h, rSize, buttonNum, buttonWidths, labelOffset, minW, frameColor, separatorColor, bgColor, selectedFillColor, selectedButton)
  144. {
  145. c.begin();
  146. //draw the frame
  147. c.setStrokeColor(frameColor);
  148. c.setFillColor(bgColor);
  149. c.rect(0, 0, w, h);
  150. c.fillAndStroke();
  151. //draw the button separators
  152. c.setStrokeColor(separatorColor);
  153. c.begin();
  154. for (var i = 1; i < buttonNum; i++)
  155. {
  156. if (i !== selectedButton && i !== (selectedButton + 1))
  157. {
  158. var currWidth = 0;
  159. for (var j = 0; j < i; j++)
  160. {
  161. currWidth += buttonWidths[j] + 2 * labelOffset;
  162. }
  163. currWidth = currWidth * w / minW;
  164. c.moveTo(currWidth, 0);
  165. c.lineTo(currWidth, h);
  166. }
  167. }
  168. c.stroke();
  169. //draw the selected button
  170. var buttonLeft = 0;
  171. c.setFillColor(selectedFillColor);
  172. for (var i = 0; i < selectedButton; i++)
  173. {
  174. buttonLeft += buttonWidths[i] + 2 * labelOffset;
  175. }
  176. buttonLeft = buttonLeft * w / minW;
  177. var buttonRight = (buttonWidths[selectedButton] + 2 * labelOffset) * w / minW;
  178. buttonRight += buttonLeft;
  179. if (selectedButton === 0)
  180. {
  181. c.rect(0, 0, buttonRight, h);
  182. c.fill();
  183. }
  184. else if (selectedButton === buttonNum - 1)
  185. {
  186. c.rect(buttonLeft, 0, buttonRight - buttonLeft, h);
  187. c.fill();
  188. }
  189. else if (selectedButton !== -1)
  190. {
  191. c.rect(buttonLeft, 0, buttonRight - buttonLeft, h);
  192. c.fill();
  193. }
  194. //draw the frame again, to achieve a nicer effect
  195. c.setStrokeColor(frameColor);
  196. c.setFillColor(bgColor);
  197. c.rect(0, 0, w, h);
  198. c.stroke();
  199. };
  200. mxShapeMockupLinkBar.prototype.buttonText = function(c, w, h, textString, buttonWidth, fontSize, minW, trueW)
  201. {
  202. if(textString.charAt(0) === mxShapeMockupLinkBar.prototype.cst.SELECTED)
  203. {
  204. textString = textString.substring(1);
  205. }
  206. c.begin();
  207. c.setFontSize(fontSize);
  208. c.text((w + buttonWidth * 0.5) * trueW / minW, h * 0.5, 0, 0, textString, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  209. var textW = mxUtils.getSizeForString(textString, fontSize, mxConstants.DEFAULT_FONTFAMILY).width * 0.5;
  210. if (textString !== null && textString !== '')
  211. {
  212. c.begin();
  213. c.moveTo((w + buttonWidth * 0.5) * trueW / minW - textW, h * 0.5 + fontSize * 0.5);
  214. c.lineTo((w + buttonWidth * 0.5) * trueW / minW + textW, h * 0.5 + fontSize * 0.5);
  215. c.stroke();
  216. }
  217. };
  218. mxCellRenderer.registerShape(mxShapeMockupLinkBar.prototype.cst.SHAPE_LINK_BAR, mxShapeMockupLinkBar);
  219. //**********************************************************************************************************************************************************
  220. //Callout
  221. //**********************************************************************************************************************************************************
  222. /**
  223. * Extends mxShape.
  224. */
  225. function mxShapeMockupCallout(bounds, fill, stroke, strokewidth)
  226. {
  227. mxShape.call(this);
  228. this.bounds = bounds;
  229. this.fill = fill;
  230. this.stroke = stroke;
  231. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  232. };
  233. /**
  234. * Extends mxShape.
  235. */
  236. mxUtils.extend(mxShapeMockupCallout, mxShape);
  237. mxShapeMockupCallout.prototype.cst = {
  238. CALLOUT_TEXT : 'linkText',
  239. CALLOUT_DIR : 'callDir',
  240. CALLOUT_STYLE : 'callStyle',
  241. STYLE_LINE : 'line',
  242. STYLE_RECT : 'rect',
  243. STYLE_ROUNDRECT : 'roundRect',
  244. DIR_NW : 'NW',
  245. DIR_NE : 'NE',
  246. DIR_SE : 'SE',
  247. DIR_SW : 'SW',
  248. TEXT_SIZE : 'textSize',
  249. TEXT_COLOR : 'textColor',
  250. SHAPE_CALLOUT : 'mxgraph.mockup.text.callout'
  251. };
  252. mxShapeMockupCallout.prototype.customProperties = [
  253. {name: 'callDir', dispName: 'Direction', type: 'enum',
  254. enumList:[{val: 'NW', dispName:'North-West'},
  255. {val: 'NE', dispName:'North-East'},
  256. {val: 'SE', dispName:'South-East'},
  257. {val: 'SW', dispName:'South-West'}]},
  258. {name: 'callStyle', dispName: 'Style', type: 'enum',
  259. enumList:[{val: 'line', dispName:'Line'},
  260. {val: 'rect', dispName:'Rectangle'}]}
  261. ];
  262. /**
  263. * Function: paintVertexShape
  264. *
  265. * Paints the vertex shape.
  266. */
  267. mxShapeMockupCallout.prototype.paintVertexShape = function(c, x, y, w, h)
  268. {
  269. var calloutText = mxUtils.getValue(this.style, mxShapeMockupCallout.prototype.cst.CALLOUT_TEXT, 'Callout');
  270. var textSize = mxUtils.getValue(this.style, mxShapeMockupCallout.prototype.cst.TEXT_SIZE, '17');
  271. var textColor = mxUtils.getValue(this.style, mxShapeMockupCallout.prototype.cst.TEXT_COLOR, '#666666');
  272. var callStyle = mxUtils.getValue(this.style, mxShapeMockupCallout.prototype.cst.CALLOUT_STYLE, mxShapeMockupCallout.prototype.cst.STYLE_LINE);
  273. var callDir = mxUtils.getValue(this.style, mxShapeMockupCallout.prototype.cst.CALLOUT_DIR, mxShapeMockupCallout.prototype.cst.DIR_NW);
  274. var textWidth = mxUtils.getSizeForString(calloutText, textSize, mxConstants.DEFAULT_FONTFAMILY).width;
  275. textWidth = textWidth * 1.2;
  276. if (textWidth == 0)
  277. {
  278. textWidth = 70;
  279. }
  280. c.translate(x, y);
  281. c.setFontSize(textSize);
  282. c.setFontColor(textColor);
  283. var callH = textSize * 1.5;
  284. if (callDir === mxShapeMockupCallout.prototype.cst.DIR_NW)
  285. {
  286. if (callStyle === mxShapeMockupCallout.prototype.cst.STYLE_LINE)
  287. {
  288. c.begin();
  289. c.moveTo(0, callH);
  290. c.lineTo(textWidth, callH);
  291. c.lineTo(w, h);
  292. c.stroke();
  293. }
  294. else if (callStyle === mxShapeMockupCallout.prototype.cst.STYLE_RECT)
  295. {
  296. c.rect(0,0, textWidth, callH);
  297. c.fillAndStroke();
  298. c.begin();
  299. c.moveTo(textWidth * 0.5, callH);
  300. c.lineTo(w, h);
  301. c.stroke();
  302. }
  303. else if (callStyle === mxShapeMockupCallout.prototype.cst.STYLE_ROUNDRECT)
  304. {
  305. c.roundrect(0, 0, textWidth, callH, callH * 0.25, callH * 0.25);
  306. c.fillAndStroke();
  307. c.begin();
  308. c.moveTo(textWidth * 0.5, callH);
  309. c.lineTo(w, h);
  310. c.stroke();
  311. }
  312. c.text(textWidth * 0.5, callH * 0.5, 0, 0, calloutText, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  313. }
  314. else if (callDir === mxShapeMockupCallout.prototype.cst.DIR_NE)
  315. {
  316. if (callStyle === mxShapeMockupCallout.prototype.cst.STYLE_LINE)
  317. {
  318. c.begin();
  319. c.moveTo(w, callH);
  320. c.lineTo(w - textWidth, callH);
  321. c.lineTo(0, h);
  322. c.stroke();
  323. }
  324. else if (callStyle === mxShapeMockupCallout.prototype.cst.STYLE_RECT)
  325. {
  326. c.rect(w - textWidth,0, textWidth, callH);
  327. c.fillAndStroke();
  328. c.begin();
  329. c.moveTo(w - textWidth * 0.5, callH);
  330. c.lineTo(0, h);
  331. c.stroke();
  332. }
  333. else if (callStyle === mxShapeMockupCallout.prototype.cst.STYLE_ROUNDRECT)
  334. {
  335. c.roundrect(w - textWidth,0, textWidth, callH, callH * 0.25, callH * 0.25);
  336. c.fillAndStroke();
  337. c.begin();
  338. c.moveTo(w - textWidth * 0.5, callH);
  339. c.lineTo(0, h);
  340. c.stroke();
  341. }
  342. c.text(w - textWidth * 0.5, callH * 0.5, 0, 0, calloutText, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  343. }
  344. else if (callDir === mxShapeMockupCallout.prototype.cst.DIR_SE)
  345. {
  346. if (callStyle === mxShapeMockupCallout.prototype.cst.STYLE_LINE)
  347. {
  348. c.begin();
  349. c.moveTo(w, h);
  350. c.lineTo(w - textWidth, h);
  351. c.lineTo(0, 0);
  352. c.stroke();
  353. }
  354. else if (callStyle === mxShapeMockupCallout.prototype.cst.STYLE_RECT)
  355. {
  356. c.rect(w - textWidth, h - callH, textWidth, callH);
  357. c.fillAndStroke();
  358. c.begin();
  359. c.moveTo(w - textWidth * 0.5, h - callH);
  360. c.lineTo(0, 0);
  361. c.stroke();
  362. }
  363. else if (callStyle === mxShapeMockupCallout.prototype.cst.STYLE_ROUNDRECT)
  364. {
  365. c.roundrect(w - textWidth,h - callH, textWidth, callH, callH * 0.25, callH * 0.25);
  366. c.fillAndStroke();
  367. c.begin();
  368. c.moveTo(w - textWidth * 0.5, h - callH);
  369. c.lineTo(0, 0);
  370. c.stroke();
  371. }
  372. c.text(w - textWidth * 0.5, h - callH * 0.5, 0, 0, calloutText, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  373. }
  374. else if (callDir === mxShapeMockupCallout.prototype.cst.DIR_SW)
  375. {
  376. if (callStyle === mxShapeMockupCallout.prototype.cst.STYLE_LINE)
  377. {
  378. c.begin();
  379. c.moveTo(0, h);
  380. c.lineTo(textWidth, h);
  381. c.lineTo(w, 0);
  382. c.stroke();
  383. }
  384. else if (callStyle === mxShapeMockupCallout.prototype.cst.STYLE_RECT)
  385. {
  386. c.rect(0, h - callH, textWidth, callH);
  387. c.fillAndStroke();
  388. c.begin();
  389. c.moveTo(textWidth * 0.5, h - callH);
  390. c.lineTo(w, 0);
  391. c.stroke();
  392. }
  393. else if (callStyle === mxShapeMockupCallout.prototype.cst.STYLE_ROUNDRECT)
  394. {
  395. c.roundrect(0, h - callH, textWidth, callH, callH * 0.25, callH * 0.25);
  396. c.fillAndStroke();
  397. c.begin();
  398. c.moveTo(textWidth * 0.5, h - callH);
  399. c.lineTo(w, 0);
  400. c.stroke();
  401. }
  402. c.text(textWidth * 0.5, h - callH * 0.5, 0, 0, calloutText, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  403. }
  404. };
  405. mxCellRenderer.registerShape(mxShapeMockupCallout.prototype.cst.SHAPE_CALLOUT, mxShapeMockupCallout);
  406. //**********************************************************************************************************************************************************
  407. //Sticky Note (LEGACY)
  408. //**********************************************************************************************************************************************************
  409. /**
  410. * Extends mxShape.
  411. */
  412. function mxShapeMockupStickyNote(bounds, fill, stroke, strokewidth)
  413. {
  414. mxShape.call(this);
  415. this.bounds = bounds;
  416. this.fill = fill;
  417. this.stroke = stroke;
  418. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  419. };
  420. /**
  421. * Extends mxShape.
  422. */
  423. mxUtils.extend(mxShapeMockupStickyNote, mxShape);
  424. mxShapeMockupStickyNote.prototype.cst = {
  425. MAIN_TEXT : 'mainText',
  426. TEXT_COLOR : 'textColor',
  427. TEXT_SIZE : 'textSize',
  428. SHAPE_STICKY_NOTE : 'mxgraph.mockup.text.stickyNote'
  429. };
  430. /**
  431. * Function: paintVertexShape
  432. *
  433. * Paints the vertex shape.
  434. */
  435. mxShapeMockupStickyNote.prototype.paintVertexShape = function(c, x, y, w, h)
  436. {
  437. c.translate(x, y);
  438. this.background(c, w, h);
  439. c.setShadow(false);
  440. this.foreground(c, w, h);
  441. };
  442. mxShapeMockupStickyNote.prototype.background = function(c, w, h)
  443. {
  444. c.setFillColor('#ffffcc');
  445. c.begin();
  446. c.moveTo(w * 0.03, h * 0.07);
  447. c.lineTo(w * 0.89, h * 0.06);
  448. c.arcTo(2.81 * w, 2.92 * h, 1, 0, 0, w * 0.99, h * 0.98);
  449. c.lineTo(w * 0.09, h * 0.99);
  450. c.arcTo(2.81 * w, 2.92 * h, 1, 0, 1, w * 0.03, h * 0.07);
  451. c.close();
  452. c.fill();
  453. };
  454. mxShapeMockupStickyNote.prototype.foreground = function(c, w, h)
  455. {
  456. var mainText = mxUtils.getValue(this.style, mxShapeMockupStickyNote.prototype.cst.MAIN_TEXT, 'Note line 1,Note line 2,Note line 3').toString().split(',');
  457. var fontColor = mxUtils.getValue(this.style, mxShapeMockupStickyNote.prototype.cst.TEXT_COLOR, '#666666').toString();
  458. var fontSize = mxUtils.getValue(this.style, mxShapeMockupStickyNote.prototype.cst.TEXT_SIZE, '17').toString();
  459. c.setFillColor('#ff3300');
  460. c.begin();
  461. c.moveTo(w * 0.28 , 0);
  462. c.lineTo(w * 0.59, 0);
  463. c.lineTo(w * 0.6, h * 0.12);
  464. c.lineTo(w * 0.28, h * 0.13);
  465. c.close();
  466. c.fill();
  467. c.setFontSize(fontSize);
  468. c.setFontColor(fontColor);
  469. var lineNum = mainText.length;
  470. var textH = lineNum * fontSize * 1.5;
  471. for (var i = 0; i < mainText.length; i++)
  472. {
  473. c.text(w / 2, (h - textH) / 2 + i * fontSize * 1.5 + fontSize * 0.75, 0, 0, mainText[i], mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  474. }
  475. };
  476. mxCellRenderer.registerShape(mxShapeMockupStickyNote.prototype.cst.SHAPE_STICKY_NOTE, mxShapeMockupStickyNote);
  477. //**********************************************************************************************************************************************************
  478. //Sticky Note v2
  479. //**********************************************************************************************************************************************************
  480. /**
  481. * Extends mxShape.
  482. */
  483. function mxShapeMockupStickyNote2(bounds, fill, stroke, strokewidth)
  484. {
  485. mxShape.call(this);
  486. this.bounds = bounds;
  487. this.fill = fill;
  488. this.stroke = stroke;
  489. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  490. };
  491. /**
  492. * Extends mxShape.
  493. */
  494. mxUtils.extend(mxShapeMockupStickyNote2, mxShape);
  495. mxShapeMockupStickyNote2.prototype.cst = {
  496. SHAPE_STICKY_NOTE : 'mxgraph.mockup.text.stickyNote2'
  497. };
  498. /**
  499. * Function: paintVertexShape
  500. *
  501. * Paints the vertex shape.
  502. */
  503. mxShapeMockupStickyNote2.prototype.paintVertexShape = function(c, x, y, w, h)
  504. {
  505. c.translate(x, y);
  506. this.background(c, w, h);
  507. c.setShadow(false);
  508. this.foreground(c, w, h);
  509. };
  510. mxShapeMockupStickyNote2.prototype.background = function(c, w, h)
  511. {
  512. c.begin();
  513. c.moveTo(w * 0.03, h * 0.07);
  514. c.lineTo(w * 0.89, h * 0.06);
  515. c.arcTo(2.81 * w, 2.92 * h, 1, 0, 0, w * 0.99, h * 0.98);
  516. c.lineTo(w * 0.09, h * 0.99);
  517. c.arcTo(2.81 * w, 2.92 * h, 1, 0, 1, w * 0.03, h * 0.07);
  518. c.close();
  519. c.fill();
  520. };
  521. mxShapeMockupStickyNote2.prototype.foreground = function(c, w, h)
  522. {
  523. var strokeColor = mxUtils.getValue(this.style, 'strokeColor', '#000000');
  524. c.setFillColor(strokeColor);
  525. c.begin();
  526. c.moveTo(w * 0.28 , 0);
  527. c.lineTo(w * 0.59, 0);
  528. c.lineTo(w * 0.6, h * 0.12);
  529. c.lineTo(w * 0.28, h * 0.13);
  530. c.close();
  531. c.fill();
  532. };
  533. mxCellRenderer.registerShape(mxShapeMockupStickyNote2.prototype.cst.SHAPE_STICKY_NOTE, mxShapeMockupStickyNote2);
  534. //**********************************************************************************************************************************************************
  535. //Bulleted List
  536. //**********************************************************************************************************************************************************
  537. /**
  538. * Extends mxShape.
  539. */
  540. function mxShapeMockupBulletedList(bounds, fill, stroke, strokewidth)
  541. {
  542. mxShape.call(this);
  543. this.bounds = bounds;
  544. this.fill = fill;
  545. this.stroke = stroke;
  546. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  547. };
  548. /**
  549. * Extends mxShape.
  550. */
  551. mxUtils.extend(mxShapeMockupBulletedList, mxShape);
  552. mxShapeMockupBulletedList.prototype.cst = {
  553. MAIN_TEXT : 'mainText',
  554. TEXT_COLOR : 'textColor',
  555. TEXT_SIZE : 'textSize',
  556. BULLET_STYLE : 'bulletStyle',
  557. STYLE_HYPHEN : 'hyphen',
  558. STYLE_NUM : 'number',
  559. STYLE_DOT : 'dot',
  560. SHAPE_BULLETED_LIST : 'mxgraph.mockup.text.bulletedList'
  561. };
  562. /**
  563. * Function: paintVertexShape
  564. *
  565. * Paints the vertex shape.
  566. */
  567. mxShapeMockupBulletedList.prototype.paintVertexShape = function(c, x, y, w, h)
  568. {
  569. c.translate(x, y);
  570. this.background(c, w, h);
  571. c.setShadow(false);
  572. this.foreground(c, w, h);
  573. };
  574. mxShapeMockupBulletedList.prototype.background = function(c, w, h)
  575. {
  576. c.rect(0, 0, w, h);
  577. c.fillAndStroke();
  578. };
  579. mxShapeMockupBulletedList.prototype.foreground = function(c, w, h)
  580. {
  581. var mainText = mxUtils.getValue(this.style, mxShapeMockupBulletedList.prototype.cst.MAIN_TEXT, 'Note line 1,Note line 2,Note line 3').toString().split(',');
  582. var fontColor = mxUtils.getValue(this.style, mxShapeMockupBulletedList.prototype.cst.TEXT_COLOR, '#666666');
  583. var fontSize = mxUtils.getValue(this.style, mxShapeMockupBulletedList.prototype.cst.TEXT_SIZE, '17');
  584. var bulletStyle = mxUtils.getValue(this.style, mxShapeMockupBulletedList.prototype.cst.BULLET_STYLE, 'none');
  585. c.setFontColor(fontColor);
  586. c.setFontSize(fontSize);
  587. var bullet = '';
  588. for (var i = 0; i < mainText.length; i++)
  589. {
  590. var currText = '';
  591. if (bulletStyle === mxShapeMockupBulletedList.prototype.cst.STYLE_NUM)
  592. {
  593. currText = (i + 1) + ') ' + mainText[i];
  594. }
  595. else if (bulletStyle === mxShapeMockupBulletedList.prototype.cst.STYLE_HYPHEN)
  596. {
  597. currText = '- ' + mainText[i];
  598. }
  599. else if(bulletStyle === mxShapeMockupBulletedList.prototype.cst.STYLE_DOT)
  600. {
  601. currText = String.fromCharCode(8226) + ' ' + mainText[i];
  602. }
  603. else
  604. {
  605. currText = ' ' + mainText[i];
  606. }
  607. c.text(10, i * fontSize * 1.5 + fontSize * 0.75, 0, 0, currText, mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  608. }
  609. };
  610. mxCellRenderer.registerShape(mxShapeMockupBulletedList.prototype.cst.SHAPE_BULLETED_LIST, mxShapeMockupBulletedList);
  611. //**********************************************************************************************************************************************************
  612. //Text Box
  613. //**********************************************************************************************************************************************************
  614. /**
  615. * Extends mxShape.
  616. */
  617. function mxShapeMockupTextBox(bounds, fill, stroke, strokewidth)
  618. {
  619. mxShape.call(this);
  620. this.bounds = bounds;
  621. this.fill = fill;
  622. this.stroke = stroke;
  623. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  624. };
  625. /**
  626. * Extends mxShape.
  627. */
  628. mxUtils.extend(mxShapeMockupTextBox, mxShape);
  629. mxShapeMockupTextBox.prototype.cst = {
  630. MAIN_TEXT : 'mainText',
  631. TEXT_COLOR : 'textColor',
  632. TEXT_SIZE : 'textSize',
  633. SHAPE_TEXT_BOX : 'mxgraph.mockup.text.textBox'
  634. };
  635. /**
  636. * Function: paintVertexShape
  637. *
  638. * Paints the vertex shape.
  639. */
  640. mxShapeMockupTextBox.prototype.paintVertexShape = function(c, x, y, w, h)
  641. {
  642. c.translate(x, y);
  643. this.background(c, w, h);
  644. c.setShadow(false);
  645. this.foreground(c, w, h);
  646. };
  647. mxShapeMockupTextBox.prototype.background = function(c, w, h)
  648. {
  649. c.rect(0, 0, w, h);
  650. c.fillAndStroke();
  651. };
  652. mxShapeMockupTextBox.prototype.foreground = function(c, w, h)
  653. {
  654. var mainText = mxUtils.getValue(this.style, mxShapeMockupTextBox.prototype.cst.MAIN_TEXT, 'Note line 1').toString().split(',');
  655. var fontColor = mxUtils.getValue(this.style, mxShapeMockupTextBox.prototype.cst.TEXT_COLOR, '#666666');
  656. var fontSize = mxUtils.getValue(this.style, mxShapeMockupTextBox.prototype.cst.TEXT_SIZE, '17');
  657. c.setFontColor(fontColor);
  658. c.setFontSize(fontSize);
  659. for (var i = 0; i < mainText.length; i++)
  660. {
  661. c.text(5, i * fontSize * 1.5 + fontSize * 0.75, 0, 0, mainText[i], mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  662. }
  663. };
  664. mxCellRenderer.registerShape(mxShapeMockupTextBox.prototype.cst.SHAPE_TEXT_BOX, mxShapeMockupTextBox);
  665. //**********************************************************************************************************************************************************
  666. //Captcha
  667. //**********************************************************************************************************************************************************
  668. /**
  669. * Extends mxShape.
  670. */
  671. function mxShapeMockupCaptcha(bounds, fill, stroke, strokewidth)
  672. {
  673. mxShape.call(this);
  674. this.bounds = bounds;
  675. this.fill = fill;
  676. this.stroke = stroke;
  677. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  678. };
  679. /**
  680. * Extends mxShape.
  681. */
  682. mxUtils.extend(mxShapeMockupCaptcha, mxShape);
  683. mxShapeMockupCaptcha.prototype.cst = {
  684. MAIN_TEXT : 'mainText',
  685. TEXT_COLOR : 'textColor',
  686. TEXT_SIZE : 'textSize',
  687. SHAPE_CAPTCHA : 'mxgraph.mockup.text.captcha'
  688. };
  689. /**
  690. * Function: paintVertexShape
  691. *
  692. * Paints the vertex shape.
  693. */
  694. mxShapeMockupCaptcha.prototype.paintVertexShape = function(c, x, y, w, h)
  695. {
  696. c.translate(x, y);
  697. this.background(c, w, h);
  698. c.setShadow(false);
  699. this.foreground(c, w, h);
  700. };
  701. mxShapeMockupCaptcha.prototype.background = function(c, w, h)
  702. {
  703. c.rect(0, 0, w, h);
  704. c.fillAndStroke();
  705. };
  706. mxShapeMockupCaptcha.prototype.foreground = function(c, w, h)
  707. {
  708. var mainText = mxUtils.getValue(this.style, mxShapeMockupCaptcha.prototype.cst.MAIN_TEXT, 'Note line 1');
  709. var fontColor = mxUtils.getValue(this.style, mxShapeMockupCaptcha.prototype.cst.TEXT_COLOR, '#666666');
  710. var fontSize = mxUtils.getValue(this.style, mxShapeMockupCaptcha.prototype.cst.TEXT_SIZE, '25');
  711. c.setFillColor('#88aaff');
  712. c.begin();
  713. c.moveTo(0, 0);
  714. c.lineTo(w * 0.35, 0);
  715. c.lineTo(w * 0.55, h * 0.85);
  716. c.lineTo(w * 0.4, h * 0.75);
  717. c.close();
  718. c.fill();
  719. c.begin();
  720. c.moveTo(w * 0.7, h * 0.1);
  721. c.lineTo(w * 0.95, h * 0.23);
  722. c.lineTo(w, h * 0.4);
  723. c.lineTo(w, h * 0.9);
  724. c.lineTo(w, h);
  725. c.lineTo(w * 0.8, h);
  726. c.close();
  727. c.fill();
  728. c.setFontColor(fontColor);
  729. c.setFontSize(fontSize);
  730. c.text(w * 0.5, h * 0.5, 0, 0, mainText, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  731. c.rect(0, 0, w, h);
  732. c.stroke();
  733. };
  734. mxCellRenderer.registerShape(mxShapeMockupCaptcha.prototype.cst.SHAPE_CAPTCHA, mxShapeMockupCaptcha);
  735. //**********************************************************************************************************************************************************
  736. //Alphanumeric
  737. //**********************************************************************************************************************************************************
  738. /**
  739. * Extends mxShape.
  740. */
  741. function mxShapeMockupAlphanumeric(bounds, fill, stroke, strokewidth)
  742. {
  743. mxShape.call(this);
  744. this.bounds = bounds;
  745. this.fill = fill;
  746. this.stroke = stroke;
  747. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  748. };
  749. /**
  750. * Extends mxShape.
  751. */
  752. mxUtils.extend(mxShapeMockupAlphanumeric, mxShape);
  753. mxShapeMockupAlphanumeric.prototype.cst = {
  754. MAIN_TEXT : 'linkText',
  755. TEXT_SIZE : 'textSize',
  756. TEXT_COLOR : 'textColor',
  757. SHAPE_ALPHANUMERIC : 'mxgraph.mockup.text.alphanumeric'
  758. };
  759. /**
  760. * Function: paintVertexShape
  761. *
  762. * Paints the vertex shape.
  763. */
  764. mxShapeMockupAlphanumeric.prototype.paintVertexShape = function(c, x, y, w, h)
  765. {
  766. var mainText = mxUtils.getValue(this.style, mxShapeMockupAlphanumeric.prototype.cst.MAIN_TEXT, '0-9 A B C D E F G H I J K L M N O P Q R S T U V X Y Z');
  767. var textSize = mxUtils.getValue(this.style, mxShapeMockupAlphanumeric.prototype.cst.TEXT_SIZE, '17');
  768. var textColor = mxUtils.getValue(this.style, mxShapeMockupAlphanumeric.prototype.cst.TEXT_COLOR, '#0000ff');
  769. c.translate(x, y);
  770. var width = mxUtils.getSizeForString(mainText, textSize, mxConstants.DEFAULT_FONTFAMILY).width;
  771. c.setStrokeColor(textColor);
  772. c.setFontSize(textSize);
  773. c.setFontColor(textColor);
  774. c.text(w * 0.5, h * 0.5, 0, 0, mainText, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  775. c.begin();
  776. c.moveTo(w * 0.5 - width * 0.5, (h + parseInt(textSize, 10)) * 0.5);
  777. c.lineTo(w * 0.5 + width * 0.5, (h + parseInt(textSize, 10)) * 0.5);
  778. c.stroke();
  779. };
  780. mxCellRenderer.registerShape(mxShapeMockupAlphanumeric.prototype.cst.SHAPE_ALPHANUMERIC, mxShapeMockupAlphanumeric);
  781. //**********************************************************************************************************************************************************
  782. //Rounded rectangle (adjustable rounding)
  783. //**********************************************************************************************************************************************************
  784. /**
  785. * Extends mxShape.
  786. */
  787. function mxShapeMockupTextRRect(bounds, fill, stroke, strokewidth)
  788. {
  789. mxShape.call(this);
  790. this.bounds = bounds;
  791. this.fill = fill;
  792. this.stroke = stroke;
  793. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  794. };
  795. /**
  796. * Extends mxShape.
  797. */
  798. mxUtils.extend(mxShapeMockupTextRRect, mxShape);
  799. mxShapeMockupTextRRect.prototype.cst = {
  800. RRECT : 'mxgraph.mockup.text.rrect',
  801. R_SIZE : 'rSize'
  802. };
  803. /**
  804. * Function: paintVertexShape
  805. *
  806. * Paints the vertex shape.
  807. */
  808. mxShapeMockupTextRRect.prototype.paintVertexShape = function(c, x, y, w, h)
  809. {
  810. c.translate(x, y);
  811. var rSize = parseInt(mxUtils.getValue(this.style, mxShapeMockupTextRRect.prototype.cst.R_SIZE, '10'));
  812. c.roundrect(0, 0, w, h, rSize);
  813. c.fillAndStroke();
  814. };
  815. mxCellRenderer.registerShape(mxShapeMockupTextRRect.prototype.cst.RRECT, mxShapeMockupTextRRect);