[927] | 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.
|
---|
[835] | 14 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.plugin.jfc.guimodel;
|
---|
[573] | 16 |
|
---|
[922] | 17 | import de.ugoe.cs.autoquest.eventcore.guimodel.AbstractDefaultGUIElement;
|
---|
[1490] | 18 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
|
---|
[922] | 19 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec;
|
---|
[573] | 20 |
|
---|
| 21 | /**
|
---|
[835] | 22 | * <p>
|
---|
| 23 | * Base class for all JFC GUI elements.
|
---|
| 24 | * </p>
|
---|
[573] | 25 | *
|
---|
[835] | 26 | * @version 1.0
|
---|
| 27 | * @author Patrick Harms
|
---|
[573] | 28 | */
|
---|
| 29 | public class JFCGUIElement extends AbstractDefaultGUIElement {
|
---|
[835] | 30 |
|
---|
[778] | 31 | /**
|
---|
| 32 | * <p>
|
---|
| 33 | * Id for object serialization.
|
---|
| 34 | * </p>
|
---|
| 35 | */
|
---|
[573] | 36 | private static final long serialVersionUID = 1L;
|
---|
| 37 |
|
---|
[835] | 38 | /**
|
---|
| 39 | * <p>
|
---|
| 40 | * Specification of the GUI Element
|
---|
| 41 | * </p>
|
---|
| 42 | */
|
---|
[573] | 43 | private JFCGUIElementSpec specification;
|
---|
| 44 |
|
---|
| 45 | /**
|
---|
[835] | 46 | * <p>
|
---|
| 47 | * Constructor. Creates a new JFCGUIElement.
|
---|
| 48 | * </p>
|
---|
| 49 | *
|
---|
| 50 | * @param specification
|
---|
| 51 | * specification of created GUI element
|
---|
| 52 | * @param parent
|
---|
| 53 | * parent of the created GUI element; null means that the element is a top-level
|
---|
| 54 | * window
|
---|
[573] | 55 | */
|
---|
[605] | 56 | public JFCGUIElement(JFCGUIElementSpec specification, JFCGUIElement parent) {
|
---|
| 57 | super(specification, parent);
|
---|
[573] | 58 | this.specification = specification;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[835] | 61 | /*
|
---|
| 62 | * (non-Javadoc)
|
---|
| 63 | *
|
---|
[922] | 64 | * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getPlatform()
|
---|
[573] | 65 | */
|
---|
| 66 | @Override
|
---|
| 67 | public String getPlatform() {
|
---|
| 68 | return "JFC";
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | /**
|
---|
[835] | 72 | * <p>
|
---|
| 73 | * Returns the type of the GUI element, i.e., the name of its Java class.
|
---|
| 74 | * </p>
|
---|
[573] | 75 | *
|
---|
[835] | 76 | * @return the Java class name
|
---|
[573] | 77 | */
|
---|
| 78 | public String getJavaType() {
|
---|
| 79 | return specification.getType();
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | /**
|
---|
[835] | 83 | * <p>
|
---|
| 84 | * Returns the name of the GUI element.
|
---|
| 85 | * </p>
|
---|
| 86 | *
|
---|
| 87 | * @return the name
|
---|
[573] | 88 | */
|
---|
[1678] | 89 | public String getName() {
|
---|
[573] | 90 | return specification.getName();
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | /**
|
---|
[835] | 94 | * <p>
|
---|
| 95 | * Returns the icon of the GUI element.
|
---|
| 96 | * </p>
|
---|
| 97 | *
|
---|
[573] | 98 | * @return the icon
|
---|
| 99 | */
|
---|
| 100 | String getIcon() {
|
---|
| 101 | return specification.getIcon();
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | /**
|
---|
[835] | 105 | * <p>
|
---|
| 106 | * Returns the index of the GUI element.
|
---|
| 107 | * </p>
|
---|
| 108 | *
|
---|
[573] | 109 | * @return the index
|
---|
| 110 | */
|
---|
| 111 | int getIndex() {
|
---|
| 112 | return specification.getIndex();
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | /**
|
---|
[835] | 116 | * <p>
|
---|
| 117 | * Returns the object hash of the GUI element.
|
---|
| 118 | * </p>
|
---|
| 119 | *
|
---|
| 120 | * @return the object hash
|
---|
[573] | 121 | */
|
---|
[743] | 122 | int getElementHash() {
|
---|
[573] | 123 | return specification.getElementHash();
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[835] | 126 | /*
|
---|
| 127 | * (non-Javadoc)
|
---|
| 128 | *
|
---|
| 129 | * @see
|
---|
[1678] | 130 | * de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#updateSpecification(de.ugoe.cs.autoquest
|
---|
| 131 | * .eventcore .guimodel.IGUIElementSpec)
|
---|
[599] | 132 | */
|
---|
[589] | 133 | @Override
|
---|
| 134 | public void updateSpecification(IGUIElementSpec updateSpecification) {
|
---|
[714] | 135 | if (updateSpecification instanceof JFCGUIElementSpec) {
|
---|
| 136 | specification.update(((JFCGUIElementSpec) updateSpecification));
|
---|
[589] | 137 | }
|
---|
| 138 | }
|
---|
[835] | 139 |
|
---|
[606] | 140 | /*
|
---|
| 141 | * (non-Javadoc)
|
---|
| 142 | *
|
---|
| 143 | * @see java.lang.Object#toString()
|
---|
| 144 | */
|
---|
| 145 | @Override
|
---|
[681] | 146 | public String getStringIdentifier() {
|
---|
| 147 | String str = this.toString();
|
---|
[835] | 148 | if (getParent() != null) {
|
---|
[994] | 149 | return str + "<-" + getParent().getStringIdentifier();
|
---|
[606] | 150 | }
|
---|
| 151 | return str;
|
---|
| 152 | }
|
---|
[835] | 153 |
|
---|
[1674] | 154 | public String getJacaretoHierarchy() {
|
---|
[1678] | 155 | String str;
|
---|
| 156 |
|
---|
| 157 | // get the Java classname, ignore the package hierarchy if present
|
---|
| 158 | String[] parts = getSpecification().getType().split("\\.");
|
---|
| 159 | String name = parts[parts.length - 1];
|
---|
| 160 |
|
---|
| 161 | // find the correct Jacareto index
|
---|
| 162 | // jacareto indices start at 1
|
---|
| 163 | int jacIndex = getIndex() + 1;
|
---|
| 164 | // some class specific hacks
|
---|
| 165 | if (name.equals("JFrame")) {
|
---|
| 166 | jacIndex++;
|
---|
| 167 | }
|
---|
| 168 | else if (name.equals("JLayeredPane")) {
|
---|
| 169 | jacIndex--;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | str = parts[parts.length - 1] + "_(" + jacIndex + ")";
|
---|
| 173 |
|
---|
[1674] | 174 | if (getParent() != null) {
|
---|
| 175 | return ((JFCGUIElement) getParent()).getJacaretoHierarchy() + "." + str;
|
---|
| 176 | }
|
---|
| 177 | return str;
|
---|
| 178 | }
|
---|
[1678] | 179 |
|
---|
[1683] | 180 | public String getJacaretoRoot() {
|
---|
| 181 | return getJacaretoHierarchy().split("\\.")[0];
|
---|
| 182 | }
|
---|
| 183 |
|
---|
[1674] | 184 | /*
|
---|
| 185 | * (non-Javadoc)
|
---|
| 186 | *
|
---|
| 187 | * @see java.lang.Object#toString()
|
---|
| 188 | */
|
---|
[681] | 189 | @Override
|
---|
| 190 | public String toString() {
|
---|
[835] | 191 | String str =
|
---|
| 192 | getElementDescriptor() + "(" + getName() + "," + getElementHash() + "," + getIcon() +
|
---|
| 193 | "," + getIndex() + ")";
|
---|
[681] | 194 | return str;
|
---|
| 195 | }
|
---|
[835] | 196 |
|
---|
[1678] | 197 | /*
|
---|
| 198 | * (non-Javadoc)
|
---|
| 199 | *
|
---|
[1490] | 200 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getDistanceTo(IGUIElement)
|
---|
| 201 | */
|
---|
| 202 | @Override
|
---|
| 203 | public double getDistanceTo(IGUIElement otherElement) {
|
---|
| 204 | throw new UnsupportedOperationException("not implemented yet");
|
---|
| 205 | }
|
---|
| 206 |
|
---|
[835] | 207 | /**
|
---|
| 208 | * <p>
|
---|
| 209 | * A short string describing the GUI element, e.g., Button, Canvas, or ScrollBar.
|
---|
| 210 | * </p>
|
---|
| 211 | *
|
---|
| 212 | * @return short element descriptor
|
---|
| 213 | */
|
---|
[606] | 214 | protected String getElementDescriptor() {
|
---|
| 215 | return "Default";
|
---|
| 216 | }
|
---|
[589] | 217 |
|
---|
[573] | 218 | }
|
---|