ColorTable.java :  » XML-UI » xui32 » com » xoetrope » svgscanner » color » Java Open Source

Java Open Source » XML UI » xui32 
xui32 » com » xoetrope » svgscanner » color » ColorTable.java
package com.xoetrope.svgscanner.color;

import java.util.Enumeration;
import java.util.Hashtable;

/**
 *
 * <p> Copyright (c) Xoetrope Ltd., 2001-2007, This software is licensed under
 * the GNU Public License (GPL), please see license.txt for more details. If
 * you make commercial use of this software you must purchase a commercial
 * license from Xoetrope.</p>
 * <p>$Revision: 1.1 $</p>
 */
public class ColorTable 
{
  private static Hashtable<String,ColorMapping> commonColors;
  
  public Hashtable<String,ColorMapping> colors;
  public String name;
  public String outputImage;
  public String colorizedImage;
  
  /** Creates a new instance of ColorTable */
  public ColorTable() 
  {
    if ( commonColors == null )
      commonColors = new Hashtable<String,ColorMapping>();
    
    colors = new Hashtable<String,ColorMapping>();
  }    
  
  public void addImage( String source )
  {
    name = source;
  }
  
  public String addColor( String c )
  {
    String colorName = "C" + commonColors.size();
    
    // Check the existing colors
    Enumeration<ColorMapping> ce = commonColors.elements();
    while ( ce.hasMoreElements()  ) {
      ColorMapping m = ce.nextElement();
      if ( m.getOriginalColor().equalsIgnoreCase( c )) {
        colors.put( m.getName(), m );
        if ( !m.getUsages().containsKey( name ))
          m.getUsages().put( name, this );
        colorName = m.getName();
        break;
      }
    }
    
    if ( !colors.containsKey( colorName )) {
      ColorMapping mapping = new ColorMapping();
      mapping.setOriginalColor( c );
      mapping.setName( colorName );
      mapping.getUsages().put( name, this );
      colors.put( colorName, mapping );
      commonColors.put( colorName, mapping );
    }
    
    return colorName;
  }

  public static Hashtable<String, ColorMapping> getCommonColors() 
  {
    return commonColors;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.