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