| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | package org.pathvisio.model; |
|---|
| 18 | |
|---|
| 19 | import java.util.ArrayList; |
|---|
| 20 | import java.util.HashMap; |
|---|
| 21 | import java.util.List; |
|---|
| 22 | import java.util.Map; |
|---|
| 23 | |
|---|
| 24 | import org.bridgedb.DataSource; |
|---|
| 25 | import org.jdom.Element; |
|---|
| 26 | import org.jdom.Namespace; |
|---|
| 27 | import org.pathvisio.model.PathwayElement.MAnchor; |
|---|
| 28 | import org.pathvisio.model.PathwayElement.MPoint; |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | class GpmlFormat200X extends GpmlFormatAbstract implements GpmlFormatReader |
|---|
| 35 | { |
|---|
| 36 | public static final GpmlFormatReader GPML_2007 = new GpmlFormat200X ( |
|---|
| 37 | "GPML2007.xsd", Namespace.getNamespace("http://genmapp.org/GPML/2007") |
|---|
| 38 | ); |
|---|
| 39 | public static final GpmlFormatReader GPML_2008A = new GpmlFormat200X ( |
|---|
| 40 | "GPML2008a.xsd", Namespace.getNamespace("http://genmapp.org/GPML/2008a") |
|---|
| 41 | ); |
|---|
| 42 | |
|---|
| 43 | public GpmlFormat200X(String xsdFile, Namespace ns) { |
|---|
| 44 | super (xsdFile, ns); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | private static final Map<String, AttributeInfo> ATTRIBUTE_INFO = initAttributeInfo(); |
|---|
| 48 | |
|---|
| 49 | private static Map<String, AttributeInfo> initAttributeInfo() |
|---|
| 50 | { |
|---|
| 51 | Map<String, AttributeInfo> result = new HashMap<String, AttributeInfo>(); |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | result.put("Comment@Source", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 56 | result.put("PublicationXref@ID", new AttributeInfo ("xsd:string", null, "required")); |
|---|
| 57 | result.put("PublicationXref@Database", new AttributeInfo ("xsd:string", null, "required")); |
|---|
| 58 | result.put("Attribute@Key", new AttributeInfo ("xsd:string", null, "required")); |
|---|
| 59 | result.put("Attribute@Value", new AttributeInfo ("xsd:string", null, "required")); |
|---|
| 60 | result.put("Pathway.Graphics@BoardWidth", new AttributeInfo ("gpml:Dimension", null, "required")); |
|---|
| 61 | result.put("Pathway.Graphics@BoardHeight", new AttributeInfo ("gpml:Dimension", null, "required")); |
|---|
| 62 | result.put("Pathway.Graphics@WindowWidth", new AttributeInfo ("gpml:Dimension", "18000", "optional")); |
|---|
| 63 | result.put("Pathway.Graphics@WindowHeight", new AttributeInfo ("gpml:Dimension", "12000", "optional")); |
|---|
| 64 | result.put("Pathway@Name", new AttributeInfo ("gpml:NameType", null, "required")); |
|---|
| 65 | result.put("Pathway@Organism", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 66 | result.put("Pathway@Data-Source", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 67 | result.put("Pathway@Version", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 68 | result.put("Pathway@Author", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 69 | result.put("Pathway@Maintainer", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 70 | result.put("Pathway@Email", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 71 | result.put("Pathway@License", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 72 | result.put("Pathway@Copyright", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 73 | result.put("Pathway@Last-Modified", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 74 | result.put("Pathway@BiopaxRef", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 75 | result.put("DataNode.Graphics@CenterX", new AttributeInfo ("xsd:float", null, "required")); |
|---|
| 76 | result.put("DataNode.Graphics@CenterY", new AttributeInfo ("xsd:float", null, "required")); |
|---|
| 77 | result.put("DataNode.Graphics@Width", new AttributeInfo ("gpml:Dimension", null, "required")); |
|---|
| 78 | result.put("DataNode.Graphics@Height", new AttributeInfo ("gpml:Dimension", null, "required")); |
|---|
| 79 | result.put("DataNode.Graphics@Color", new AttributeInfo ("gpml:ColorType", null, "optional")); |
|---|
| 80 | result.put("DataNode.Graphics@ZOrder", new AttributeInfo ("xsd:integer", null, "optional")); |
|---|
| 81 | result.put("DataNode.Xref@Database", new AttributeInfo ("gpml:DatabaseType", null, "required")); |
|---|
| 82 | result.put("DataNode.Xref@ID", new AttributeInfo ("gpml:NameType", null, "required")); |
|---|
| 83 | result.put("DataNode@BiopaxRef", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 84 | result.put("DataNode@GraphId", new AttributeInfo ("xsd:ID", null, "optional")); |
|---|
| 85 | result.put("DataNode@GroupRef", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 86 | result.put("DataNode@ObjectType", new AttributeInfo ("gpml:ObjectType", "Annotation", "optional")); |
|---|
| 87 | result.put("DataNode@TextLabel", new AttributeInfo ("xsd:string", null, "required")); |
|---|
| 88 | result.put("DataNode@BackpageHead", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 89 | result.put("DataNode@GenMAPP-Xref", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 90 | result.put("DataNode@Type", new AttributeInfo ("gpml:DataNodeType", "Unknown", "optional")); |
|---|
| 91 | result.put("State.Graphics@relX", new AttributeInfo ("xsd:float", null, "required")); |
|---|
| 92 | result.put("State.Graphics@relY", new AttributeInfo ("xsd:float", null, "required")); |
|---|
| 93 | result.put("State.Graphics@Width", new AttributeInfo ("gpml:Dimension", null, "required")); |
|---|
| 94 | result.put("State.Graphics@Height", new AttributeInfo ("gpml:Dimension", null, "required")); |
|---|
| 95 | result.put("State.Graphics@Color", new AttributeInfo ("gpml:ColorType", null, "optional")); |
|---|
| 96 | result.put("State.Graphics@FillColor", new AttributeInfo ("gpml:ColorType", null, "optional")); |
|---|
| 97 | result.put("State.Xref@Database", new AttributeInfo ("gpml:DatabaseType", null, "required")); |
|---|
| 98 | result.put("State.Xref@ID", new AttributeInfo ("gpml:NameType", null, "required")); |
|---|
| 99 | result.put("State@BiopaxRef", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 100 | result.put("State@GraphId", new AttributeInfo ("xsd:ID", null, "optional")); |
|---|
| 101 | result.put("State@GraphRef", new AttributeInfo ("xsd:IDREF", null, "optional")); |
|---|
| 102 | result.put("State@Style", new AttributeInfo ("gpml:StyleType", "Solid", "optional")); |
|---|
| 103 | result.put("State@TextLabel", new AttributeInfo ("xsd:string", null, "required")); |
|---|
| 104 | result.put("State@StateType", new AttributeInfo ("xsd:string", "Unknown", "optional")); |
|---|
| 105 | result.put("State@ShapeType", new AttributeInfo ("xsd:string", null, "required")); |
|---|
| 106 | result.put("Line.Graphics.Point@x", new AttributeInfo ("xsd:float", null, "required")); |
|---|
| 107 | result.put("Line.Graphics.Point@y", new AttributeInfo ("xsd:float", null, "required")); |
|---|
| 108 | result.put("Line.Graphics.Point@relX", new AttributeInfo ("xsd:float", null, "optional")); |
|---|
| 109 | result.put("Line.Graphics.Point@relY", new AttributeInfo ("xsd:float", null, "optional")); |
|---|
| 110 | result.put("Line.Graphics.Point@GraphRef", new AttributeInfo ("xsd:IDREF", null, "optional")); |
|---|
| 111 | result.put("Line.Graphics.Point@GraphId", new AttributeInfo ("xsd:ID", null, "optional")); |
|---|
| 112 | result.put("Line.Graphics.Point@ArrowHead", new AttributeInfo ("xsd:string", "Line", "optional")); |
|---|
| 113 | result.put("Line.Graphics.Point@Head", new AttributeInfo ("xsd:string", "Line", "optional")); |
|---|
| 114 | result.put("Line.Graphics.Anchor@position", new AttributeInfo ("xsd:float", null, "required")); |
|---|
| 115 | result.put("Line.Graphics.Anchor@GraphId", new AttributeInfo ("xsd:ID", null, "optional")); |
|---|
| 116 | result.put("Line.Graphics.Anchor@Shape", new AttributeInfo ("xsd:string", "ReceptorRound", "optional")); |
|---|
| 117 | result.put("Line.Graphics@Color", new AttributeInfo ("gpml:ColorType", "Black", "optional")); |
|---|
| 118 | result.put("Line.Graphics@ConnectorType", new AttributeInfo ("xsd:string", "Straight", "optional")); |
|---|
| 119 | result.put("Line.Graphics@ZOrder", new AttributeInfo ("xsd:integer", null, "optional")); |
|---|
| 120 | result.put("Line@Style", new AttributeInfo ("gpml:StyleType", "Solid", "optional")); |
|---|
| 121 | result.put("Line@GroupRef", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 122 | result.put("Line@BiopaxRef", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 123 | result.put("Line@GraphId", new AttributeInfo ("xsd:ID", null, "optional")); |
|---|
| 124 | result.put("Label.Graphics@CenterX", new AttributeInfo ("xsd:float", null, "required")); |
|---|
| 125 | result.put("Label.Graphics@CenterY", new AttributeInfo ("xsd:float", null, "required")); |
|---|
| 126 | result.put("Label.Graphics@Width", new AttributeInfo ("gpml:Dimension", null, "required")); |
|---|
| 127 | result.put("Label.Graphics@Height", new AttributeInfo ("gpml:Dimension", null, "required")); |
|---|
| 128 | result.put("Label.Graphics@Color", new AttributeInfo ("gpml:ColorType", null, "optional")); |
|---|
| 129 | result.put("Label.Graphics@FontName", new AttributeInfo ("xsd:string", "Arial", "optional")); |
|---|
| 130 | result.put("Label.Graphics@FontStyle", new AttributeInfo ("xsd:string", "Normal", "optional")); |
|---|
| 131 | result.put("Label.Graphics@FontDecoration", new AttributeInfo ("xsd:string", "Normal", "optional")); |
|---|
| 132 | result.put("Label.Graphics@FontStrikethru", new AttributeInfo ("xsd:string", "Normal", "optional")); |
|---|
| 133 | result.put("Label.Graphics@FontWeight", new AttributeInfo ("xsd:string", "Normal", "optional")); |
|---|
| 134 | result.put("Label.Graphics@FontSize", new AttributeInfo ("xsd:nonNegativeInteger", "12", "optional")); |
|---|
| 135 | result.put("Label.Graphics@ZOrder", new AttributeInfo ("xsd:integer", null, "optional")); |
|---|
| 136 | result.put("Label@Href", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 137 | result.put("Label@PathwayRef", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 138 | result.put("Label@BiopaxRef", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 139 | result.put("Label@GraphId", new AttributeInfo ("xsd:ID", null, "optional")); |
|---|
| 140 | result.put("Label@GroupRef", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 141 | result.put("Label@ObjectType", new AttributeInfo ("gpml:ObjectType", "Annotation", "optional")); |
|---|
| 142 | result.put("Label@Outline", new AttributeInfo ("xsd:string", "None", "optional")); |
|---|
| 143 | result.put("Label@TextLabel", new AttributeInfo ("xsd:string", null, "required")); |
|---|
| 144 | result.put("Label@Xref", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 145 | result.put("Label@GenMAPP-Xref", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 146 | result.put("Shape.Graphics@CenterX", new AttributeInfo ("xsd:float", null, "required")); |
|---|
| 147 | result.put("Shape.Graphics@CenterY", new AttributeInfo ("xsd:float", null, "required")); |
|---|
| 148 | result.put("Shape.Graphics@Width", new AttributeInfo ("gpml:Dimension", null, "required")); |
|---|
| 149 | result.put("Shape.Graphics@Height", new AttributeInfo ("gpml:Dimension", null, "required")); |
|---|
| 150 | result.put("Shape.Graphics@Color", new AttributeInfo ("gpml:ColorType", "Black", "optional")); |
|---|
| 151 | result.put("Shape.Graphics@Rotation", new AttributeInfo ("gpml:RotationType", "Top", "optional")); |
|---|
| 152 | result.put("Shape.Graphics@FillColor", new AttributeInfo ("gpml:ColorType", "Transparent", "optional")); |
|---|
| 153 | result.put("Shape.Graphics@ZOrder", new AttributeInfo ("xsd:integer", null, "optional")); |
|---|
| 154 | result.put("Shape@Type", new AttributeInfo ("xsd:string", null, "required")); |
|---|
| 155 | result.put("Shape@BiopaxRef", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 156 | result.put("Shape@GraphId", new AttributeInfo ("xsd:ID", null, "optional")); |
|---|
| 157 | result.put("Shape@GroupRef", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 158 | result.put("Shape@ObjectType", new AttributeInfo ("gpml:ObjectType", "Annotation", "optional")); |
|---|
| 159 | result.put("Shape@Style", new AttributeInfo ("gpml:StyleType", "Solid", "optional")); |
|---|
| 160 | result.put("Group@BiopaxRef", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 161 | result.put("Group@GroupId", new AttributeInfo ("xsd:string", null, "required")); |
|---|
| 162 | result.put("Group@GroupRef", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 163 | result.put("Group@Style", new AttributeInfo ("xsd:string", "None", "optional")); |
|---|
| 164 | result.put("Group@TextLabel", new AttributeInfo ("xsd:string", null, "optional")); |
|---|
| 165 | result.put("Group@GraphId", new AttributeInfo ("xsd:ID", null, "optional")); |
|---|
| 166 | result.put("InfoBox@CenterX", new AttributeInfo ("xsd:float", null, "required")); |
|---|
| 167 | result.put("InfoBox@CenterY", new AttributeInfo ("xsd:float", null, "required")); |
|---|
| 168 | result.put("Legend@CenterX", new AttributeInfo ("xsd:float", null, "required")); |
|---|
| 169 | result.put("Legend@CenterY", new AttributeInfo ("xsd:float", null, "required")); |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | return result; |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | @Override |
|---|
| 176 | protected Map<String, AttributeInfo> getAttributeInfo() |
|---|
| 177 | { |
|---|
| 178 | return ATTRIBUTE_INFO; |
|---|
| 179 | }; |
|---|
| 180 | |
|---|
| 181 | private static final int CONVERSION = 15; |
|---|
| 182 | |
|---|
| 183 | private void mapDeprecatedAttribute(PathwayElement o, Element el, String key, String tag, String name) |
|---|
| 184 | throws ConverterException |
|---|
| 185 | { |
|---|
| 186 | String infoKey = tag + "@" + name; |
|---|
| 187 | if (!getAttributeInfo().containsKey(infoKey)) |
|---|
| 188 | throw new ConverterException("Trying to get invalid attribute " + infoKey); |
|---|
| 189 | String result = ((el == null) ? null : el.getAttributeValue(name)); |
|---|
| 190 | if (result != null) o.setDynamicProperty(key, result); |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | protected void updateMappInfoVariable(Element root, PathwayElement o) throws ConverterException |
|---|
| 194 | { |
|---|
| 195 | setAttribute("Pathway", "Copyright", root, o.getCopyright()); |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | protected void mapMappInfoDataVariable (PathwayElement o, Element e) throws ConverterException |
|---|
| 199 | { |
|---|
| 200 | o.setCopyright (getAttribute("Pathway", "Copyright", e)); |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | public PathwayElement mapElement(Element e, Pathway p) throws ConverterException |
|---|
| 208 | { |
|---|
| 209 | String tag = e.getName(); |
|---|
| 210 | ObjectType ot = ObjectType.getTagMapping(tag); |
|---|
| 211 | if (ot == null) |
|---|
| 212 | { |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | return null; |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | PathwayElement o = PathwayElement.createPathwayElement(ot); |
|---|
| 220 | if (p != null) |
|---|
| 221 | { |
|---|
| 222 | p.add (o); |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | switch (o.getObjectType()) |
|---|
| 226 | { |
|---|
| 227 | case DATANODE: |
|---|
| 228 | mapShapeData(o, e, "DataNode"); |
|---|
| 229 | mapColor(o, e); |
|---|
| 230 | mapComments(o, e); |
|---|
| 231 | mapDataNode(o, e); |
|---|
| 232 | mapGraphId(o, e); |
|---|
| 233 | mapGroupRef(o, e); |
|---|
| 234 | mapBiopaxRef(o, e); |
|---|
| 235 | mapAttributes(o, e); |
|---|
| 236 | break; |
|---|
| 237 | case STATE: |
|---|
| 238 | mapShapeColor(o, e); |
|---|
| 239 | mapStateData(o, e); |
|---|
| 240 | mapColor(o, e); |
|---|
| 241 | mapComments(o, e); |
|---|
| 242 | mapGraphId(o, e); |
|---|
| 243 | mapBiopaxRef(o, e); |
|---|
| 244 | mapAttributes(o, e); |
|---|
| 245 | break; |
|---|
| 246 | case LABEL: |
|---|
| 247 | mapShapeData(o, e, "Label"); |
|---|
| 248 | mapColor(o, e); |
|---|
| 249 | mapLabelData(o, e); |
|---|
| 250 | mapComments(o, e); |
|---|
| 251 | mapGraphId(o, e); |
|---|
| 252 | mapGroupRef(o, e); |
|---|
| 253 | mapBiopaxRef(o, e); |
|---|
| 254 | mapAttributes(o, e); |
|---|
| 255 | break; |
|---|
| 256 | case LINE: |
|---|
| 257 | mapLineData(o, e); |
|---|
| 258 | mapColor(o, e); |
|---|
| 259 | mapGraphId(o, e); |
|---|
| 260 | mapComments(o, e); |
|---|
| 261 | mapGroupRef(o, e); |
|---|
| 262 | mapBiopaxRef(o, e); |
|---|
| 263 | mapAttributes(o, e); |
|---|
| 264 | break; |
|---|
| 265 | case MAPPINFO: |
|---|
| 266 | mapMappInfoData(o, e); |
|---|
| 267 | mapBiopaxRef(o, e); |
|---|
| 268 | mapComments(o, e); |
|---|
| 269 | mapAttributes(o, e); |
|---|
| 270 | break; |
|---|
| 271 | case SHAPE: |
|---|
| 272 | mapShapeData(o, e, "Shape"); |
|---|
| 273 | mapShapeColor (o, e); |
|---|
| 274 | mapColor(o, e); |
|---|
| 275 | mapComments(o, e); |
|---|
| 276 | mapShapeType(o, e); |
|---|
| 277 | mapGraphId(o, e); |
|---|
| 278 | mapGroupRef(o, e); |
|---|
| 279 | mapBiopaxRef(o, e); |
|---|
| 280 | mapAttributes(o, e); |
|---|
| 281 | break; |
|---|
| 282 | case LEGEND: |
|---|
| 283 | mapSimpleCenter(o, e); |
|---|
| 284 | break; |
|---|
| 285 | case INFOBOX: |
|---|
| 286 | mapSimpleCenter (o, e); |
|---|
| 287 | break; |
|---|
| 288 | case GROUP: |
|---|
| 289 | mapGroupRef(o, e); |
|---|
| 290 | mapGroup (o, e); |
|---|
| 291 | mapComments(o, e); |
|---|
| 292 | mapBiopaxRef(o, e); |
|---|
| 293 | mapAttributes(o, e); |
|---|
| 294 | break; |
|---|
| 295 | case BIOPAX: |
|---|
| 296 | mapBiopax(o, e); |
|---|
| 297 | break; |
|---|
| 298 | default: |
|---|
| 299 | throw new ConverterException("Invalid ObjectType'" + tag + "'"); |
|---|
| 300 | } |
|---|
| 301 | return o; |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | protected void mapShapeType(PathwayElement o, Element e) throws ConverterException |
|---|
| 305 | { |
|---|
| 306 | o.setShapeType (ShapeType.fromGpmlName(getAttribute("Shape", "Type", e))); |
|---|
| 307 | String style = getAttribute ("Shape", "Style", e); |
|---|
| 308 | o.setLineStyle ((style.equals("Solid")) ? LineStyle.SOLID : LineStyle.DASHED); |
|---|
| 309 | Element graphics = e.getChild("Graphics", e.getNamespace()); |
|---|
| 310 | |
|---|
| 311 | String rotation = getAttribute("Shape.Graphics", "Rotation", graphics); |
|---|
| 312 | double result; |
|---|
| 313 | if (rotation.equals("Top")) |
|---|
| 314 | { |
|---|
| 315 | result = 0.0; |
|---|
| 316 | } |
|---|
| 317 | else if (rotation.equals("Right")) |
|---|
| 318 | { |
|---|
| 319 | result = 0.5 * Math.PI; |
|---|
| 320 | } |
|---|
| 321 | else if (rotation.equals("Bottom")) |
|---|
| 322 | { |
|---|
| 323 | result = Math.PI; |
|---|
| 324 | } |
|---|
| 325 | else if (rotation.equals("Left")) |
|---|
| 326 | { |
|---|
| 327 | result = 1.5 * Math.PI; |
|---|
| 328 | } |
|---|
| 329 | else |
|---|
| 330 | { |
|---|
| 331 | result = Double.parseDouble(rotation); |
|---|
| 332 | } |
|---|
| 333 | o.setRotation (result); |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | protected void mapLabelData(PathwayElement o, Element e) throws ConverterException |
|---|
| 337 | { |
|---|
| 338 | o.setTextLabel (getAttribute("Label", "TextLabel", e)); |
|---|
| 339 | Element graphics = e.getChild("Graphics", e.getNamespace()); |
|---|
| 340 | |
|---|
| 341 | String fontSizeString = getAttribute("Label.Graphics", "FontSize", graphics); |
|---|
| 342 | o.setMFontSize (Integer.parseInt(fontSizeString) / CONVERSION); |
|---|
| 343 | |
|---|
| 344 | String fontWeight = getAttribute("Label.Graphics", "FontWeight", graphics); |
|---|
| 345 | String fontStyle = getAttribute("Label.Graphics", "FontStyle", graphics); |
|---|
| 346 | String fontDecoration = getAttribute("Label.Graphics", "FontDecoration", graphics); |
|---|
| 347 | String fontStrikethru = getAttribute("Label.Graphics", "FontStrikethru", graphics); |
|---|
| 348 | |
|---|
| 349 | o.setBold (fontWeight != null && fontWeight.equals("Bold")); |
|---|
| 350 | o.setItalic (fontStyle != null && fontStyle.equals("Italic")); |
|---|
| 351 | o.setUnderline (fontDecoration != null && fontDecoration.equals("Underline")); |
|---|
| 352 | o.setStrikethru (fontStrikethru != null && fontStrikethru.equals("Strikethru")); |
|---|
| 353 | |
|---|
| 354 | String outline = getAttribute("Label", "Outline", e); |
|---|
| 355 | if ("None".equals(outline)) o.setShapeType(ShapeType.NONE); |
|---|
| 356 | else if ("Rectangle".equals(outline)) o.setShapeType(ShapeType.RECTANGLE); |
|---|
| 357 | else if ("RoundedRectangle".equals(outline)) o.setShapeType(ShapeType.ROUNDED_RECTANGLE); |
|---|
| 358 | |
|---|
| 359 | o.setFontName (getAttribute("Label.Graphics", "FontName", graphics)); |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | protected void mapShapeData(PathwayElement o, Element e, String base) throws ConverterException |
|---|
| 363 | { |
|---|
| 364 | Element graphics = e.getChild("Graphics", e.getNamespace()); |
|---|
| 365 | o.setMCenterX (Double.parseDouble(getAttribute(base + ".Graphics", "CenterX", graphics)) / CONVERSION); |
|---|
| 366 | o.setMCenterY (Double.parseDouble(getAttribute(base + ".Graphics", "CenterY", graphics)) / CONVERSION); |
|---|
| 367 | o.setMWidth (Double.parseDouble(getAttribute(base + ".Graphics", "Width", graphics)) / CONVERSION); |
|---|
| 368 | o.setMHeight (Double.parseDouble(getAttribute(base + ".Graphics", "Height", graphics)) / CONVERSION); |
|---|
| 369 | String zorder = graphics.getAttributeValue("ZOrder"); |
|---|
| 370 | if (zorder != null) |
|---|
| 371 | o.setZOrder(Integer.parseInt(zorder)); |
|---|
| 372 | } |
|---|
| 373 | |
|---|
| 374 | protected void mapDataNode(PathwayElement o, Element e) throws ConverterException |
|---|
| 375 | { |
|---|
| 376 | o.setTextLabel (getAttribute("DataNode", "TextLabel", e)); |
|---|
| 377 | mapDeprecatedAttribute(o, e, "org.pathvisio.model.BackpageHead", "DataNode", "BackpageHead"); |
|---|
| 378 | o.setDataNodeType (getAttribute("DataNode", "Type", e)); |
|---|
| 379 | Element xref = e.getChild ("Xref", e.getNamespace()); |
|---|
| 380 | o.setGeneID (getAttribute("DataNode.Xref", "ID", xref)); |
|---|
| 381 | o.setDataSource (DataSource.getByFullName (getAttribute("DataNode.Xref", "Database", xref))); |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | protected void mapStateData(PathwayElement o, Element e) throws ConverterException |
|---|
| 385 | { |
|---|
| 386 | String ref = getAttribute("State", "GraphRef", e); |
|---|
| 387 | if (ref != null) { |
|---|
| 388 | o.setGraphRef(ref); |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | Element graphics = e.getChild("Graphics", e.getNamespace()); |
|---|
| 392 | |
|---|
| 393 | o.setRelX(Double.parseDouble(getAttribute("State.Graphics", "relX", graphics))); |
|---|
| 394 | o.setRelY(Double.parseDouble(getAttribute("State.Graphics", "relY", graphics))); |
|---|
| 395 | o.setMWidth (Double.parseDouble(getAttribute("State.Graphics", "Width", graphics)) / CONVERSION); |
|---|
| 396 | o.setMHeight (Double.parseDouble(getAttribute("State.Graphics", "Height", graphics)) / CONVERSION); |
|---|
| 397 | |
|---|
| 398 | |
|---|
| 399 | |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | |
|---|
| 403 | } |
|---|
| 404 | |
|---|
| 405 | protected void mapLineData(PathwayElement o, Element e) throws ConverterException |
|---|
| 406 | { |
|---|
| 407 | String style = getAttribute("Line", "Style", e); |
|---|
| 408 | o.setLineStyle ((style.equals("Solid")) ? LineStyle.SOLID : LineStyle.DASHED); |
|---|
| 409 | |
|---|
| 410 | Element graphics = e.getChild("Graphics", e.getNamespace()); |
|---|
| 411 | |
|---|
| 412 | List<MPoint> mPoints = new ArrayList<MPoint>(); |
|---|
| 413 | |
|---|
| 414 | String startType = null; |
|---|
| 415 | String endType = null; |
|---|
| 416 | |
|---|
| 417 | List<Element> pointElements = graphics.getChildren("Point", e.getNamespace()); |
|---|
| 418 | for(int i = 0; i < pointElements.size(); i++) { |
|---|
| 419 | Element pe = pointElements.get(i); |
|---|
| 420 | MPoint mp = o.new MPoint( |
|---|
| 421 | Double.parseDouble(getAttribute("Line.Graphics.Point", "x", pe)) / CONVERSION, |
|---|
| 422 | Double.parseDouble(getAttribute("Line.Graphics.Point", "y", pe)) / CONVERSION |
|---|
| 423 | ); |
|---|
| 424 | mPoints.add(mp); |
|---|
| 425 | String ref = getAttribute("Line.Graphics.Point", "GraphRef", pe); |
|---|
| 426 | if (ref != null) { |
|---|
| 427 | mp.setGraphRef(ref); |
|---|
| 428 | String srx = pe.getAttributeValue("relX"); |
|---|
| 429 | String sry = pe.getAttributeValue("relY"); |
|---|
| 430 | if(srx != null && sry != null) { |
|---|
| 431 | mp.setRelativePosition(Double.parseDouble(srx), Double.parseDouble(sry)); |
|---|
| 432 | } |
|---|
| 433 | } |
|---|
| 434 | |
|---|
| 435 | if(i == 0) { |
|---|
| 436 | startType = getAttribute("Line.Graphics.Point", "ArrowHead", pe); |
|---|
| 437 | endType = getAttribute("Line.Graphics.Point", "Head", pe); |
|---|
| 438 | } else if(i == pointElements.size() - 1) { |
|---|
| 439 | |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | |
|---|
| 443 | |
|---|
| 444 | if (pe.getAttributeValue("ArrowHead") != null) |
|---|
| 445 | { |
|---|
| 446 | endType = getAttribute("Line.Graphics.Point", "ArrowHead", pe); |
|---|
| 447 | } |
|---|
| 448 | } |
|---|
| 449 | } |
|---|
| 450 | |
|---|
| 451 | o.setMPoints(mPoints); |
|---|
| 452 | o.setStartLineType (LineType.fromName(startType)); |
|---|
| 453 | o.setEndLineType (LineType.fromName(endType)); |
|---|
| 454 | |
|---|
| 455 | String connType = getAttribute("Line.Graphics", "ConnectorType", graphics); |
|---|
| 456 | o.setConnectorType(ConnectorType.fromName(connType)); |
|---|
| 457 | |
|---|
| 458 | String zorder = graphics.getAttributeValue("ZOrder"); |
|---|
| 459 | if (zorder != null) |
|---|
| 460 | o.setZOrder(Integer.parseInt(zorder)); |
|---|
| 461 | |
|---|
| 462 | |
|---|
| 463 | List<Element> anchors = graphics.getChildren("Anchor", e.getNamespace()); |
|---|
| 464 | for(Element ae : anchors) { |
|---|
| 465 | double position = Double.parseDouble(getAttribute("Line.Graphics.Anchor", "position", ae)); |
|---|
| 466 | MAnchor anchor = o.addMAnchor(position); |
|---|
| 467 | mapGraphId(anchor, ae); |
|---|
| 468 | String shape = getAttribute("Line.Graphics.Anchor", "Shape", ae); |
|---|
| 469 | if(shape != null) { |
|---|
| 470 | anchor.setShape(AnchorType.fromName(shape)); |
|---|
| 471 | } |
|---|
| 472 | } |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| 475 | protected void mapSimpleCenter(PathwayElement o, Element e) |
|---|
| 476 | { |
|---|
| 477 | o.setMCenterX (Double.parseDouble(e.getAttributeValue("CenterX")) / CONVERSION); |
|---|
| 478 | o.setMCenterY (Double.parseDouble(e.getAttributeValue("CenterY")) / CONVERSION); |
|---|
| 479 | } |
|---|
| 480 | |
|---|
| 481 | } |
|---|