This project has retired. For details please refer to its Attic page.
ColorPicker xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.chukwa.hicc;
20  
21  
22  public class ColorPicker {
23    private String color = "#ff5757";
24    private int index = 0;
25  
26    public ColorPicker() {
27      color = "#ff5757";
28    }
29  
30    public String get(int counter) {
31      if ((counter % 6) == 0) {
32        String purple = Integer.toHexString(256 - (counter % 255));
33        color = "#" + purple + "57" + purple;
34      } else if ((counter % 5) == 0) {
35        String red = Integer.toHexString(256 - (counter % 255));
36        color = "#" + red +"5757";
37      } else if ((counter % 4) == 0) {
38        String yellow = Integer.toHexString(256 - (counter % 255 * 20));
39        color = "#FF" + yellow + "00";
40      } else if ((counter % 3) == 0) {
41        String green = Integer.toHexString(256 - (counter % 255));
42        color = "#57" + green + "57";
43      } else if ((counter % 2) == 0) {
44        String cyan = Integer.toHexString(256 - (counter % 255));
45        color = "#57" + cyan + cyan;
46      } else {
47        String blue = Integer.toHexString(256 - (counter % 255));
48        color = "#5757" + blue + "";
49      }
50      return this.color;
51    }
52  
53    public String getNext() {
54      index++;
55      return get(index);
56    }
57  }