// Copyright 2012 Georg-August-Universität Göttingen, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package de.ugoe.cs.autoquest.plugin.jfc.guimodel; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import de.ugoe.cs.autoquest.eventcore.guimodel.GUIElementFactory; import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModelException; import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementFactory; /** *
* This class provides an the interfaces for component trees. *
** The component tree represents the hierarchical structure of the components "as it is" currently during * a session. It may change during the session due to creation and destruction of components. *
* * @author Steffen Herbold * @author Fabian Glaser * @version 1.0 */ public class JFCComponentTree { /** ** Map of all GUI element specifications that are part of the tree for efficient searching. The * keys of the map are the hash values of the GUI elements. *
*/ private Map* Map of all children of GUI elements that are part of the tree. The keys of the map are the * hash values of the parent GUI elements. *
*/ private Map* Map of all parents of GUI elements that are part of the tree. The keys of the map are the * hash values of the child GUI elements. *
*/ private Map* the internally created GUI model *
*/ private GUIModel guiModel = new GUIModel(); /** ** the GUI element factory used in the model *
*/ private IGUIElementFactory guiElementFactory = GUIElementFactory.getInstance(); /** ** Map of all GUI elements that are part of the tree for efficient searching. The keys of the * map are the hash values of the GUI elements. *
*/ private Map* Creates a new JFCComponentTree. *
*/ public JFCComponentTree() { guiElementSpecs = new HashMap* Adds a new component to the tree. *
* * @param componentHash * hash of the window to be created * @param parentHash * hash of the parent window * @param componentSpec * the component specification */ public void add(Integer componentHash, Integer parentHash, JFCGUIElementSpec componentSpec) { JFCGUIElement guiElement = guiElements.get(componentHash); if (guiElement == null) { JFCGUIElementSpec parent = guiElementSpecs.get(parentHash); if (parent != null) { List* Searches the tree for a component with the specified hash and returns its * {@link JFCGUIElementSpec} . *
* * @param hash * hash that is looked for * @return {@link JFCGUIElementSpec} of the window with the given hash if found, null otherwise */ public JFCGUIElement find(int hash) { JFCGUIElement guiElement = guiElements.get(hash); if (guiElement == null) { List* Sets the name of a GUI element given its hash. *
* * @param hash * hash of the GUI element * @param windowName * new name of the GUI element */ public void setName(int hash, String windowName) { JFCGUIElementSpec child = guiElementSpecs.get(hash); if (child != null) { child.setName(windowName); JFCGUIElement guiElement = guiElements.remove(hash); if (guiElement == null) { // we need to update the GUI model as well find(hash); } } } /** ** Removes a window (defined by its hash) from the tree. All children of the window will be * removed recursively. *
* * @param hash * hash of the window to be removed * @return number of windows that were removed */ public int remove(long hash) { JFCGUIElementSpec node = guiElementSpecs.remove(hash); int removedCounter = 1; if (node != null) { List* Returns the number of nodes contained in the JFCComponentTree. *
* * @return number of nodes */ public int size() { return guiElementSpecs.size(); } }