// 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 xaal.objects.StyledObject; import xaal.objects.Xaal; import xaal.objects.animation.GraphicalOperation; import xaal.objects.graphical.GraphicalPrimitive; import xaal.objects.graphical.Style; import xaal.objects.structures.Key; import xaal.objects.structures.Node; import xaal.objects.structures.Structure; public class ChangeStyleOperation extends GraphicalOperation implements StyledObject, Cloneable { private Style newStyle; public ChangeStyleOperation(Xaal xaalDoc) { super(xaalDoc); } public Object clone() throws CloneNotSupportedException { // WARNING: neither Keypoints nor GraphicalPrimitive is cloned ChangeStyleOperation copy = (ChangeStyleOperation) super.clone(); if (newStyle != null) copy.newStyle = (Style) newStyle.clone(); return copy; } /** * @return Returns the newStyle. */ public Style getStyle() { return newStyle; } /** * @param newStyle The newStyle to set. */ public void setStyle(Style newStyle) { this.newStyle = newStyle; } public void apply(HashMap state) { Iterator i = getGraphicals(); while (i.hasNext()) { GraphicalPrimitive gp = i.next(); Style newStyle; try { newStyle = (Style) getStyle().clone(); newStyle.setUses(gp.getStyle()); gp.setStyle(newStyle); } catch (CloneNotSupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); gp.setStyle(getStyle()); } if (gp.getId() != null && state.containsKey(gp.getId())) { state.put(gp.getId(), gp); } } Iterator strs = getStructures(); while (strs.hasNext()) { Structure str = strs.next(); str.setStyle(getStyle()); if (str instanceof Node) { ((Node) str).getParent().setGraphical(new LinkedList()); str.setGraphical(new LinkedList()); } else if (str instanceof Key){ str.setGraphical(new LinkedList()); ((Key) str).getParent().setGraphical(new LinkedList()); ((Key) str).getParent().getParent().setGraphical(new LinkedList()); } else { str.setGraphical(new LinkedList()); } if (str.getId() != null) { state.put(str.getId(), str); } } } }