mxMockupButtons.js 31 KB

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