23 |
23 |
/*
|
24 |
24 |
* AUTHORS (In addition to CIT):
|
25 |
25 |
* 2009 {DiSiD Technologies} {{Task}}
|
|
26 |
*
|
|
27 |
**************************************************************
|
|
28 |
* Colors from www.ColorBrewer.org by Cynthia A. Brewer,
|
|
29 |
* Geography, Pennsylvania State University.
|
|
30 |
* Using groups of 4 colors from the 9 Diverging Schemes
|
|
31 |
* 4 * 9 = 36 colors
|
|
32 |
**************************************************************
|
|
33 |
*
|
26 |
34 |
*/
|
27 |
35 |
package org.gvsig.fmap.mapcontext.rendering.symbols.impl;
|
28 |
36 |
|
... | ... | |
286 |
294 |
symbolClass, symbolName, e);
|
287 |
295 |
}
|
288 |
296 |
|
289 |
|
Color symbolColor;
|
|
297 |
Color the_color = null;
|
|
298 |
|
290 |
299 |
if (getSymbolPreferences().isDefaultSymbolFillColorAleatory()) {
|
291 |
|
Random rand = new Random();
|
292 |
|
int numreg = rand.nextInt(255 / 2);
|
293 |
|
double div = (1 - rand.nextDouble() * 0.66) * 0.9;
|
294 |
|
symbolColor =
|
295 |
|
new Color(
|
296 |
|
((int) (255 * div + (numreg * rand.nextDouble()))) % 255,
|
297 |
|
((int) (255 * div + (numreg * rand.nextDouble()))) % 255,
|
298 |
|
((int) (255 * div + (numreg * rand.nextDouble()))) % 255);
|
|
300 |
|
|
301 |
the_color = brewerBasedColor();
|
|
302 |
|
|
303 |
} else {
|
|
304 |
// not random
|
|
305 |
the_color = getSymbolPreferences().getDefaultSymbolFillColor();
|
299 |
306 |
}
|
300 |
|
else {
|
301 |
|
symbolColor = getSymbolPreferences().getDefaultSymbolFillColor();
|
302 |
|
}
|
303 |
|
symbol.setColor(symbolColor);
|
|
307 |
symbol.setColor(the_color);
|
304 |
308 |
// Perform this initialization into the Symbol implementation
|
305 |
309 |
// if (symbol instanceof CartographicSupport) {
|
306 |
310 |
// CartographicSupport cs = (CartographicSupport) symbol;
|
... | ... | |
315 |
319 |
public void setSymbolPreferences(SymbolPreferences symbolPreferences) {
|
316 |
320 |
this.symbolPreferences = symbolPreferences;
|
317 |
321 |
}
|
|
322 |
|
|
323 |
/**
|
|
324 |
*
|
|
325 |
* @param col
|
|
326 |
* @return color 1/3 closer to black
|
|
327 |
*/
|
|
328 |
public static Color darker(Color col) {
|
|
329 |
return new Color(
|
|
330 |
(2 * col.getRed()) / 3,
|
|
331 |
(2 * col.getGreen()) / 3,
|
|
332 |
(2 * col.getBlue()) / 3,
|
|
333 |
col.getAlpha());
|
|
334 |
}
|
|
335 |
|
|
336 |
/**
|
|
337 |
*
|
|
338 |
* @param col
|
|
339 |
* @return color 1/3 closer to white
|
|
340 |
*/
|
|
341 |
public static Color lighter(Color col) {
|
|
342 |
Color resp = invert(col);
|
|
343 |
resp = darker(resp);
|
|
344 |
return invert(resp);
|
|
345 |
}
|
|
346 |
|
|
347 |
/**
|
|
348 |
*
|
|
349 |
* @param col
|
|
350 |
* @return inverted color (inverts each band, same alpha)
|
|
351 |
*/
|
|
352 |
public static Color invert(Color col) {
|
|
353 |
return new Color(
|
|
354 |
255 - col.getRed(),
|
|
355 |
255 - col.getGreen(),
|
|
356 |
255 - col.getBlue(),
|
|
357 |
col.getAlpha());
|
|
358 |
}
|
|
359 |
|
|
360 |
private static Color brewerBasedColor() {
|
|
361 |
|
|
362 |
int ind = rnd.nextInt(BREWER_COLOR.length);
|
|
363 |
Color base = BREWER_COLOR[ind];
|
|
364 |
ind = rnd.nextInt(100);
|
|
365 |
if (ind > 66) {
|
|
366 |
return darker(base);
|
|
367 |
} else {
|
|
368 |
if (ind > 33) {
|
|
369 |
return lighter(base);
|
|
370 |
} else {
|
|
371 |
return base;
|
|
372 |
}
|
|
373 |
}
|
|
374 |
}
|
|
375 |
|
|
376 |
private static Color[] BREWER_COLOR = new Color[36];
|
|
377 |
private static final Random rnd = new Random();
|
|
378 |
|
|
379 |
static {
|
|
380 |
/**
|
|
381 |
* Colors from www.ColorBrewer.org by Cynthia A. Brewer,
|
|
382 |
* Geography, Pennsylvania State University.
|
|
383 |
*
|
|
384 |
* Using groups of 4 colors from the 9 Diverging Schemes
|
|
385 |
* 4 * 9 = 36 colors
|
|
386 |
*/
|
|
387 |
BREWER_COLOR[0] = new Color(230, 97, 1);
|
|
388 |
BREWER_COLOR[1] = new Color(253, 184, 99);
|
|
389 |
BREWER_COLOR[2] = new Color(178, 171, 210);
|
|
390 |
BREWER_COLOR[3] = new Color(94, 60, 153);
|
|
391 |
BREWER_COLOR[4] = new Color(166, 97, 26);
|
|
392 |
BREWER_COLOR[5] = new Color(223, 194, 125);
|
|
393 |
BREWER_COLOR[6] = new Color(128, 205, 193);
|
|
394 |
BREWER_COLOR[7] = new Color(1, 133, 113);
|
|
395 |
BREWER_COLOR[8] = new Color(123, 50, 148);
|
|
396 |
BREWER_COLOR[9] = new Color(194, 165, 207);
|
|
397 |
BREWER_COLOR[10] = new Color(166, 219, 160);
|
|
398 |
BREWER_COLOR[11] = new Color(0, 136, 55);
|
|
399 |
BREWER_COLOR[12] = new Color(208, 28, 139);
|
|
400 |
BREWER_COLOR[13] = new Color(241, 182, 218);
|
|
401 |
BREWER_COLOR[14] = new Color(184, 225, 134);
|
|
402 |
BREWER_COLOR[15] = new Color(77, 172, 38);
|
|
403 |
BREWER_COLOR[16] = new Color(202, 0, 32);
|
|
404 |
BREWER_COLOR[17] = new Color(244, 165, 130);
|
|
405 |
BREWER_COLOR[18] = new Color(146, 197, 222);
|
|
406 |
BREWER_COLOR[19] = new Color(5, 113, 176);
|
|
407 |
BREWER_COLOR[20] = new Color(202, 0, 32);
|
|
408 |
BREWER_COLOR[21] = new Color(244, 165, 130);
|
|
409 |
BREWER_COLOR[22] = new Color(186, 186, 186);
|
|
410 |
BREWER_COLOR[23] = new Color(64, 64, 64);
|
|
411 |
BREWER_COLOR[24] = new Color(215, 25, 28);
|
|
412 |
BREWER_COLOR[25] = new Color(253, 174, 97);
|
|
413 |
BREWER_COLOR[26] = new Color(171, 217, 233);
|
|
414 |
BREWER_COLOR[27] = new Color(44, 123, 182);
|
|
415 |
BREWER_COLOR[28] = new Color(215, 25, 28);
|
|
416 |
BREWER_COLOR[29] = new Color(253, 174, 97);
|
|
417 |
BREWER_COLOR[30] = new Color(171, 221, 164);
|
|
418 |
BREWER_COLOR[31] = new Color(43, 131, 186);
|
|
419 |
BREWER_COLOR[32] = new Color(215, 25, 28);
|
|
420 |
BREWER_COLOR[33] = new Color(253, 174, 97);
|
|
421 |
BREWER_COLOR[34] = new Color(166, 217, 106);
|
|
422 |
BREWER_COLOR[35] = new Color(26, 150, 65);
|
|
423 |
}
|
|
424 |
|
|
425 |
|
318 |
426 |
}
|