KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > util > ColorHelper


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/util/ColorHelper.java,v 1.6 2004/02/13 02:21:37 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.util;
20
21 import java.awt.Color JavaDoc;
22
23 /**
24  * This class contains the static utility methods to manipulate colors.
25  *
26  * @author Khor Soon Hin
27  * Created 2001/08/13
28  * @version $Revision: 1.6 $ $Date: 2004/02/13 02:21:37 $
29  */

30 public final class ColorHelper
31 {
32     /**
33      * Private constructor to prevent instantiation.
34      */

35     private ColorHelper()
36     {
37     }
38
39     /**
40      * Given the <code>Color</code>, get the red, green and blue components.
41      * Increment the lowest of the components by the indicated increment value.
42      * If all the components are the same value increment in the order of
43      * red, green and blue.
44      *
45      * @param inc value to increment the color components
46      * @return the color after change
47      */

48     public static Color JavaDoc changeColorCyclicIncrement(Color JavaDoc col, int inc)
49     {
50         int red = col.getRed();
51         int green = col.getGreen();
52         int blue = col.getBlue();
53         int temp1 = Math.min(red, green);
54         int temp2 = Math.min(temp1, blue);
55         // now temp2 has the lowest of the three components
56
if (red == temp2)
57         {
58             red += inc;
59             red %= 256;
60         }
61         else if (green == temp2)
62         {
63             green += inc;
64             green %= 256;
65         }
66         else if (blue == temp2)
67         {
68             blue += inc;
69             blue %= 256;
70         }
71         return new Color JavaDoc(red, green, blue);
72     }
73 }
74
Popular Tags