// 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.List; import org.apache.commons.collections15.CollectionUtils; import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec; /** *
* Implements the specification of {@link IGUIElement} for {@link JFCGUIElement}s. *
* * @version 1.0 * @author Patrick Harms */ public class JFCGUIElementSpec implements IGUIElementSpec { /** ** Id for object serialization. *
*/ private static final long serialVersionUID = 1L; /** ** Current name of the GUI element *
*/ private String name; /** ** Previous names of the GUI element as it may have changed over time. *
*/ private List* Type of the GUI element, i.e., its Java class. *
*/ private String type = null; /** ** Icon associated with the GUI element. *
*/ private String icon = null; /** ** Index of the GUI element in its parent element. *
*/ private int index = -1; /** ** Hash code of the GUI element. Used as unique identifier during its existence. *
*/ private int elementHash = -1; /** ** Previous hashes of the GUI element as the GUI element may have been destroyed and recreated. *
*/ private List* Type hierarchy of the class itself *
*/ private List* Returns the name of the specified GUI element. *
* * @return the name */ public String getName() { StringBuffer names = new StringBuffer(); if (name != null) { names.append('"'); names.append(name); names.append('"'); } else { names.append("NOT_SET"); } if (formerNames.size() > 0) { names.append(" (aka "); for (int i = 0; i < formerNames.size(); i++) { if (i > 0) { names.append("/"); } names.append('"'); names.append(formerNames.get(i)); names.append('"'); } names.append(")"); } return names.toString(); } /** ** Returns the title of the specified GUI element. *
* * @return the title */ public String getType() { return type; } /** ** Returns the icon associated with the specified GUI element. *
* * @return the icon */ public String getIcon() { return icon; } /** ** Returns the index of the specified GUI element in its parent element. *
* * @return the index */ public int getIndex() { return index; } /** ** Returns the object hash of the specified GUI element. *
* * @return the elementHash */ public int getElementHash() { return elementHash; } /** ** Sets the name of the specified GUI element. *
* * @param newName * the name */ public void setName(String newName) { if ((this.name != null) && (!this.name.equals(newName)) && (!this.formerNames.contains(this.name))) { this.formerNames.add(this.name); } this.name = newName; } /** ** Sets the type of the specified GUI element. *
* * @param type * the type */ public void setType(String type) { this.type = type; } /** ** Sets the icon associated with the specified GUI element. *
* * @param icon * the icon */ public void setIcon(String icon) { this.icon = icon; } /** ** Sets the index in its parent element of the specified GUI element. *
* * @param index * the index */ public void setIndex(int index) { this.index = index; } /** ** Sets the object hash of the specified GUI element. *
* * @param newElementHash * the element hash */ public void setElementHash(int newElementHash) { if ((this.elementHash > -1) && !this.formerElementHashes.contains(this.elementHash)) { this.formerElementHashes.add(this.elementHash); } this.elementHash = newElementHash; } /** ** Sets the type hierarchy of the specified GUI element. * @param typeHierarchy *
*/ public void setTypeHierarchy(List* Updates the specification with another specification. *
* * @param furtherSpec * specification used to update the current specification */ void update(JFCGUIElementSpec other) { if (other != this) { for (int formerElementHash : other.formerElementHashes) { setElementHash(formerElementHash); } if (elementHash != other.elementHash) { elementHash = other.elementHash; } for (String formerName : other.formerNames) { setName(formerName); } if ((name == null) || (!name.equals(other.name))) { setName(other.name); } } } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ public String toString() { return "[" + getName() + ";\"" + type + "\";\"" + icon + "\";" + index + ";" + elementHash + "]"; } @Override public String[] getTypeHierarchy() { if (typeHierarchy == null){ return new String[]{(getType())}; } else return typeHierarchy.toArray(new String[typeHierarchy.size()]); } }