// 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; import java.util.HashMap; import java.util.LinkedList; import xaal.objects.Xaal; import xaal.objects.structures.Key; import xaal.objects.structures.Node; import xaal.objects.structures.Structure; public class SwapOperation extends StructureOperation { private Structure swap, with; public SwapOperation(Xaal xaalDoc) { super(xaalDoc); } /** * @return Returns the swap. */ public Structure getSwap() { return swap; } /** * @param swap The swap to set. */ public void setSwap(Structure swap) { this.swap = swap; } /** * @return Returns the with. */ public Structure getWith() { return with; } /** * @param with The with to set. */ public void setWith(Structure with) { this.with = with; } public void apply(HashMap state) { Structure swp = getSwap();//(Structure) state.get(getSwap().getId()); Structure wth = getWith();//(Structure) state.get(getWith().getId()); if (swp == null || wth == null) { System.out.println("Failed to apply swap"); return; } if (swp instanceof Key && wth instanceof Key) { //String tmpId = swp.getId(); Node tmp = ((Key) swp).getParent(); ((Key) swp).getParent().setContent(wth); ((Key) wth).getParent().setContent(swp); ((Key) swp).setParent(((Key) wth).getParent()); ((Key) wth).setParent(tmp); tmp.getParent().setGraphical(new LinkedList()); } } }