2 * BioJava development code
4 * This code may be freely distributed and modified under the
5 * terms of the GNU Lesser General Public Licence. This should
6 * be distributed with the code. If you do not have a copy,
9 * http://www.gnu.org/copyleft/lesser.html
11 * Copyright for this code is held jointly by the individual
12 * authors. These should be listed in @author doc comments.
14 * For more information on the BioJava project and its aims,
15 * or to join the biojava-l mailing list, visit the home page
18 * http://www.biojava.org/
20 * Created on Aug 3, 2005
23 package org.biojava.dasobert.das;
26 import org.xml.sax.helpers.DefaultHandler;
27 import org.xml.sax.Attributes ;
29 import java.util.logging.Logger;
30 import java.awt.Color;
32 /** a class to parse the XML response of a DAS - stylesheet request.
33 * @author Andreas Prlic
36 public class DAS_Stylesheet_Handler extends DefaultHandler {
43 static Logger logger = Logger.getLogger("org.biojava.spice");
48 public DAS_Stylesheet_Handler() {
50 typeGlyphMaps = new ArrayList();
51 currentType = new HashMap();
52 threeDGlyphMaps = new ArrayList();
57 public Map[] getTypeStyles(){
58 return (Map[]) typeGlyphMaps.toArray(new Map[typeGlyphMaps.size()]);
61 public Map[] get3DStyles(){
62 return (Map[]) threeDGlyphMaps.toArray(new Map[threeDGlyphMaps.size()]);
65 public void startElement (String uri, String name, String qName, Attributes atts){
68 if ( qName.equals("CATEGORY")){
69 String id = atts.getValue("id");
70 if ( id.equals("3D")){
71 // here follow the 3D styles...
79 if ( qName.equals("TYPE")){
80 // this glyph matches to features of type >id<.
81 String id = atts.getValue("id");
82 currentType = new HashMap();
83 currentType.put("type",id);
86 else if ( qName.equals("ARROW")){
87 currentType.put("style","arrow");
88 } else if ( qName.equals("ANCHORED_ARROW")){
89 currentType.put("style","anchored_arrow");
90 } else if ( qName.equals("BOX")){
91 currentType.put("style","box");
92 } else if ( qName.equals("CROSS")){
93 currentType.put("style","cross");
94 } else if ( qName.equals("EX")){
95 currentType.put("style","EX");
96 } else if ( qName.equals("HELIX")){
97 currentType.put("style","helix");
98 } else if ( qName.equals("LINE")){
99 currentType.put("style","LINE");
100 } else if ( qName.equals("SPAN")){
101 currentType.put("style","span");
102 } else if ( qName.equals("TRIANGLE")){
103 currentType.put("style","triangle");
108 /** convert the color provided by the stylesheet to a java Color
113 private Color getColorFromString(String chars){
116 if (chars.equals("rotate")) {
117 // use the default SPICE colors ...
122 Color col = Color.decode(chars);
124 } catch ( Exception e) {
125 logger.finest("could not decode color from stylesheet " + e.getMessage());
129 // map the string to a build in color...
130 // thanks to the Xpm.java script provided by Phil Brown (under LGPL)
131 // AP downloaded it from http://www.bolthole.com/java/Xpm.java
133 // the DAS spec stylesheet only requires 16 VGA colors to be supported, but here we do more... :-)
135 int[] rgb = Xpm.NameToRGB3(chars);
137 Color col = new Color(rgb[0],rgb[1],rgb[2]);
143 public void endElement(String uri, String name, String qName) {
144 if ( qName.equals("HEIGHT")){
145 currentType.put("height",chars);
146 } else if ( qName.equals("COLOR")){
147 //System.out.println("got color " + chars);
148 Color col = getColorFromString(chars);
150 currentType.put("color",col);
152 if ( chars.equals("cpk")){
153 currentType.put("cpkcolor","true");
157 } else if ( qName.equals("OUTLINECOLOR")){
158 currentType.put("outlinecolor",chars);
159 } else if ( qName.equals("BACKGROUND")){
160 currentType.put("background",chars);
161 } else if ( qName.equals("BUMP")){
162 if ( chars.equals("no"))
163 currentType.put("bump","no");
165 currentType.put("bump","yes");
168 } else if ( qName.equals("WIREFRAME")){
169 currentType.put("display","wireframe");
170 } else if ( qName.equals("SPACEFILL")){
171 currentType.put("display","spacefill");
172 } else if ( qName.equals("BACKBONE")){
173 currentType.put("display","backbone");
174 } else if ( qName.equals("CARTOON")){
175 currentType.put("display","cartoon");
176 } else if ( qName.equals("RIBBONS")){
177 currentType.put("display","ribbons");
178 } else if ( qName.equals("WIDTH")){
179 currentType.put("width",chars);
182 else if ( qName.equals("TYPE")){
184 threeDGlyphMaps.add(currentType);
186 typeGlyphMaps.add(currentType);
191 public void characters (char ch[], int start, int length){
194 for (int i = start; i < start + length; i++) {