01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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;
22:
23: /**
24: * This class contains the static utility methods to manipulate colors.
25: *
26: * @author Khor Soon Hin Created 2001/08/13
27: * @version $Revision: 493779 $ $Date: 2007-01-07 17:46:38 +0000 (Sun, 07 Jan 2007) $
28: */
29: public final class ColorHelper {
30: /**
31: * Private constructor to prevent instantiation.
32: */
33: private ColorHelper() {
34: }
35:
36: /**
37: * Given the <code>Color</code>, get the red, green and blue components.
38: * Increment the lowest of the components by the indicated increment value.
39: * If all the components are the same value increment in the order of red,
40: * green and blue.
41: *
42: * @param inc
43: * value to increment the color components
44: * @return the color after change
45: */
46: public static Color changeColorCyclicIncrement(Color col, int inc) {
47: int red = col.getRed();
48: int green = col.getGreen();
49: int blue = col.getBlue();
50: int temp1 = Math.min(red, green);
51: int temp2 = Math.min(temp1, blue);
52: // now temp2 has the lowest of the three components
53: if (red == temp2) {
54: red += inc;
55: red %= 256;
56: } else if (green == temp2) {
57: green += inc;
58: green %= 256;
59: } else if (blue == temp2) {
60: blue += inc;
61: blue %= 256;
62: }
63: return new Color(red, green, blue);
64: }
65: }
|