// 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.List; /** *
* convenience methods for working with GUI elements. E.g. to determine, if two GUI elements have a * common parent on their parent hierarchies. *
* * @author Patrick Harms, Ralph Krimmel */ public class GUIModelHelpers { /** ** return a common denominator for the provided list of GUI elements, i.e. a GUI element, that * is part of the parent GUI hiearchy of all GUI elements in the list. If there is no common * denominator, the method returns null. *
* * @param guiElements the GUI elements to get the common denominator of */ public static IGUIElement getCommonDenominator(IGUIElement... guiElements) { IGUIElement commonDenominator = null; if (guiElements.length > 0) { List* determines the number of hops through the GUI element hierarchy to get from one GUI element * to another. *
* * @param first the first GUI element, i.e., the start in the hierarchy * @param second the second GUI element, i.e., the end in the hierarchy * * @return the number of required hops to get from the first GUI element to the second, * INTEGER.MAX_INT if the GUI elements do not share a common parent */ public static int getDistance(IGUIElement first, IGUIElement second) { int hopcount = 0; IGUIElement commonDenominator = getCommonDenominator(first, second); while (!(first.equals(commonDenominator))) { first = first.getParent(); hopcount++; } while (!(second.equals(commonDenominator))) { second = second.getParent(); hopcount++; } return hopcount; } }