Changeset 831 for trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/guimodel/GUIElementFactory.java
- Timestamp:
- 09/20/12 09:40:26 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/guimodel/GUIElementFactory.java
r784 r831 1 1 2 package de.ugoe.cs.quest.eventcore.guimodel; 2 3 … … 14 15 15 16 /** 16 * TODO comment 17 * <p> 18 * Creates {@link IGUIElement}s from a given specification. Implemented as singleton. 19 * </p> 17 20 * 18 * @version $Revision: $ $Date: 13.05.2012$19 * @author 2012, last modified by $Author: patrick$21 * @version 1.0 22 * @author Patrick Harms 20 23 */ 21 24 public class GUIElementFactory implements IGUIElementFactory { 22 23 /** */ 25 26 /** 27 * <p> 28 * Instance of the class (singleton) 29 * </p> 30 */ 24 31 private static GUIElementFactory instance = new GUIElementFactory(); 25 32 26 33 /** 27 * TODO: comment 34 * <p> 35 * Constructor. Creates a new GUIElementFactory. Private to preserve singleton property. 36 * </p> 37 */ 38 private GUIElementFactory() {} 39 40 /** 41 * <p> 42 * Returns the instance of this class. 43 * </p> 28 44 * 29 */ 30 private GUIElementFactory() { 31 } 32 33 /** 34 * TODO: comment 35 * 36 * @return 45 * @return the instance 37 46 */ 38 47 public static synchronized GUIElementFactory getInstance() { … … 40 49 } 41 50 51 /** 52 * <p> 53 * A property mapping that defines to which Java class is created given the type of the GUI 54 * element found in the specification. 55 * </p> 56 */ 57 private Properties mappingsFromConfiguration; 58 42 59 43 /** */ 44 private Properties mappingsFromConfiguration; 45 46 /** 47 * TODO: comment 60 /* 61 * (non-Javadoc) 48 62 * 49 * @param object1 50 * @param object2 51 * @return 52 */ 53 protected boolean equals(Object object1, Object object2) { 54 if (object1 == object2) { 55 return true; 56 } 57 else if (object1 != null) { 58 return object1.equals(object2); 59 } 60 else { 61 // object 1 is null but object 2 not --> return false 62 return false; 63 } 64 } 65 66 /** 67 * TODO: comment 68 * 69 * @param parameterTypes 70 * @param parameters 71 * @return 72 * @throws GUIModelConfigurationException 63 * @see 64 * de.ugoe.cs.quest.eventcore.guimodel.IGUIElementFactory#instantiateGUIElement(de.ugoe.cs.quest 65 * .eventcore.guimodel.IGUIElementSpec, de.ugoe.cs.quest.eventcore.guimodel.IGUIElement) 73 66 */ 74 67 @Override … … 86 79 if (!IGUIElement.class.isAssignableFrom(clazz)) { 87 80 Console.traceln(Level.WARNING, "configured GUI element representing class " + 88 81 className + " is no valid GUIElement derivate."); 89 82 90 83 return null; … … 93 86 Constructor<?> constructor = null; 94 87 Class<?> parentClass = (parent == null) ? null : parent.getClass(); 95 88 96 89 // search for a constructor, that perfectly matches the types 97 90 for (Constructor<?> candidate : clazz.getConstructors()) { 98 if ((parentClass != null) && 99 (candidate.getParameterTypes().length == 2) && 91 if ((parentClass != null) && (candidate.getParameterTypes().length == 2) && 100 92 (candidate.getParameterTypes()[0].equals(specification.getClass())) && 101 93 (candidate.getParameterTypes()[1].equals(parentClass))) … … 113 105 } 114 106 } 115 107 116 108 if (constructor == null) { 117 109 // search for an assignable constructor … … 125 117 } 126 118 } 127 119 128 120 } 129 121 … … 205 197 206 198 /** 207 * TODO: comment 199 * <p> 200 * Loads the mappings for GUI elements. All files that start with "guimapping", end 201 * with ".txt", and are located in the folter "data/guimappings" (relative 202 * to the working directory) are loaded. 203 * </p> 208 204 * 209 * @return 205 * @return loaded GUI mappings 210 206 */ 211 207 private synchronized Properties getMappingsFromConfiguration() … … 217 213 else { 218 214 mappingsFromConfiguration = new Properties(); 219 215 220 216 File mappingsFolder = new File("data/guimappings"); 221 217 File[] children = mappingsFolder.listFiles(); 222 218 223 219 if (children != null) { 224 220 for (File mappingsFile : children) { … … 233 229 } 234 230 catch (FileNotFoundException e) { 235 throw new GUIModelConfigurationException 236 ("could not read mapping configuration file " + mappingsFile, e); 231 throw new GUIModelConfigurationException( 232 "could not read mapping configuration file " + 233 mappingsFile, e); 237 234 } 238 235 catch (IOException e) { 239 throw new GUIModelConfigurationException 240 ("could not read mapping configuration file " + mappingsFile, e); 236 throw new GUIModelConfigurationException( 237 "could not read mapping configuration file " + 238 mappingsFile, e); 241 239 } 242 240 finally { … … 254 252 } 255 253 else { 256 throw new GUIModelConfigurationException 257 ("no GUI mappings file provided in folder " + mappingsFolder); 254 throw new GUIModelConfigurationException( 255 "no GUI mappings file provided in folder " + 256 mappingsFolder); 258 257 } 259 258
Note: See TracChangeset
for help on using the changeset viewer.