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.jfc.guimodel;
|
---|
16 |
|
---|
17 | import de.ugoe.cs.autoquest.eventcore.guimodel.AbstractDefaultGUIElement;
|
---|
18 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * <p>
|
---|
22 | * Base class for all JFC GUI elements.
|
---|
23 | * </p>
|
---|
24 | *
|
---|
25 | * @version 1.0
|
---|
26 | * @author Patrick Harms
|
---|
27 | */
|
---|
28 | public class JFCGUIElement extends AbstractDefaultGUIElement {
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * <p>
|
---|
32 | * Id for object serialization.
|
---|
33 | * </p>
|
---|
34 | */
|
---|
35 | private static final long serialVersionUID = 1L;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * <p>
|
---|
39 | * Specification of the GUI Element
|
---|
40 | * </p>
|
---|
41 | */
|
---|
42 | private JFCGUIElementSpec specification;
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * <p>
|
---|
46 | * Constructor. Creates a new JFCGUIElement.
|
---|
47 | * </p>
|
---|
48 | *
|
---|
49 | * @param specification
|
---|
50 | * specification of created GUI element
|
---|
51 | * @param parent
|
---|
52 | * parent of the created GUI element; null means that the element is a top-level
|
---|
53 | * window
|
---|
54 | */
|
---|
55 | public JFCGUIElement(JFCGUIElementSpec specification, JFCGUIElement parent) {
|
---|
56 | super(specification, parent);
|
---|
57 | this.specification = specification;
|
---|
58 | }
|
---|
59 |
|
---|
60 | /*
|
---|
61 | * (non-Javadoc)
|
---|
62 | *
|
---|
63 | * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getPlatform()
|
---|
64 | */
|
---|
65 | @Override
|
---|
66 | public String getPlatform() {
|
---|
67 | return "JFC";
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * <p>
|
---|
72 | * Returns the type of the GUI element, i.e., the name of its Java class.
|
---|
73 | * </p>
|
---|
74 | *
|
---|
75 | * @return the Java class name
|
---|
76 | */
|
---|
77 | public String getJavaType() {
|
---|
78 | return specification.getType();
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * <p>
|
---|
83 | * Returns the name of the GUI element.
|
---|
84 | * </p>
|
---|
85 | *
|
---|
86 | * @return the name
|
---|
87 | */
|
---|
88 | String getName() {
|
---|
89 | return specification.getName();
|
---|
90 | }
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * <p>
|
---|
94 | * Returns the icon of the GUI element.
|
---|
95 | * </p>
|
---|
96 | *
|
---|
97 | * @return the icon
|
---|
98 | */
|
---|
99 | String getIcon() {
|
---|
100 | return specification.getIcon();
|
---|
101 | }
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * <p>
|
---|
105 | * Returns the index of the GUI element.
|
---|
106 | * </p>
|
---|
107 | *
|
---|
108 | * @return the index
|
---|
109 | */
|
---|
110 | int getIndex() {
|
---|
111 | return specification.getIndex();
|
---|
112 | }
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * <p>
|
---|
116 | * Returns the object hash of the GUI element.
|
---|
117 | * </p>
|
---|
118 | *
|
---|
119 | * @return the object hash
|
---|
120 | */
|
---|
121 | int getElementHash() {
|
---|
122 | return specification.getElementHash();
|
---|
123 | }
|
---|
124 |
|
---|
125 | /*
|
---|
126 | * (non-Javadoc)
|
---|
127 | *
|
---|
128 | * @see
|
---|
129 | * de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#updateSpecification(de.ugoe.cs.autoquest.eventcore
|
---|
130 | * .guimodel.IGUIElementSpec)
|
---|
131 | */
|
---|
132 | @Override
|
---|
133 | public void updateSpecification(IGUIElementSpec updateSpecification) {
|
---|
134 | if (updateSpecification instanceof JFCGUIElementSpec) {
|
---|
135 | specification.update(((JFCGUIElementSpec) updateSpecification));
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|
139 | /*
|
---|
140 | * (non-Javadoc)
|
---|
141 | *
|
---|
142 | * @see java.lang.Object#toString()
|
---|
143 | */
|
---|
144 | @Override
|
---|
145 | public String getStringIdentifier() {
|
---|
146 | String str = this.toString();
|
---|
147 | if (getParent() != null) {
|
---|
148 | return str + "<-" + getParent().getStringIdentifier();
|
---|
149 | }
|
---|
150 | return str;
|
---|
151 | }
|
---|
152 |
|
---|
153 | /*
|
---|
154 | * (non-Javadoc)
|
---|
155 | *
|
---|
156 | * @see java.lang.Object#toString()
|
---|
157 | */
|
---|
158 | @Override
|
---|
159 | public String toString() {
|
---|
160 | String str =
|
---|
161 | getElementDescriptor() + "(" + getName() + "," + getElementHash() + "," + getIcon() +
|
---|
162 | "," + getIndex() + ")";
|
---|
163 | return str;
|
---|
164 | }
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * <p>
|
---|
168 | * A short string describing the GUI element, e.g., Button, Canvas, or ScrollBar.
|
---|
169 | * </p>
|
---|
170 | *
|
---|
171 | * @return short element descriptor
|
---|
172 | */
|
---|
173 | protected String getElementDescriptor() {
|
---|
174 | return "Default";
|
---|
175 | }
|
---|
176 |
|
---|
177 | }
|
---|