// 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.eventcore.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 the interfaces for GUI element trees. *
** The GUIElementTree represents the hierarchical structure of the GUI elements "as it is" currently during * a session. It may change during the session due to creation and destruction of GUI elements. The parameter * T represents the id type of the GUI elements that are handled internally. *
* * @author Fabian Glaser * @author Steffen Herbold * @version 1.0 */ public class GUIElementTree* Map of all GUI elements that are part of the tree for efficient searching. The keys of the * map are the ids of the GUI elements. *
*/ private Map* Map of all GUI element specifications that are part of the tree for efficient searching. The * keys of the map are the ids 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 * ids 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 * ids of the child GUI elements. *
*/ private Map* the internally created GUI model *
*/ private GUIModel guiModel; /** ** the GUI element factory used in the model *
*/ private IGUIElementFactory guiElementFactory = GUIElementFactory.getInstance(); /** ** Creates a new GUIElementTree. *
*/ public GUIElementTree() { guiElementSpecs = new HashMap* Creates a GUIElementTree with an already existing guiModel * @param guiModel *
*/ public GUIElementTree(GUIModel guiModel){ guiElementSpecs = new HashMap* Adds a new GUI element to the tree. *
* * @param guiElementID * id of the GUI element to be created * @param parentID * id of the parent GUI element * @param guiElementSpec * the GUI element specification * * @throws GUIModelException if the GUI element can not be added to the underlying GUI model */ public void add(T guiElementID, T parentID, IGUIElementSpec guiElementSpec) throws GUIModelException { IGUIElement guiElement = guiElements.get(guiElementID); if (guiElement == null) { IGUIElementSpec parent = guiElementSpecs.get(parentID); if (parent != null) { List* Searches the tree for a GUI element with the specified id and returns its * {@link IGUIElement} . *
* * @param id * id that is looked for * @return {@link IGUIElementSpec} of the GUI element with the given id if found, null otherwise */ public IGUIElement find(T id) { return guiElements.get(id); } /** ** Returns the id of the provided {@link IGUIElement}. The comparison is performed using the * equals method of the GUI element. *
* * @param guiElement * guiElement that is looked for * @return the id of the GUI element, null if the GUI element can not be found */ public T find(IGUIElement guiElement) { for (Map.Entry* Removes a GUI element (defined by its id) from the tree. All children of the GUI element will be * removed recursively. *
* * @param id * id of the GUI element to be removed * @return number of GUI elements that were removed */ public int remove(T id) { int removedCounter = 0; IGUIElementSpec node = guiElementSpecs.remove(id); if (node != null) { removedCounter++; List* Returns the number of nodes contained in the JFCComponentTree. *
* * @return number of nodes */ public int size() { return guiElementSpecs.size(); } }