1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
2 | //
|
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
4 | // you may not use this file except in compliance with the License.
|
---|
5 | // You may obtain a copy of the License at
|
---|
6 | //
|
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
8 | //
|
---|
9 | // Unless required by applicable law or agreed to in writing, software
|
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
12 | // See the License for the specific language governing permissions and
|
---|
13 | // limitations under the License.
|
---|
14 |
|
---|
15 | package de.ugoe.cs.autoquest.plugin.html.guimodel;
|
---|
16 |
|
---|
17 | import java.net.URL;
|
---|
18 |
|
---|
19 | import de.ugoe.cs.autoquest.eventcore.guimodel.AbstractDefaultGUIElement;
|
---|
20 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * <p>
|
---|
24 | * Base class for all HTML GUI elements.
|
---|
25 | * </p>
|
---|
26 | *
|
---|
27 | * @version 1.0
|
---|
28 | * @author Patrick Harms
|
---|
29 | */
|
---|
30 | public class HTMLGUIElement extends AbstractDefaultGUIElement {
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * <p>
|
---|
34 | * Id for object serialization.
|
---|
35 | * </p>
|
---|
36 | */
|
---|
37 | private static final long serialVersionUID = 1L;
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * <p>
|
---|
41 | * Specification of the GUI Element
|
---|
42 | * </p>
|
---|
43 | */
|
---|
44 | private HTMLGUIElementSpec specification;
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * <p>
|
---|
48 | * Constructor. Creates a new HTMLGUIElement.
|
---|
49 | * </p>
|
---|
50 | *
|
---|
51 | * @param specification
|
---|
52 | * specification of created GUI element
|
---|
53 | * @param parent
|
---|
54 | * parent of the created GUI element; null means that the element is a top-level
|
---|
55 | * window
|
---|
56 | */
|
---|
57 | public HTMLGUIElement(HTMLGUIElementSpec specification, HTMLGUIElement parent) {
|
---|
58 | super(specification, parent);
|
---|
59 | this.specification = specification;
|
---|
60 | }
|
---|
61 |
|
---|
62 | /*
|
---|
63 | * (non-Javadoc)
|
---|
64 | *
|
---|
65 | * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getPlatform()
|
---|
66 | */
|
---|
67 | @Override
|
---|
68 | public String getPlatform() {
|
---|
69 | return "HTML";
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * <p>
|
---|
74 | * Returns web page to which this GUI element belongs
|
---|
75 | * </p>
|
---|
76 | *
|
---|
77 | * @return the page URL
|
---|
78 | */
|
---|
79 | URL getPageURL() {
|
---|
80 | return specification.getPageURL();
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * <p>
|
---|
85 | * Returns the title of the page to which the GUI element belongs
|
---|
86 | * </p>
|
---|
87 | *
|
---|
88 | * @return the title
|
---|
89 | */
|
---|
90 | String getPageTitle() {
|
---|
91 | return specification.getPageTitle();
|
---|
92 | }
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * <p>
|
---|
96 | * Returns the type of the GUI element, i.e., the name of its tag in HTML
|
---|
97 | * </p>
|
---|
98 | *
|
---|
99 | * @return the tag in HTML
|
---|
100 | */
|
---|
101 | String getTagName() {
|
---|
102 | return specification.getType();
|
---|
103 | }
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * <p>
|
---|
107 | * Returns the id of the tag in HTML
|
---|
108 | * </p>
|
---|
109 | *
|
---|
110 | * @return the id of the HTML tag
|
---|
111 | */
|
---|
112 | String getTagId() {
|
---|
113 | return specification.getTagId();
|
---|
114 | }
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * <p>
|
---|
118 | * Returns the child index of the tag referring to all tags with the same type within the same
|
---|
119 | * parent tag
|
---|
120 | * </p>
|
---|
121 | *
|
---|
122 | * @return the index
|
---|
123 | */
|
---|
124 | int getIndex() {
|
---|
125 | return specification.getIndex();
|
---|
126 | }
|
---|
127 |
|
---|
128 | /*
|
---|
129 | * (non-Javadoc)
|
---|
130 | *
|
---|
131 | * @see
|
---|
132 | * de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#updateSpecification(de.ugoe.cs.autoquest.eventcore
|
---|
133 | * .guimodel.IGUIElementSpec)
|
---|
134 | */
|
---|
135 | @Override
|
---|
136 | public void updateSpecification(IGUIElementSpec updateSpecification) {
|
---|
137 | if (updateSpecification instanceof HTMLGUIElementSpec) {
|
---|
138 | specification.update(((HTMLGUIElementSpec) updateSpecification));
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | /*
|
---|
143 | * (non-Javadoc)
|
---|
144 | *
|
---|
145 | * @see java.lang.Object#toString()
|
---|
146 | */
|
---|
147 | @Override
|
---|
148 | public String getStringIdentifier() {
|
---|
149 | String str = this.toString();
|
---|
150 | if (getParent() != null) {
|
---|
151 | return getParent().getStringIdentifier() + "->" + str;
|
---|
152 | }
|
---|
153 | return str;
|
---|
154 | }
|
---|
155 |
|
---|
156 | /*
|
---|
157 | * (non-Javadoc)
|
---|
158 | *
|
---|
159 | * @see java.lang.Object#toString()
|
---|
160 | */
|
---|
161 | @Override
|
---|
162 | public String toString() {
|
---|
163 | String str = getElementDescriptor() + "(" + getTagName();
|
---|
164 | if (getTagId() != null) {
|
---|
165 | str += "(id=" + getTagId() + ")";
|
---|
166 | }
|
---|
167 | else {
|
---|
168 | str += "[" + getIndex() + "]";
|
---|
169 | }
|
---|
170 |
|
---|
171 | str += ")";
|
---|
172 | return str;
|
---|
173 | }
|
---|
174 |
|
---|
175 | /**
|
---|
176 | * <p>
|
---|
177 | * A short string describing the GUI element, e.g., Button, Canvas, or ScrollBar.
|
---|
178 | * </p>
|
---|
179 | *
|
---|
180 | * @return short element descriptor
|
---|
181 | */
|
---|
182 | protected String getElementDescriptor() {
|
---|
183 | return "Default";
|
---|
184 | }
|
---|
185 |
|
---|
186 | }
|
---|