// 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 xaal.objects.Xaal; import xaal.objects.animation.GraphicalOperation; import xaal.objects.graphical.GraphicalPrimitive; import xaal.objects.structures.DataStructure; import xaal.objects.structures.Marker; import xaal.objects.structures.Structure; import xaal.util.XaalConstants; public class HideOperation extends GraphicalOperation { private String type; public HideOperation(Xaal xaalDoc) { this(xaalDoc, XaalConstants.DEFAULT_PROPERTY_HIDETYPE); } public HideOperation(Xaal xaalDoc, String type) { super(xaalDoc); this.type = type; } public void setType(String value) { if (value.equals("all") || value.equals("allBut") || value.equals("selected")) type = value; // TODO common error handling } public String getType() { return type; } public void apply(HashMap state) { if (type.equals("all")) { setAll(state, true); } else if (type.equals("allBut")) { setAll(state, true); setSelected(false); } else if (type.equals("selected")) { setSelected(true); } } protected void setAll(HashMap state, boolean hidden) { Iterator i = state.values().iterator(); while (i.hasNext()) { Object curr = i.next(); if (curr instanceof GraphicalPrimitive) { if (hidden) ((GraphicalPrimitive) curr).setOpacity(0); else ((GraphicalPrimitive) curr).setOpacity(1); } else if (curr instanceof Structure) //((Structure) curr).setVisible(!hidden); setStructureVisibility((Structure) curr, !hidden); } } protected void setSelected(boolean hidden) { Iterator i = getGraphicals(); while (i.hasNext()) { GraphicalPrimitive gp = (GraphicalPrimitive) i.next(); if (hidden) { gp.setOpacity(0); gp.setHidden(true); } else { gp.setOpacity(1); gp.setHidden(false); } } i = getStructures(); while (i.hasNext()) { setStructureVisibility((Structure)i.next(), !hidden); } } private void setStructureVisibility(Structure str, boolean vis) { str.setVisible(vis); if (str instanceof DataStructure) { Iterator i = ((DataStructure)str).getNodes(); while (i.hasNext()) { setStructureVisibility(i.next(), vis); } } Iterator markers = str.getMarkers(); while (markers.hasNext()) { markers.next().setVisible(vis); } } }