source: trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/guimodel/GUIModel.java @ 589

Last change on this file since 589 was 589, checked in by sherbold, 12 years ago
  • started changing the similarity structure of the GUI model. The equality is now absolute (i.e., boolean instead of an int indicating the degree). Also, lists of equally observed name/hash combinations are now stored. There still seem to be mistakes, however, the structural changes to the interfaces warrant a commit.
File size: 5.1 KB
Line 
1// Module    : $RCSfile: GUIModel.java,v $
2// Version   : $Revision: 0.0 $  $Author: pharms $  $Date: 14.08.2012 $
3// Project   : quest-core-events
4// Creation  : 2012 by pharms
5// Copyright : Patrick Harms, 2012
6
7package de.ugoe.cs.quest.eventcore.guimodel;
8
9import java.util.ArrayList;
10import java.util.LinkedList;
11import java.util.List;
12
13/**
14 * <p>
15 * The goal of a GUI model is to correctly l
16 * </p>
17 *
18 * @version $Revision: $ $Date: 14.08.2012$
19 * @author 2012, last modified by $Author: pharms$
20 */
21public class GUIModel {
22   
23    /**
24     *
25     */
26    private TreeNode root = new TreeNode();
27   
28    /**
29     *
30     */
31    private List<TreeNode> allNodes = new ArrayList<TreeNode>();
32
33    /**
34     * TODO: comment
35     *
36     * @param currentGUIElementPath
37     * @return
38     * @throws GUIModelException
39     */
40    public IGUIElement integratePath(List<? extends IGUIElementSpec> guiElementPath,
41                                     IGUIElementFactory              guiElementFactory)
42        throws GUIModelException
43    {
44        List<IGUIElementSpec> remainingPath = new ArrayList<IGUIElementSpec>();
45       
46        for (IGUIElementSpec spec : guiElementPath)
47        {
48            remainingPath.add(spec);
49        }
50       
51        return integratePath(root, remainingPath, guiElementFactory);
52    }
53
54    /**
55     * TODO: comment
56     *
57     * @param root
58     * @return
59     */
60    public List<IGUIElement> getChildren(IGUIElement guiElement) {
61        for (TreeNode node : allNodes) {
62            if (node.guiElement.equals(guiElement)) {
63                List<IGUIElement> result = new ArrayList<IGUIElement>();
64               
65                if (node.children != null) {
66                    for (TreeNode child : node.children) {
67                      result.add(child.guiElement);
68                    }
69                }
70               
71                return result;
72            }
73        }
74       
75        return null;
76    }
77
78    /**
79     * TODO: comment
80     *
81     * @return
82     */
83    public List<IGUIElement> getRootElements() {
84        List<IGUIElement> roots = new ArrayList<IGUIElement>();
85        for (TreeNode rootChild : root.children) {
86            roots.add(rootChild.guiElement);
87        }
88        return roots;
89    }
90
91    /**
92     * <p>
93     * TODO: comment
94     * </p>
95     *
96     * @param root2
97     * @param guiElementPath
98     * @param guiElementFactory
99     * @return
100     * @throws GUIModelException
101     */
102    private IGUIElement integratePath(TreeNode                        parentNode,
103                                      List<? extends IGUIElementSpec> remainingPath,
104                                      IGUIElementFactory              guiElementFactory)
105        throws GUIModelException
106    {
107        IGUIElementSpec specToIntegrateElementFor = remainingPath.remove(0);
108       
109        List<TreeNode> matchingChildren = new LinkedList<TreeNode>();
110       
111        if (parentNode.children != null) {
112            for (TreeNode child : parentNode.children) {
113                if( specToIntegrateElementFor.getSimilarity(child.guiElement.getSpecification())) {
114                    matchingChildren.add(child);
115                }
116            }
117        }
118       
119        // if we get here, the corresponding path does not exist yet. So create it
120        if (matchingChildren.size() == 0) {
121            matchingChildren.add
122                (parentNode.addChild
123                     (guiElementFactory.instantiateGUIElement(specToIntegrateElementFor)));
124        }
125        else if (matchingChildren.size() > 1) {
126            throw new GUIModelException
127              ("several children of gui element " + parentNode.guiElement +
128               " match the specification " + specToIntegrateElementFor + " at the same level. " +
129               "Can not decide which is the right one.");
130        }
131       
132        if (remainingPath.size() > 0) {
133            // TODO update spec here matchingChildren.get(0).guiElement
134            matchingChildren.get(0).guiElement.updateSpecification(specToIntegrateElementFor);
135            return integratePath(matchingChildren.get(0), remainingPath, guiElementFactory);
136        }
137        else {
138            return matchingChildren.get(0).guiElement;
139        }
140    }
141
142    /**
143     * <p>
144     * TODO comment
145     * </p>
146     *
147     * @version $Revision: $ $Date: 17.08.2012$
148     * @author 2012, last modified by $Author: pharms$
149     */
150    private class TreeNode
151    {
152        /** */
153        private IGUIElement guiElement;
154       
155        /** */
156        private List<TreeNode> children;
157       
158        /** */
159        //private TreeNode parent;
160       
161        /**
162         * <p>
163         * TODO: comment
164         * </p>
165         *
166         * @param guiElement
167         * @return
168         */
169        private TreeNode addChild(IGUIElement guiElement)
170        {
171            if (children == null)
172            {
173                children = new ArrayList<TreeNode>();
174            }
175           
176            TreeNode child = new TreeNode();
177            child.guiElement = guiElement;
178            //child.parent = this;
179            children.add(child);
180           
181            allNodes.add(child);
182           
183            return child;
184        }
185    }
186}
Note: See TracBrowser for help on using the repository browser.