/**
	* ColorTable Class describe Color used in graph
	**/

// this Class is a memeber of GCRawData package
package GCRawData;

import java.util.*;
import java.awt.*;

public class ColorTable{
	private Vector Vt;
	private int size = 0;
        private int index = 0;
  
  // construc
	public ColorTable(int sz) {
		size = sz;
		Vt = new Vector( size );
		size = buildColorTable();
	}
	
	public int size() {
		return size;
	}
        //error
        public Color getNextColor() {
                if ( index < size ) {
                    Color c = new Color( ((Color)(Vt.elementAt(index))).getRed(), ((Color)(Vt.elementAt(index))).getGreen(), ((Color)(Vt.elementAt(index))).getBlue() );
                    index += 1;
                    return c;
                } else return null;
        }
        
        public void setStart() {
                index = 0;
        }
        private int buildColorTable() {
		// maximun buildable color size is 15*8;
		int R, G, B;
		final int sat = 30;
		final int stripSize = 15;
		int min; 
		int term;
		int sz = size;
		
		// R:255 G,B:( 254,0 -> 127,0 -> 0,0 -> 0,254 -> 0,127 )
		for ( int i=0; i<(size/stripSize)+1; i++ ) {
			min = sat*i;
			term = (255 - min)/2;
			
			R = 255; G = B = min;
			for( G = 254; G>=min; G-=term ) if( sz-- > 0 )Vt.add(new Color(R, G, B));
			for( B = 254; B>=min+term; B-=term ) if( sz-- > 0 )Vt.add(new Color(R, G+term, B));
		
			G = 255; R = B = min;
			for( R = 254; R>=min; R-=term ) if( sz-- > 0 )Vt.add(new Color(R, G, B));
			for( B = 254; B>=min+term; B-=term ) if( sz-- > 0 )Vt.add(new Color(R+term, G, B));

			B = 255; R = G = min;
			for( R = 254; R>=min; R-=term )	if( sz-- > 0 )Vt.add(new Color(R, G, B));
			for( G = 254; G>=term; G-=term ) if( sz-- > 0 )Vt.add(new Color(R+term, G, B));
		}

		return Vt.size();
	}

}