// 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.parser.modules; import org.xml.sax.Attributes; import xaal.objects.Xaal; import xaal.objects.animation.AddAnimationOperation; import xaal.objects.animation.AnimationOperation; import xaal.objects.animation.CreateOperation; import xaal.objects.animation.DeleteOperation; import xaal.objects.animation.InsertOperation; import xaal.objects.animation.SwapOperation; import xaal.parser.ParserModule; /** * @author vkaravir * */ public class XaalDSAnimParserModule extends ParserModule { public XaalDSAnimParserModule() { super(); } public void startElementCreate(String namespaceURI, String localName, String qName, Attributes atts) { Object o = peek(); if (o == null || !(o instanceof AddAnimationOperation)) o = getAAOObject(); if (o != null) { CreateOperation cre = new CreateOperation(getXaalObject()); if (atts.getIndex("target") != -1) cre.setTarget(((Xaal) getProperty("xaal-root")).getStructure(atts.getValue("target"))); handleAnimationAttributes(cre, atts); push(ParserModule.getProperty(XaalMainParserModule.ADD_GRAPHICALPRIMITIVE_OBJECT)); push(cre); ((AddAnimationOperation) o).addAnimationOperation(cre); if (atts.getIndex("source") != -1) { cre.addStructure(((Xaal) getProperty("xaal-root")).getStructure(atts.getValue("source"))); } } else { //TODO Common error handling System.out.println("Element create in illegal position"); push(ParserModule.getProperty(XaalMainParserModule.ADD_GRAPHICALPRIMITIVE_OBJECT)); push(null); } } public void endElementCreate(String namespaceURI, String localName, String qName) { pop(); ParserModule.setProperty(XaalMainParserModule.ADD_GRAPHICALPRIMITIVE_OBJECT, pop()); } public void startElementDelete(String namespaceURI, String localName, String qName, Attributes atts) { Object o = peek(); if (o == null || !(o instanceof AddAnimationOperation)) o = getAAOObject(); if (o != null) { DeleteOperation del = new DeleteOperation(getXaalObject()); if (atts.getIndex("target") != -1) del.setTarget(((Xaal) getProperty("xaal-root")).getStructure(atts.getValue("target"))); if (atts.getIndex("key") != -1) del.setKey(atts.getValue("key")); handleAnimationAttributes(del, atts); push(ParserModule.getProperty(XaalMainParserModule.ADD_GRAPHICALPRIMITIVE_OBJECT)); push(del); ((AddAnimationOperation) o).addAnimationOperation(del); } else { //TODO Common error handling System.out.println("Element delete in illegal position"); push(ParserModule.getProperty(XaalMainParserModule.ADD_GRAPHICALPRIMITIVE_OBJECT)); push(null); } } public void endElementDelete(String namespaceURI, String localName, String qName) { pop(); ParserModule.setProperty(XaalMainParserModule.ADD_GRAPHICALPRIMITIVE_OBJECT, pop()); } public void startElementElementary(String namespaceURI, String localName, String qName, Attributes atts) { // nothing to do here, actually } public void startElementInsert(String namespaceURI, String localName, String qName, Attributes atts) { Object o = peek(); if (o == null || !(o instanceof AddAnimationOperation)) o = getAAOObject(); if (o != null) { InsertOperation ins = new InsertOperation(getXaalObject()); if (atts.getIndex("target") != -1) ins.setTarget(((Xaal) getProperty("xaal-root")).getStructure(atts.getValue("target"))); handleAnimationAttributes(ins, atts); //push(ParserModule.getProperty(XaalMainParserModule.ADD_GRAPHICALPRIMITIVE_OBJECT)); push(ins); ((AddAnimationOperation) o).addAnimationOperation(ins); } else { //TODO Common error handling System.out.println("Element insert in illegal position"); //push(ParserModule.getProperty(XaalMainParserModule.ADD_GRAPHICALPRIMITIVE_OBJECT)); push(null); } } public void endElementInsert(String namespaceURI, String localName, String qName) { pop(); //ParserModule.setProperty(XaalMainParserModule.ADD_GRAPHICALPRIMITIVE_OBJECT, pop()); } public void startElementSwap(String namespaceURI, String localName, String qName, Attributes atts) { Object o = peek(); if (o == null || !(o instanceof AddAnimationOperation)) o = getAAOObject(); if (o != null) { SwapOperation so = new SwapOperation(getXaalObject()); so.setSwap(((Xaal) getProperty("xaal-root")).getStructure(atts.getValue("swap"))); so.setWith(((Xaal) getProperty("xaal-root")).getStructure(atts.getValue("with"))); handleAnimationAttributes(so, atts); ((AddAnimationOperation) o).addAnimationOperation(so); push(ParserModule.getProperty(XaalMainParserModule.ADD_GRAPHICALPRIMITIVE_OBJECT)); push(so); } else { //TODO Common error handling System.out.println("Element insert in illegal position"); push(ParserModule.getProperty(XaalMainParserModule.ADD_GRAPHICALPRIMITIVE_OBJECT)); push(null); } } public void endElementSwap(String namespaceURI, String localName, String qName) { pop(); ParserModule.setProperty(XaalMainParserModule.ADD_GRAPHICALPRIMITIVE_OBJECT, pop()); } /** * Sets the attributes of the given AnimationOperation if they exists in the * given set of attributes. * * @param oper * The AnimationOperation to add the attributes. * @param atts * The set of attributes. */ private void handleAnimationAttributes(AnimationOperation oper, Attributes atts) { if (atts.getIndex("id") != -1) oper.setId(atts.getValue("id")); } private AddAnimationOperation getAAOObject() { Object o = getProperty(XaalMainParserModule.ADD_ANIMATIONOPERATION_OBJECT); if (o == null || !(o instanceof AddAnimationOperation)) return null; else return (AddAnimationOperation) o; } }