1
2
3
4
5
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
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 }