Ignore:
Timestamp:
05/19/17 11:31:29 (7 years ago)
Author:
pharms
Message:
  • refactored GUI model so that hierarchical event target structures can also be used and created by plugins not being strictly for GUIs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-events/src/main/java/de/ugoe/cs/autoquest/eventcore/guimodel/GUIElementGroup.java

    • Property svn:mime-type set to text/plain
    r1876 r2146  
    1 //   Copyright 2012 Georg-August-Universität Göttingen, Germany 
     1//   Copyright 2015 Georg-August-Universität Göttingen, Germany 
    22// 
    33//   Licensed under the Apache License, Version 2.0 (the "License"); 
     
    1515package de.ugoe.cs.autoquest.eventcore.guimodel; 
    1616 
    17 import java.util.Collections; 
    18 import java.util.LinkedList; 
    19 import java.util.List; 
     17import de.ugoe.cs.autoquest.eventcore.HierarchicalEventTargetGroup; 
     18import de.ugoe.cs.autoquest.eventcore.IEventTargetSpec; 
    2019 
    2120/** 
    2221 * <p> 
    23  * This class is a dummy GUI element to represent groups of GUI elements. A group of GUI elements 
    24  * can be integrated in any GUI model using the method 
    25  * {@link GUIModel#groupGUIElements(java.util.List, String)}. A group has the same behavior as 
    26  * any other parent GUI element. 
     22 * implementation of event target groups for GUI elements 
    2723 * </p> 
    2824 *  
    2925 * @author Patrick Harms 
    3026 */ 
    31 public class GUIElementGroup extends AbstractDefaultGUIElement { 
     27public class GUIElementGroup extends HierarchicalEventTargetGroup implements IGUIElement { 
    3228 
    33     /** 
    34      * <p> 
    35      * default serial version UID 
    36      * </p> 
    37      */ 
     29    /**  */ 
    3830    private static final long serialVersionUID = 1L; 
    3931     
    40     /** 
    41      * the list of grouped GUIElements 
    42      */ 
    43     private List<IGUIElement> groupedGUIElements = new LinkedList<IGUIElement>(); 
     32    /** the internal fake event target specification */ 
     33    private GroupSpecification groupSpecification; 
     34     
     35    /** stores if the usage of the group was observed (just to match the implemented interface */ 
     36    private boolean usageObserved = false; 
    4437 
    4538    /** 
     
    4841     * </p> 
    4942     * 
    50      * @param groupName the name of the GUI element group 
    51      * @param parent    the optional parent GUI element of the group 
    52      * @param guiModel the GUI model to which the group will belong 
     43     * @param groupName        the name of the GUI element group 
     44     * @param parent           the optional parent GUI element of the group 
     45     * @param eventTargetModel the GUI model to which the group will belong 
    5346     */ 
    54     public GUIElementGroup(String groupName, IGUIElement parent, GUIModel guiModel) { 
    55         super(new GroupSpecification(groupName), parent); 
    56         super.setGUIModel(guiModel); 
     47    public GUIElementGroup(String      groupName, 
     48                           IGUIElement parent, 
     49                           GUIModel    guiModel) 
     50    { 
     51        super(groupName, parent, guiModel); 
     52        groupSpecification = new GroupSpecification(groupName); 
    5753    } 
    5854 
    5955    /* (non-Javadoc) 
    60      * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#updateSpecification(IGUIElementSpec) 
     56     * @see de.ugoe.cs.autoquest.eventcore.AbstractDefaultHierarchicalEventTarget#getSpecification() 
    6157     */ 
    6258    @Override 
    63     public final void updateSpecification(IGUIElementSpec furtherSpec) { 
    64         // do nothing 
    65     } 
    66  
    67     /* (non-Javadoc) 
    68      * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getPlatform() 
    69      */ 
    70     @Override 
    71     public String getPlatform() { 
    72         return "none"; 
     59    public IGUIElementSpec getSpecification() { 
     60        return groupSpecification; 
    7361    } 
    7462 
     
    7866    @Override 
    7967    public String getStringIdentifier() { 
    80         return ((GroupSpecification) super.getSpecification()).name; 
     68        return groupSpecification.name; 
    8169    } 
    8270 
    8371    /* (non-Javadoc) 
    84      * @see java.lang.Object#toString() 
     72     * @see de.ugoe.cs.autoquest.eventcore.AbstractDefaultHierarchicalEventTarget#getParent() 
    8573     */ 
    8674    @Override 
    87     public String toString() { 
    88         return getStringIdentifier(); 
     75    public IGUIElement getParent() { 
     76        return (IGUIElement) super.getParent(); 
    8977    } 
    9078 
     
    9886 
    9987    /* (non-Javadoc) 
     88     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getGUIModel() 
     89     */ 
     90    @Override 
     91    public GUIModel getGUIModel() { 
     92        return (GUIModel) super.getEventTargetModel(); 
     93    } 
     94 
     95    /* (non-Javadoc) 
     96     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#isUsed() 
     97     */ 
     98    @Override 
     99    public boolean isUsed() { 
     100        return usageObserved; 
     101    } 
     102 
     103    /* (non-Javadoc) 
     104     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#markUsed() 
     105     */ 
     106    @Override 
     107    public void markUsed() { 
     108        usageObserved = true; 
     109    } 
     110 
     111    /* (non-Javadoc) 
    100112     * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getDistanceTo(IGUIElement) 
    101113     */ 
     
    105117            return 0.0; 
    106118        } 
    107         else if (super.getParent() != null) { 
    108             return super.getParent().getDistanceTo(otherElement); 
     119        else if (getParent() != null) { 
     120            return getParent().getDistanceTo(otherElement); 
    109121        } 
    110122        else { 
    111123            return 1.0; 
    112124        } 
    113     } 
    114  
    115     /** 
    116      * <p> 
    117      * returns the list of GUI elements belonging to this group. 
    118      * </p> 
    119      *  
    120      * @return the GUI elements belonging to this group 
    121      *  
    122      */ 
    123     public List<IGUIElement> getGroupedElements() { 
    124         return Collections.unmodifiableList(groupedGUIElements); 
    125     } 
    126      
    127     /** 
    128      * <p> 
    129      * allows adding a new GUI element to the group 
    130      * </p> 
    131      * 
    132      * @param guiElement the new member of the group 
    133      */ 
    134     void addToGroup(IGUIElement guiElement) { 
    135         this.groupedGUIElements.add(guiElement); 
    136125    } 
    137126     
     
    174163 
    175164        /* (non-Javadoc) 
     165         * @see de.ugoe.cs.autoquest.eventcore.IEventTargetSpec#getSimilarity(IEventTargetSpec) 
     166         */ 
     167        @Override 
     168        public boolean getSimilarity(IEventTargetSpec other) { 
     169            return 
     170                (other instanceof GroupSpecification) && 
     171                name.equals(((GroupSpecification) other).name); 
     172        } 
     173 
     174        /* (non-Javadoc) 
    176175         * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getType() 
    177176         */ 
     
    189188        } 
    190189 
    191         /* (non-Javadoc) 
    192          * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSimilarity(IGUIElementSpec) 
    193          */ 
    194         @Override 
    195         public boolean getSimilarity(IGUIElementSpec other) { 
    196             return 
    197                 (other instanceof GroupSpecification) && 
    198                 name.equals(((GroupSpecification) other).name); 
    199         } 
    200  
    201190    } 
    202  
    203191} 
Note: See TracChangeset for help on using the changeset viewer.