mxMockupText.js 28 KB

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