mxMockupButtons.js 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. /**
  2. * Copyright (c) 2006-2010, JGraph Holdings Ltd
  3. */
  4. //**********************************************************************************************************************************************************
  5. //Multiline Button
  6. //**********************************************************************************************************************************************************
  7. /**
  8. * Extends mxShape.
  9. */
  10. function mxShapeMockupMultiButton(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(mxShapeMockupMultiButton, mxShape);
  22. mxShapeMockupMultiButton.prototype.cst = {
  23. MAIN_TEXT : 'mainText',
  24. SHAPE_MULTILINE_BUTTON : 'mxgraph.mockup.buttons.multiButton',
  25. SUB_TEXT : 'subText',
  26. TEXT_COLOR : 'textColor',
  27. TEXT_SIZE : 'textSize',
  28. BUTTON_STYLE : 'buttonStyle',
  29. ROUND : 'round',
  30. CHEVRON : 'chevron'
  31. };
  32. mxShapeMockupMultiButton.prototype.customProperties = [
  33. {name: 'buttonStyle', dispName: 'Style', type: 'enum', defVal:'round',
  34. enumList: [{val: 'round', dispName: 'Round'}, {val: 'chevron', dispName: 'Chevron'}]
  35. }
  36. ];
  37. /**
  38. * Function: paintVertexShape
  39. *
  40. * Paints the vertex shape.
  41. */
  42. mxShapeMockupMultiButton.prototype.paintVertexShape = function(c, x, y, w, h)
  43. {
  44. var mainText = mxUtils.getValue(this.style, mxShapeMockupMultiButton.prototype.cst.MAIN_TEXT, 'Main Text');
  45. var subText = mxUtils.getValue(this.style, mxShapeMockupMultiButton.prototype.cst.SUB_TEXT, 'Sub Text');
  46. var fontColor = mxUtils.getValue(this.style, mxShapeMockupMultiButton.prototype.cst.TEXT_COLOR, '#666666');
  47. var fontSize = mxUtils.getValue(this.style, mxShapeMockupMultiButton.prototype.cst.TEXT_SIZE, '17');
  48. c.translate(x, y);
  49. this.background(c, x, y, w, h);
  50. c.setShadow(false);
  51. c.setFontStyle(mxConstants.FONT_BOLD);
  52. this.mainText(c, x, y, w, h, mainText, fontSize, fontColor);
  53. this.subText(c, x, y, w, h, subText, fontSize / 1.4, fontColor);
  54. };
  55. mxShapeMockupMultiButton.prototype.background = function(c, x, y, w, h)
  56. {
  57. var buttonStyle = mxUtils.getValue(this.style, mxShapeMockupMultiButton.prototype.cst.BUTTON_STYLE, mxShapeMockupMultiButton.prototype.cst.ROUND).toString();
  58. var rSize = 10;
  59. c.begin();
  60. if (buttonStyle === mxShapeMockupMultiButton.prototype.cst.ROUND)
  61. {
  62. c.moveTo(0, rSize);
  63. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  64. c.lineTo(w - rSize, 0);
  65. c.arcTo(rSize, rSize, 0, 0, 1, w, rSize);
  66. c.lineTo(w, h - rSize);
  67. c.arcTo(rSize, rSize, 0, 0, 1, w - rSize, h);
  68. c.lineTo(rSize, h);
  69. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  70. }
  71. else if (buttonStyle === mxShapeMockupMultiButton.prototype.cst.CHEVRON)
  72. {
  73. c.moveTo(0, h * 0.1);
  74. c.arcTo(w * 0.0372, h * 0.1111, 0, 0, 1, w * 0.0334, 0);
  75. c.lineTo(w * 0.768, 0);
  76. c.arcTo(w * 0.0722, h * 0.216, 0, 0, 1, w * 0.8014, h * 0.0399);
  77. c.lineTo(w * 0.99, h * 0.4585);
  78. c.arcTo(w * 0.09, h * 0.1, 0, 0, 1, w * 0.99, h * 0.5415);
  79. c.lineTo(w * 0.8014, h * 0.9568);
  80. c.arcTo(w * 0.0722, h * 0.216, 0, 0, 1, w * 0.768, h);
  81. c.lineTo(w * 0.0334, h);
  82. c.arcTo(w * 0.0372, h * 0.1111, 0, 0, 1, 0, h * 0.9);
  83. }
  84. c.close();
  85. c.fillAndStroke();
  86. };
  87. mxShapeMockupMultiButton.prototype.mainText = function(c, x, y, w, h, text, fontSize, fontColor)
  88. {
  89. c.begin();
  90. c.setFontSize(fontSize);
  91. c.setFontColor(fontColor);
  92. c.text(w * 0.5, h * 0.4, 0, 0, text, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  93. };
  94. mxShapeMockupMultiButton.prototype.subText = function(c, x, y, w, h, text, fontSize, fontColor)
  95. {
  96. c.begin();
  97. c.setFontSize(fontSize);
  98. c.text(w * 0.5, h * 0.7, 0, 0, text, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  99. };
  100. mxCellRenderer.registerShape(mxShapeMockupMultiButton.prototype.cst.SHAPE_MULTILINE_BUTTON, mxShapeMockupMultiButton);
  101. //**********************************************************************************************************************************************************
  102. //Button
  103. //**********************************************************************************************************************************************************
  104. /**
  105. * Extends mxShape.
  106. */
  107. function mxShapeMockupButton(bounds, fill, stroke, strokewidth)
  108. {
  109. mxShape.call(this);
  110. this.bounds = bounds;
  111. this.fill = fill;
  112. this.stroke = stroke;
  113. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  114. };
  115. /**
  116. * Extends mxShape.
  117. */
  118. mxUtils.extend(mxShapeMockupButton, mxShape);
  119. mxShapeMockupButton.prototype.cst = {
  120. MAIN_TEXT : 'mainText',
  121. SHAPE_BUTTON : 'mxgraph.mockup.buttons.button',
  122. TEXT_COLOR : 'textColor',
  123. TEXT_SIZE : 'textSize',
  124. BUTTON_STYLE : 'buttonStyle',
  125. ROUND : 'round',
  126. CHEVRON : 'chevron'
  127. };
  128. mxShapeMockupButton.prototype.customProperties = [
  129. {name: 'buttonStyle', dispName: 'Style', type: 'enum', defVal:'round',
  130. enumList: [{val: 'round', dispName: 'Round'}, {val: 'chevron', dispName: 'Chevron'}]
  131. }
  132. ];
  133. /**
  134. * Function: paintVertexShape
  135. *
  136. * Paints the vertex shape.
  137. */
  138. mxShapeMockupButton.prototype.paintVertexShape = function(c, x, y, w, h)
  139. {
  140. var mainText = mxUtils.getValue(this.style, mxShapeMockupButton.prototype.cst.MAIN_TEXT, 'Main Text');
  141. var fontColor = mxUtils.getValue(this.style, mxShapeMockupButton.prototype.cst.TEXT_COLOR, '#666666').toString();
  142. var fontSize = mxUtils.getValue(this.style, mxShapeMockupButton.prototype.cst.TEXT_SIZE, '17').toString();
  143. c.translate(x, y);
  144. this.background(c, x, y, w, h);
  145. c.setShadow(false);
  146. this.mainText(c, x, y, w, h, mainText, fontSize, fontColor);
  147. };
  148. mxShapeMockupButton.prototype.background = function(c, x, y, w, h)
  149. {
  150. var buttonStyle = mxUtils.getValue(this.style, mxShapeMockupButton.prototype.cst.BUTTON_STYLE, mxShapeMockupButton.prototype.cst.ROUND).toString();
  151. var rSize = 10;
  152. c.begin();
  153. if (buttonStyle === mxShapeMockupButton.prototype.cst.ROUND)
  154. {
  155. c.moveTo(0, rSize);
  156. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  157. c.lineTo(w - rSize, 0);
  158. c.arcTo(rSize, rSize, 0, 0, 1, w, rSize);
  159. c.lineTo(w, h - rSize);
  160. c.arcTo(rSize, rSize, 0, 0, 1, w - rSize, h);
  161. c.lineTo(rSize, h);
  162. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  163. }
  164. else if (buttonStyle === mxShapeMockupButton.prototype.cst.CHEVRON)
  165. {
  166. c.moveTo(0, h * 0.1);
  167. c.arcTo(w * 0.0372, h * 0.1111, 0, 0, 1, w * 0.0334, 0);
  168. c.lineTo(w * 0.768, 0);
  169. c.arcTo(w * 0.0722, h * 0.216, 0, 0, 1, w * 0.8014, h * 0.0399);
  170. c.lineTo(w * 0.99, h * 0.4585);
  171. c.arcTo(w * 0.09, h * 0.1, 0, 0, 1, w * 0.99, h * 0.5415);
  172. c.lineTo(w * 0.8014, h * 0.9568);
  173. c.arcTo(w * 0.0722, h * 0.216, 0, 0, 1, w * 0.768, h);
  174. c.lineTo(w * 0.0334, h);
  175. c.arcTo(w * 0.0372, h * 0.1111, 0, 0, 1, 0, h * 0.9);
  176. }
  177. c.close();
  178. c.fillAndStroke();
  179. };
  180. mxShapeMockupButton.prototype.mainText = function(c, x, y, w, h, text, fontSize, fontColor)
  181. {
  182. c.begin();
  183. c.setFontSize(fontSize);
  184. c.setFontColor(fontColor);
  185. c.setFontStyle(mxConstants.FONT_BOLD);
  186. c.text(w / 2, h / 2, 0, 0, text, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  187. };
  188. mxCellRenderer.registerShape(mxShapeMockupButton.prototype.cst.SHAPE_BUTTON, mxShapeMockupButton);
  189. //**********************************************************************************************************************************************************
  190. //Horizontal Button Bar
  191. //**********************************************************************************************************************************************************
  192. /**
  193. * Extends mxShape.
  194. */
  195. function mxShapeMockupHorButtonBar(bounds, fill, stroke, strokewidth)
  196. {
  197. mxShape.call(this);
  198. this.bounds = bounds;
  199. this.fill = fill;
  200. this.stroke = stroke;
  201. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  202. };
  203. /**
  204. * Extends mxShape.
  205. */
  206. mxUtils.extend(mxShapeMockupHorButtonBar, mxShape);
  207. mxShapeMockupHorButtonBar.prototype.cst = {
  208. MAIN_TEXT : 'mainText',
  209. SHAPE_HOR_BUTTON_BAR : 'mxgraph.mockup.buttons.horButtonBar',
  210. TEXT_COLOR : 'textColor',
  211. TEXT_COLOR2 : 'textColor2',
  212. STROKE_COLOR2 : 'strokeColor2',
  213. FILL_COLOR2 : 'fillColor2',
  214. SELECTED : '+', //must be 1 char
  215. TEXT_SIZE : 'textSize'
  216. };
  217. /**
  218. * Function: paintVertexShape
  219. *
  220. * Paints the vertex shape.
  221. */
  222. mxShapeMockupHorButtonBar.prototype.paintVertexShape = function(c, x, y, w, h)
  223. {
  224. var textStrings = mxUtils.getValue(this.style, mxShapeMockupHorButtonBar.prototype.cst.MAIN_TEXT, '+Button 1, Button 2, Button 3').toString().split(',');
  225. var fontColor = mxUtils.getValue(this.style, mxShapeMockupHorButtonBar.prototype.cst.TEXT_COLOR, '#666666');
  226. var selectedFontColor = mxUtils.getValue(this.style, mxShapeMockupHorButtonBar.prototype.cst.TEXT_COLOR2, '#ffffff');
  227. var fontSize = mxUtils.getValue(this.style, mxShapeMockupHorButtonBar.prototype.cst.TEXT_SIZE, '17').toString();
  228. var frameColor = mxUtils.getValue(this.style, mxConstants.STYLE_STROKECOLOR, '#666666');
  229. var separatorColor = mxUtils.getValue(this.style, mxShapeMockupHorButtonBar.prototype.cst.STROKE_COLOR2, '#c4c4c4');
  230. var bgColor = mxUtils.getValue(this.style, mxConstants.STYLE_FILLCOLOR, '#ffffff');
  231. var selectedFillColor = mxUtils.getValue(this.style, mxShapeMockupHorButtonBar.prototype.cst.FILL_COLOR2, '#008cff');
  232. var buttonNum = textStrings.length;
  233. var buttonWidths = new Array(buttonNum);
  234. var buttonTotalWidth = 0;
  235. var selectedButton = -1;
  236. var rSize = 10; //rounding size
  237. var labelOffset = 5;
  238. for (var i = 0; i < buttonNum; i++)
  239. {
  240. var buttonText = textStrings[i];
  241. if(buttonText.charAt(0) === mxShapeMockupHorButtonBar.prototype.cst.SELECTED)
  242. {
  243. buttonText = textStrings[i].substring(1);
  244. selectedButton = i;
  245. }
  246. buttonWidths[i] = mxUtils.getSizeForString(buttonText, fontSize, mxConstants.DEFAULT_FONTFAMILY).width;
  247. buttonTotalWidth += buttonWidths[i];
  248. }
  249. var trueH = Math.max(h, fontSize * 1.5, 20);
  250. var minW = 2 * labelOffset * buttonNum + buttonTotalWidth;
  251. var trueW = Math.max(w, minW);
  252. c.translate(x, y);
  253. this.background(c, trueW, trueH, rSize, buttonNum, buttonWidths, labelOffset, minW, frameColor, separatorColor, bgColor, selectedFillColor, selectedButton);
  254. c.setShadow(false);
  255. c.setFontStyle(mxConstants.FONT_BOLD);
  256. var currWidth = 0;
  257. for (var i = 0; i < buttonNum; i++)
  258. {
  259. if (i === selectedButton)
  260. {
  261. c.setFontColor(selectedFontColor);
  262. }
  263. else
  264. {
  265. c.setFontColor(fontColor);
  266. }
  267. currWidth = currWidth + labelOffset;
  268. this.buttonText(c, currWidth, trueH, textStrings[i], buttonWidths[i], fontSize, minW, trueW);
  269. currWidth = currWidth + buttonWidths[i] + labelOffset;
  270. }
  271. };
  272. mxShapeMockupHorButtonBar.prototype.background = function(c, w, h, rSize, buttonNum, buttonWidths, labelOffset, minW, frameColor, separatorColor, bgColor, selectedFillColor, selectedButton)
  273. {
  274. c.begin();
  275. //draw the frame
  276. c.setStrokeColor(frameColor);
  277. c.setFillColor(bgColor);
  278. c.moveTo(0, rSize);
  279. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  280. c.lineTo(w - rSize, 0);
  281. c.arcTo(rSize, rSize, 0, 0, 1, w, rSize);
  282. c.lineTo(w, h - rSize);
  283. c.arcTo(rSize, rSize, 0, 0, 1, w - rSize, h);
  284. c.lineTo(rSize, h);
  285. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  286. c.close();
  287. c.fillAndStroke();
  288. //draw the button separators
  289. c.setStrokeColor(separatorColor);
  290. c.begin();
  291. for (var i = 1; i < buttonNum; i++)
  292. {
  293. if (i !== selectedButton && i !== (selectedButton + 1))
  294. {
  295. var currWidth = 0;
  296. for (var j = 0; j < i; j++)
  297. {
  298. currWidth += buttonWidths[j] + 2 * labelOffset;
  299. }
  300. currWidth = currWidth * w / minW;
  301. c.moveTo(currWidth, 0);
  302. c.lineTo(currWidth, h);
  303. }
  304. }
  305. c.stroke();
  306. //draw the selected button
  307. var buttonLeft = 0;
  308. c.setFillColor(selectedFillColor);
  309. for (var i = 0; i < selectedButton; i++)
  310. {
  311. buttonLeft += buttonWidths[i] + 2 * labelOffset;
  312. }
  313. buttonLeft = buttonLeft * w / minW;
  314. var buttonRight = (buttonWidths[selectedButton] + 2 * labelOffset) * w / minW;
  315. buttonRight += buttonLeft;
  316. if (selectedButton === 0)
  317. {
  318. c.begin();
  319. // we draw a path for the first button
  320. c.moveTo(0, rSize);
  321. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  322. c.lineTo(buttonRight, 0);
  323. c.lineTo(buttonRight, h);
  324. c.lineTo(rSize, h);
  325. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  326. c.close();
  327. c.fill();
  328. }
  329. else if (selectedButton === buttonNum - 1)
  330. {
  331. c.begin();
  332. // we draw a path for the last button
  333. c.moveTo(buttonLeft, 0);
  334. c.lineTo(buttonRight - rSize, 0);
  335. c.arcTo(rSize, rSize, 0, 0, 1, buttonRight, rSize);
  336. c.lineTo(buttonRight, h - rSize);
  337. c.arcTo(rSize, rSize, 0, 0, 1, buttonRight - rSize, h);
  338. c.lineTo(buttonLeft, h);
  339. c.close();
  340. c.fill();
  341. }
  342. else if (selectedButton !== -1)
  343. {
  344. c.begin();
  345. // we draw a path rectangle for one of the buttons in the middle
  346. c.moveTo(buttonLeft, 0);
  347. c.lineTo(buttonRight, 0);
  348. c.lineTo(buttonRight, h);
  349. c.lineTo(buttonLeft, h);
  350. c.close();
  351. c.fill();
  352. }
  353. //draw the frame again, to achieve a nicer effect
  354. c.setStrokeColor(frameColor);
  355. c.setFillColor(bgColor);
  356. c.begin();
  357. c.moveTo(0, rSize);
  358. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  359. c.lineTo(w - rSize, 0);
  360. c.arcTo(rSize, rSize, 0, 0, 1, w, rSize);
  361. c.lineTo(w, h - rSize);
  362. c.arcTo(rSize, rSize, 0, 0, 1, w - rSize, h);
  363. c.lineTo(rSize, h);
  364. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  365. c.close();
  366. c.stroke();
  367. };
  368. mxShapeMockupHorButtonBar.prototype.buttonText = function(c, w, h, textString, buttonWidth, fontSize, minW, trueW)
  369. {
  370. if(textString.charAt(0) === mxShapeMockupHorButtonBar.prototype.cst.SELECTED)
  371. {
  372. textString = textString.substring(1);
  373. }
  374. c.begin();
  375. c.setFontSize(fontSize);
  376. 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);
  377. };
  378. mxCellRenderer.registerShape(mxShapeMockupHorButtonBar.prototype.cst.SHAPE_HOR_BUTTON_BAR, mxShapeMockupHorButtonBar);
  379. //**********************************************************************************************************************************************************
  380. //Vertical Button Bar
  381. //**********************************************************************************************************************************************************
  382. /**
  383. * Extends mxShape.
  384. */
  385. function mxShapeMockupVerButtonBar(bounds, fill, stroke, strokewidth)
  386. {
  387. mxShape.call(this);
  388. this.bounds = bounds;
  389. this.fill = fill;
  390. this.stroke = stroke;
  391. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  392. };
  393. /**
  394. * Extends mxShape.
  395. */
  396. mxUtils.extend(mxShapeMockupVerButtonBar, mxShape);
  397. mxShapeMockupVerButtonBar.prototype.cst = {
  398. MAIN_TEXT : 'mainText',
  399. SHAPE_VER_BUTTON_BAR : 'mxgraph.mockup.buttons.verButtonBar',
  400. TEXT_COLOR : 'textColor',
  401. TEXT_COLOR2 : 'textColor2',
  402. STROKE_COLOR2 : 'strokeColor2',
  403. FILL_COLOR2 : 'fillColor2',
  404. SELECTED : '+', //must be 1 char
  405. TEXT_SIZE : 'textSize'
  406. };
  407. /**
  408. * Function: paintVertexShape
  409. *
  410. * Paints the vertex shape.
  411. */
  412. mxShapeMockupVerButtonBar.prototype.paintVertexShape = function(c, x, y, w, h)
  413. {
  414. var textStrings = mxUtils.getValue(this.style, mxShapeMockupVerButtonBar.prototype.cst.MAIN_TEXT, '+Button 1, Button 2, Button 3').toString().split(',');
  415. var fontColor = mxUtils.getValue(this.style, mxShapeMockupVerButtonBar.prototype.cst.TEXT_COLOR, '#666666');
  416. var selectedFontColor = mxUtils.getValue(this.style, mxShapeMockupVerButtonBar.prototype.cst.TEXT_COLOR2, '#ffffff');
  417. var fontSize = mxUtils.getValue(this.style, mxShapeMockupVerButtonBar.prototype.cst.TEXT_SIZE, '17').toString();
  418. var frameColor = mxUtils.getValue(this.style, mxConstants.STYLE_STROKECOLOR, '#666666');
  419. var separatorColor = mxUtils.getValue(this.style, mxShapeMockupVerButtonBar.prototype.cst.STROKE_COLOR2, '#c4c4c4');
  420. var bgColor = mxUtils.getValue(this.style, mxConstants.STYLE_FILLCOLOR, '#ffffff');
  421. var selectedFillColor = mxUtils.getValue(this.style, mxShapeMockupVerButtonBar.prototype.cst.FILL_COLOR2, '#008cff');
  422. var buttonNum = textStrings.length;
  423. var maxButtonWidth = 0;
  424. var selectedButton = -1;
  425. var rSize = 10; //rounding size
  426. var labelOffset = 5;
  427. for (var i = 0; i < buttonNum; i++)
  428. {
  429. var buttonText = textStrings[i];
  430. if(buttonText.charAt(0) === mxShapeMockupVerButtonBar.prototype.cst.SELECTED)
  431. {
  432. buttonText = textStrings[i].substring(1);
  433. selectedButton = i;
  434. }
  435. var currWidth = mxUtils.getSizeForString(buttonText, fontSize, mxConstants.DEFAULT_FONTFAMILY).width;
  436. if (currWidth > maxButtonWidth)
  437. {
  438. maxButtonWidth = currWidth;
  439. }
  440. }
  441. var minButtonHeight = fontSize * 1.5;
  442. var minH = buttonNum * minButtonHeight;
  443. var trueH = Math.max(h, minH);
  444. var minW = 2 * labelOffset + maxButtonWidth;
  445. var trueW = Math.max(w, minW);
  446. c.translate(x, y);
  447. this.background(c, trueW, trueH, rSize, buttonNum, labelOffset, buttonNum * minButtonHeight, frameColor, separatorColor, bgColor, selectedFillColor, selectedButton, minButtonHeight);
  448. c.setShadow(false);
  449. var currWidth = 0;
  450. c.setFontStyle(mxConstants.FONT_BOLD);
  451. for (var i = 0; i < buttonNum; i++)
  452. {
  453. if (i === selectedButton)
  454. {
  455. c.setFontColor(selectedFontColor);
  456. }
  457. else
  458. {
  459. c.setFontColor(fontColor);
  460. }
  461. currWidth = currWidth + labelOffset;
  462. var currHeight = (i * minButtonHeight + minButtonHeight * 0.5) * trueH / minH;
  463. this.buttonText(c, trueW, currHeight, textStrings[i], fontSize);
  464. }
  465. };
  466. mxShapeMockupVerButtonBar.prototype.background = function(c, w, h, rSize, buttonNum, labelOffset, minH, frameColor, separatorColor, bgColor, selectedFillColor, selectedButton, minButtonHeight)
  467. {
  468. c.begin();
  469. //draw the frame
  470. c.setStrokeColor(frameColor);
  471. c.setFillColor(bgColor);
  472. c.moveTo(0, rSize);
  473. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  474. c.lineTo(w - rSize, 0);
  475. c.arcTo(rSize, rSize, 0, 0, 1, w, rSize);
  476. c.lineTo(w, h - rSize);
  477. c.arcTo(rSize, rSize, 0, 0, 1, w - rSize, h);
  478. c.lineTo(rSize, h);
  479. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  480. c.close();
  481. c.fillAndStroke();
  482. //draw the button separators
  483. c.setStrokeColor(separatorColor);
  484. c.begin();
  485. for (var i = 1; i < buttonNum; i++)
  486. {
  487. if (i !== selectedButton && i !== (selectedButton + 1))
  488. {
  489. var currHeight = i * minButtonHeight * h / minH;
  490. c.moveTo(0, currHeight);
  491. c.lineTo(w, currHeight);
  492. }
  493. }
  494. c.stroke();
  495. //draw the selected button
  496. c.setFillColor(selectedFillColor);
  497. if (selectedButton === 0)
  498. {
  499. // we draw a path for the first button
  500. c.begin();
  501. var buttonBottom = minButtonHeight * h / minH;
  502. c.moveTo(0, rSize);
  503. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  504. c.lineTo(w - rSize, 0);
  505. c.arcTo(rSize, rSize, 0, 0, 1, w, rSize);
  506. c.lineTo(w, buttonBottom);
  507. c.lineTo(0, buttonBottom);
  508. c.close();
  509. c.fill();
  510. }
  511. else if (selectedButton === buttonNum - 1)
  512. {
  513. // we draw a path for the last button
  514. c.begin();
  515. var buttonTop = h - minButtonHeight * h / minH;
  516. c.moveTo(0, buttonTop);
  517. c.lineTo(w, buttonTop);
  518. c.lineTo(w, h - rSize);
  519. c.arcTo(rSize, rSize, 0, 0, 1, w - rSize, h);
  520. c.lineTo(rSize, h);
  521. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  522. c.close();
  523. c.fill();
  524. }
  525. else if (selectedButton !== -1)
  526. {
  527. // we draw a path rectangle for one of the buttons in the middle
  528. c.begin();
  529. var buttonTop = minButtonHeight * selectedButton * h / minH;
  530. var buttonBottom = minButtonHeight * (selectedButton + 1) * h / minH;
  531. c.moveTo(0, buttonTop);
  532. c.lineTo(w, buttonTop);
  533. c.lineTo(w, buttonBottom);
  534. c.lineTo(0, buttonBottom);
  535. c.close();
  536. c.fill();
  537. }
  538. // //draw the frame again, to achieve a nicer effect
  539. c.begin();
  540. c.setStrokeColor(frameColor);
  541. c.setFillColor(bgColor);
  542. c.moveTo(0, rSize);
  543. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  544. c.lineTo(w - rSize, 0);
  545. c.arcTo(rSize, rSize, 0, 0, 1, w, rSize);
  546. c.lineTo(w, h - rSize);
  547. c.arcTo(rSize, rSize, 0, 0, 1, w - rSize, h);
  548. c.lineTo(rSize, h);
  549. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  550. c.close();
  551. c.stroke();
  552. };
  553. mxShapeMockupVerButtonBar.prototype.buttonText = function(c, w, h, textString, fontSize)
  554. {
  555. if(textString.charAt(0) === mxShapeMockupVerButtonBar.prototype.cst.SELECTED)
  556. {
  557. textString = textString.substring(1);
  558. }
  559. c.begin();
  560. c.setFontSize(fontSize);
  561. c.text((w * 0.5), h, 0, 0, textString, mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  562. };
  563. mxCellRenderer.registerShape(mxShapeMockupVerButtonBar.prototype.cst.SHAPE_VER_BUTTON_BAR, mxShapeMockupVerButtonBar);
  564. //**********************************************************************************************************************************************************
  565. //On-Off Button
  566. //**********************************************************************************************************************************************************
  567. /**
  568. * Extends mxShape.
  569. */
  570. function mxShapeMockupOnOffButton(bounds, fill, stroke, strokewidth)
  571. {
  572. mxShape.call(this);
  573. this.bounds = bounds;
  574. this.fill = fill;
  575. this.stroke = stroke;
  576. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  577. };
  578. /**
  579. * Extends mxShape.
  580. */
  581. mxUtils.extend(mxShapeMockupOnOffButton, mxShape);
  582. mxShapeMockupOnOffButton.prototype.cst = {
  583. SHAPE_ON_OFF_BUTTON : 'mxgraph.mockup.buttons.onOffButton',
  584. BUTTON_STATE : 'buttonState',
  585. STATE_ON : 'on',
  586. STATE_OFF : 'off',
  587. FILL_COLOR2 : 'fillColor2',
  588. MAIN_TEXT : 'mainText',
  589. TEXT_COLOR : 'textColor',
  590. TEXT_SIZE : 'textSize'
  591. };
  592. mxShapeMockupOnOffButton.prototype.customProperties = [
  593. {name: 'buttonState', dispName: 'Button State', type: 'enum',
  594. enumList: [{val: 'on', dispName: 'On'}, {val: 'off', dispName: 'Off'}]
  595. }
  596. ];
  597. /**
  598. * Function: paintVertexShape
  599. *
  600. * Paints the vertex shape.
  601. */
  602. mxShapeMockupOnOffButton.prototype.paintVertexShape = function(c, x, y, w, h)
  603. {
  604. c.translate(x, y);
  605. w = Math.max(w, 10);
  606. h = Math.max(h, 10);
  607. this.background(c, x, y, w, h);
  608. c.setShadow(false);
  609. this.foreground(c, x, y, w, h);
  610. };
  611. mxShapeMockupOnOffButton.prototype.background = function(c, x, y, w, h)
  612. {
  613. c.roundrect(0, 0, w, h, 10, 10);
  614. c.fillAndStroke();
  615. };
  616. mxShapeMockupOnOffButton.prototype.foreground = function(c, x, y, w, h)
  617. {
  618. var state = mxUtils.getValue(this.style, mxShapeMockupOnOffButton.prototype.cst.BUTTON_STATE, mxShapeMockupOnOffButton.prototype.cst.STATE_ON);
  619. var fillColor2 = mxUtils.getValue(this.style, mxShapeMockupOnOffButton.prototype.cst.FILL_COLOR2, '#008cff');
  620. var textColor = mxUtils.getValue(this.style, mxShapeMockupOnOffButton.prototype.cst.TEXT_COLOR, '#ffffff,#999999').toString().split(',');
  621. var mainText = mxUtils.getValue(this.style, mxShapeMockupOnOffButton.prototype.cst.MAIN_TEXT, 'ON,OFF').toString().split(',');
  622. var textSize = mxUtils.getValue(this.style, mxShapeMockupOnOffButton.prototype.cst.TEXT_SIZE, '17');
  623. if (state === mxShapeMockupOnOffButton.prototype.cst.STATE_ON)
  624. {
  625. c.setFillColor(fillColor2);
  626. c.setFontColor(textColor[0]);
  627. c.roundrect(0, 0, w * 0.75, h, 10, 10);
  628. }
  629. else
  630. {
  631. c.setFontColor(textColor[1]);
  632. c.roundrect(w * 0.25, 0, w * 0.75, h, 10, 10);
  633. }
  634. c.fillAndStroke();
  635. c.setFontSize(textSize);
  636. c.setFontStyle(mxConstants.FONT_BOLD);
  637. if(state === mxShapeMockupOnOffButton.prototype.cst.STATE_ON)
  638. {
  639. c.text(w * 0.375, h * 0.5, 0, 0, mainText[0], mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  640. }
  641. else if (state === mxShapeMockupOnOffButton.prototype.cst.STATE_OFF)
  642. {
  643. c.text(w * 0.625, h * 0.5, 0, 0, mainText[1], mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  644. }
  645. };
  646. mxCellRenderer.registerShape(mxShapeMockupOnOffButton.prototype.cst.SHAPE_ON_OFF_BUTTON, mxShapeMockupOnOffButton);
  647. //**********************************************************************************************************************************************************
  648. //Rounded rectangle (adjustable rounding)
  649. //**********************************************************************************************************************************************************
  650. /**
  651. * Extends mxShape.
  652. */
  653. function mxShapeMockupRRect(bounds, fill, stroke, strokewidth)
  654. {
  655. mxShape.call(this);
  656. this.bounds = bounds;
  657. this.fill = fill;
  658. this.stroke = stroke;
  659. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  660. };
  661. /**
  662. * Extends mxShape.
  663. */
  664. mxUtils.extend(mxShapeMockupRRect, mxShape);
  665. mxShapeMockupRRect.prototype.cst = {
  666. RRECT : 'mxgraph.mockup.rrect',
  667. R_SIZE : 'rSize'
  668. };
  669. mxShapeMockupRRect.prototype.customProperties = [
  670. {name: 'rSize', dispName: 'Arc Size', type: 'float', min:0, defVal:10}
  671. ];
  672. /**
  673. * Function: paintVertexShape
  674. *
  675. * Paints the vertex shape.
  676. */
  677. mxShapeMockupRRect.prototype.paintVertexShape = function(c, x, y, w, h)
  678. {
  679. c.translate(x, y);
  680. var rSize = parseInt(mxUtils.getValue(this.style, mxShapeMockupRRect.prototype.cst.R_SIZE, '10'));
  681. c.roundrect(0, 0, w, h, rSize);
  682. c.fillAndStroke();
  683. };
  684. mxCellRenderer.registerShape(mxShapeMockupRRect.prototype.cst.RRECT, mxShapeMockupRRect);
  685. //**********************************************************************************************************************************************************
  686. //Anchor (a dummy shape without visuals used for anchoring)
  687. //**********************************************************************************************************************************************************
  688. /**
  689. * Extends mxShape.
  690. */
  691. function mxShapeMockupAnchor(bounds, fill, stroke, strokewidth)
  692. {
  693. mxShape.call(this);
  694. this.bounds = bounds;
  695. };
  696. /**
  697. * Extends mxShape.
  698. */
  699. mxUtils.extend(mxShapeMockupAnchor, mxShape);
  700. mxShapeMockupAnchor.prototype.cst = {
  701. ANCHOR : 'mxgraph.mockup.anchor'
  702. };
  703. mxShapeMockupAnchor.prototype.customProperties = [
  704. {name: 'rSize', dispName: 'Arc Size', type: 'float', min:0, defVal:10}
  705. ];
  706. /**
  707. * Function: paintVertexShape
  708. *
  709. * Paints the vertex shape.
  710. */
  711. mxShapeMockupAnchor.prototype.paintVertexShape = function(c, x, y, w, h)
  712. {
  713. };
  714. mxCellRenderer.registerShape(mxShapeMockupAnchor.prototype.cst.ANCHOR, mxShapeMockupAnchor);
  715. //**********************************************************************************************************************************************************
  716. //Top Button
  717. //**********************************************************************************************************************************************************
  718. /**
  719. * Extends mxShape.
  720. */
  721. function mxShapeMockupTopButton(bounds, fill, stroke, strokewidth)
  722. {
  723. mxShape.call(this);
  724. this.bounds = bounds;
  725. this.fill = fill;
  726. this.stroke = stroke;
  727. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  728. };
  729. /**
  730. * Extends mxShape.
  731. */
  732. mxUtils.extend(mxShapeMockupTopButton, mxShape);
  733. mxShapeMockupTopButton.prototype.cst = {
  734. TOP_BUTTON : 'mxgraph.mockup.topButton',
  735. R_SIZE : 'rSize'
  736. };
  737. mxShapeMockupTopButton.prototype.customProperties = [
  738. {name: 'rSize', dispName: 'Arc Size', type: 'float', min:0, defVal:10}
  739. ];
  740. /**
  741. * Function: paintVertexShape
  742. *
  743. * Paints the vertex shape.
  744. */
  745. mxShapeMockupTopButton.prototype.paintVertexShape = function(c, x, y, w, h)
  746. {
  747. c.translate(x, y);
  748. var rSize = parseInt(mxUtils.getValue(this.style, mxShapeMockupTopButton.prototype.cst.R_SIZE, '10'));
  749. c.begin();
  750. c.moveTo(0, rSize);
  751. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  752. c.lineTo(w - rSize, 0);
  753. c.arcTo(rSize, rSize, 0, 0, 1, w, rSize);
  754. c.lineTo(w, h);
  755. c.lineTo(0, h);
  756. c.close();
  757. c.fillAndStroke();
  758. };
  759. mxCellRenderer.registerShape(mxShapeMockupTopButton.prototype.cst.TOP_BUTTON, mxShapeMockupTopButton);
  760. //**********************************************************************************************************************************************************
  761. //Bottom Button
  762. //**********************************************************************************************************************************************************
  763. /**
  764. * Extends mxShape.
  765. */
  766. function mxShapeMockupBottomButton(bounds, fill, stroke, strokewidth)
  767. {
  768. mxShape.call(this);
  769. this.bounds = bounds;
  770. this.fill = fill;
  771. this.stroke = stroke;
  772. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  773. };
  774. /**
  775. * Extends mxShape.
  776. */
  777. mxUtils.extend(mxShapeMockupBottomButton, mxShape);
  778. mxShapeMockupBottomButton.prototype.cst = {
  779. BOTTOM_BUTTON : 'mxgraph.mockup.bottomButton',
  780. R_SIZE : 'rSize'
  781. };
  782. mxShapeMockupBottomButton.prototype.customProperties = [
  783. {name: 'rSize', dispName: 'Arc Size', type: 'float', min:0, defVal:10}
  784. ];
  785. /**
  786. * Function: paintVertexShape
  787. *
  788. * Paints the vertex shape.
  789. */
  790. mxShapeMockupBottomButton.prototype.paintVertexShape = function(c, x, y, w, h)
  791. {
  792. c.translate(x, y);
  793. var rSize = parseInt(mxUtils.getValue(this.style, mxShapeMockupBottomButton.prototype.cst.R_SIZE, '10'));
  794. c.begin();
  795. c.moveTo(0, 0);
  796. c.lineTo(w, 0);
  797. c.lineTo(w, h - rSize);
  798. c.arcTo(rSize, rSize, 0, 0, 1, w - rSize, h);
  799. c.lineTo(rSize, h);
  800. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  801. c.close();
  802. c.fillAndStroke();
  803. };
  804. mxCellRenderer.registerShape(mxShapeMockupBottomButton.prototype.cst.BOTTOM_BUTTON, mxShapeMockupBottomButton);
  805. //**********************************************************************************************************************************************************
  806. //Right Button
  807. //**********************************************************************************************************************************************************
  808. /**
  809. * Extends mxShape.
  810. */
  811. function mxShapeMockupRightButton(bounds, fill, stroke, strokewidth)
  812. {
  813. mxShape.call(this);
  814. this.bounds = bounds;
  815. this.fill = fill;
  816. this.stroke = stroke;
  817. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  818. };
  819. /**
  820. * Extends mxShape.
  821. */
  822. mxUtils.extend(mxShapeMockupRightButton, mxShape);
  823. mxShapeMockupRightButton.prototype.cst = {
  824. RIGHT_BUTTON : 'mxgraph.mockup.rightButton',
  825. R_SIZE : 'rSize'
  826. };
  827. mxShapeMockupRightButton.prototype.customProperties = [
  828. {name: 'rSize', dispName: 'Arc Size', type: 'float', min:0, defVal:10}
  829. ];
  830. /**
  831. * Function: paintVertexShape
  832. *
  833. * Paints the vertex shape.
  834. */
  835. mxShapeMockupRightButton.prototype.paintVertexShape = function(c, x, y, w, h)
  836. {
  837. c.translate(x, y);
  838. var rSize = parseInt(mxUtils.getValue(this.style, mxShapeMockupRightButton.prototype.cst.R_SIZE, '10'));
  839. c.begin();
  840. c.moveTo(0, 0);
  841. c.lineTo(w - rSize, 0);
  842. c.arcTo(rSize, rSize, 0, 0, 1, w, rSize);
  843. c.lineTo(w, h - rSize);
  844. c.arcTo(rSize, rSize, 0, 0, 1, w - rSize, h);
  845. c.lineTo(0, h);
  846. c.close();
  847. c.fillAndStroke();
  848. };
  849. mxCellRenderer.registerShape(mxShapeMockupRightButton.prototype.cst.RIGHT_BUTTON, mxShapeMockupRightButton);
  850. //**********************************************************************************************************************************************************
  851. //Left Button
  852. //**********************************************************************************************************************************************************
  853. /**
  854. * Extends mxShape.
  855. */
  856. function mxShapeMockupLeftButton(bounds, fill, stroke, strokewidth)
  857. {
  858. mxShape.call(this);
  859. this.bounds = bounds;
  860. this.fill = fill;
  861. this.stroke = stroke;
  862. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  863. };
  864. /**
  865. * Extends mxShape.
  866. */
  867. mxUtils.extend(mxShapeMockupLeftButton, mxShape);
  868. mxShapeMockupLeftButton.prototype.cst = {
  869. LEFT_BUTTON : 'mxgraph.mockup.leftButton',
  870. R_SIZE : 'rSize'
  871. };
  872. mxShapeMockupLeftButton.prototype.customProperties = [
  873. {name: 'rSize', dispName: 'Arc Size', type: 'float', min:0, defVal:10}
  874. ];
  875. /**
  876. * Function: paintVertexShape
  877. *
  878. * Paints the vertex shape.
  879. */
  880. mxShapeMockupLeftButton.prototype.paintVertexShape = function(c, x, y, w, h)
  881. {
  882. c.translate(x, y);
  883. var rSize = parseInt(mxUtils.getValue(this.style, mxShapeMockupLeftButton.prototype.cst.R_SIZE, '10'));
  884. c.begin();
  885. c.moveTo(w, 0);
  886. c.lineTo(w, h);
  887. c.lineTo(rSize, h);
  888. c.arcTo(rSize, rSize, 0, 0, 1, 0, h - rSize);
  889. c.lineTo(0, rSize);
  890. c.arcTo(rSize, rSize, 0, 0, 1, rSize, 0);
  891. c.close();
  892. c.fillAndStroke();
  893. };
  894. mxCellRenderer.registerShape(mxShapeMockupLeftButton.prototype.cst.LEFT_BUTTON, mxShapeMockupLeftButton);