KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > console > lib > gui > GraphColorChooser


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2003,2004 France Telecom R&D
4 * Copyright (C) 2003 INRIA
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * CLIF $Name: $
21 *
22 * Contact: clif@objectweb.org
23 */

24
25 package org.objectweb.clif.console.lib.gui;
26
27 import java.awt.Color JavaDoc;
28 import java.util.Vector JavaDoc;
29
30 /**
31  * This class handles colors for the graphics. It provide a new color available
32  * within a defined list of colors.
33  * @author Julien Buret
34  * @author Nicolas Droze
35  * @author Bruno Dillenseger
36  */

37 public class GraphColorChooser
38 {
39     private Vector JavaDoc colors = new Vector JavaDoc();
40     private int currentColor = -1;
41
42
43     public GraphColorChooser()
44     {
45         initColors();
46     }
47
48     /**
49      * Initialize a list of available colors.
50      */

51     private void initColors()
52     {
53         colors.add(Color.BLUE);
54         colors.add(Color.RED);
55         colors.add(Color.GREEN);
56         colors.add(Color.CYAN);
57         colors.add(Color.MAGENTA);
58         colors.add(Color.PINK);
59         colors.add(Color.ORANGE);
60         colors.add(Color.YELLOW);
61         colors.add(Color.GRAY);
62         colors.add(Color.DARK_GRAY);
63         colors.add(Color.LIGHT_GRAY);
64     }
65
66     /**
67      * Return the next color available.
68      * @return the next available color. Once all colors have been used,
69      * it loops on the same color sequence.
70      */

71     public Color JavaDoc getNextColor() {
72         currentColor++;
73         if (currentColor == colors.size())
74             currentColor = 0;
75         return (Color JavaDoc) colors.elementAt(currentColor);
76     }
77 }
Popular Tags