// Copyright 2004, FreeHEP.
package hep.graphics.heprep1.adapter;

import java.util.*;

/**
 *
 * @author Mark Donszelmann
 * @version $Id: AttributeNameTranslator.java,v 1.2 2005/03/02 15:23:53 duns Exp $
 */
public class AttributeNameTranslator {

    private static final Map/*<name2, names1[]>*/ heprep1;
    private static final Map/*<name1, name2>*/ heprep2;
    
    static {
        heprep1 = new HashMap();
        heprep2 = new HashMap();
        // NOTE: lowercase only, include name2 in names1.
        put("color",                new String[] {"color", "linecolor", "markcolor"} );
        put("framecolor",           new String[] {"framecolor", "lineframecolor", "markframecolor"} );
        put("framewidth",           new String[] {"framewidth", "lineframewidth", "markframewidth"} );
        put("hasframe",             new String[] {"hasframe", "linehasframe", "markhasframe"} );
//        put("phi",                  new String[] {"phi", "phi1", "phi2"} );
//        put("theta",                new String[] {"theta", "theta1", "theta2"} );
//        put("radius",               new String[] {"radius", "radius1", "radius2", "radiusx", "radiusy", "radiusz"} );
        
        // FIXME: NOTE: there are some such as "sum, sum1" which need more than a translation..
    }
    
    private AttributeNameTranslator() {
    }
    
    // FIXME, strictly not correct because a lookup of "phi" may result in "phi1" being found, while "phi2"
    // is meant... We need something better for this, unless it is never used...
    public static void put(String name2, String[] names1) {
        for (int i=0; i<names1.length; i++) {
            heprep2.put(names1[i], name2);
        }
        heprep1.put(name2, names1);
    }
    
    public static String[] getName1(String name2) {
        return (String[])heprep1.get(name2.toLowerCase());
    }
    
    public static String getName2(String name1) {
        String name2 = (String)heprep2.get(name1.toLowerCase());
        return (name2 != null) ? name2 : name1;
    }
}
