01: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/framework/util/ColorUtils.java $
02: /*---------------- FILE HEADER ------------------------------------------
03:
04: This file is part of deegree.
05: Copyright (C) 2001-2008 by:
06: EXSE, Department of Geography, University of Bonn
07: http://www.giub.uni-bonn.de/deegree/
08: lat/lon GmbH
09: http://www.lat-lon.de
10:
11: This library is free software; you can redistribute it and/or
12: modify it under the terms of the GNU Lesser General Public
13: License as published by the Free Software Foundation; either
14: version 2.1 of the License, or (at your option) any later version.
15:
16: This library is distributed in the hope that it will be useful,
17: but WITHOUT ANY WARRANTY; without even the implied warranty of
18: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19: Lesser General Public License for more details.
20:
21: You should have received a copy of the GNU Lesser General Public
22: License along with this library; if not, write to the Free Software
23: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24:
25: Contact:
26:
27: Andreas Poth
28: lat/lon GmbH
29: Aennchenstr. 19
30: 53177 Bonn
31: Germany
32: E-Mail: poth@lat-lon.de
33:
34: Prof. Dr. Klaus Greve
35: Department of Geography
36: University of Bonn
37: Meckenheimer Allee 166
38: 53115 Bonn
39: Germany
40: E-Mail: greve@giub.uni-bonn.de
41:
42: ---------------------------------------------------------------------------*/
43: package org.deegree.framework.util;
44:
45: import java.awt.Color;
46:
47: /**
48: * offeres some methods for handling colors
49: *
50: *
51: * @version $Revision: 9339 $
52: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
53: * @author last edited by: $Author: apoth $
54: *
55: * @version 1.0. $Revision: 9339 $, $Date: 2007-12-27 04:31:52 -0800 (Thu, 27 Dec 2007) $
56: *
57: * @since 2.0
58: */
59: public class ColorUtils {
60:
61: /**
62: * returns a random color
63: *
64: * @param useTransparency
65: * @return a random color
66: */
67: public static Color getRandomColor(boolean useTransparency) {
68: float r = (float) Math.random();
69: float g = (float) Math.random();
70: float b = (float) Math.random();
71: float a = 0;
72: if (useTransparency) {
73: a = (float) Math.random() / 1.5f;
74: }
75: return new Color(r, g, b, a);
76: }
77:
78: /**
79: * transforms the color of the request from java.awt.Color to the hexadecimal representation as
80: * in an OGC conform WMS-GetMap request (e.g. white == "#ffffff").
81: *
82: * @return the color as hexadecimal representation
83: */
84: public static String toHexCode(String prefix, Color color) {
85: String r = Integer.toHexString(color.getRed());
86: if (r.length() < 2)
87: r = "0" + r;
88: String g = Integer.toHexString(color.getGreen());
89: if (g.length() < 2)
90: g = "0" + g;
91: String b = Integer.toHexString(color.getBlue());
92: if (b.length() < 2)
93: b = "0" + b;
94: return prefix + r + g + b;
95: }
96:
97: }
|