import java.awt.*;
import java.awt.geom.*;
import java.io.*;
import java.util.*;

public class Hand {
	private static final Color GREEN = new Color( 0, 205, 100 ),
		BLACK = Color.black;
	private GeneralPath _shape;
	private Color _fill, _stroke;

	/**
	 */
	public Hand( String[] lines ) {
		_fill = GREEN;
		_stroke = BLACK;
		_shape = new GeneralPath();
		_shape.moveTo(0,0);
		int[] args;
		for(int ctr=0;ctr<lines.length;ctr++) {
			String line = lines[ctr];
			switch (line.charAt(0)) {
				case 'f': // FILL color
					_fill = parseColor( line );
					break;
				case 's': // STROKE color
					_stroke = parseColor( line );
					break;
				case 'q': // QUAD
					args = parseInts( line );
					_shape.quadTo( args[0], args[1], args[2], args[3] );
					break;
				case 'm': // MOVE
					args = parseInts( line );
					_shape.moveTo( args[0], args[1] );
					break;
				case 'l': // LINE
					args = parseInts( line );
					_shape.lineTo( args[0], args[1] );
					break;
				case 'c': // CLOSE
					_shape.closePath();
				default:
					break;
			}
		}
	}

	public final Shape getShape() { return _shape; }

	public final Color getStroke() { return _stroke; }

	public final Color getFill() { return _fill; }

	// This whole method would be, like, 2 lines in Ruby :-/
	private int[] parseInts( String line ) { 
		StringTokenizer st = new StringTokenizer( line, " " );
		st.nextToken();  // get rid of the prefix
		ArrayList list = new ArrayList();
		while (st.hasMoreTokens()) {
			list.add( Integer.valueOf( st.nextToken() ) );
		}
		int[] rv = new int[ list.size() ];
		int ind = 0;
		for (Iterator i=list.iterator(); i.hasNext(); ) {
			rv[ind++] = ((Integer)i.next()).intValue();
		}
		return rv;
	}

	private Color parseColor( String line ) {
		StringTokenizer st = new StringTokenizer( line, " " );
		st.nextToken();  // get rid of the prefix
		Color c = Color.decode( st.nextToken() );
		return c;
	}
}
