source: trunk/autoquest-core-usability/src/main/java/de/ugoe/cs/autoquest/usability/UsabilitySmellDescription.java @ 2216

Last change on this file since 2216 was 2162, checked in by pharms, 7 years ago
  • changes for first VR oriented usability evaluation
File size: 8.0 KB
RevLine 
[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.
14
[922]15package de.ugoe.cs.autoquest.usability;
[442]16
17import java.io.IOException;
18import java.io.InputStream;
[2162]19import java.io.Serializable;
[475]20import java.util.ArrayList;
[1493]21import java.util.Collection;
[475]22import java.util.List;
[442]23import java.util.Map;
24
25import javax.xml.bind.JAXBContext;
26import javax.xml.bind.JAXBElement;
27import javax.xml.bind.Unmarshaller;
28
29/**
30 * TODO comment
31 *
32 * @version $Revision: $ $Date: 18.07.2012$
33 * @author 2012, last modified by $Author: pharms$
34 */
[2162]35public enum UsabilitySmellDescription implements Serializable {
[561]36   
[1493]37    INEFFICIENT_ACTIONS,
[561]38    TEXT_FIELD_INPUT_RATIO,
39    TEXT_FIELD_INPUT_REPETITIONS,
[1493]40    TEXT_FIELD_NO_LETTER_OR_DIGIT_RATIO,
41    COOCCURENCE_SUCCEED,
42    COOCCURENCE_PRECED,
43    HIGH_EVENT_COVERAGE,
44    HIGH_TARGET_DISTANCE,
45    MISSING_FEEDBACK,
[2162]46    TASK_RETRIED,
[1918]47    UNUSED_GUI_ELEMENTS,
48    DATA_ENTRY_METHOD_CHANGE,
49    GOOD_DEFAULTS,
50    CHECK_BOX_SINGLE_SELECTION,
51    COMMON_TASK_RATE,
52    MISLEADING_CLICK_CUE,
53    MOST_OFTEN_DONE_FIRST;
[442]54
[561]55    /** */
[1918]56    private static final String DEFAULT_MESSAGES_FILE = "smellDescriptions_en.xml";
[442]57
[561]58    /** */
[1918]59    private static SmellDescriptions sSmellDescriptions;
[442]60
[561]61    /** */
[1918]62    private SmellDescription smellDescription;
[442]63
[561]64    /**
[1301]65     *
[561]66     */
[1918]67    private UsabilitySmellDescription() {
[561]68        init();
69    }
70
71    /**
[1301]72     *
[561]73     */
74    @SuppressWarnings("unchecked")
75    private void init() {
76        synchronized (this.getClass()) {
[1918]77            if (sSmellDescriptions == null) {
[561]78                InputStream inputStream =
79                    ClassLoader.getSystemResourceAsStream(DEFAULT_MESSAGES_FILE);
80
81                try {
[1918]82                    String packageName = SmellDescriptions.class.getPackage().getName();
[561]83                    JAXBContext jaxbContext = JAXBContext.newInstance(packageName);
84                    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
85
[1918]86                    sSmellDescriptions =
87                        ((JAXBElement<SmellDescriptions>) unmarshaller.unmarshal(inputStream))
[561]88                            .getValue();
89                }
90                catch (Exception e) {
91                    throw new RuntimeException
[1918]92                        ("error while initializing usability smell descriptions", e);
[561]93                }
94                finally {
95                    if (inputStream != null) {
96                        try {
97                            inputStream.close();
98                        }
99                        catch (IOException e) {
100                            // ignore
101                        }
102                    }
103                }
104            }
[442]105        }
[561]106
[1918]107        for (SmellDescription description : sSmellDescriptions.getSmellDescription()) {
108            if (this.name().equals(description.getSmellId())) {
109                smellDescription = description;
[561]110                break;
[442]111            }
112        }
[561]113
[1918]114        if (smellDescription == null) {
[561]115            throw new RuntimeException
[1918]116                ("error while initializing usability smell descriptions. No " +
[561]117                 "description text available for description " + this.name());
118        }
[442]119    }
120
[561]121    /**
[1301]122     *
123     */
[561]124    public String[] getDescriptionParameters() {
125        List<String> parameters = new ArrayList<String>();
126
[1918]127        for (Object fragment : smellDescription.getTextFragmentOrParameterFragment()) {
[561]128            if (fragment instanceof ParameterFragment) {
129                parameters.add(((ParameterFragment) fragment).getParameterName());
130            }
131        }
132
133        return parameters.toArray(new String[parameters.size()]);
[475]134    }
[561]135
136    /**
[1301]137     *
138     */
[1493]139    public String toString(Map<String, Object> parameters) throws IllegalArgumentException {
[561]140        StringBuffer result = new StringBuffer();
141
[1918]142        for (Object fragment : smellDescription.getTextFragmentOrParameterFragment()) {
[561]143            if (result.length() > 0) {
144                result.append(" ");
145            }
146
147            if (fragment instanceof ParameterFragment) {
[1493]148                Object value = null;
[561]149                if (parameters != null) {
150                    value = parameters.get(((ParameterFragment) fragment).getParameterName());
151                }
152
153                if (value != null) {
[1493]154                    if (value instanceof Collection<?>) {
155                        int counter = 1;
156                        for (Object elem : ((Collection<?>) value)) {
157                            result.append('\n');
158                            result.append(counter++);
159                            result.append(".: ");
160                            result.append(elem);
161                        }
162                    }
163                    else {
164                        result.append(value.toString());
165                    }
[561]166                }
167                else {
168                    throw new IllegalArgumentException
169                        ("required parameter \"" +
170                         ((ParameterFragment) fragment).getParameterName() +
[1918]171                         "\" for usability smell description " + this.name() + " not provided");
[561]172                }
173            }
174            else {
175                result.append(getFragmentString(fragment));
176            }
[442]177        }
[561]178
179        return result.toString();
[442]180    }
181
[1493]182    /**
183     *
184     */
185    public List<Object> toFragmentList(Map<String, Object> parameters)
186        throws IllegalArgumentException
187    {
188        List<Object> result = new ArrayList<Object>();
189
[1918]190        for (Object fragment : smellDescription.getTextFragmentOrParameterFragment()) {
[1493]191            if (fragment instanceof ParameterFragment) {
192                Object value = null;
193                if (parameters != null) {
194                    value = parameters.get(((ParameterFragment) fragment).getParameterName());
195                }
196
197                if (value != null) {
198                    result.add(value);
199                }
200                else {
201                    throw new IllegalArgumentException
202                        ("required parameter \"" +
203                         ((ParameterFragment) fragment).getParameterName() +
[1918]204                         "\" for usability smell description " + this.name() + " not provided");
[1493]205                }
206            }
207            else {
208                result.add(getFragmentString(fragment));
209            }
210        }
211
212        return result;
213    }
214   
215    /**
216     *
217     */
218    public String getBriefDescription() {
[1918]219        return smellDescription.briefText;
[1493]220    }
221
[561]222    /*
223     * (non-Javadoc)
224     *
225     * @see java.lang.Enum#toString()
226     */
227    @Override
228    public String toString() {
229        StringBuffer result = new StringBuffer();
230
231        int paramCount = 1;
[1918]232        for (Object fragment : smellDescription.getTextFragmentOrParameterFragment()) {
[561]233            if (result.length() > 0) {
234                result.append(" ");
235            }
236
237            if (fragment instanceof ParameterFragment) {
238                result.append("<parameter");
239                result.append(paramCount++);
240                result.append(">");
241            }
242            else {
243                result.append(getFragmentString(fragment));
244            }
245        }
246
247        return result.toString();
[442]248    }
249
[561]250    /**
[1301]251     *
[561]252     */
253    private String getFragmentString(Object fragment) {
254        String fragmentStr = fragment.toString().trim();
255
256        fragmentStr = fragmentStr.replaceAll("\n", " ");
257
258        while (fragmentStr.indexOf("  ") > -1) {
259            fragmentStr = fragmentStr.replaceAll("  ", " ");
260        }
261
262        return fragmentStr;
[442]263    }
264
265}
Note: See TracBrowser for help on using the repository browser.