// XAAL toolkit // Copyright (C) 2009 Ville Karavirta // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . package xaal.objects; import java.util.HashMap; import xaal.objects.graphical.Style; import xaal.objects.metadata.Metadata; import xaal.objects.structures.Structure; import xaal.util.XaalErrorLog; /** * Represents the top-level element of a XAAL document. */ public class Xaal { private Metadata metadata; private Initial initial; private Defs defs; private Animation animation; private String version; private HashMap structures; private XaalErrorLog errorLog; private HashMap objects; /** * */ public Xaal() { super(); } /** * @return Returns the animation. */ public Animation getAnimation() { if (animation == null) animation = new Animation(this); return animation; } /** * @param animation The animation to set. */ public void setAnimation(Animation animation) { this.animation = animation; } /** * @return Returns the defs. */ public Defs getDefs() { if (defs == null) defs = new Defs(); return defs; } /** * @param defs The defs to set. */ public void setDefs(Defs defs) { this.defs = defs; } /** * @return Returns the initial. */ public Initial getInitial() { if (initial == null) { initial = new Initial(); } return initial; } /** * @param initial The initial to set. */ public void setInitial(Initial initial) { this.initial = initial; } /** * @return Returns the metadata. */ public Metadata getMetadata() { if (metadata == null) { metadata = new Metadata(); } return metadata; } /** * @param metadata The metadata to set. */ public void setMetadata(Metadata metadata) { this.metadata = metadata; } /** * @return Returns the version. */ public String getVersion() { return version; } /** * @param version The version to set. */ public void setVersion(String version) { this.version = version; } public void addStructure(String id, Structure str) { if (structures == null) structures = new HashMap(); structures.put(id, str); addObject(id, str); } public Structure getStructure(String id) { if (structures != null) return (Structure) structures.get(id); else return null; } public void addObject(String id, Object o) { if (objects == null) objects = new HashMap(); objects.put(id, o); } public Object getObject(String id) { if (objects != null) return objects.get(id); else return null; } /** * @return */ public Object getStructures() { return structures; } public void setErrorLog(XaalErrorLog errorLog) { this.errorLog = errorLog; } /** * Returns the XaalErrorLog attached to this object. By default, * this is a log that outputs errors to System.err on level * XaalErrorLog.NONE. * @return The XaalErrorLog attached to this object. */ public XaalErrorLog getErrorLog() { if (errorLog == null) { errorLog = new XaalErrorLog(System.err); errorLog.setLevel(XaalErrorLog.NONE); } return errorLog; } public void addStyle(Style s) { getDefs().addStyle(s); } public Style getStyle(String id) { return getDefs().getStyle(id); } public XaalObject getXaalObject(String value) { if (objects.containsKey(value)) { return (XaalObject) objects.get(value); } else if (structures.containsKey(value)) { return (XaalObject) structures.get(value); } // todo: coordinates etc for getXaalObject return null; } }