mxMockupButtons.js 30 KB

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