1 16 package com.buchuki.ensmer; 17 18 import java.io.*; 19 import java.lang.reflect.Method ; 20 import java.util.*; 21 import javax.media.j3d.Transform3D; 22 import javax.vecmath.*; 23 import com.buchuki.annotations.*; 24 import com.buchuki.ensmer.builtin.*; 25 import com.buchuki.ensmer.object.Backend; 26 import com.buchuki.ensmer.prevayler.queries.*; 27 28 29 48 public class SpecialAreaManager { 49 50 53 public final static String ADD_OBJECT = "ensmer.addObjectArea"; 54 55 58 public final static String ADD_STATIC_OBJECT = "ensmer.addStaticObjectArea"; 59 60 63 public final static String INVENTORY = "ensmer.inventory"; 64 65 68 public final static String STORAGE = "ensmer.storage"; 69 70 77 public Long removeSpecialID(String specialID) { 78 try { 79 return (Long ) EnsmerManager.instance().getPrevayler().execute( 80 new RemoveSpecialAreaIDTransaction(specialID)); 81 } catch (Exception e) { 82 e.printStackTrace(); 83 return null; 84 } 85 } 86 87 92 public void buildAddObjectArea() { 93 AreaManager man = EnsmerManager.instance().getAreaManager(); 94 Long id = getAreaID(ADD_OBJECT); 95 Area area; 96 if (id == null) { 97 area = man.newArea(); 98 id = area.getAreaID(); 99 setSpecialID(ADD_OBJECT, id); 100 } 101 else { 102 area = man.getArea(id); 103 } 104 area.setReadOnly(false); 105 106 Set<Class <? extends Backend>> classes = EnsmerManager.instance().getBackhoe().getBackendClasses(); 107 List<Backend> existingBackends = area.getBackends(); 108 for (Backend backend : existingBackends) { 110 ClassIcon icon = (ClassIcon) backend; 111 if (!classes.contains(icon.getRepresentedClass())) { 112 area.destroyObject(backend.getId()); 113 } 114 } 115 for (Class <? extends Backend> backendClass : classes) { 117 if (!containsClass(existingBackends, backendClass)) { 118 Object obj = null; 119 try { 120 Method getRep = backendClass.getMethod("getRepresentation"); 121 obj = getRep.invoke(null); 122 } catch (Exception e) {} if (obj != null) { 124 ClassIcon icon = new ClassIcon(); 125 icon.setRepresentedClass(backendClass); 126 Matrix4f mat = SceneGraphUtils.randomPositionInFrontOfUser(area); 127 area.newObject(icon, mat); 128 } 129 } 130 } 131 area.setReadOnly(true); 132 } 133 134 135 140 public void buildAddStaticArea() { 141 EnsmerManager ens = EnsmerManager.instance(); 142 AreaManager man = ens.getAreaManager(); 143 Long id = getAreaID(ADD_STATIC_OBJECT); 144 Area area; 145 if (id == null) { 146 area = man.newArea(); 147 id = area.getAreaID(); 148 setSpecialID(ADD_STATIC_OBJECT, id); 149 } 150 else { 151 area = man.getArea(id); 152 } 153 area.setReadOnly(false); 154 File dir = EnsmerManager.instance().getConfigManager().getSettingsDirectory("static"); 155 List<String > files = Arrays.asList(dir.list( 156 new FilenameFilter() { 157 public boolean accept(File dir, String name) { 158 return name.endsWith(".wrl"); 159 } 160 })); 161 162 List<Backend> existingBackends = area.getBackends(); 163 for (Backend backend : existingBackends) { 165 StaticIcon icon = (StaticIcon) backend; 166 if (!files.contains(icon.getFilename())) { 167 area.destroyObject(backend.getId()); 168 } 169 } 170 for (String filename : files) { 172 if (!containsStatic(existingBackends, filename)) { 173 StaticIcon obj = new StaticIcon(); 174 obj.setFilename(filename); 175 Matrix4f mat = SceneGraphUtils.randomPositionInFrontOfUser(area); 176 area.newObject(obj, mat); 177 } 178 } 179 180 213 area.setReadOnly(true); 214 } 215 216 224 public Long getAreaID(String specialID) { 225 try { 226 return (Long ) EnsmerManager.instance().getPrevayler().execute( 227 new GetAreaIDForSpecial(specialID)); 228 } catch (Exception e) { 229 e.printStackTrace(); 230 return null; 231 } 232 } 233 234 241 public void setSpecialID(String specialID, Long areaID) { 242 try { 243 EnsmerManager.instance().getPrevayler().execute( 244 new SetSpecialAreaIDTransaction(specialID, areaID)); 245 } catch (Exception e) { 246 e.printStackTrace(); 247 } 248 } 249 250 259 private boolean containsClass(List<Backend> backends, Class clazz) { 260 for (Backend backend : backends) { 261 ClassIcon icon = (ClassIcon) backend; 262 if (icon.getRepresentedClass().equals(clazz)) { 263 return true; 264 } 265 } 266 return false; 267 } 268 269 277 private boolean containsStatic(List<Backend> backends, String file) { 278 for (Backend backend : backends) { 279 StaticIcon icon = (StaticIcon) backend; 280 if (icon.getFilename().equals(file)) { 281 return true; 282 } 283 } 284 return false; 285 } 286 287 290 private long staticLastModified; 291 292 296 private Set<Class <? extends Backend>> classSet; 297 } 298 299 | Popular Tags |