mxAndroid.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561
  1. /**
  2. * Copyright (c) 2006-2013, JGraph Holdings Ltd
  3. */
  4. //**********************************************************************************************************************************************************
  5. //Horizontal Tab Bar (LEGACY)
  6. //**********************************************************************************************************************************************************
  7. /**
  8. * Extends mxShape.
  9. */
  10. function mxShapeAndroidTabBar(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(mxShapeAndroidTabBar, mxShape);
  22. mxShapeAndroidTabBar.prototype.cst = {
  23. MAIN_TEXT : 'mainText',
  24. SHAPE_TAB_BAR : 'mxgraph.android.tabBar',
  25. TEXT_COLOR : 'textColor',
  26. TEXT_COLOR2 : 'textColor2',
  27. STROKE_COLOR2 : 'strokeColor2',
  28. FILL_COLOR2 : 'fillColor2',
  29. SELECTED : '+', //must be 1 char
  30. TEXT_SIZE : 'textSize'
  31. };
  32. /**
  33. * Function: paintVertexShape
  34. *
  35. * Paints the vertex shape.
  36. */
  37. mxShapeAndroidTabBar.prototype.paintVertexShape = function(c, x, y, w, h)
  38. {
  39. var textStrings = mxUtils.getValue(this.style, mxShapeAndroidTabBar.prototype.cst.MAIN_TEXT, '+Tab 1, Tab 2, Tab 3').toString().split(',');
  40. var fontColor = mxUtils.getValue(this.style, mxShapeAndroidTabBar.prototype.cst.TEXT_COLOR, 'none');
  41. var selectedFontColor = mxUtils.getValue(this.style, mxShapeAndroidTabBar.prototype.cst.TEXT_COLOR2, 'none');
  42. var fontSize = mxUtils.getValue(this.style, mxShapeAndroidTabBar.prototype.cst.TEXT_SIZE, '17').toString();
  43. var frameColor = mxUtils.getValue(this.style, mxConstants.STYLE_STROKECOLOR, 'none');
  44. var separatorColor = mxUtils.getValue(this.style, mxShapeAndroidTabBar.prototype.cst.STROKE_COLOR2, 'none');
  45. var bgColor = mxUtils.getValue(this.style, mxConstants.STYLE_FILLCOLOR, 'none');
  46. var selectedFillColor = mxUtils.getValue(this.style, mxShapeAndroidTabBar.prototype.cst.FILL_COLOR2, 'none');
  47. var buttonNum = textStrings.length;
  48. var buttonWidths = new Array(buttonNum);
  49. var buttonTotalWidth = 0;
  50. var selectedButton = -1;
  51. var labelOffset = 5;
  52. for (var i = 0; i < buttonNum; i++)
  53. {
  54. var buttonText = textStrings[i];
  55. if(buttonText.charAt(0) === mxShapeAndroidTabBar.prototype.cst.SELECTED)
  56. {
  57. buttonText = textStrings[i].substring(1);
  58. selectedButton = i;
  59. }
  60. buttonWidths[i] = mxUtils.getSizeForString(buttonText, fontSize, mxConstants.DEFAULT_FONTFAMILY).width;
  61. buttonTotalWidth += buttonWidths[i];
  62. }
  63. var trueH = Math.max(h, fontSize * 1.5, 7);
  64. var minW = 2 * labelOffset * buttonNum + buttonTotalWidth;
  65. var trueW = Math.max(w, minW);
  66. c.translate(x, y);
  67. this.background(c, trueW, trueH, buttonNum, buttonWidths, labelOffset, minW, frameColor, separatorColor, bgColor, selectedFillColor, selectedButton);
  68. c.setShadow(false);
  69. c.setFontStyle(mxConstants.FONT_BOLD);
  70. var currWidth = 0;
  71. for (var i = 0; i < buttonNum; i++)
  72. {
  73. if (i === selectedButton)
  74. {
  75. c.setFontColor(selectedFontColor);
  76. }
  77. else
  78. {
  79. c.setFontColor(fontColor);
  80. }
  81. currWidth = currWidth + labelOffset;
  82. this.buttonText(c, currWidth, trueH, textStrings[i], buttonWidths[i], fontSize, minW, trueW);
  83. currWidth = currWidth + buttonWidths[i] + labelOffset;
  84. }
  85. };
  86. mxShapeAndroidTabBar.prototype.background = function(c, w, h, buttonNum, buttonWidths, labelOffset, minW, frameColor, separatorColor, bgColor, selectedFillColor, selectedButton)
  87. {
  88. c.begin();
  89. //draw the frame
  90. c.setStrokeColor(frameColor);
  91. c.setFillColor(bgColor);
  92. c.rect(0, 0, w, h);
  93. c.fillAndStroke();
  94. //draw the button separators
  95. c.setStrokeColor(separatorColor);
  96. c.begin();
  97. for (var i = 1; i < buttonNum; i++)
  98. {
  99. if (i !== selectedButton && i !== (selectedButton + 1))
  100. {
  101. var currWidth = 0;
  102. for (var j = 0; j < i; j++)
  103. {
  104. currWidth += buttonWidths[j] + 2 * labelOffset;
  105. }
  106. currWidth = currWidth * w / minW;
  107. c.moveTo(currWidth, h * 0.2);
  108. c.lineTo(currWidth, h * 0.8);
  109. }
  110. }
  111. c.stroke();
  112. //draw the selected button
  113. var buttonLeft = 0;
  114. c.setFillColor(selectedFillColor);
  115. for (var i = 0; i < selectedButton; i++)
  116. {
  117. buttonLeft += buttonWidths[i] + 2 * labelOffset;
  118. }
  119. buttonLeft = buttonLeft * w / minW;
  120. var buttonRight = (buttonWidths[selectedButton] + 2 * labelOffset) * w / minW;
  121. buttonRight += buttonLeft;
  122. c.rect(buttonLeft, 0, buttonRight - buttonLeft, h);
  123. c.fill();
  124. c.setAlpha(1);
  125. c.setFillColor('#33b5e5');
  126. c.rect(buttonLeft, h * 0.9, buttonRight - buttonLeft, h * 0.1);
  127. c.fill();
  128. };
  129. mxShapeAndroidTabBar.prototype.buttonText = function(c, w, h, textString, buttonWidth, fontSize, minW, trueW)
  130. {
  131. if(textString.charAt(0) === mxShapeAndroidTabBar.prototype.cst.SELECTED)
  132. {
  133. textString = textString.substring(1);
  134. }
  135. c.begin();
  136. c.setFontSize(fontSize);
  137. 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);
  138. };
  139. mxCellRenderer.registerShape(mxShapeAndroidTabBar.prototype.cst.SHAPE_TAB_BAR, mxShapeAndroidTabBar);
  140. //**********************************************************************************************************************************************************
  141. //Android Phone Vertical
  142. //**********************************************************************************************************************************************************
  143. /**
  144. * Extends mxShape.
  145. */
  146. function mxShapeAndroidPhone(bounds, fill, stroke, strokewidth)
  147. {
  148. mxShape.call(this);
  149. this.bounds = bounds;
  150. this.fill = fill;
  151. this.stroke = stroke;
  152. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  153. };
  154. /**
  155. * Extends mxShape.
  156. */
  157. mxUtils.extend(mxShapeAndroidPhone, mxShape);
  158. /**
  159. * Function: paintVertexShape
  160. *
  161. * Paints the vertex shape.
  162. */
  163. mxShapeAndroidPhone.prototype.paintVertexShape = function(c, x, y, w, h)
  164. {
  165. c.translate(x, y);
  166. var rSize = 25;
  167. c.roundrect(0, 0, w, h, rSize, rSize);
  168. c.fillAndStroke();
  169. c.setShadow(false);
  170. this.foreground(c, x, y, w, h, rSize);
  171. };
  172. mxShapeAndroidPhone.prototype.foreground = function(c, x, y, w, h, rSize)
  173. {
  174. c.rect(w * 0.0625, h * 0.15, w * 0.875, h * 0.7);
  175. c.stroke();
  176. c.ellipse(w * 0.4875, h * 0.04125, w * 0.025, h * 0.0125);
  177. c.stroke();
  178. c.roundrect(w * 0.375, h * 0.075, w * 0.25, h * 0.01875, w * 0.02, h * 0.01);
  179. c.stroke();
  180. c.ellipse(w * 0.4, h * 0.875, w * 0.2, h * 0.1);
  181. c.stroke();
  182. c.roundrect(w * 0.4575, h * 0.905, w * 0.085, h * 0.04375, h * 0.00625, h * 0.00625);
  183. c.stroke();
  184. };
  185. mxCellRenderer.registerShape('mxgraph.android.phone', mxShapeAndroidPhone);
  186. //**********************************************************************************************************************************************************
  187. //Android Status Bar
  188. //**********************************************************************************************************************************************************
  189. /**
  190. * Extends mxShape.
  191. */
  192. function mxShapeAndroidStatusBar(bounds, fill, stroke, strokewidth)
  193. {
  194. mxShape.call(this);
  195. this.bounds = bounds;
  196. this.fill = fill;
  197. this.stroke = stroke;
  198. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  199. };
  200. /**
  201. * Extends mxShape.
  202. */
  203. mxUtils.extend(mxShapeAndroidStatusBar, mxShape);
  204. mxShapeAndroidStatusBar.prototype.customProperties = [
  205. {name: 'batteryColor', dispName: 'Battery Color', defVal: '#444444', type: 'color', primary:true}
  206. ];
  207. /**
  208. * Function: paintVertexShape
  209. *
  210. * Paints the vertex shape.
  211. */
  212. mxShapeAndroidStatusBar.prototype.paintVertexShape = function(c, x, y, w, h)
  213. {
  214. c.translate(x, y);
  215. this.background(c, x, y, w, h);
  216. c.setShadow(false);
  217. this.foreground(c, x, y, w, h);
  218. };
  219. mxShapeAndroidStatusBar.prototype.background = function(c, x, y, w, h)
  220. {
  221. c.rect(0, 0, w, h);
  222. c.fill();
  223. };
  224. mxShapeAndroidStatusBar.prototype.foreground = function(c, x, y, w, h)
  225. {
  226. c.rect(0, 0, w, h);
  227. c.fill();
  228. c.setFontColor(mxUtils.getValue(this.style, mxConstants.STYLE_FONTCOLOR, '#222222'));
  229. c.setFontSize(mxUtils.getValue(this.style, mxConstants.STYLE_FONTSIZE, '5'));
  230. c.text(w - 30, h * 0.5 + 1, 0, 0, '12:00', mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  231. c.setFillColor(mxUtils.getValue(this.style, 'batteryColor', '#444444'));
  232. c.begin();
  233. c.moveTo(w - 37, h * 0.5 + 6);
  234. c.lineTo(w - 37, h * 0.5 - 5);
  235. c.lineTo(w - 36, h * 0.5 - 5);
  236. c.lineTo(w - 36, h * 0.5 - 6);
  237. c.lineTo(w - 32, h * 0.5 - 6);
  238. c.lineTo(w - 32, h * 0.5 - 5);
  239. c.lineTo(w - 31, h * 0.5 - 5);
  240. c.lineTo(w - 31, h * 0.5 + 6);
  241. c.close();
  242. c.fill();
  243. c.setFillColor(mxUtils.getValue(this.style, mxConstants.STYLE_STROKECOLOR, 'none'));
  244. c.ellipse(w - 56, h * 0.5 + 2, 2, 2);
  245. c.fillAndStroke();
  246. c.setStrokeWidth(2);
  247. c.begin();
  248. c.moveTo(w - 52, h * 0.5 + 1);
  249. c.arcTo(3.5, 3.5, 0, 0, 0, w - 58, h * 0.5 + 1);
  250. c.stroke();
  251. c.begin();
  252. c.moveTo(w - 50, h * 0.5 - 1);
  253. c.arcTo(6, 6, 0, 0, 0, w - 60, h * 0.5 - 1);
  254. c.stroke();
  255. c.setStrokeWidth(1);
  256. c.rect(w - 51, h * 0.5 + 5, 2, 1);
  257. c.fill();
  258. c.rect(w - 48, h * 0.5 + 2, 2, 4);
  259. c.fill();
  260. c.rect(w - 45, h * 0.5 - 1, 2, 7);
  261. c.fill();
  262. c.rect(w - 42, h * 0.5 - 4, 2, 10);
  263. c.fill();
  264. c.rect(w - 37, h * 0.5 - 2, 6, 8);
  265. c.fill();
  266. };
  267. mxCellRenderer.registerShape('mxgraph.android.statusBar', mxShapeAndroidStatusBar);
  268. //**********************************************************************************************************************************************************
  269. //Checkbox Button Group
  270. //**********************************************************************************************************************************************************
  271. /**
  272. * Extends mxShape.
  273. */
  274. function mxShapeAndroidCheckboxGroup(bounds, fill, stroke, strokewidth)
  275. {
  276. mxShape.call(this);
  277. this.bounds = bounds;
  278. this.fill = fill;
  279. this.stroke = stroke;
  280. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  281. };
  282. /**
  283. * Extends mxShape.
  284. */
  285. mxUtils.extend(mxShapeAndroidCheckboxGroup, mxShape);
  286. mxShapeAndroidCheckboxGroup.prototype.cst = {
  287. STYLE_TEXTCOLOR2 : 'textColor2',
  288. STYLE_STROKECOLOR2 : 'strokeColor2',
  289. BUTTON_TEXT : 'buttonText',
  290. SELECTED : '+' //has to be one character long
  291. };
  292. /**
  293. * Function: paintVertexShape
  294. *
  295. * Paints the vertex shape.
  296. */
  297. mxShapeAndroidCheckboxGroup.prototype.paintVertexShape = function(c, x, y, w, h)
  298. {
  299. c.translate(x, y);
  300. var fontColor = mxUtils.getValue(this.style, mxConstants.STYLE_TEXTCOLOR, '#666666');
  301. var fontSize = mxUtils.getValue(this.style, mxConstants.STYLE_FONTSIZE, '8').toString();
  302. var optionText = mxUtils.getValue(this.style, mxShapeAndroidCheckboxGroup.prototype.cst.BUTTON_TEXT, 'Option 1').toString().split(',');
  303. var strokeColor = mxUtils.getValue(this.style, mxConstants.STYLE_STROKECOLOR, 'none');
  304. var strokeColor2 = mxUtils.getValue(this.style, mxShapeAndroidCheckboxGroup.prototype.cst.STYLE_STROKECOLOR2, 'none');
  305. c.setStrokeColor(strokeColor2);
  306. var optionNum = optionText.length;
  307. var buttonSize = 5;
  308. var lineH = Math.max(fontSize * 1.5, buttonSize);
  309. var maxTextWidth = 0;
  310. var selected = -1;
  311. var labelOffset = 2.5;
  312. var minH = optionNum * lineH;
  313. var trueH = Math.max(h, minH);
  314. //get min width and selected option
  315. for (var i = 0; i < optionNum; i++)
  316. {
  317. var currText = optionText[i];
  318. if(currText.charAt(0) === mxShapeAndroidCheckboxGroup.prototype.cst.SELECTED)
  319. {
  320. currText = optionText[i].substring(1);
  321. selected = i;
  322. }
  323. var currWidth = mxUtils.getSizeForString(currText, fontSize, mxConstants.DEFAULT_FONTFAMILY).width;
  324. if (currWidth > maxTextWidth)
  325. {
  326. maxTextWidth = currWidth;
  327. }
  328. }
  329. var minW = 2 * labelOffset + maxTextWidth + 2 * buttonSize;
  330. var trueW = Math.max(w, minW);
  331. //draw the background
  332. c.roundrect(0, 0, trueW, trueH, 2.5, 2.5);
  333. c.fillAndStroke();
  334. c.setShadow(false);
  335. c.setFontSize(fontSize);
  336. c.setFontColor(fontColor);
  337. c.setStrokeColor(strokeColor);
  338. for (var i = 0; i < optionNum; i++)
  339. {
  340. var currHeight = (i * lineH + lineH * 0.5) * trueH / minH;
  341. var currText = optionText[i];
  342. if(currText.charAt(0) === mxShapeAndroidCheckboxGroup.prototype.cst.SELECTED)
  343. {
  344. currText = optionText[i].substring(1);
  345. selected = i;
  346. }
  347. c.text(buttonSize * 2 + labelOffset, currHeight, 0, 0, currText, mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  348. var iconX = buttonSize * 0.5;
  349. var iconY = currHeight - buttonSize * 0.5;
  350. if (selected === i)
  351. {
  352. c.rect(iconX, iconY, buttonSize, buttonSize);
  353. c.fillAndStroke();
  354. c.begin();
  355. c.moveTo(iconX + buttonSize * 0.25, iconY + buttonSize * 0.5);
  356. c.lineTo(iconX + buttonSize * 0.5, iconY + buttonSize * 0.75);
  357. c.lineTo(iconX + buttonSize * 0.75, iconY + buttonSize * 0.25);
  358. c.stroke();
  359. }
  360. else
  361. {
  362. c.rect(iconX, iconY, buttonSize, buttonSize);
  363. c.fillAndStroke();
  364. }
  365. selected = -1;
  366. }
  367. };
  368. mxCellRenderer.registerShape('mxgraph.android.checkboxGroup', mxShapeAndroidCheckboxGroup);
  369. //**********************************************************************************************************************************************************
  370. //Radio Button Group
  371. //**********************************************************************************************************************************************************
  372. /**
  373. * Extends mxShape.
  374. */
  375. function mxShapeAndroidRadioGroup(bounds, fill, stroke, strokewidth)
  376. {
  377. mxShape.call(this);
  378. this.bounds = bounds;
  379. this.fill = fill;
  380. this.stroke = stroke;
  381. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  382. };
  383. /**
  384. * Extends mxShape.
  385. */
  386. mxUtils.extend(mxShapeAndroidRadioGroup, mxShape);
  387. mxShapeAndroidRadioGroup.prototype.cst = {
  388. STYLE_TEXTCOLOR2 : 'textColor2',
  389. STYLE_STROKECOLOR2 : 'strokeColor2',
  390. BUTTON_TEXT : 'buttonText',
  391. SELECTED : '+' //has to be one character long
  392. };
  393. /**
  394. * Function: paintVertexShape
  395. *
  396. * Paints the vertex shape.
  397. */
  398. mxShapeAndroidRadioGroup.prototype.paintVertexShape = function(c, x, y, w, h)
  399. {
  400. c.translate(x, y);
  401. var fontColor = mxUtils.getValue(this.style, mxConstants.STYLE_TEXTCOLOR, '#666666');
  402. var fontSize = mxUtils.getValue(this.style, mxConstants.STYLE_FONTSIZE, '8').toString();
  403. var optionText = mxUtils.getValue(this.style, mxShapeAndroidRadioGroup.prototype.cst.BUTTON_TEXT, 'Option 1').toString().split(',');
  404. var strokeColor = mxUtils.getValue(this.style, mxConstants.STYLE_STROKECOLOR, 'none');
  405. var strokeColor2 = mxUtils.getValue(this.style, mxShapeAndroidRadioGroup.prototype.cst.STYLE_STROKECOLOR2, 'none');
  406. c.setStrokeColor(strokeColor2);
  407. var optionNum = optionText.length;
  408. var buttonSize = 5;
  409. var lineH = Math.max(fontSize * 1.5, buttonSize);
  410. var maxTextWidth = 0;
  411. var selected = -1;
  412. var labelOffset = 2.5;
  413. var minH = optionNum * lineH;
  414. var trueH = Math.max(h, minH);
  415. //get min width and selected option
  416. for (var i = 0; i < optionNum; i++)
  417. {
  418. var currText = optionText[i];
  419. if(currText.charAt(0) === mxShapeAndroidRadioGroup.prototype.cst.SELECTED)
  420. {
  421. currText = optionText[i].substring(1);
  422. selected = i;
  423. }
  424. var currWidth = mxUtils.getSizeForString(currText, fontSize, mxConstants.DEFAULT_FONTFAMILY).width;
  425. if (currWidth > maxTextWidth)
  426. {
  427. maxTextWidth = currWidth;
  428. }
  429. }
  430. var minW = 2 * labelOffset + maxTextWidth + 2 * buttonSize;
  431. var trueW = Math.max(w, minW);
  432. //draw the background
  433. c.roundrect(0, 0, trueW, trueH, 2.5, 2.5);
  434. c.fillAndStroke();
  435. c.setShadow(false);
  436. c.setFontSize(fontSize);
  437. c.setFontColor(fontColor);
  438. c.setStrokeColor(strokeColor);
  439. c.setFillColor(strokeColor);
  440. for (var i = 0; i < optionNum; i++)
  441. {
  442. var currHeight = (i * lineH + lineH * 0.5) * trueH / minH;
  443. var currText = optionText[i];
  444. if(currText.charAt(0) === mxShapeAndroidRadioGroup.prototype.cst.SELECTED)
  445. {
  446. currText = optionText[i].substring(1);
  447. selected = i;
  448. }
  449. c.text(buttonSize * 2 + labelOffset, currHeight, 0, 0, currText, mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  450. var iconX = buttonSize * 0.5;
  451. var iconY = currHeight - buttonSize * 0.5;
  452. if (selected === i)
  453. {
  454. c.ellipse(iconX, iconY, buttonSize, buttonSize);
  455. c.stroke();
  456. c.ellipse(iconX + buttonSize * 0.25, iconY + buttonSize * 0.25, buttonSize * 0.5, buttonSize * 0.5);
  457. c.fillAndStroke();
  458. }
  459. else
  460. {
  461. c.ellipse(iconX, iconY, buttonSize, buttonSize);
  462. c.stroke();
  463. }
  464. }
  465. };
  466. mxCellRenderer.registerShape('mxgraph.android.radioGroup', mxShapeAndroidRadioGroup);
  467. //**********************************************************************************************************************************************************
  468. //Menu Bar (LEGACY)
  469. //**********************************************************************************************************************************************************
  470. /**
  471. * Extends mxShape.
  472. */
  473. function mxShapeAndroidMenuBar(bounds, fill, stroke, strokewidth)
  474. {
  475. mxShape.call(this);
  476. this.bounds = bounds;
  477. this.fill = fill;
  478. this.stroke = stroke;
  479. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  480. };
  481. /**
  482. * Extends mxShape.
  483. */
  484. mxUtils.extend(mxShapeAndroidMenuBar, mxShape);
  485. mxShapeAndroidMenuBar.prototype.cst = {
  486. MENU_TEXT : 'menuText'
  487. };
  488. /**
  489. * Function: paintVertexShape
  490. *
  491. * Paints the vertex shape.
  492. */
  493. mxShapeAndroidMenuBar.prototype.paintVertexShape = function(c, x, y, w, h)
  494. {
  495. var textStrings = mxUtils.getValue(this.style, mxShapeAndroidMenuBar.prototype.cst.MENU_TEXT, 'Item 1, Item 2, Item 3').toString().split(',');
  496. var fontSize = mxUtils.getValue(this.style, mxConstants.STYLE_FONTSIZE, '12');
  497. var buttonNum = textStrings.length;
  498. var maxButtonWidth = 0;
  499. var labelOffset = 2.5;
  500. for (var i = 0; i < buttonNum; i++)
  501. {
  502. var buttonText = textStrings[i];
  503. var currWidth = mxUtils.getSizeForString(buttonText, fontSize, mxConstants.DEFAULT_FONTFAMILY).width;
  504. if (currWidth > maxButtonWidth)
  505. {
  506. maxButtonWidth = currWidth;
  507. }
  508. }
  509. var minButtonHeight = fontSize * 1.5;
  510. var minH = buttonNum * minButtonHeight;
  511. var trueH = Math.max(h, minH);
  512. var minW = 2 * labelOffset + maxButtonWidth;
  513. var trueW = Math.max(w, minW);
  514. c.translate(x, y);
  515. c.rect(0, 0, w, trueH);
  516. c.fillAndStroke();
  517. c.setShadow(false);
  518. //draw the button separators
  519. c.begin();
  520. for (var i = 1; i < buttonNum; i++)
  521. {
  522. var currHeight = i * minButtonHeight * trueH / minH;
  523. c.moveTo(0, currHeight);
  524. c.lineTo(w, currHeight);
  525. }
  526. c.stroke();
  527. for (var i = 0; i < buttonNum; i++)
  528. {
  529. currWidth = currWidth + labelOffset;
  530. var currHeight = (i * minButtonHeight + minButtonHeight * 0.5) * trueH / minH;
  531. c.text(10, currHeight, 0, 0, textStrings[i], mxConstants.ALIGN_LEFT, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  532. }
  533. };
  534. mxCellRenderer.registerShape('mxgraph.android.menuBar', mxShapeAndroidMenuBar);
  535. //**********************************************************************************************************************************************************
  536. //Text Selection Handles
  537. //**********************************************************************************************************************************************************
  538. /**
  539. * Extends mxShape.
  540. */
  541. function mxShapeAndroidTextSelHandles(bounds, fill, stroke, strokewidth)
  542. {
  543. mxShape.call(this);
  544. this.bounds = bounds;
  545. this.fill = fill;
  546. this.stroke = stroke;
  547. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  548. };
  549. /**
  550. * Extends mxShape.
  551. */
  552. mxUtils.extend(mxShapeAndroidTextSelHandles, mxShape);
  553. /**
  554. * Function: paintVertexShape
  555. *
  556. * Paints the vertex shape.
  557. */
  558. mxShapeAndroidTextSelHandles.prototype.paintVertexShape = function(c, x, y, w, h)
  559. {
  560. var strokeColor = mxUtils.getValue(this.style, mxConstants.STYLE_STROKECOLOR, 'none');
  561. c.translate(x, y);
  562. var handleSizeX = 15;
  563. var barH = Math.max(0, h - handleSizeX * 1.5);
  564. c.setAlpha(0.5);
  565. c.rect(handleSizeX, 0, w - 2 * handleSizeX, barH);
  566. c.fill();
  567. c.begin();
  568. c.moveTo(0, h - handleSizeX);
  569. c.lineTo(handleSizeX * 0.5, h - handleSizeX * 1.5);
  570. c.lineTo(handleSizeX, h - handleSizeX);
  571. c.close();
  572. c.moveTo(w - handleSizeX, h - handleSizeX);
  573. c.lineTo(w - handleSizeX * 0.5, h - handleSizeX * 1.5);
  574. c.lineTo(w, h - handleSizeX);
  575. c.close();
  576. c.fill();
  577. c.setFillColor(strokeColor);
  578. c.rect(0, h - handleSizeX, handleSizeX, handleSizeX);
  579. c.fill();
  580. c.rect(w - handleSizeX, h - handleSizeX, handleSizeX, handleSizeX);
  581. c.fill();
  582. };
  583. mxCellRenderer.registerShape('mxgraph.android.textSelHandles', mxShapeAndroidTextSelHandles);
  584. //**********************************************************************************************************************************************************
  585. //Android Indeterminate Spinner
  586. //**********************************************************************************************************************************************************
  587. /**
  588. * Extends mxShape.
  589. */
  590. function mxShapeAndroidIndeterminateSpinner(bounds, fill, stroke, strokewidth)
  591. {
  592. mxShape.call(this);
  593. this.bounds = bounds;
  594. this.fill = fill;
  595. this.stroke = stroke;
  596. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  597. };
  598. /**
  599. * Extends mxShape.
  600. */
  601. mxUtils.extend(mxShapeAndroidIndeterminateSpinner, mxShape);
  602. mxShapeAndroidIndeterminateSpinner.prototype.customProperties = [
  603. {name: 'spinnerColor', dispName: 'Spinner Color', defVal: '#ffffff', type: 'color', primary:true}
  604. ];
  605. /**
  606. * Function: paintVertexShape
  607. *
  608. * Paints the vertex shape.
  609. */
  610. mxShapeAndroidIndeterminateSpinner.prototype.paintVertexShape = function(c, x, y, w, h)
  611. {
  612. c.translate(x, y);
  613. this.background(c, x, y, w, h);
  614. };
  615. mxShapeAndroidIndeterminateSpinner.prototype.background = function(c, x, y, w, h)
  616. {
  617. var spinnerColor = mxUtils.getValue(this.style, 'spinnerColor', 'none');
  618. var darkStop, midStop, brightStop;
  619. if (spinnerColor !== 'none')
  620. {
  621. // Derive shaded variants from spinnerColor.
  622. // 0.67 and 0.87 chosen so a white input reproduces the original #aaaaaa / #dddddd.
  623. var hex = spinnerColor.charAt(0) === '#' ? spinnerColor.substr(1) : spinnerColor;
  624. if (hex.length === 3) hex = hex.charAt(0) + hex.charAt(0) + hex.charAt(1) + hex.charAt(1) + hex.charAt(2) + hex.charAt(2);
  625. var r = parseInt(hex.substr(0, 2), 16);
  626. var g = parseInt(hex.substr(2, 2), 16);
  627. var b = parseInt(hex.substr(4, 2), 16);
  628. var shade = function(factor)
  629. {
  630. var sr = Math.floor(r * factor);
  631. var sg = Math.floor(g * factor);
  632. var sb = Math.floor(b * factor);
  633. return '#' + ('0' + sr.toString(16)).slice(-2) + ('0' + sg.toString(16)).slice(-2) + ('0' + sb.toString(16)).slice(-2);
  634. };
  635. darkStop = shade(0.67);
  636. midStop = shade(0.87);
  637. brightStop = spinnerColor;
  638. }
  639. else
  640. {
  641. darkStop = '#aaaaaa';
  642. midStop = '#dddddd';
  643. brightStop = '#ffffff';
  644. }
  645. c.setGradient(darkStop, midStop, w * 0.325, 0, w * 0.675, h * 0.5, mxConstants.DIRECTION_SOUTH, 1, 1);
  646. c.begin();
  647. c.moveTo(w * 0.5, h * 0.1);
  648. c.arcTo(w * 0.4, h * 0.4, 0, 0, 0, w * 0.5, h * 0.9);
  649. c.lineTo(w * 0.5, h);
  650. c.arcTo(w * 0.5, h * 0.5, 0, 0, 1, w * 0.5, 0);
  651. c.close();
  652. c.fill();
  653. c.setGradient(brightStop, midStop, w * 0.325, 0, w * 0.675, h * 0.5, mxConstants.DIRECTION_SOUTH, 1, 1);
  654. c.begin();
  655. c.moveTo(w * 0.5, h * 0.1);
  656. c.arcTo(w * 0.4, h * 0.4, 0, 0, 1, w * 0.5, h * 0.9);
  657. c.lineTo(w * 0.5, h);
  658. c.arcTo(w * 0.5, h * 0.5, 0, 0, 0, w * 0.5, 0);
  659. c.close();
  660. c.fill();
  661. };
  662. mxCellRenderer.registerShape('mxgraph.android.indeterminateSpinner', mxShapeAndroidIndeterminateSpinner);
  663. //**********************************************************************************************************************************************************
  664. //Anchor (a dummy shape without visuals used for anchoring)
  665. //**********************************************************************************************************************************************************
  666. /**
  667. * Extends mxShape.
  668. */
  669. function mxShapeAndroidAnchor(bounds, fill, stroke, strokewidth)
  670. {
  671. mxShape.call(this);
  672. this.bounds = bounds;
  673. };
  674. /**
  675. * Extends mxShape.
  676. */
  677. mxUtils.extend(mxShapeAndroidAnchor, mxShape);
  678. mxShapeAndroidAnchor.prototype.cst = {
  679. ANCHOR : 'mxgraph.android.anchor'
  680. };
  681. /**
  682. * Function: paintVertexShape
  683. *
  684. * Paints the vertex shape.
  685. */
  686. mxShapeAndroidAnchor.prototype.paintVertexShape = function(c, x, y, w, h)
  687. {
  688. };
  689. mxCellRenderer.registerShape(mxShapeAndroidAnchor.prototype.cst.ANCHOR, mxShapeAndroidAnchor);
  690. //**********************************************************************************************************************************************************
  691. //Rounded rectangle (adjustable rounding)
  692. //**********************************************************************************************************************************************************
  693. /**
  694. * Extends mxShape.
  695. */
  696. function mxShapeAndroidRRect(bounds, fill, stroke, strokewidth)
  697. {
  698. mxShape.call(this);
  699. this.bounds = bounds;
  700. this.fill = fill;
  701. this.stroke = stroke;
  702. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  703. };
  704. /**
  705. * Extends mxShape.
  706. */
  707. mxUtils.extend(mxShapeAndroidRRect, mxShape);
  708. mxShapeAndroidRRect.prototype.cst = {
  709. RRECT : 'mxgraph.android.rrect',
  710. R_SIZE : 'rSize'
  711. };
  712. /**
  713. * Function: paintVertexShape
  714. *
  715. * Paints the vertex shape.
  716. */
  717. mxShapeAndroidRRect.prototype.paintVertexShape = function(c, x, y, w, h)
  718. {
  719. c.translate(x, y);
  720. var rSize = parseInt(mxUtils.getValue(this.style, mxShapeAndroidRRect.prototype.cst.R_SIZE, '10'));
  721. c.roundrect(0, 0, w, h, rSize);
  722. c.fillAndStroke();
  723. };
  724. mxCellRenderer.registerShape(mxShapeAndroidRRect.prototype.cst.RRECT, mxShapeAndroidRRect);
  725. //**********************************************************************************************************************************************************
  726. //Checkbox
  727. //**********************************************************************************************************************************************************
  728. /**
  729. * Extends mxShape.
  730. */
  731. function mxShapeAndroidCheckbox(bounds, fill, stroke, strokewidth)
  732. {
  733. mxShape.call(this);
  734. this.bounds = bounds;
  735. this.fill = fill;
  736. this.stroke = stroke;
  737. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  738. };
  739. /**
  740. * Extends mxShape.
  741. */
  742. mxUtils.extend(mxShapeAndroidCheckbox, mxShape);
  743. mxShapeAndroidCheckbox.prototype.cst = {
  744. CHECKBOX : 'mxgraph.android.checkbox'
  745. };
  746. /**
  747. * Function: paintVertexShape
  748. *
  749. * Paints the vertex shape.
  750. */
  751. mxShapeAndroidCheckbox.prototype.paintVertexShape = function(c, x, y, w, h)
  752. {
  753. c.translate(x, y);
  754. c.rect(0, 0, w, h);
  755. c.fillAndStroke();
  756. c.begin();
  757. c.moveTo(w * 0.8, h * 0.2);
  758. c.lineTo(w * 0.4, h * 0.8);
  759. c.lineTo(w * 0.25, h * 0.6);
  760. c.stroke();
  761. };
  762. mxCellRenderer.registerShape(mxShapeAndroidCheckbox.prototype.cst.CHECKBOX, mxShapeAndroidCheckbox);
  763. //**********************************************************************************************************************************************************
  764. //Progress Bar
  765. //**********************************************************************************************************************************************************
  766. /**
  767. * Extends mxShape.
  768. */
  769. function mxShapeAndroidProgressBar(bounds, fill, stroke, strokewidth)
  770. {
  771. mxShape.call(this);
  772. this.bounds = bounds;
  773. this.fill = fill;
  774. this.stroke = stroke;
  775. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  776. this.dx1 = 0.8;
  777. this.dx2 = 0.6;
  778. };
  779. /**
  780. * Extends mxShape.
  781. */
  782. mxUtils.extend(mxShapeAndroidProgressBar, mxShape);
  783. mxShapeAndroidProgressBar.prototype.customProperties = [
  784. {name: 'strokeColor2', dispName: 'Stroke Color 2', type: 'color', defVal:"#444444", primary: true},
  785. {name: 'dx1', dispName: 'Middle Bar Length', type: 'float', min:0, max:1, defVal:0.8},
  786. {name: 'dx2', dispName: 'Left Bar Length', type: 'float', min:0, max:1, defVal:0.6}
  787. ];
  788. mxShapeAndroidProgressBar.prototype.cst = {
  789. PROGRESS_BAR : 'mxgraph.android.progressBar'
  790. };
  791. /**
  792. * Function: paintVertexShape
  793. *
  794. * Paints the vertex shape.
  795. */
  796. mxShapeAndroidProgressBar.prototype.paintVertexShape = function(c, x, y, w, h)
  797. {
  798. var dx1 = w * Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'dx1', this.dx1))));
  799. var dx2 = w * Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'dx2', this.dx2))));
  800. var strokeColor2 = mxUtils.getValue(this.style, 'strokeColor2', '#444444');
  801. c.translate(x, y);
  802. c.save();
  803. c.save();
  804. c.setStrokeColor(strokeColor2);
  805. c.begin();
  806. c.moveTo(0, h * 0.5);
  807. c.lineTo(w , h * 0.5);
  808. c.stroke();
  809. c.restore();
  810. c.setShadow(false);
  811. c.begin();
  812. c.moveTo(0, h * 0.5);
  813. c.lineTo(dx1, h * 0.5);
  814. c.stroke();
  815. c.setStrokeColor("#000000");
  816. c.setAlpha('0.2');
  817. c.begin();
  818. c.moveTo(0, h * 0.5);
  819. c.lineTo(dx1, h * 0.5);
  820. c.stroke();
  821. c.restore();
  822. c.setShadow(false);
  823. c.begin();
  824. c.moveTo(0, h * 0.5);
  825. c.lineTo(dx2, h * 0.5);
  826. c.stroke();
  827. };
  828. mxCellRenderer.registerShape(mxShapeAndroidProgressBar.prototype.cst.PROGRESS_BAR, mxShapeAndroidProgressBar);
  829. mxShapeAndroidProgressBar.prototype.constraints = null;
  830. Graph.handleFactory[mxShapeAndroidProgressBar.prototype.cst.PROGRESS_BAR] = function(state)
  831. {
  832. var handles = [Graph.createHandle(state, ['dx1'], function(bounds)
  833. {
  834. var dx1 = Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.state.style, 'dx1', this.dx1))));
  835. return new mxPoint(bounds.x + dx1 * bounds.width, bounds.y + bounds.height / 2);
  836. }, function(bounds, pt)
  837. {
  838. this.state.style['dx1'] = Math.round(100 * Math.max(0, Math.min(1, (pt.x - bounds.x) / bounds.width))) / 100;
  839. })];
  840. var handle2 = Graph.createHandle(state, ['dx2'], function(bounds)
  841. {
  842. var dx2 = Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.state.style, 'dx2', this.dx1))));
  843. return new mxPoint(bounds.x + dx2 * bounds.width, bounds.y + bounds.height / 2);
  844. }, function(bounds, pt)
  845. {
  846. this.state.style['dx2'] = Math.round(100 * Math.max(0, Math.min(1, (pt.x - bounds.x) / bounds.width))) / 100;
  847. });
  848. handles.push(handle2);
  849. return handles;
  850. }
  851. //**********************************************************************************************************************************************************
  852. //Progress Scrubber Disabled
  853. //**********************************************************************************************************************************************************
  854. /**
  855. * Extends mxShape.
  856. */
  857. function mxShapeAndroidProgressScrubberDisabled(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. this.dx = 0.3;
  865. };
  866. /**
  867. * Extends mxShape.
  868. */
  869. mxUtils.extend(mxShapeAndroidProgressScrubberDisabled, mxShape);
  870. mxShapeAndroidProgressScrubberDisabled.prototype.customProperties = [
  871. {name: 'strokeColor2', dispName: 'Stroke Color 2', type: 'color', defVal:"#444444", primary: true},
  872. {name: 'dx', dispName: 'Handle Position', type: 'float', min:0, max:1, defVal:0.3}
  873. ];
  874. mxShapeAndroidProgressScrubberDisabled.prototype.cst = {
  875. PROGRESS_SCRUBBER_DISABLED : 'mxgraph.android.progressScrubberDisabled'
  876. };
  877. /**
  878. * Function: paintVertexShape
  879. *
  880. * Paints the vertex shape.
  881. */
  882. mxShapeAndroidProgressScrubberDisabled.prototype.paintVertexShape = function(c, x, y, w, h)
  883. {
  884. var dx = w * Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'dx', this.dx))));
  885. var strokeColor2 = mxUtils.getValue(this.style, 'strokeColor2', '#444444');
  886. c.translate(x, y);
  887. c.save();
  888. c.save();
  889. c.setStrokeColor(strokeColor2);
  890. c.begin();
  891. c.moveTo(0, h * 0.5);
  892. c.lineTo(w, h * 0.5);
  893. c.stroke();
  894. c.restore();
  895. c.setShadow(false);
  896. c.setAlpha('0.5');
  897. c.setFillColor('#666666');
  898. c.begin();
  899. var r = Math.min(h, w * 0.1) / 2;
  900. c.ellipse(dx - r, h * 0.5 - r, 2 * r, 2 * r);
  901. c.fill();
  902. c.restore();
  903. c.setShadow(false);
  904. c.begin();
  905. var r = Math.min(h, w * 0.1) / 8;
  906. c.ellipse(dx - r, h * 0.5 - r, 2 * r, 2 * r);
  907. c.fill();
  908. };
  909. mxCellRenderer.registerShape(mxShapeAndroidProgressScrubberDisabled.prototype.cst.PROGRESS_SCRUBBER_DISABLED, mxShapeAndroidProgressScrubberDisabled);
  910. mxShapeAndroidProgressScrubberDisabled.prototype.constraints = null;
  911. Graph.handleFactory[mxShapeAndroidProgressScrubberDisabled.prototype.cst.PROGRESS_SCRUBBER_DISABLED] = function(state)
  912. {
  913. var handles = [Graph.createHandle(state, ['dx'], function(bounds)
  914. {
  915. var dx = Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.state.style, 'dx', this.dx))));
  916. return new mxPoint(bounds.x + dx * bounds.width, bounds.y + bounds.height / 2);
  917. }, function(bounds, pt)
  918. {
  919. this.state.style['dx'] = Math.round(100 * Math.max(0, Math.min(1, (pt.x - bounds.x) / bounds.width))) / 100;
  920. })];
  921. return handles;
  922. }
  923. //**********************************************************************************************************************************************************
  924. //Progress Scrubber Focused
  925. //**********************************************************************************************************************************************************
  926. /**
  927. * Extends mxShape.
  928. */
  929. function mxShapeAndroidProgressScrubberFocused(bounds, fill, stroke, strokewidth)
  930. {
  931. mxShape.call(this);
  932. this.bounds = bounds;
  933. this.fill = fill;
  934. this.stroke = stroke;
  935. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  936. this.dx = 0.3;
  937. };
  938. /**
  939. * Extends mxShape.
  940. */
  941. mxUtils.extend(mxShapeAndroidProgressScrubberFocused, mxShape);
  942. mxShapeAndroidProgressScrubberFocused.prototype.customProperties = [
  943. {name: 'strokeColor2', dispName: 'Stroke Color 2', type: 'color', defVal:"#444444", primary: true},
  944. {name: 'dx', dispName: 'Handle Position', type: 'float', min:0, max:1, defVal:0.3}
  945. ];
  946. mxShapeAndroidProgressScrubberFocused.prototype.cst = {
  947. PROGRESS_SCRUBBER_FOCUSED : 'mxgraph.android.progressScrubberFocused'
  948. };
  949. /**
  950. * Function: paintVertexShape
  951. *
  952. * Paints the vertex shape.
  953. */
  954. mxShapeAndroidProgressScrubberFocused.prototype.paintVertexShape = function(c, x, y, w, h)
  955. {
  956. var dx = w * Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'dx', this.dx))));
  957. var fillColor = mxUtils.getValue(this.style, 'fillColor', '#ffffff');
  958. var strokeColor2 = mxUtils.getValue(this.style, 'strokeColor2', '#444444');
  959. c.translate(x, y);
  960. c.save();
  961. c.save();
  962. c.setStrokeColor(strokeColor2);
  963. c.begin();
  964. c.moveTo(0, h * 0.5);
  965. c.lineTo(w, h * 0.5);
  966. c.stroke();
  967. c.restore();
  968. c.setShadow(false);
  969. c.setAlpha('0.75');
  970. c.begin();
  971. var r = Math.min(h, w * 0.1) / 2;
  972. c.ellipse(dx - r, h * 0.5 - r, 2 * r, 2 * r);
  973. c.fill();
  974. c.restore();
  975. c.setShadow(false);
  976. c.setStrokeColor(fillColor);
  977. c.begin();
  978. c.moveTo(0, h * 0.5);
  979. c.lineTo(dx, h * 0.5);
  980. c.stroke();
  981. c.begin();
  982. var r = Math.min(h, w * 0.1) / 8;
  983. c.ellipse(dx - r, h * 0.5 - r, 2 * r, 2 * r);
  984. c.fill();
  985. };
  986. mxCellRenderer.registerShape(mxShapeAndroidProgressScrubberFocused.prototype.cst.PROGRESS_SCRUBBER_FOCUSED, mxShapeAndroidProgressScrubberFocused);
  987. mxShapeAndroidProgressScrubberFocused.prototype.constraints = null;
  988. Graph.handleFactory[mxShapeAndroidProgressScrubberFocused.prototype.cst.PROGRESS_SCRUBBER_FOCUSED] = function(state)
  989. {
  990. var handles = [Graph.createHandle(state, ['dx'], function(bounds)
  991. {
  992. var dx = Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.state.style, 'dx', this.dx))));
  993. return new mxPoint(bounds.x + dx * bounds.width, bounds.y + bounds.height / 2);
  994. }, function(bounds, pt)
  995. {
  996. this.state.style['dx'] = Math.round(100 * Math.max(0, Math.min(1, (pt.x - bounds.x) / bounds.width))) / 100;
  997. })];
  998. return handles;
  999. }
  1000. //**********************************************************************************************************************************************************
  1001. //Progress Scrubber Pressed
  1002. //**********************************************************************************************************************************************************
  1003. /**
  1004. * Extends mxShape.
  1005. */
  1006. function mxShapeAndroidProgressScrubberPressed(bounds, fill, stroke, strokewidth)
  1007. {
  1008. mxShape.call(this);
  1009. this.bounds = bounds;
  1010. this.fill = fill;
  1011. this.stroke = stroke;
  1012. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  1013. this.dx = 0.3;
  1014. };
  1015. /**
  1016. * Extends mxShape.
  1017. */
  1018. mxUtils.extend(mxShapeAndroidProgressScrubberPressed, mxShape);
  1019. mxShapeAndroidProgressScrubberPressed.prototype.customProperties = [
  1020. {name: 'strokeColor2', dispName: 'Stroke Color 2', type: 'color', defVal:"#444444", primary: true},
  1021. {name: 'dx', dispName: 'Handle Position', type: 'float', min:0, max:1, defVal:0.3}
  1022. ];
  1023. mxShapeAndroidProgressScrubberPressed.prototype.cst = {
  1024. PROGRESS_SCRUBBER_PRESSED : 'mxgraph.android.progressScrubberPressed'
  1025. };
  1026. /**
  1027. * Function: paintVertexShape
  1028. *
  1029. * Paints the vertex shape.
  1030. */
  1031. mxShapeAndroidProgressScrubberPressed.prototype.paintVertexShape = function(c, x, y, w, h)
  1032. {
  1033. var dx = w * Math.max(0, Math.min(w, parseFloat(mxUtils.getValue(this.style, 'dx', this.dx))));
  1034. var fillColor = mxUtils.getValue(this.style, 'fillColor', '#ffffff');
  1035. var strokeColor2 = mxUtils.getValue(this.style, 'strokeColor2', '#444444');
  1036. c.translate(x, y);
  1037. c.save();
  1038. c.save();
  1039. c.setStrokeColor(strokeColor2);
  1040. c.begin();
  1041. c.moveTo(0, h * 0.5);
  1042. c.lineTo(w, h * 0.5);
  1043. c.stroke();
  1044. c.restore();
  1045. c.setShadow(false);
  1046. c.setStrokeColor(fillColor);
  1047. c.setAlpha('0.5');
  1048. c.begin();
  1049. var r = Math.min(h, w * 0.1) / 2;
  1050. c.ellipse(dx - r, h * 0.5 - r, 2 * r, 2 * r);
  1051. c.fillAndStroke();
  1052. c.restore();
  1053. c.setShadow(false);
  1054. c.setStrokeColor(fillColor);
  1055. c.begin();
  1056. c.moveTo(0, h * 0.5);
  1057. c.lineTo(dx, h * 0.5);
  1058. c.stroke();
  1059. c.begin();
  1060. var r = Math.min(h, w * 0.1) / 8;
  1061. c.ellipse(dx - r, h * 0.5 - r, 2 * r, 2 * r);
  1062. c.fill();
  1063. };
  1064. mxCellRenderer.registerShape(mxShapeAndroidProgressScrubberPressed.prototype.cst.PROGRESS_SCRUBBER_PRESSED, mxShapeAndroidProgressScrubberPressed);
  1065. mxShapeAndroidProgressScrubberPressed.prototype.constraints = null;
  1066. Graph.handleFactory[mxShapeAndroidProgressScrubberPressed.prototype.cst.PROGRESS_SCRUBBER_PRESSED] = function(state)
  1067. {
  1068. var handles = [Graph.createHandle(state, ['dx'], function(bounds)
  1069. {
  1070. var dx = Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.state.style, 'dx', this.dx))));
  1071. return new mxPoint(bounds.x + dx * bounds.width, bounds.y + bounds.height / 2);
  1072. }, function(bounds, pt)
  1073. {
  1074. this.state.style['dx'] = Math.round(100 * Math.max(0, Math.min(1, (pt.x - bounds.x) / bounds.width))) / 100;
  1075. })];
  1076. return handles;
  1077. }
  1078. //**********************************************************************************************************************************************************
  1079. //Quickscroll2
  1080. //**********************************************************************************************************************************************************
  1081. /**
  1082. * Extends mxShape.
  1083. */
  1084. function mxShapeAndroidQuickscroll2(bounds, fill, stroke, strokewidth)
  1085. {
  1086. mxShape.call(this);
  1087. this.bounds = bounds;
  1088. this.fill = fill;
  1089. this.stroke = stroke;
  1090. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  1091. this.dy = 0.5;
  1092. };
  1093. /**
  1094. * Extends mxShape.
  1095. */
  1096. mxUtils.extend(mxShapeAndroidQuickscroll2, mxShape);
  1097. mxShapeAndroidQuickscroll2.prototype.customProperties = [
  1098. {name: 'fillColor2', dispName: 'Fill Color 2', type: 'color', defVal:"#cccccc", primary: true},
  1099. {name: 'fillColor3', dispName: 'Fill Color 3', type: 'color', defVal:"#666666", primary: true},
  1100. {name: 'dy', dispName: 'Handle Position', type: 'float', min:0, max:1, defVal:0.5}
  1101. ];
  1102. mxShapeAndroidQuickscroll2.prototype.cst = {
  1103. QUICKSCROLL : 'mxgraph.android.quickscroll2'
  1104. };
  1105. /**
  1106. * Function: paintVertexShape
  1107. *
  1108. * Paints the vertex shape.
  1109. */
  1110. mxShapeAndroidQuickscroll2.prototype.paintVertexShape = function(c, x, y, w, h)
  1111. {
  1112. var dy = Math.min(h - 20, Math.max(20, h * Math.max(0, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'dy', this.dy))))));
  1113. var fillColor = mxUtils.getValue(this.style, 'fillColor', '#ffffff');
  1114. var fillColor2 = mxUtils.getValue(this.style, 'fillColor2', '#cccccc');
  1115. var fillColor3 = mxUtils.getValue(this.style, 'fillColor3', '#666666');
  1116. c.translate(x, y);
  1117. c.save();
  1118. c.save();
  1119. c.setStrokeColor(fillColor2);
  1120. c.begin();
  1121. c.moveTo(w - 3, 0);
  1122. c.lineTo(w - 3, h);
  1123. c.stroke();
  1124. c.restore();
  1125. c.begin();
  1126. c.roundrect(w - 6, dy - 10, 6, 20, 1, 1);
  1127. c.fillAndStroke();
  1128. c.setFillColor(fillColor2);
  1129. c.begin();
  1130. c.rect(0, dy - 20, w - 18, 40);
  1131. c.fill();
  1132. c.setFillColor(fillColor3);
  1133. c.begin();
  1134. c.moveTo(w - 18, dy - 20);
  1135. c.lineTo(w - 6, dy);
  1136. c.lineTo(w - 18, dy + 20);
  1137. c.close();
  1138. c.fill();
  1139. c.setFontSize('12');
  1140. c.text((w - 18) * 0.5, dy, 0, 0, 'Aa', mxConstants.ALIGN_CENTER, mxConstants.ALIGN_MIDDLE, 0, null, 0, 0, 0);
  1141. };
  1142. mxCellRenderer.registerShape(mxShapeAndroidQuickscroll2.prototype.cst.QUICKSCROLL, mxShapeAndroidQuickscroll2);
  1143. mxShapeAndroidQuickscroll2.prototype.constraints = null;
  1144. Graph.handleFactory[mxShapeAndroidQuickscroll2.prototype.cst.QUICKSCROLL] = function(state)
  1145. {
  1146. var handles = [Graph.createHandle(state, ['dy'], function(bounds)
  1147. {
  1148. var dy = Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.state.style, 'dy', this.dy))));
  1149. return new mxPoint(bounds.x + bounds.width - 3, bounds.y + Math.min(bounds.height - 20, Math.max(20, dy * bounds.height)));
  1150. }, function(bounds, pt)
  1151. {
  1152. this.state.style['dy'] = Math.round(1000 * Math.max(0, Math.min(1, (pt.y - bounds.y) / bounds.height))) / 1000;
  1153. })];
  1154. return handles;
  1155. }
  1156. //**********************************************************************************************************************************************************
  1157. //Quickscroll3
  1158. //**********************************************************************************************************************************************************
  1159. /**
  1160. * Extends mxShape.
  1161. */
  1162. function mxShapeAndroidQuickscroll3(bounds, fill, stroke, strokewidth)
  1163. {
  1164. mxShape.call(this);
  1165. this.bounds = bounds;
  1166. this.fill = fill;
  1167. this.stroke = stroke;
  1168. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  1169. this.dy = 0.5;
  1170. };
  1171. /**
  1172. * Extends mxShape.
  1173. */
  1174. mxUtils.extend(mxShapeAndroidQuickscroll3, mxShape);
  1175. mxShapeAndroidQuickscroll3.prototype.customProperties = [
  1176. {name: 'fillColor2', dispName: 'Fill Color 2', type: 'color', defVal:"#cccccc", primary: true},
  1177. {name: 'dy', dispName: 'Handle Position', type: 'float', min:0, max:1, defVal:0.5}
  1178. ];
  1179. mxShapeAndroidQuickscroll3.prototype.cst = {
  1180. QUICKSCROLL : 'mxgraph.android.quickscroll3'
  1181. };
  1182. /**
  1183. * Function: paintVertexShape
  1184. *
  1185. * Paints the vertex shape.
  1186. */
  1187. mxShapeAndroidQuickscroll3.prototype.paintVertexShape = function(c, x, y, w, h)
  1188. {
  1189. var dy = Math.min(h - 10, Math.max(10, h * Math.max(0, Math.min(h, parseFloat(mxUtils.getValue(this.style, 'dy', this.dy))))));
  1190. var fillColor = mxUtils.getValue(this.style, 'fillColor', '#ffffff');
  1191. var fillColor2 = mxUtils.getValue(this.style, 'fillColor2', '#cccccc');
  1192. c.translate(x, y);
  1193. c.save();
  1194. c.setStrokeColor(fillColor2);
  1195. c.begin();
  1196. c.moveTo(w * 0.5, 0);
  1197. c.lineTo(w * 0.5, h);
  1198. c.stroke();
  1199. c.restore();
  1200. c.begin();
  1201. c.roundrect(w * 0.5 - 3, dy - 10, 6, 20, 1, 1);
  1202. c.fillAndStroke();
  1203. };
  1204. mxCellRenderer.registerShape(mxShapeAndroidQuickscroll3.prototype.cst.QUICKSCROLL, mxShapeAndroidQuickscroll3);
  1205. mxShapeAndroidQuickscroll3.prototype.constraints = null;
  1206. Graph.handleFactory[mxShapeAndroidQuickscroll3.prototype.cst.QUICKSCROLL] = function(state)
  1207. {
  1208. var handles = [Graph.createHandle(state, ['dy'], function(bounds)
  1209. {
  1210. var dy = Math.max(0, Math.min(1, parseFloat(mxUtils.getValue(this.state.style, 'dy', this.dy))));
  1211. return new mxPoint(bounds.x + bounds.width * 0.5, bounds.y + Math.min(bounds.height - 10, Math.max(10, dy * bounds.height)));
  1212. }, function(bounds, pt)
  1213. {
  1214. this.state.style['dy'] = Math.round(1000 * Math.max(0, Math.min(1, (pt.y - bounds.y) / bounds.height))) / 1000;
  1215. })];
  1216. return handles;
  1217. }
  1218. //**********************************************************************************************************************************************************
  1219. //Scrollbars
  1220. //**********************************************************************************************************************************************************
  1221. /**
  1222. * Extends mxShape.
  1223. */
  1224. function mxShapeAndroidScrollbars2(bounds, fill, stroke, strokewidth)
  1225. {
  1226. mxShape.call(this);
  1227. this.bounds = bounds;
  1228. this.fill = fill;
  1229. this.stroke = stroke;
  1230. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  1231. };
  1232. /**
  1233. * Extends mxShape.
  1234. */
  1235. mxUtils.extend(mxShapeAndroidScrollbars2, mxShape);
  1236. mxShapeAndroidScrollbars2.prototype.cst = {
  1237. SCROLLBARS : 'mxgraph.android.scrollbars2'
  1238. };
  1239. /**
  1240. * Function: paintVertexShape
  1241. *
  1242. * Paints the vertex shape.
  1243. */
  1244. mxShapeAndroidScrollbars2.prototype.paintVertexShape = function(c, x, y, w, h)
  1245. {
  1246. c.translate(x, y);
  1247. c.begin();
  1248. c.rect(w - 5, 0, 5, h - 7);
  1249. c.fillAndStroke();
  1250. c.begin();
  1251. c.rect(0, h - 5, w - 7, 5);
  1252. c.fillAndStroke();
  1253. };
  1254. mxCellRenderer.registerShape(mxShapeAndroidScrollbars2.prototype.cst.SCROLLBARS, mxShapeAndroidScrollbars2);
  1255. mxShapeAndroidScrollbars2.prototype.constraints = null;
  1256. //**********************************************************************************************************************************************************
  1257. //Spinner
  1258. //**********************************************************************************************************************************************************
  1259. /**
  1260. * Extends mxShape.
  1261. */
  1262. function mxShapeAndroidSpinner2(bounds, fill, stroke, strokewidth)
  1263. {
  1264. mxShape.call(this);
  1265. this.bounds = bounds;
  1266. this.fill = fill;
  1267. this.stroke = stroke;
  1268. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  1269. };
  1270. /**
  1271. * Extends mxShape.
  1272. */
  1273. mxUtils.extend(mxShapeAndroidSpinner2, mxShape);
  1274. mxShapeAndroidSpinner2.prototype.cst = {
  1275. SPINNER : 'mxgraph.android.spinner2'
  1276. };
  1277. /**
  1278. * Function: paintVertexShape
  1279. *
  1280. * Paints the vertex shape.
  1281. */
  1282. mxShapeAndroidSpinner2.prototype.paintVertexShape = function(c, x, y, w, h)
  1283. {
  1284. c.translate(x, y);
  1285. c.begin();
  1286. c.moveTo(0, h);
  1287. c.lineTo(w, h);
  1288. c.stroke();
  1289. var s = Math.min(w / 10, h)
  1290. c.begin();
  1291. c.moveTo(w - s, h);
  1292. c.lineTo(w, h - s);
  1293. c.lineTo(w, h);
  1294. c.close();
  1295. c.fillAndStroke();
  1296. };
  1297. mxCellRenderer.registerShape(mxShapeAndroidSpinner2.prototype.cst.SPINNER, mxShapeAndroidSpinner2);
  1298. mxShapeAndroidSpinner2.prototype.constraints = null;