PageRenderTime 60ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/core/src/main/java/org/kabeja/common/Color.java

http://github.com/fuzziness/kabeja
Java | 304 lines | 277 code | 5 blank | 22 comment | 2 complexity | 124ce22c8a16a7efe00933a26edae24d MD5 | raw file
Possible License(s): Apache-2.0
  1. /*******************************************************************************
  2. * Copyright 2010 Simon Mieth
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. ******************************************************************************/
  16. package org.kabeja.common;
  17. /**
  18. * @author <a href="mailto:simon.mieth@gmx.de>Simon Mieth</a>
  19. * @author <a href="mailto:michele.franzin@gmail.com>Michele Franzin</a>
  20. *
  21. * taken from http://www.isctex.com/acadcolors.php
  22. */
  23. public class Color {
  24. private static final String[] rgbs = {
  25. /* 0 */"0,0,0",
  26. /* 1 */ "255,0,0",
  27. /* 2 */ "255,255,0",
  28. /* 3 */ "0,255,0",
  29. /* 4 */ "0,255,255",
  30. /* 5 */ "0,0,255",
  31. /* 6 */ "255,0,255",
  32. /* 7 */ "255,255,255",
  33. /* 8 */ "65,65,65",
  34. /* 9 */ "128,128,128",
  35. /* 10 */ "255,0,0",
  36. /* 11 */ "255,170,170",
  37. /* 12 */ "189,0,0",
  38. /* 13 */ "189,126,126",
  39. /* 14 */ "129,0,0",
  40. /* 15 */ "129,86,86",
  41. /* 16 */ "104,0,0",
  42. /* 17 */ "104,69,69",
  43. /* 18 */ "79,0,0",
  44. /* 19 */ "79,53,53",
  45. /* 20 */ "255,63,0",
  46. /* 21 */ "255,191,170",
  47. /* 22 */ "189,46,0",
  48. /* 23 */ "189,141,126",
  49. /* 24 */ "129,31,0",
  50. /* 25 */ "129,96,86",
  51. /* 26 */ "104,25,0",
  52. /* 27 */ "104,78,69",
  53. /* 28 */ "79,19,0",
  54. /* 29 */ "79,59,53",
  55. /* 30 */ "255,127,0",
  56. /* 31 */ "255,212,170",
  57. /* 32 */ "189,94,0",
  58. /* 33 */ "189,157,126",
  59. /* 34 */ "129,64,0",
  60. /* 35 */ "129,107,86",
  61. /* 36 */ "104,52,0",
  62. /* 37 */ "104,86,69",
  63. /* 38 */ "79,39,0",
  64. /* 39 */ "79,66,53",
  65. /* 40 */ "255,191,0",
  66. /* 41 */ "255,234,170",
  67. /* 42 */ "189,141,0",
  68. /* 43 */ "189,173,126",
  69. /* 44 */ "129,96,0",
  70. /* 45 */ "129,118,86",
  71. /* 46 */ "104,78,0",
  72. /* 47 */ "104,95,69",
  73. /* 48 */ "79,59,0",
  74. /* 49 */ "79,73,53",
  75. /* 50 */ "255,255,0",
  76. /* 51 */ "255,255,170",
  77. /* 52 */ "189,189,0",
  78. /* 53 */ "189,189,126",
  79. /* 54 */ "129,129,0",
  80. /* 55 */ "129,129,86",
  81. /* 56 */ "104,104,0",
  82. /* 57 */ "104,104,69",
  83. /* 58 */ "79,79,0",
  84. /* 59 */ "79,79,53",
  85. /* 60 */ "191,255,0",
  86. /* 61 */ "234,255,170",
  87. /* 62 */ "141,189,0",
  88. /* 63 */ "173,189,126",
  89. /* 64 */ "96,129,0",
  90. /* 65 */ "118,129,86",
  91. /* 66 */ "78,104,0",
  92. /* 67 */ "95,104,69",
  93. /* 68 */ "59,79,0",
  94. /* 69 */ "73,79,53",
  95. /* 70 */ "127,255,0",
  96. /* 71 */ "212,255,170",
  97. /* 72 */ "94,189,0",
  98. /* 73 */ "157,189,126",
  99. /* 74 */ "64,129,0",
  100. /* 75 */ "107,129,86",
  101. /* 76 */ "52,104,0",
  102. /* 77 */ "86,104,69",
  103. /* 78 */ "39,79,0",
  104. /* 79 */ "66,79,53",
  105. /* 80 */ "63,255,0",
  106. /* 81 */ "191,255,170",
  107. /* 82 */ "46,189,0",
  108. /* 83 */ "141,189,126",
  109. /* 84 */ "31,129,0",
  110. /* 85 */ "96,129,86",
  111. /* 86 */ "25,104,0",
  112. /* 87 */ "78,104,69",
  113. /* 88 */ "19,79,0",
  114. /* 89 */ "59,79,53",
  115. /* 90 */ "0,255,0",
  116. /* 91 */ "170,255,170",
  117. /* 92 */ "0,189,0",
  118. /* 93 */ "126,189,126",
  119. /* 94 */ "0,129,0",
  120. /* 95 */ "86,129,86",
  121. /* 96 */ "0,104,0",
  122. /* 97 */ "69,104,69",
  123. /* 98 */ "0,79,0",
  124. /* 99 */ "53,79,53",
  125. /* 100 */ "0,255,63",
  126. /* 101 */ "170,255,191",
  127. /* 102 */ "0,189,46",
  128. /* 103 */ "126,189,141",
  129. /* 104 */ "0,129,31",
  130. /* 105 */ "86,129,96",
  131. /* 106 */ "0,104,25",
  132. /* 107 */ "69,104,78",
  133. /* 108 */ "0,79,19",
  134. /* 109 */ "53,79,59",
  135. /* 110 */ "0,255,127",
  136. /* 111 */ "170,255,212",
  137. /* 112 */ "0,189,94",
  138. /* 113 */ "126,189,157",
  139. /* 114 */ "0,129,64",
  140. /* 115 */ "86,129,107",
  141. /* 116 */ "0,104,52",
  142. /* 117 */ "69,104,86",
  143. /* 118 */ "0,79,39",
  144. /* 119 */ "53,79,66",
  145. /* 120 */ "0,255,191",
  146. /* 121 */ "170,255,234",
  147. /* 122 */ "0,189,141",
  148. /* 123 */ "126,189,173",
  149. /* 124 */ "0,129,96",
  150. /* 125 */ "86,129,118",
  151. /* 126 */ "0,104,78",
  152. /* 127 */ "69,104,95",
  153. /* 128 */ "0,79,59",
  154. /* 129 */ "53,79,73",
  155. /* 130 */ "0,255,255",
  156. /* 131 */ "170,255,255",
  157. /* 132 */ "0,189,189",
  158. /* 133 */ "126,189,189",
  159. /* 134 */ "0,129,129",
  160. /* 135 */ "86,129,129",
  161. /* 136 */ "0,104,104",
  162. /* 137 */ "69,104,104",
  163. /* 138 */ "0,79,79",
  164. /* 139 */ "53,79,79",
  165. /* 140 */ "0,191,255",
  166. /* 141 */ "170,234,255",
  167. /* 142 */ "0,141,189",
  168. /* 143 */ "126,173,189",
  169. /* 144 */ "0,96,129",
  170. /* 145 */ "86,118,129",
  171. /* 146 */ "0,78,104",
  172. /* 147 */ "69,95,104",
  173. /* 148 */ "0,59,79",
  174. /* 149 */ "53,73,79",
  175. /* 150 */ "0,127,255",
  176. /* 151 */ "170,212,255",
  177. /* 152 */ "0,94,189",
  178. /* 153 */ "126,157,189",
  179. /* 154 */ "0,64,129",
  180. /* 155 */ "86,107,129",
  181. /* 156 */ "0,52,104",
  182. /* 157 */ "69,86,104",
  183. /* 158 */ "0,39,79",
  184. /* 159 */ "53,66,79",
  185. /* 160 */ "0,63,255",
  186. /* 161 */ "170,191,255",
  187. /* 162 */ "0,46,189",
  188. /* 163 */ "126,141,189",
  189. /* 164 */ "0,31,129",
  190. /* 165 */ "86,96,129",
  191. /* 166 */ "0,25,104",
  192. /* 167 */ "69,78,104",
  193. /* 168 */ "0,19,79",
  194. /* 169 */ "53,59,79",
  195. /* 170 */ "0,0,255",
  196. /* 171 */ "170,170,255",
  197. /* 172 */ "0,0,189",
  198. /* 173 */ "126,126,189",
  199. /* 174 */ "0,0,129",
  200. /* 175 */ "86,86,129",
  201. /* 176 */ "0,0,104",
  202. /* 177 */ "69,69,104",
  203. /* 178 */ "0,0,79",
  204. /* 179 */ "53,53,79",
  205. /* 180 */ "63,0,255",
  206. /* 181 */ "191,170,255",
  207. /* 182 */ "46,0,189",
  208. /* 183 */ "141,126,189",
  209. /* 184 */ "31,0,129",
  210. /* 185 */ "96,86,129",
  211. /* 186 */ "25,0,104",
  212. /* 187 */ "78,69,104",
  213. /* 188 */ "19,0,79",
  214. /* 189 */ "59,53,79",
  215. /* 190 */ "127,0,255",
  216. /* 191 */ "212,170,255",
  217. /* 192 */ "94,0,189",
  218. /* 193 */ "157,126,189",
  219. /* 194 */ "64,0,129",
  220. /* 195 */ "107,86,129",
  221. /* 196 */ "52,0,104",
  222. /* 197 */ "86,69,104",
  223. /* 198 */ "39,0,79",
  224. /* 199 */ "66,53,79",
  225. /* 200 */ "191,0,255",
  226. /* 201 */ "234,170,255",
  227. /* 202 */ "141,0,189",
  228. /* 203 */ "173,126,189",
  229. /* 204 */ "96,0,129",
  230. /* 205 */ "118,86,129",
  231. /* 206 */ "78,0,104",
  232. /* 207 */ "95,69,104",
  233. /* 208 */ "59,0,79",
  234. /* 209 */ "73,53,79",
  235. /* 210 */ "255,0,255",
  236. /* 211 */ "255,170,255",
  237. /* 212 */ "189,0,189",
  238. /* 213 */ "189,126,189",
  239. /* 214 */ "129,0,129",
  240. /* 215 */ "129,86,129",
  241. /* 216 */ "104,0,104",
  242. /* 217 */ "104,69,104",
  243. /* 218 */ "79,0,79",
  244. /* 219 */ "79,53,79",
  245. /* 220 */ "255,0,191",
  246. /* 221 */ "255,170,234",
  247. /* 222 */ "189,0,141",
  248. /* 223 */ "189,126,173",
  249. /* 224 */ "129,0,96",
  250. /* 225 */ "129,86,118",
  251. /* 226 */ "104,0,78",
  252. /* 227 */ "104,69,95",
  253. /* 228 */ "79,0,59",
  254. /* 229 */ "79,53,73",
  255. /* 230 */ "255,0,127",
  256. /* 231 */ "255,170,212",
  257. /* 232 */ "189,0,94",
  258. /* 233 */ "189,126,157",
  259. /* 234 */ "129,0,64",
  260. /* 235 */ "129,86,107",
  261. /* 236 */ "104,0,52",
  262. /* 237 */ "104,69,86",
  263. /* 238 */ "79,0,39",
  264. /* 239 */ "79,53,66",
  265. /* 240 */ "255,0,63",
  266. /* 241 */ "255,170,191",
  267. /* 242 */ "189,0,46",
  268. /* 243 */ "189,126,141",
  269. /* 244 */ "129,0,31",
  270. /* 245 */ "129,86,96",
  271. /* 246 */ "104,0,25",
  272. /* 247 */ "104,69,78",
  273. /* 248 */ "79,0,19",
  274. /* 249 */ "79,53,59",
  275. /* 250 */ "51,51,51",
  276. /* 251 */ "80,80,80",
  277. /* 252 */ "105,105,105",
  278. /* 253 */ "130,130,130",
  279. /* 254 */ "190,190,190",
  280. /* 255 */ "255,255,255"
  281. };
  282. public static String getRGBString(int dxfColorCode) {
  283. if ((dxfColorCode < 0) || (dxfColorCode > rgbs.length)) {
  284. // default is white
  285. dxfColorCode = 7;
  286. }
  287. return "rgb(" + rgbs[dxfColorCode] + ")";
  288. }
  289. public static String getRGBString(byte[] b) {
  290. StringBuilder buf = new StringBuilder("rgb(");
  291. buf.append((int) b[0]);
  292. buf.append(",");
  293. buf.append((int) b[1]);
  294. buf.append(",");
  295. buf.append((int) b[2]);
  296. buf.append(")");
  297. return buf.toString();
  298. }
  299. }