// 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.animation.graphical; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import xaal.objects.AddStructure; import xaal.objects.Xaal; import xaal.objects.animation.StructureOperation; import xaal.objects.graphical.GraphicalPrimitive; import xaal.objects.graphical.Text; import xaal.objects.structures.DataStructure; import xaal.objects.structures.Marker; import xaal.objects.structures.Node; import xaal.objects.structures.Structure; public class ChangePropertyOperation extends StructureOperation implements AddStructure { private List structures; private String propertyType; private String propertyValue; public ChangePropertyOperation(Xaal xaalDoc) { super(xaalDoc); structures = new LinkedList(); } public String getPropertyType() { return propertyType; } public void setPropertyType(String propertyType) { this.propertyType = propertyType; } public String getPropertyValue() { return propertyValue; } public void setPropertyValue(String propertyValue) { this.propertyValue = propertyValue; } /* * (non-Javadoc) * * @see xaal.parser.AddStructure#addStructure(xaal.parser.structures.DataStructure) */ public void addStructure(Structure s) { structures.add(s); } /** * @return */ public Iterator getStructures() { return structures.iterator(); } public void addStructure(DataStructure ds) { structures.add(ds); } public void apply(HashMap state) { Iterator strs = getStructures(); while (strs.hasNext()) { Structure str = strs.next(); if (str instanceof Marker && getPropertyType().equals("target")) { ((Marker) str).setTarget(getXaal().getStructure(getPropertyValue())); } // TODO: handle other properties if (str instanceof Node) { ((Node) str).getParent().setGraphical(new LinkedList()); } else { str.setGraphical(new LinkedList()); } if (str.getId() != null) state.put(str.getId(), str); } Iterator iter = getGraphicals(); while (iter.hasNext()) { GraphicalPrimitive gp = iter.next(); if (gp instanceof Text && getPropertyType().equals("contents")) { ((Text)gp).setContents(getPropertyValue()); } } } }