View Javadoc

1   /*
2    * @(#)DistributionParser.java Jun 25, 2004 Copyright (c) 2002-2005, 2004 Delft
3    * University of Technology Jaffalaan 5, 2628 BX Delft, the Netherlands. All
4    * rights reserved. This software is proprietary information of Delft University
5    * of Technology The code is published under the Lesser General Public License
6    */
7   
8   package nl.tudelft.simulation.xml.language;
9   
10  import java.awt.Color;
11  import java.io.IOException;
12  import java.net.URL;
13  
14  import org.jdom.Element;
15  
16  /***
17   * <br>
18   * (c) copyright 2002-2005-2004 <a href="http://www.simulation.tudelft.nl">Delft
19   * University of Technology </a>, the Netherlands. <br>
20   * See for project information <a href="http://www.simulation.tudelft.nl">
21   * www.simulation.tudelft.nl </a> <br>
22   * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
23   * General Public License (LGPL) </a>, no warranty.
24   * 
25   * @version Jun 25, 2004 <br>
26   * @author <a
27   *         href="mailto:a.verbraeck@tbm.tudelft.nl">Alexander
28   *         Verbraeck </a>
29   */
30  public final class ColorParser
31  {
32      /*** the default mapfile */
33      public static final URL COLORFILE_SCHEMA = ColorParser.class
34              .getResource("/xsd/color.xsd");
35  
36      /***
37       * constructs a new ColorParser
38       */
39      private ColorParser()
40      {
41          super();
42          // unreachable code
43      }
44  
45      /***
46       * parses a xml-element representing a Color
47       * 
48       * @param element The j-dom element
49       * @return Color the color
50       * @throws IOException on failure
51       */
52      public static Color parseColor(final Element element) throws IOException
53      {
54          try
55          {
56              int r = new Integer(element.getAttributeValue("R")).intValue();
57              int g = new Integer(element.getAttributeValue("G")).intValue();
58              int b = new Integer(element.getAttributeValue("B")).intValue();
59              return new Color(r, g, b);
60          } catch (Exception exception)
61          {
62              throw new IOException(exception.getMessage());
63          }
64      }
65  }