Ignore:
Timestamp:
09/20/12 10:36:09 (12 years ago)
Author:
sherbold
Message:
  • code documentation and clean-up
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/guimodel/JFCGUIElementSpec.java

    r832 r835  
     1 
    12package de.ugoe.cs.quest.plugin.jfc.guimodel; 
    23 
     
    67import org.apache.commons.collections15.CollectionUtils; 
    78 
     9import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 
    810import de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec; 
    911 
    1012/** 
    1113 * <p> 
    12  * TODO comment 
     14 * Implements the specification of {@link IGUIElement} for {@link JFCGUIElement}s. 
    1315 * </p> 
    1416 *  
    15  * @version $Revision: $ $Date: 17.08.2012$ 
    16  * @author 2012, last modified by $Author: pharms$ 
     17 * @version 1.0 
     18 * @author Patrick Harms 
    1719 */ 
    1820public class JFCGUIElementSpec implements IGUIElementSpec { 
    1921 
    20     /**  */ 
     22    /** 
     23     * <p> 
     24     * Id for object serialization. 
     25     * </p> 
     26     */ 
    2127    private static final long serialVersionUID = 1L; 
    2228 
    2329    /** 
    2430     * <p> 
    25      * current name of the GUI element 
     31     * Current name of the GUI element 
    2632     * </p> 
    2733     */ 
     
    3036    /** 
    3137     * <p> 
    32      * previous names of the GUI element as it may have changed over time. 
     38     * Previous names of the GUI element as it may have changed over time. 
    3339     * </p> 
    3440     */ 
    3541    private List<String> formerNames = new ArrayList<String>(); 
    3642 
    37     /** */ 
     43    /** 
     44     * <p> 
     45     * Type of the GUI element, i.e., its Java class. 
     46     * </p> 
     47     */ 
    3848    private String type = null; 
    39      
    40     /** */ 
     49 
     50    /** 
     51     * <p> 
     52     * Icon associated with the GUI element. 
     53     * </p> 
     54     */ 
    4155    private String icon = null; 
    42      
    43     /** */ 
     56 
     57    /** 
     58     * <p> 
     59     * Index of the GUI element in its parent element. 
     60     * </p> 
     61     */ 
    4462    private int index = -1; 
    45      
    46     /** 
    47      * <p> 
    48      * hash code of the window element. Used as unique identifier during its existence. 
     63 
     64    /** 
     65     * <p> 
     66     * Hash code of the window element. Used as unique identifier during its existence. 
    4967     * </p> 
    5068     */ 
     
    5371    /** 
    5472     * <p> 
    55      * previous handles of the window as the window may have been destroyed and recreated 
     73     * Previous hashes of the window as the window may have been destroyed and recreated. 
    5674     * </p> 
    5775     */ 
    5876    private List<Integer> formerElementHashes = new ArrayList<Integer>(); 
    5977 
    60     /* (non-Javadoc) 
    61      * @see de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec#getSecificationSimilarity(IGUIElementSpec) 
     78    /* 
     79     * (non-Javadoc) 
     80     *  
     81     * @see 
     82     * de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec#getSecificationSimilarity(IGUIElementSpec 
     83     * ) 
    6284     */ 
    6385    @Override 
    6486    public boolean getSimilarity(IGUIElementSpec other) { 
    65         if (this == other) 
    66         { 
    67             return true; 
    68         } 
    69          
    70         if (!(other instanceof JFCGUIElementSpec)) 
    71         { 
     87        if (this == other) { 
     88            return true; 
     89        } 
     90 
     91        if (!(other instanceof JFCGUIElementSpec)) { 
    7292            return false; 
    7393        } 
    74          
     94 
    7595        JFCGUIElementSpec otherSpec = (JFCGUIElementSpec) other; 
    76          
     96 
    7797        if ((type != otherSpec.type) && ((type != null) && (!type.equals(otherSpec.type)))) { 
    7898            return false; 
     
    89109        // a new element is added or another one is removed. If the element hash or the name stay 
    90110        // the same, then similarity is given. Therefore these are the first two comparisons 
    91          
     111 
    92112        if (elementHash == otherSpec.elementHash) { 
    93113            return true; 
    94114        } 
    95          
     115 
    96116        if ((name != null) && (name.equals(otherSpec.name))) { 
    97117            return true; 
    98118        } 
    99          
    100         if ((((name == null) && (otherSpec.name == null)) || 
    101              (("".equals(name)) && ("".equals(otherSpec.name)))) && 
    102             (formerNames.size() == 0) && (otherSpec.formerNames.size() == 0)) 
     119 
     120        if ((((name == null) && (otherSpec.name == null)) || (("".equals(name)) && ("" 
     121            .equals(otherSpec.name)))) && 
     122            (formerNames.size() == 0) && 
     123            (otherSpec.formerNames.size() == 0)) 
    103124        { 
    104125            return true; 
    105126        } 
    106          
     127 
    107128        // if the id and the name did not stay the same, then the name should be checked first. 
    108129        // One of all known names of one of the specs must be equal to one of the known names of the 
     
    117138            return index == otherSpec.index; 
    118139        } 
    119          
     140 
    120141        if (CollectionUtils.containsAny(formerNames, otherSpec.formerNames)) { 
    121142            return index == otherSpec.index; 
    122143        } 
    123          
     144 
    124145        // ok. Even the names do not match. This is usually a clear indication, that the elements 
    125146        // are distinct. However, we check, if the former ids matched. This is very unlikely 
     
    135156            return index == otherSpec.index; 
    136157        } 
    137          
     158 
    138159        if (CollectionUtils.containsAny(formerElementHashes, otherSpec.formerElementHashes)) { 
    139160            return index == otherSpec.index; 
    140161        } 
    141          
     162 
    142163        // now we can be really sure, that the GUI elements differ 
    143          
     164 
    144165        return false; 
    145166    } 
    146167 
    147     /* (non-Javadoc) 
     168    /* 
     169     * (non-Javadoc) 
     170     *  
    148171     * @see de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec#equals(IGUIElementSpec) 
    149172     */ 
    150173    @Override 
    151174    public boolean equals(Object other) { 
    152         if (this == other) 
    153         { 
    154             return true; 
    155         } 
    156          
    157         if (!(other instanceof JFCGUIElementSpec)) 
    158         { 
     175        if (this == other) { 
     176            return true; 
     177        } 
     178 
     179        if (!(other instanceof JFCGUIElementSpec)) { 
    159180            return false; 
    160181        } 
    161          
     182 
    162183        JFCGUIElementSpec otherSpec = (JFCGUIElementSpec) other; 
    163          
    164         return 
    165             ((name == otherSpec.name) || ((name != null) && (name.equals(otherSpec.name)))) && 
     184 
     185        return ((name == otherSpec.name) || ((name != null) && (name.equals(otherSpec.name)))) && 
    166186            ((type == otherSpec.type) || ((type != null) && (type.equals(otherSpec.type)))) && 
    167187            ((icon == otherSpec.icon) || ((icon != null) && (icon.equals(otherSpec.icon)))) && 
     
    169189    } 
    170190 
    171     /* (non-Javadoc) 
     191    /* 
     192     * (non-Javadoc) 
     193     *  
    172194     * @see java.lang.Object#hashCode() 
    173195     */ 
     
    178200 
    179201    /** 
     202     * <p> 
     203     * Returns the name of the specified GUI element. 
     204     * </p> 
     205     *  
    180206     * @return the name 
    181207     */ 
    182208    public String getName() { 
    183209        StringBuffer names = new StringBuffer(); 
    184          
     210 
    185211        if (name != null) { 
    186212            names.append('"'); 
     
    191217            names.append("NOT_SET"); 
    192218        } 
    193          
     219 
    194220        if (formerNames.size() > 0) { 
    195              
     221 
    196222            names.append(" (aka "); 
    197              
     223 
    198224            for (int i = 0; i < formerNames.size(); i++) { 
    199225                if (i > 0) { 
     
    205231                names.append('"'); 
    206232            } 
    207              
     233 
    208234            names.append(")"); 
    209235        } 
    210          
     236 
    211237        return names.toString(); 
    212238    } 
    213239 
    214240    /** 
     241     * <p> 
     242     * Returns the title of the specified GUI element. 
     243     * </p> 
     244     *  
    215245     * @return the title 
    216246     */ 
     
    220250 
    221251    /** 
     252     * <p> 
     253     * Returns the icon associated with the specified GUI element. 
     254     * </p> 
     255     *  
    222256     * @return the icon 
    223257     */ 
     
    227261 
    228262    /** 
     263     * <p> 
     264     * Returns the index of the specified GUI element in its parent element. 
     265     * </p> 
     266     *  
    229267     * @return the index 
    230268     */ 
     
    234272 
    235273    /** 
     274     * <p> 
     275     * Returns the object hash of the specified GUI element. 
     276     * </p> 
     277     *  
    236278     * @return the elementHash 
    237279     */ 
     
    241283 
    242284    /** 
    243      * @param name the name to set 
     285     * <p> 
     286     * Sets the name of the specified GUI element. 
     287     * </p> 
     288     *  
     289     * @param name 
     290     *            the name 
    244291     */ 
    245292    public void setName(String newName) { 
    246         if ((this.name != null) && 
    247             (!this.name.equals(newName)) && 
     293        if ((this.name != null) && (!this.name.equals(newName)) && 
    248294            (!this.formerNames.contains(this.name))) 
    249295        { 
    250296            this.formerNames.add(this.name); 
    251297        } 
    252          
     298 
    253299        this.name = newName; 
    254300    } 
    255301 
    256302    /** 
    257      * @param title the title to set 
     303     * <p> 
     304     * Sets the type of the specified GUI element. 
     305     * </p> 
     306     *  
     307     * @param title 
     308     *            the title 
    258309     */ 
    259310    public void setType(String type) { 
     
    262313 
    263314    /** 
    264      * @param icon the icon to set 
     315     * <p> 
     316     * Sets the icon associated with the specified GUI element. 
     317     * </p> 
     318     *  
     319     * @param icon 
     320     *            the icon 
    265321     */ 
    266322    public void setIcon(String icon) { 
     
    269325 
    270326    /** 
    271      * @param index the index to set 
     327     * <p> 
     328     * Sets the index in its parent element of the specified GUI element. 
     329     * </p> 
     330     *  
     331     * @param index 
     332     *            the index 
    272333     */ 
    273334    public void setIndex(int index) { 
     
    276337 
    277338    /** 
    278      * @param elementHash the elementHash to set 
     339     * <p> 
     340     * Sets the object hash of the specified GUI element. 
     341     * </p> 
     342     *  
     343     * @param elementHash 
     344     *            the elementHash 
    279345     */ 
    280346    public void setElementHash(int newElementHash) { 
    281         if ((this.elementHash > -1) && 
    282             !this.formerElementHashes.contains(this.elementHash)) 
    283         { 
     347        if ((this.elementHash > -1) && !this.formerElementHashes.contains(this.elementHash)) { 
    284348            this.formerElementHashes.add(this.elementHash); 
    285349        } 
    286          
     350 
    287351        this.elementHash = newElementHash; 
    288352    } 
    289      
    290     /** 
    291      * <p> 
    292      * TODO: comment 
    293      * </p> 
    294      * 
     353 
     354    /** 
     355     * <p> 
     356     * Updates the specification with another specification. 
     357     * </p> 
     358     *  
    295359     * @param furtherSpec 
     360     *            specification used to update the current specification 
    296361     */ 
    297362    void update(JFCGUIElementSpec other) { 
     
    309374            } 
    310375 
    311             if ((name != other.name) && (name != null) && (!name.equals(other.name))) 
    312             { 
     376            if ((name != other.name) && (name != null) && (!name.equals(other.name))) { 
    313377                setName(other.name); 
    314378            } 
     
    316380    } 
    317381 
     382    /* 
     383     * (non-Javadoc) 
     384     *  
     385     * @see java.lang.Object#toString() 
     386     */ 
    318387    public String toString() { 
    319         return "[" + getName() + ";\"" + type + "\";\"" + icon + "\";" + index + ";" + 
    320                 elementHash + "]"; 
     388        return "[" + getName() + ";\"" + type + "\";\"" + icon + "\";" + index + ";" + elementHash + 
     389            "]"; 
    321390    } 
    322391 
Note: See TracChangeset for help on using the changeset viewer.