package cl.jtv;
/*
 * Hellada.java
 *
 * Created on 29 de agosto de 2002, 03:47 AM
 */

/**
 *
 * @author  Administrador
 * @version 
 */
import java.io.*;
import java.util.*;
import java.awt.*;

public class Hellada {
    
    //private static String[] greekChars = new String[30];
    //private static Hashtable greekChars = new Hashtable();
    private static Vector greekChars = new Vector();
    private static Font font = new Font("TIMESROMAN", Font.ITALIC, 25);

    public static final int ALPHA=0;
    public static final int BETA=1;
    public static final int GAMMA=2;
    public static final int DELTA=3;
    public static final int EPSILON=4;
    public static final int ZETA=5;
    public static final int ETA=6;
    public static final int THETA=7;
    public static final int IOTA=8;
    public static final int KAPPA=9;
    public static final int LAMBDA=10;
    public static final int MU=11;
    public static final int NU=12;
    public static final int XI=13;
    public static final int OMICRON=14;
    public static final int PI=15;
    public static final int RHO=16;
    public static final int VARSIGMA=17;
    public static final int SIGMA=18;
    public static final int TAU=19;
    public static final int UPSILON=20;
    public static final int PHI=21;
    public static final int CHI=22;
    public static final int PSI=23;
    public static final int OMEGA=24;

    /** Creates new Hellada */
    public Hellada() {
    }
    
    static{
         ByteArrayOutputStream byteArray = new ByteArrayOutputStream(100);
         String str = "\u03B1,\u03B2,\u03B3,\u03B4,\u03B5,\u03B6,\u03B7,\u03B8,\u03B9,\u03BA,\u03BB,\u03BC,\u03BD,\u03BE,\u03BF,\u03C0,\u03C1,\u03C2,\u03C3,\u03C4,\u03C5,\u03C6,\u03C7,\u03C8,\u03C9";

        try {
            //Writer out = new OutputStreamWriter(new FileOutputStream("hellada.txt"), "8859_7");
            
            
            Writer out = new OutputStreamWriter(byteArray, "8859_7");
		//8859_7 is the ISO code for ASCII plus greek, although this
		//example also works on my machine if it is set to UTF8
            out.write(str);
            out.close();
            
        } catch (IOException e) {
            e.printStackTrace();
        }
         
         
         try {
        //FileInputStream fis = new FileInputStream("hellada.txt");    
	//InputStreamReader isr = new InputStreamReader(fis,"8859_7");
        ByteArrayInputStream bais = new ByteArrayInputStream(byteArray.toByteArray());      
        InputStreamReader isr = new InputStreamReader(bais,"8859_7");
	Reader in = new BufferedReader(isr);

            StringBuffer buf = new StringBuffer();
            int ch;
            while ((ch = in.read()) > -1) {
                buf.append((char)ch);
            }
            in.close();
	   str = buf.toString();
	  
        } catch (IOException e) {
            e.printStackTrace();
        }
         
         int i = 0;
         StringTokenizer st = new StringTokenizer(str,",");
         while(st.hasMoreTokens()){
            
            //greekChars.put(new Integer(i++),st.nextToken());
             greekChars.add(st.nextToken());
            //greekChars[i++] = st.nextToken();
             
         }
        
    }
    
    public static String getChar(int indexChar){
        
         return (String)greekChars.get(indexChar);
         //return (String)greekChars.get(new Integer(indexChar));
         //return greekChars[indexChar];
    }
    
    
    public static void setFont(Font newFont){
        
        font = newFont;
    }
    
    public static void drawChar(Graphics g,int indexChar,int x,int y){
        g.setFont(font);
        g.drawString(getChar(indexChar),x,y);
        
    }
    
    public static String symbol2XML(String symbol){
        
        if(Hellada.greekChars.contains(symbol))
            return "HELLADA_"+Hellada.greekChars.indexOf(symbol);
        else
            return symbol;
    }
    
    public static String XML2symbol(String symbol){
           
        if(symbol.startsWith("HELLADA_"))
            return (String)Hellada.greekChars.get(Integer.parseInt(((symbol.substring(symbol.indexOf('_')+1)))));
        else
            return symbol;
    }
    
    public static void main(String argc[]){
         
        //System.out.println(Hellada.symbol2XML(Hellada.getChar(Hellada.OMEGA)));
        /*System.out.println(Hellada.XML2symbol(Hellada.symbol2XML(Hellada.getChar(Hellada.OMEGA))));
        System.out.println(System.getProperty("user.dir"));
        Enumeration en = System.getProperties().propertyNames();
        while(en.hasMoreElements())
            System.out.println((String)en.nextElement());*/
        File file = new File("./");
        System.out.println(file.getAbsolutePath());
    }
}
